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

Revision 217, 11.8 KB (checked in by jgaeddert, 15 years ago)

More fixes to c++ CE.

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 <cstring>
22#include <stdint.h>
23#include <string>
24
25#include "containers.h"
26#include "socketcomm.h"
27
28
29/* Component abstract base class that all component classes should inherit from,
30 * including cognitive and policy engines, and the service management layer.
31 * Defines only functions required by all component types.
32 */
33class Component
34{
35    public:
36        /* Asks the component at the passed socket FD for its component type
37         * string.  Note that this implementation is global for all component
38         * types, so is implemented here.  Should a component need to override
39         * it, that is possible via dynamic binding or overloading.
40         */
41        virtual std::string GetRemoteComponentType(int32_t componentSocketFD)
42        {
43            SendMessage(componentSocketFD, "request_component_type");
44
45            char buffer[256];
46            memset(buffer, 0, 256);
47            ReadMessage(componentSocketFD, buffer);
48
49            return std::string(buffer);
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        /* Wait for a command signal containing task instructions.
58         */
59        virtual void WaitForSignal() = 0;
60
61        /* Completely shutdown the radio and all operations.
62         */
63        virtual void Shutdown() = 0;
64
65        /* Reset the radio and reload all configuration files.
66         *
67         * TODO are we remembering experiences in CEs?
68         */
69        virtual void Reset() = 0;
70
71        /* Register or deregister a component with the primary radio shell.
72         */
73        virtual void RegisterComponent() = 0;
74        virtual void DeregisterComponent() = 0;
75};
76
77
78/* Engine abstract base class from which all engine component types should
79 * inherit (e.g. cognitive and policy engines). Inherits all functions from the
80 * ABC Component publically.
81 */
82class Engine : public Component
83{
84    public:
85        /* Connect to the remote control component, which will always be either
86         * the VTCROSS shell or SML.  Based on the status of the SML_present
87         * bool, this function will also register the component or services.
88         *
89         * TODO I feel like the name of this function could be changed to be a
90         * little more descriptive?
91         */
92        virtual void ConnectToRemoteComponent(const char* serverName, \
93                const char* serverPort, const bool SML) = 0;
94
95        /* Register or deregister services that this engine provides with the
96         * service management layer.
97         */
98        virtual void RegisterServices() = 0;
99        virtual void DeregisterServices() = 0;
100};
101
102
103/* Service Management Layer (SML) class declaration.  The functions listed here
104 * are required by the VTCROSS API for service-oriented VTCROSS radio
105 * architectures.
106 */
107class ServiceManagementLayer : public Component
108{
109    public:
110        ServiceManagementLayer();
111        ~ServiceManagementLayer();
112
113        /* Overloaded constructor that creates an SML and connects it to the
114         * shell with the passed hostname and port.
115         */
116        ServiceManagementLayer(const char* serverName, const char* serverPort);
117
118        /* Connect and register with the shell component at the passed hostname
119         * and port.
120         */
121        void ConnectToShell(const char* serverName, \
122                const char* serverPort);
123
124        void SendComponentType();
125        void WaitForSignal();
126        void Shutdown();
127        void Reset();
128        void RegisterComponent();
129        void DeregisterComponent();
130
131    private:
132        /* Receive the radio configuration settings from the shell and pass them
133         * on to another component.
134         */
135        void TransferRadioConfiguration();
136
137        /* Receive information regarding a completed 'experience' and pass it on
138         * to the appropriate cognitive engine.
139         */
140        void TransferExperience();
141       
142        /* Listen for other components registering their available services with
143         * the SML.
144         */
145        void ReceiveServices();
146
147        /* Change the active mission of the radio to a new one and adjust radio
148         * behavoir appropriately.
149         */
150        void SetActiveMission();
151
152        /* List all services provided to the radio by registered components.
153         */
154        void ListServices();
155
156        /* Load/Relead the XML configuration file.
157         */
158        void ReloadConfiguration();
159        void LoadConfiguration();
160
161        /* The socket file descriptor information for the shell which this SML
162         * is connected to.
163         */
164        int32_t shellSocketFD;
165};
166
167
168/* Policy Engine class declaration.  All public functions are inherited from
169 * parent classes.
170 */
171class PolicyEngine : public Engine
172{
173    public:
174        PolicyEngine();
175        ~PolicyEngine();
176
177        /* Overloaded constructor that creates a policy engine object and
178         * connects it to either the shell or an SML, depening on the SML bool.
179         */
180        PolicyEngine(const char* serverName, const char* serverPort, \
181                const bool SML);
182
183        void SendComponentType();
184        void ConnectToRemoteComponent(const char* serverName, \
185                const char* serverPort, const bool SML);
186        void WaitForSignal();
187        void Shutdown();
188        void Reset();
189        void RegisterComponent();
190        void DeregisterComponent();
191
192        void RegisterServices();
193        void DeregisterServices();
194
195    private:
196        /* Parse and load/reload policies into the policy engine.
197         */
198        void LoadPolicies();
199        void ReloadPolicies();
200
201        /* Return a decision made by the policy engine regarding a certain set
202         * of transmission parameters.
203         */
204        void SendPEDecision(struct Parameter pList[], struct Radio_Info *radio_info, \
205                int32_t decision_array[]);
206
207        /* Validate a set of transmission parameters received from the radio.
208         */
209        void ValidateParameters();
210
211        /* The SML_present bool reflects whether or not the remote component
212         * this object is connected to is an SML.  If it isn't, then it must be
213         * a shell.  The socketFD stores the socket file descriptor for this
214         * connection.
215         */
216        bool SML_present;
217        int32_t commandSocketFD;
218};
219
220
221/* Cognitive Engine class declaration.  All public functions are inherited from
222 * parent classes.
223 */
224class CognitiveEngine : public Engine
225{
226    public:
227        CognitiveEngine();
228        ~CognitiveEngine();
229
230        /* Overloaded constructor that creates a cognitive engine object and
231         * connects it to either the shell or an SML, depening on the SML bool.
232         */
233        CognitiveEngine(const char* serverName, const char* serverPort, \
234                const bool SML);
235       
236        void SendComponentType();
237        void ConnectToRemoteComponent(const char* serverName, \
238                const char* serverPort, const bool SML);
239        void WaitForSignal();
240        void Shutdown();
241        void Reset();
242        void RegisterComponent();
243        void DeregisterComponent();
244
245        void RegisterServices();
246        void DeregisterServices();
247
248    private:
249        /* Receive the transmitted radio configuration from the radio itself
250         * (the CE will not always be local to the radio).
251         */
252        void ReceiveRadioConfiguration();
253
254        /* Receive an 'experience' report from the radio.
255         */
256        void ReceiveExperience();
257
258        /* Find the most optimal set of transmission parameters given certain
259         * observables and possibly a service if the SML component is present
260         * and active.
261         */
262        void GetSolution(Observable *observables);
263        void GetSolution(Observable *observables, std::string service);
264
265        /* Receive a feedback from the radio regarding the performance of a
266         * certain set of parameters, possibly associated with a service.
267         *
268         * Feedback is a single set of performance statistics that is achieved
269         * corresponding to a specific set of transmission parameters.  Feedback
270         * helps a Cognitive Engine make better future decisions based upon
271         * more accurate performance statistics.
272         */
273        void ReceiveFeedback(Observable *observables,\
274                Parameter *parameters, Utility *utilities);
275        void ReceiveFeedback(Observable *observables, \
276                Parameter *parameters, Utility *utilities, std::string service);
277
278        /* The SML_present bool reflects whether or not the remote component
279         * this object is connected to is an SML.  If it isn't, then it must be
280         * a shell.  The socketFD stores the socket file descriptor for this
281         * connection.
282         */
283        bool SML_present;
284        int32_t commandSocketFD;
285       
286        Utility * uList;
287        Parameter * pList;
288        Observable * oList;
289        struct Radio_Info * radioInfo;
290};
291
292/* Cognitive Radio Shell class declaration.
293 */
294class CognitiveRadioShell
295{
296    public:
297        CognitiveRadioShell();
298        ~CognitiveRadioShell();
299
300        /* Overloaded constructor that creates a CR Shell object and loads the
301         * passed radio configuration XML file.
302         */
303        CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \
304            int16_t policyPort, int16_t commandPort);
305
306        /* Ask for the component type of a remote component via sockets, or
307         * respond to such a query sent to the shell itself.
308         */
309        std::string GetRemoteComponentType(int32_t socketFD);
310        void SendComponentType(int32_t socketFD);
311
312        void Shutdown();
313        void Reset();
314       
315        /* Start all the socket servers */
316        void StartShellServer();
317
318        int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \
319            Utility* &uList, Observable* &oList, Radio_Info* radioInfo);
320    private:
321        /* Parse and load/reload policies into the policy engine.
322         */
323        void LoadPolicies();
324        void ReloadPolicies();
325
326        /* Register and Deregister the different components.
327         */
328        void RegisterCognitiveEngine(int32_t socketFD);
329        void DeregisterCognitiveEngine(int32_t socketFD);
330        void RegisterPolicyEngine(int32_t socketFD);
331        void DeregisterPolicyEngine(int32_t socketFD);
332        void RegisterSML(int32_t socketFD);
333        void DeregisterSML(int32_t socketFD);
334
335        /* Handle a message that is received from a component.
336         */
337        void HandleMessage(int32_t socketFD);
338       
339        /* Send optimization request to primary port FD.
340         */
341        void GetOptimalParameters(int32_t socketFD);
342
343        bool SendRadioConfiguration(int32_t socketFD);
344        bool SendRadioExperience(int32_t socketFD);
345 
346        bool SML_present;
347        bool PE_present;
348        bool CE_present;
349       
350        int32_t numberOfCognitiveEngines;
351        int16_t primaryPort;
352        int16_t policyPort;
353        int16_t commandPort;
354
355        Utility *utils;
356        Parameter *params;
357        Observable *observables;
358        struct Radio_Info *radio_info;
359};
360
361#endif
Note: See TracBrowser for help on using the browser.