1 | /* |
---|
2 | Copyright 2009 Virginia Polytechnic Institute and State University |
---|
3 | |
---|
4 | Licensed under the Apache License, Version 2.0 (the "License"); |
---|
5 | you may not use this file except in compliance with the License. |
---|
6 | You may obtain a copy of the License at |
---|
7 | |
---|
8 | http://www.apache.org/licenses/LICENSE-2.0 |
---|
9 | |
---|
10 | Unless required by applicable law or agreed to in writing, software |
---|
11 | distributed under the License is distributed on an "AS IS" BASIS, |
---|
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
13 | See the License for the specific language governing permissions and |
---|
14 | limitations under the License. |
---|
15 | */ |
---|
16 | |
---|
17 | /* This header exports the base declarations for all VT-CROSS radio components. |
---|
18 | * It contains two pure abstract base classes, Component and Engine; Engine derives |
---|
19 | * from Component. All functions contained within the abstract base classes are |
---|
20 | * dynamically linked and pure, and all child non-abstract classes derive using |
---|
21 | * private inheritence. Class functions of the abstract base classes are public |
---|
22 | * for two reasons: (1) To allow for public/protected inheritence in other |
---|
23 | * implementations, (2) So that symbolic debuggers can navigate the call tree |
---|
24 | * for typecasted objects of derivative classes. |
---|
25 | * |
---|
26 | * Note that any new component type declaration MUST include this header and |
---|
27 | * extend a parent component type. |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef COMPONENTS_H |
---|
31 | #define COMPONENTS_H |
---|
32 | |
---|
33 | |
---|
34 | #include <cstring> |
---|
35 | #include <stdint.h> |
---|
36 | #include <string> |
---|
37 | |
---|
38 | #include "containers.h" |
---|
39 | #include "socketcomm.h" |
---|
40 | |
---|
41 | |
---|
42 | /* Component abstract base class that all component classes should inherit from, |
---|
43 | * including cognitive and policy engines, and the service management layer. |
---|
44 | * Defines only functions required by all component types. |
---|
45 | */ |
---|
46 | class Component |
---|
47 | { |
---|
48 | public: |
---|
49 | /* Asks the component at the passed socket FD for its component type |
---|
50 | * string. Note that this implementation is global for all component |
---|
51 | * types, so is implemented here. Should a component need to override |
---|
52 | * it, that is possible via dynamic binding or overloading. |
---|
53 | */ |
---|
54 | virtual std::string GetRemoteComponentType(int32_t componentSocketFD) |
---|
55 | { |
---|
56 | SendMessage(componentSocketFD, "request_component_type"); |
---|
57 | |
---|
58 | char buffer[256]; |
---|
59 | memset(buffer, 0, 256); |
---|
60 | ReadMessage(componentSocketFD, buffer); |
---|
61 | |
---|
62 | return std::string(buffer); |
---|
63 | } |
---|
64 | |
---|
65 | /* Send an indentfying string for this object's component type in |
---|
66 | * response to a GetRemoteComponentType query. |
---|
67 | */ |
---|
68 | virtual void SendComponentType() = 0; |
---|
69 | |
---|
70 | /* Completely shutdown the radio and all operations. |
---|
71 | */ |
---|
72 | virtual void Shutdown() = 0; |
---|
73 | |
---|
74 | /* Reset the radio and reload all configuration files. |
---|
75 | * |
---|
76 | * TODO are we remembering experiences in CEs? |
---|
77 | */ |
---|
78 | virtual void Reset() = 0; |
---|
79 | |
---|
80 | /* Register or deregister a component with the primary radio shell. |
---|
81 | */ |
---|
82 | virtual void RegisterComponent() = 0; |
---|
83 | virtual void DeregisterComponent() = 0; |
---|
84 | }; |
---|
85 | |
---|
86 | |
---|
87 | /* Engine abstract base class from which all engine component types should |
---|
88 | * inherit (e.g. cognitive and policy engines). Inherits all functions from the |
---|
89 | * ABC Component publically. |
---|
90 | */ |
---|
91 | class Engine : public Component |
---|
92 | { |
---|
93 | public: |
---|
94 | /* Connect to the remote control component, which will always be either |
---|
95 | * the VTCROSS shell or SML. Based on the status of the SML_present |
---|
96 | * bool, this function will also register the component or services. |
---|
97 | * |
---|
98 | * TODO I feel like the name of this function could be changed to be a |
---|
99 | * little more descriptive? |
---|
100 | */ |
---|
101 | virtual void ConnectToRemoteComponent(const char* serverName, \ |
---|
102 | const char* serverPort, const bool SML) = 0; |
---|
103 | |
---|
104 | /* Wait for a command signal containing task instructions. |
---|
105 | */ |
---|
106 | virtual void WaitForSignal() = 0; |
---|
107 | |
---|
108 | /* Register or deregister services that this engine provides with the |
---|
109 | * service management layer. |
---|
110 | */ |
---|
111 | virtual void RegisterServices() = 0; |
---|
112 | virtual void DeregisterServices() = 0; |
---|
113 | }; |
---|
114 | |
---|
115 | #endif |
---|