[411] | 1 | /* |
---|
| 2 | Copyright 2009 Virginia Polytechnic Institute and State University |
---|
[161] | 3 | |
---|
[411] | 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 | |
---|
[465] | 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 |
---|
[161] | 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. |
---|
[465] | 25 | * |
---|
| 26 | * Note that any new component type declaration MUST include this header and |
---|
| 27 | * extend a parent component type. |
---|
[161] | 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef COMPONENTS_H |
---|
| 31 | #define COMPONENTS_H |
---|
| 32 | |
---|
| 33 | |
---|
[211] | 34 | #include <cstring> |
---|
[161] | 35 | #include <stdint.h> |
---|
[173] | 36 | #include <string> |
---|
[161] | 37 | |
---|
| 38 | #include "containers.h" |
---|
[190] | 39 | #include "socketcomm.h" |
---|
[161] | 40 | |
---|
| 41 | |
---|
[170] | 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 | */ |
---|
[161] | 46 | class Component |
---|
| 47 | { |
---|
| 48 | public: |
---|
[170] | 49 | /* Asks the component at the passed socket FD for its component type |
---|
[190] | 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. |
---|
[170] | 53 | */ |
---|
[190] | 54 | virtual std::string GetRemoteComponentType(int32_t componentSocketFD) |
---|
| 55 | { |
---|
| 56 | SendMessage(componentSocketFD, "request_component_type"); |
---|
[170] | 57 | |
---|
[190] | 58 | char buffer[256]; |
---|
| 59 | memset(buffer, 0, 256); |
---|
| 60 | ReadMessage(componentSocketFD, buffer); |
---|
[170] | 61 | |
---|
[190] | 62 | return std::string(buffer); |
---|
| 63 | } |
---|
| 64 | |
---|
[194] | 65 | /* Send an indentfying string for this object's component type in |
---|
| 66 | * response to a GetRemoteComponentType query. |
---|
| 67 | */ |
---|
| 68 | virtual void SendComponentType() = 0; |
---|
[190] | 69 | |
---|
[170] | 70 | /* Completely shutdown the radio and all operations. |
---|
| 71 | */ |
---|
[161] | 72 | virtual void Shutdown() = 0; |
---|
[170] | 73 | |
---|
| 74 | /* Reset the radio and reload all configuration files. |
---|
| 75 | * |
---|
| 76 | * TODO are we remembering experiences in CEs? |
---|
| 77 | */ |
---|
[161] | 78 | virtual void Reset() = 0; |
---|
[170] | 79 | |
---|
| 80 | /* Register or deregister a component with the primary radio shell. |
---|
| 81 | */ |
---|
[188] | 82 | virtual void RegisterComponent() = 0; |
---|
| 83 | virtual void DeregisterComponent() = 0; |
---|
[161] | 84 | }; |
---|
| 85 | |
---|
| 86 | |
---|
[170] | 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 | */ |
---|
[161] | 91 | class Engine : public Component |
---|
| 92 | { |
---|
| 93 | public: |
---|
[203] | 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; |
---|
[431] | 103 | |
---|
| 104 | /* Wait for a command signal containing task instructions. |
---|
| 105 | */ |
---|
| 106 | virtual void WaitForSignal() = 0; |
---|
[203] | 107 | |
---|
[170] | 108 | /* Register or deregister services that this engine provides with the |
---|
| 109 | * service management layer. |
---|
| 110 | */ |
---|
[188] | 111 | virtual void RegisterServices() = 0; |
---|
[278] | 112 | virtual void DeregisterServices() = 0; |
---|
[161] | 113 | }; |
---|
| 114 | |
---|
| 115 | #endif |
---|