root/vtcross/trunk/src/include/vtcross/components.h @ 203

Revision 203, 9.1 KB (checked in by bhilburn, 15 years ago)

Making ConnectToRemoteComponent? an engine function since the SML doesn't
need it, adding a bool representing presence of SML, updating
PolicyEngine? to reflect changes.

Line 
1/* Virginia Tech Cognitive Radio Open Source Systems
2 * Virginia Tech, 2009
3 *
4 * LICENSE INFORMATION GOES HERE
5 */
6
7/* This header exports the declarations for all VT-CROSS radio components.  It
8 * contains two pure abstract base classes, Component and Engine; Engine derives
9 * from Component.  All functions contained within the abstract base classes are
10 * dynamically linked and pure, and all child non-abstract classes derive using
11 * private inheritence.  Class functions of the abstract base classes are public
12 * for two reasons: (1) To allow for public/protected inheritence in other
13 * implementations, (2) So that symbolic debuggers can navigate the call tree
14 * for typecasted objects of derivative classes.
15 */
16
17#ifndef COMPONENTS_H
18#define COMPONENTS_H
19
20
21#include <stdint.h>
22#include <string>
23
24#include "containers.h"
25#include "socketcomm.h"
26
27
28/* Component abstract base class that all component classes should inherit from,
29 * including cognitive and policy engines, and the service management layer.
30 * Defines only functions required by all component types.
31 */
32class Component
33{
34    public:
35        /* Asks the component at the passed socket FD for its component type
36         * string.  Note that this implementation is global for all component
37         * types, so is implemented here.  Should a component need to override
38         * it, that is possible via dynamic binding or overloading.
39         */
40        virtual std::string GetRemoteComponentType(int32_t componentSocketFD)
41        {
42            SendMessage(componentSocketFD, "request_component_type");
43
44            char buffer[256];
45            memset(buffer, 0, 256);
46            ReadMessage(componentSocketFD, buffer);
47
48            return std::string(buffer);
49        }
50
51       
52        /* Send an indentfying string for this object's component type in
53         * response to a GetRemoteComponentType query.
54         */
55        virtual void SendComponentType() = 0;
56
57
58        /* Wait for a command signal containing task instructions.
59         */
60        virtual void WaitForSignal() = 0;
61
62
63        /* Completely shutdown the radio and all operations.
64         */
65        virtual void Shutdown() = 0;
66
67
68        /* Reset the radio and reload all configuration files.
69         *
70         * TODO are we remembering experiences in CEs?
71         */
72        virtual void Reset() = 0;
73
74
75        /* Register or deregister a component with the primary radio shell.
76         */
77        virtual void RegisterComponent() = 0;
78        virtual void DeregisterComponent() = 0;
79};
80
81
82/* Engine abstract base class from which all engine component types should
83 * inherit (e.g. cognitive and policy engines). Inherits all functions from the
84 * ABC Component publically.
85 */
86class Engine : public Component
87{
88    public:
89        /* Connect to the remote control component, which will always be either
90         * the VTCROSS shell or SML.  Based on the status of the SML_present
91         * bool, this function will also register the component or services.
92         *
93         * TODO I feel like the name of this function could be changed to be a
94         * little more descriptive?
95         */
96        virtual void ConnectToRemoteComponent(const char* serverName, \
97                const char* serverPort, const bool SML) = 0;
98
99
100        /* Register or deregister services that this engine provides with the
101         * service management layer.
102         */
103        virtual void RegisterServices() = 0;
104        virtual void DeregisterServices() = 0;
105};
106
107
108/* Service Management Layer (SML) class declaration.  The functions listed here
109 * are required by the VTCROSS API for service-oriented VTCROSS radio
110 * architectures.
111 */
112class ServiceManagementLayer : public Component
113{
114    public:
115        ServiceManagementLayer();
116        ~ServiceManagementLayer();
117
118        /* Overloaded constructor that creates an SML and connects it to the
119         * shell with the passed hostname and port.
120         */
121        ServiceManagementLayer(const char* serverName, const char* serverPort);
122
123        /* Connect and register with the shell component at the passed hostname
124         * and port.
125         */
126        void ConnectToShell(const char* serverName, \
127                const char* serverPort);
128
129        void SendComponentType();
130        void WaitForSignal();
131        void Shutdown();
132        void Reset();
133        void RegisterComponent();
134        void DeregisterComponent();
135
136    private:
137        /* Receive the radio configuration settings from the shell and pass them
138         * on to another component.
139         */
140        void TransferRadioConfiguration();
141
142       
143        /* Receive information regarding a completed 'experience' and pass it on
144         * to the appropriate cognitive engine.
145         */
146        void TransferExperience();
147
148       
149        /* Listen for other components registering their available services with
150         * the SML.
151         */
152        void ReceiveServices();
153
154
155        /* Change the active mission of the radio to a new one and adjust radio
156         * behavoir appropriately.
157         */
158        void SetActiveMission();
159
160
161        /* List all services provided to the radio by registered components.
162         */
163        void ListServices();
164
165
166        /* Load/Relead the XML configuration file.
167         */
168        void ReloadConfiguration();
169        void LoadConfiguration();
170
171
172        /* The socket file descriptor information for the shell which this SML
173         * is connected to.
174         */
175        int32_t shellSocketFD;
176};
177
178
179/* Policy Engine class declaration.  All public functions are inherited from
180 * parent classes.
181 */
182class PolicyEngine : public Engine
183{
184    public:
185        PolicyEngine();
186        ~PolicyEngine();
187
188
189        /* Overloaded constructor that creates a policy engine object and
190         * connects it to either the shell or an SML, depening on the SML bool.
191         */
192        PolicyEngine(const char* serverName, const char* serverPort, \
193                const bool SML);
194
195        void SendComponentType();
196        void ConnectToRemoteComponent(const char* serverName, \
197                const char* serverPort, const bool SML);
198        void WaitForSignal();
199        void Shutdown();
200        void Reset();
201        void RegisterComponent();
202        void DeregisterComponent();
203
204        void RegisterServices();
205        void DeregisterServices();
206
207    private:
208        /* Parse and load/reload policies into the policy engine.
209         */
210        void LoadPolicies();
211        void ReloadPolicies();
212
213       
214        /* Return a decision made by the policy engine regarding a certain set
215         * of transmission parameters.
216         */
217        void SendPEDecision(struct Parameter pList[], struct Radio_Info *radio_info, \
218                int32_t decision_array[]);
219
220
221        /* Validate a set of transmission parameters received from the radio.
222         */
223        void ValidateParameters();
224
225
226        /* The SML_present bool reflects whether or not the remote component
227         * this object is connected to is an SML.  If it isn't, then it must be
228         * a shell.  The socketFD stores the socket file descriptor for this
229         * connection.
230         */
231        bool SML_present;
232        int32_t commandSocketFD;
233};
234
235
236/* Cognitive Engine class declaration.  All public functions are inherited from
237 * parent classes.
238 */
239class CognitiveEngine : public Engine
240{
241    public:
242        CognitiveEngine();
243        ~CognitiveEngine();
244
245        void SendComponentType();
246        void ConnectToRemoteComponent(const char* serverName, \
247                const char* serverPort, const bool SML);
248        void WaitForSignal();
249        void Shutdown();
250        void Reset();
251        void RegisterComponent();
252        void DeregisterComponent();
253
254        void RegisterServices();
255        void DeregisterServices();
256
257    private:
258        /* Receive the transmitted radio configuration from the radio itself
259         * (the CE will not always be local to the radio).
260         */
261        void ReceiveRadioConfiguration();
262
263
264        /* Receive an 'experience' report from the radio.
265         */
266        void ReceiveExperience();
267
268
269        /* Find the most optimal set of transmission parameters given certain
270         * observables and possibly a service if the SML component is present
271         * and active.
272         */
273        void GetSolution(Observable *observables);
274        void GetSolution(Observable *observables, std::string service);
275
276
277        /* Receive a feedback from the radio regarding the performance of a
278         * certain set of parameters, possibly associated with a service.
279         *
280         * TODO what is the difference between experiences and feedback,
281         * exactly? we should explain that explicitly here.
282         */
283        void ReceiveFeedback(Observable *observables,\
284                Parameter *parameters, Utility *utilities);
285        void ReceiveFeedback(Observable *observables, \
286                Parameter *parameters, std::string service);
287
288        /* The SML_present bool reflects whether or not the remote component
289         * this object is connected to is an SML.  If it isn't, then it must be
290         * a shell.  The socketFD stores the socket file descriptor for this
291         * connection.
292         */
293        bool SML_present;
294        int32_t commandSocketFD;
295};
296
297#endif
Note: See TracBrowser for help on using the browser.