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

Revision 191, 7.9 KB (checked in by bhilburn, 15 years ago)

Renamed the private socketFD to commandSocketFD to make it easier to
distinguish (and it just makes more sense).

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