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

Revision 190, 8.0 KB (checked in by bhilburn, 15 years ago)

Implemented the GetRemoteComponentType? function is the components header
for all subclasses of 'component'.

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