[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 | |
---|
[518] | 17 | /*! This header exports the base declarations for all CROSS radio components. |
---|
| 18 | * |
---|
| 19 | * It contains two pure abstract base classes, Component and Engine; Engine |
---|
| 20 | * derives from Component. All functions contained within the abstract base |
---|
| 21 | * classes are dynamically linked and pure, and all child non-abstract classes |
---|
| 22 | * derive using private inheritence. Class functions of the abstract base |
---|
| 23 | * classes are public for two reasons: (1) To allow for public/protected |
---|
| 24 | * inheritence in other implementations, (2) So that symbolic debuggers can |
---|
| 25 | * navigate the call tree for typecasted objects of derivative classes. |
---|
[465] | 26 | * |
---|
| 27 | * Note that any new component type declaration MUST include this header and |
---|
| 28 | * extend a parent component type. |
---|
[161] | 29 | */ |
---|
| 30 | |
---|
| 31 | #ifndef COMPONENTS_H |
---|
| 32 | #define COMPONENTS_H |
---|
| 33 | |
---|
| 34 | |
---|
[211] | 35 | #include <cstring> |
---|
[161] | 36 | #include <stdint.h> |
---|
[173] | 37 | #include <string> |
---|
[161] | 38 | |
---|
| 39 | #include "containers.h" |
---|
[190] | 40 | #include "socketcomm.h" |
---|
[161] | 41 | |
---|
| 42 | |
---|
[518] | 43 | /*! \brief The Component class is the top-level abstract base class in CROSS. |
---|
| 44 | * |
---|
| 45 | * Component abstract base class that all component classes should inherit from, |
---|
[170] | 46 | * including cognitive and policy engines, and the service management layer. |
---|
| 47 | * Defines only functions required by all component types. |
---|
| 48 | */ |
---|
[161] | 49 | class Component |
---|
| 50 | { |
---|
| 51 | public: |
---|
[518] | 52 | /*! \brief Asks a component to identify itself. |
---|
| 53 | * |
---|
| 54 | * Asks the component at the passed socket FD for its component type |
---|
[190] | 55 | * string. Note that this implementation is global for all component |
---|
| 56 | * types, so is implemented here. Should a component need to override |
---|
| 57 | * it, that is possible via dynamic binding or overloading. |
---|
[170] | 58 | */ |
---|
[190] | 59 | virtual std::string GetRemoteComponentType(int32_t componentSocketFD) |
---|
| 60 | { |
---|
| 61 | SendMessage(componentSocketFD, "request_component_type"); |
---|
[170] | 62 | |
---|
[190] | 63 | char buffer[256]; |
---|
| 64 | memset(buffer, 0, 256); |
---|
| 65 | ReadMessage(componentSocketFD, buffer); |
---|
[170] | 66 | |
---|
[190] | 67 | return std::string(buffer); |
---|
| 68 | } |
---|
| 69 | |
---|
[518] | 70 | /*! \brief Responds to a request for identification. |
---|
| 71 | * |
---|
| 72 | * Send an indentfying string for this object's component type in |
---|
[194] | 73 | * response to a GetRemoteComponentType query. |
---|
| 74 | */ |
---|
| 75 | virtual void SendComponentType() = 0; |
---|
[190] | 76 | |
---|
[518] | 77 | /*! \brief Shutdown the component. */ |
---|
[161] | 78 | virtual void Shutdown() = 0; |
---|
[170] | 79 | |
---|
[518] | 80 | /*! \brief Reset the component and reload configurations. */ |
---|
[161] | 81 | virtual void Reset() = 0; |
---|
[170] | 82 | |
---|
[518] | 83 | /*! \brief Compenent registration procedures. */ |
---|
[188] | 84 | virtual void RegisterComponent() = 0; |
---|
| 85 | virtual void DeregisterComponent() = 0; |
---|
[161] | 86 | }; |
---|
| 87 | |
---|
| 88 | |
---|
[518] | 89 | /*! \brief Engine abstract base class declaration. |
---|
| 90 | * |
---|
| 91 | * Engine abstract base class from which all engine component types should |
---|
[170] | 92 | * inherit (e.g. cognitive and policy engines). Inherits all functions from the |
---|
| 93 | * ABC Component publically. |
---|
| 94 | */ |
---|
[161] | 95 | class Engine : public Component |
---|
| 96 | { |
---|
| 97 | public: |
---|
[518] | 98 | /*! \brief Connect to a remote controlling component. |
---|
| 99 | * |
---|
| 100 | * Connect to the remote control component, which will always be either |
---|
| 101 | * the CROSS shell or SML. Based on the status of the SML_present |
---|
[203] | 102 | * bool, this function will also register the component or services. |
---|
| 103 | * |
---|
| 104 | * TODO I feel like the name of this function could be changed to be a |
---|
[518] | 105 | * little more descriptive? */ |
---|
[203] | 106 | virtual void ConnectToRemoteComponent(const char* serverName, \ |
---|
| 107 | const char* serverPort, const bool SML) = 0; |
---|
[431] | 108 | |
---|
[518] | 109 | /*! \brief Wait for a command signal containing task instructions. |
---|
| 110 | * |
---|
| 111 | * This is the general run-time loop from which all radio operation |
---|
| 112 | * occurs. Once the Engine has started up and initialized, it will |
---|
| 113 | * remain in this function until it receives a command to perform some |
---|
| 114 | * action. */ |
---|
[431] | 115 | virtual void WaitForSignal() = 0; |
---|
[203] | 116 | |
---|
[518] | 117 | /*! \brief Functions for interacting with the service management layer. |
---|
| 118 | * |
---|
| 119 | * Register or deregister services that this engine provides with the |
---|
| 120 | * service management layer. */ |
---|
[188] | 121 | virtual void RegisterServices() = 0; |
---|
[278] | 122 | virtual void DeregisterServices() = 0; |
---|
[161] | 123 | }; |
---|
| 124 | |
---|
| 125 | #endif |
---|