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

Revision 213, 11.3 KB (checked in by bhilburn, 15 years ago)

Making field names more descriptive and easier to read. Also, added a
bug not about a possible segfault.

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        void SendComponentType();
231        void ConnectToRemoteComponent(const char* serverName, \
232                const char* serverPort, const bool SML);
233        void WaitForSignal();
234        void Shutdown();
235        void Reset();
236        void RegisterComponent();
237        void DeregisterComponent();
238
239        void RegisterServices();
240        void DeregisterServices();
241
242    private:
243        /* Receive the transmitted radio configuration from the radio itself
244         * (the CE will not always be local to the radio).
245         */
246        void ReceiveRadioConfiguration();
247
248        /* Receive an 'experience' report from the radio.
249         */
250        void ReceiveExperience();
251
252        /* Find the most optimal set of transmission parameters given certain
253         * observables and possibly a service if the SML component is present
254         * and active.
255         */
256        void GetSolution(Observable *observables);
257        void GetSolution(Observable *observables, std::string service);
258
259        /* Receive a feedback from the radio regarding the performance of a
260         * certain set of parameters, possibly associated with a service.
261         *
262         * TODO what is the difference between experiences and feedback,
263         * exactly? we should explain that explicitly here.
264         */
265        void ReceiveFeedback(Observable *observables,\
266                Parameter *parameters, Utility *utilities);
267        void ReceiveFeedback(Observable *observables, \
268                Parameter *parameters, std::string service);
269
270        /* The SML_present bool reflects whether or not the remote component
271         * this object is connected to is an SML.  If it isn't, then it must be
272         * a shell.  The socketFD stores the socket file descriptor for this
273         * connection.
274         */
275        bool SML_present;
276        int32_t commandSocketFD;
277};
278
279/* Cognitive Radio Shell class declaration.
280 */
281class CognitiveRadioShell
282{
283    public:
284        CognitiveRadioShell();
285        ~CognitiveRadioShell();
286
287        /* Overloaded constructor that creates a CR Shell object and loads the
288         * passed radio configuration XML file.
289         */
290        CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \
291            int16_t policyPort, int16_t commandPort);
292
293        /* Ask for the component type of a remote component via sockets, or
294         * respond to such a query sent to the shell itself.
295         */
296        std::string GetRemoteComponentType(int32_t socketFD);
297        void SendComponentType(int32_t socketFD);
298
299        void Shutdown();
300        void Reset();
301       
302        /* Start all the socket servers */
303        void StartShellServer();
304
305        int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \
306            Utility* &uList, Observable* &oList, Radio_Info* radioInfo);
307    private:
308        /* Parse and load/reload policies into the policy engine.
309         */
310        void LoadPolicies();
311        void ReloadPolicies();
312
313        /* Register and Deregister the different components.
314         */
315        void RegisterCognitiveEngine(int32_t socketFD);
316        void DeregisterCognitiveEngine(int32_t socketFD);
317        void RegisterPolicyEngine(int32_t socketFD);
318        void DeregisterPolicyEngine(int32_t socketFD);
319        void RegisterSML(int32_t socketFD);
320        void DeregisterSML(int32_t socketFD);
321
322        /* Handle a message that is received from a component.
323         */
324        void HandleMessage(int32_t socketFD);
325       
326        /* Send optimization request to primary port FD.
327         */
328        void GetOptimalParameters(int32_t socketFD);
329
330        void SendRadioConfiguration(int32_t socketFD);
331        void SendRadioExperience(int32_t socketFD);
332 
333        bool SML_present;
334        bool PE_present;
335        bool CE_present;
336       
337        int32_t numberOfCognitiveEngines;
338        int16_t primaryPort;
339        int16_t policyPort;
340        int16_t commandPort;
341
342        Utility *utils;
343        Parameter *params;
344        Observable *observables;
345        struct Radio_Info *radio_info;
346};
347
348#endif
Note: See TracBrowser for help on using the browser.