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

Revision 194, 8.8 KB (checked in by bhilburn, 15 years ago)

Finished implementing basic structure of WaitForSignal?, added new
functions to components to allow proper response to component type
queries, modularized the connect & register step for engines, and added
a few TODOs in areas that need review. This is an abnormally large
commit.

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        /* Connect to the remote control component, which will always be either
59         * the VTCROSS shell or SML.  Based on the status of the SML_present
60         * bool, this function will also register the component or services.
61         *
62         * TODO I feel like the name of this function could be changed to be a
63         * little more descriptive?
64         */
65        virtual void ConnectToRemoteComponent(const char* serverName, \
66                const char* serverPort) = 0;
67
68        /* Wait for a command signal containing task instructions.
69         */
70        virtual void WaitForSignal() = 0;
71
72
73        /* Completely shutdown the radio and all operations.
74         */
75        virtual void Shutdown() = 0;
76
77
78        /* Reset the radio and reload all configuration files.
79         *
80         * TODO are we remembering experiences in CEs?
81         */
82        virtual void Reset() = 0;
83
84
85        /* Register or deregister a component with the primary radio shell.
86         */
87        virtual void RegisterComponent() = 0;
88        virtual void DeregisterComponent() = 0;
89};
90
91
92/* Engine abstract base class from which all engine component types should
93 * inherit (e.g. cognitive and policy engines). Inherits all functions from the
94 * ABC Component publically.
95 */
96class Engine : public Component
97{
98    public:
99        /* Register or deregister services that this engine provides with the
100         * service management layer.
101         */
102        virtual void RegisterServices() = 0;
103        virtual void DeregisterServices() = 0;
104};
105
106
107/* Service Management Layer (SML) class declaration.  The functions listed here
108 * are required by the VTCROSS API for service-oriented VTCROSS radio
109 * architectures.
110 */
111class ServiceManagementLayer : public Component
112{
113    public:
114        ServiceManagementLayer();
115        ~ServiceManagementLayer();
116
117        void SendComponentType();
118        void ConnectToRemoteComponent(const char* serverName, \
119                const char* serverPort);
120        void WaitForSignal();
121        void Shutdown();
122        void Reset();
123        void RegisterComponent();
124        void DeregisterComponent();
125
126    private:
127        /* Receive the radio configuration settings from the shell and pass them
128         * on to another component.
129         */
130        void TransferRadioConfiguration();
131
132       
133        /* Receive information regarding a completed 'experience' and pass it on
134         * to the appropriate cognitive engine.
135         */
136        void TransferExperience();
137
138       
139        /* Listen for other components registering their available services with
140         * the SML.
141         */
142        void ReceiveServices();
143
144
145        /* Change the active mission of the radio to a new one and adjust radio
146         * behavoir appropriately.
147         */
148        void SetActiveMission();
149
150
151        /* List all services provided to the radio by registered components.
152         */
153        void ListServices();
154
155
156        /* Load/Relead the XML configuration file.
157         */
158        void ReloadConfiguration();
159        void LoadConfiguration();
160
161
162        /* The socket file descriptor information for the shell which this SML
163         * is connected to.
164         */
165        int32_t shellSocketFD;
166};
167
168
169/* Policy Engine class declaration.  All public functions are inherited from
170 * parent classes.
171 */
172class PolicyEngine : public Engine
173{
174    public:
175        PolicyEngine();
176        ~PolicyEngine();
177
178
179        /* Overloaded constructor that creates a policy engine object and
180         * connects it to either the shell or an SML, depening on the SML bool.
181         */
182        PolicyEngine(const char* serverName, const char* serverPort, \
183                const bool SML);
184
185        void SendComponentType();
186        void ConnectToRemoteComponent(const char* serverName, \
187                const char* serverPort);
188        void WaitForSignal();
189        void Shutdown();
190        void Reset();
191        void RegisterComponent();
192        void DeregisterComponent();
193
194        void RegisterServices();
195        void DeregisterServices();
196
197    private:
198        /* Parse and load/reload policies into the policy engine.
199         */
200        void LoadPolicies();
201        void ReloadPolicies();
202
203       
204        /* Return a decision made by the policy engine regarding a certain set
205         * of transmission parameters.
206         */
207        void SendPEDecision(struct Parameter pList[], struct CE_Info *ce_info, \
208                int32_t decision_array[]);
209
210
211        /* Validate a set of transmission parameters received from the radio.
212         */
213        void ValidateParameters();
214
215
216        /* The SML_present bool reflects whether or not the remote component
217         * this object is connected to is an SML.  If it isn't, then it must be
218         * a shell.  The socketFD stores the socket file descriptor for this
219         * connection.
220         */
221        bool SML_present;
222        int32_t commandSocketFD;
223};
224
225
226/* Cognitive Engine class declaration.  All public functions are inherited from
227 * parent classes.
228 */
229class CognitiveEngine : public Engine
230{
231    public:
232        CognitiveEngine();
233        ~CognitiveEngine();
234
235        void SendComponentType();
236        void ConnectToRemoteComponent(const char* serverName, \
237                const char* serverPort);
238        void WaitForSignal();
239        void Shutdown();
240        void Reset();
241        void RegisterComponent();
242        void DeregisterComponent();
243
244        void RegisterServices();
245        void DeregisterServices();
246
247    private:
248        /* Receive the transmitted radio configuration from the radio itself
249         * (the CE will not always be local to the radio).
250         */
251        void ReceiveRadioConfiguration();
252
253
254        /* Receive an 'experience' report from the radio.
255         */
256        void ReceiveExperience();
257
258
259        /* Find the most optimal set of transmission parameters given certain
260         * observables and possibly a service if the SML component is present
261         * and active.
262         */
263        void GetSolution(Observable *observables);
264        void GetSolution(Observable *observables, std::string service);
265
266
267        /* Receive a feedback from the radio regarding the performance of a
268         * certain set of parameters, possibly associated with a service.
269         *
270         * TODO what is the difference between experiences and feedback,
271         * exactly? we should explain that explicitly here.
272         */
273        void ReceiveFeedback(Observable *observables,\
274                Parameter *parameters, Utility *utilities);
275        void ReceiveFeedback(Observable *observables, \
276                Parameter *parameters, 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
287#endif
Note: See TracBrowser for help on using the browser.