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

Revision 193, 7.8 KB (checked in by bhilburn, 15 years ago)

Minor change to make things more consistent.

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 WaitForSignal();
102        void Shutdown();
103        void Reset();
104        void RegisterComponent();
105        void DeregisterComponent();
106
107    private:
108        /* Receive the radio configuration settings from the shell and pass them
109         * on to another component.
110         */
111        void TransferRadioConfiguration();
112
113       
114        /* Receive information regarding a completed 'experience' and pass it on
115         * to the appropriate cognitive engine.
116         */
117        void TransferExperience();
118
119       
120        /* Listen for other components registering their available services with
121         * the SML.
122         */
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* serverPort, \
164                const bool SML);
165
166        void WaitForSignal();
167        void Shutdown();
168        void Reset();
169        void RegisterComponent();
170        void DeregisterComponent();
171
172        void RegisterServices();
173        void DeregisterServices();
174
175    private:
176        /* Parse and load/reload policies into the policy engine.
177         */
178        void LoadPolicies();
179        void ReloadPolicies();
180
181       
182        /* Return a decision made by the policy engine regarding a certain set
183         * of transmission parameters.
184         */
185        void SendPEDecision(struct Parameter pList[], struct CE_Info *ce_info, \
186                int32_t decision_array[]);
187
188
189        /* Validate a set of transmission parameters received from the radio.
190         */
191        void ValidateParameters(struct Parameter pList[], \
192                struct CE_Info *ce_info, int decision_array[]);
193
194
195        /* The SML_present bool reflects whether or not the remote component
196         * this object is connected to is an SML.  If it isn't, then it must be
197         * a shell.  The socketFD stores the socket file descriptor for this
198         * connection.
199         */
200        bool SML_present;
201        int32_t commandSocketFD;
202};
203
204
205/* Cognitive Engine class declaration.  All public functions are inherited from
206 * parent classes.
207 */
208class CognitiveEngine : public Engine
209{
210    public:
211        CognitiveEngine();
212        ~CognitiveEngine();
213
214        void WaitForSignal();
215        void Shutdown();
216        void Reset();
217        void RegisterComponent();
218        void DeregisterComponent();
219
220        void RegisterServices();
221        void DeregisterServices();
222
223    private:
224        /* Receive the transmitted radio configuration from the radio itself
225         * (the CE will not always be local to the radio).
226         */
227        void ReceiveRadioConfiguration();
228
229
230        /* Receive an 'experience' report from the radio.
231         */
232        void ReceiveExperience();
233
234
235        /* Find the most optimal set of transmission parameters given certain
236         * observables and possibly a service if the SML component is present
237         * and active.
238         */
239        void GetSolution(Observable *observables);
240        void GetSolution(Observable *observables, std::string service);
241
242
243        /* Receive a feedback from the radio regarding the performance of a
244         * certain set of parameters, possibly associated with a service.
245         *
246         * TODO what is the difference between experiences and feedback,
247         * exactly? we should explain that explicitly here.
248         */
249        void ReceiveFeedback(Observable *observables,\
250                Parameter *parameters, Utility *utilities);
251        void ReceiveFeedback(Observable *observables, \
252                Parameter *parameters, std::string service);
253
254        /* The SML_present bool reflects whether or not the remote component
255         * this object is connected to is an SML.  If it isn't, then it must be
256         * a shell.  The socketFD stores the socket file descriptor for this
257         * connection.
258         */
259        bool SML_present;
260        int32_t commandSocketFD;
261};
262
263#endif
Note: See TracBrowser for help on using the browser.