root/vtcross/trunk/src/service_management_layer/ServiceManagementLayer.cpp @ 206

Revision 206, 3.7 KB (checked in by bhilburn, 15 years ago)

Wrote out basic structure for the WaitForSignal? for the SML. Note that
I still think integer opcodes are the way to go.

Line 
1/* Virginia Tech Cognitive Radio Open Source Systems
2 * Virginia Tech, 2009
3 *
4 * LICENSE INFORMATION GOES HERE
5 */
6
7/* DESCRIPTION OF FILE.
8 */
9
10
11#include <cstdlib>
12#include <cstring>
13#include <stdint.h>
14
15#include "vtcross/common.h"
16#include "vtcross/components.h"
17#include "vtcross/containers.h"
18#include "vtcross/debug.h"
19#include "vtcross/error.h"
20#include "vtcross/socketcomm.h"
21
22
23ServiceManagementLayer::ServiceManagementLayer()
24{
25    LOG("Creating Service Management Layer.\n");
26    shellSocketFD = -1;
27    LoadConfiguration();
28}
29
30
31ServiceManagementLayer::~ServiceManagementLayer()
32{
33}
34
35
36ServiceManagementLayer::ServiceManagementLayer(const char* serverName, \
37        const char* serverPort)
38{
39    LOG("Creating Service Management Layer.\n");
40
41    ConnectToShell(serverName, serverPort);
42
43    LoadConfiguration();
44}
45
46
47void
48ServiceManagementLayer::SendComponentType()
49{
50    SendMessage(shellSocketFD, "response_sml");
51    LOG("SML responded to GetRemoteComponentType query.\n");
52}
53
54
55void
56ServiceManagementLayer::ConnectToShell(const char* serverName, \
57        const char* serverPort)
58{
59    shellSocketFD = ClientSocket(serverName, serverPort);
60
61    RegisterComponent();
62}
63
64
65void
66ServiceManagementLayer::WaitForSignal()
67{
68    char buffer[256];
69
70    while(true) {
71        memset(buffer, 0, 256);
72       
73        ReadMessage(shellSocketFD, buffer);
74
75        // TODO
76        // If we send integer op codes rather than strings, this process will be
77        // MUCH faster since instead of donig string compares we can simply
78        // switch on the integer value...
79        if(strcmp(buffer, "register_service") == 0) {
80            if(strcmp(buffer, "policy_geo") == 0) {
81            }
82            else if(strcmp(buffer, "policy_time") == 0) {
83            }
84            else if(strcmp(buffer, "policy_spectrum") == 0) {
85            }
86            else if(strcmp(buffer, "policy_spacial") == 0) {
87            }
88        }
89        else if(strcmp(buffer, "deregister_service") == 0) {
90            if(strcmp(buffer, "policy_geo") == 0) {
91            }
92            else if(strcmp(buffer, "policy_time") == 0) {
93            }
94            else if(strcmp(buffer, "policy_spectrum") == 0) {
95            }
96            else if(strcmp(buffer, "policy_spacial") == 0) {
97            }
98        }
99        else if(strcmp(buffer, "query_component_type") == 0) {
100            SendComponentType();
101        }
102        else if(strcmp(buffer, "reset_sml") == 0) {
103            Reset();
104        }
105        else if(strcmp(buffer, "shutdown_sml") == 0) {
106            Shutdown();
107        }
108    }
109}
110
111
112void
113ServiceManagementLayer::Shutdown()
114{
115    DeregisterComponent();
116}
117
118
119void
120ServiceManagementLayer::Reset()
121{
122    DeregisterComponent();
123    LoadConfiguration();
124}
125
126
127void
128ServiceManagementLayer::RegisterComponent()
129{
130    SendMessage(shellSocketFD, "register_sml");
131    LOG("ServiceManagementLayer:: Registration message sent.\n");
132}
133
134
135void
136ServiceManagementLayer::DeregisterComponent()
137{
138    SendMessage(shellSocketFD, "deregister_sml");
139    LOG("ServiceManagementLayer:: Deregistration message sent.\n");
140
141    shutdown(shellSocketFD, 2);
142    close(shellSocketFD);
143    shellSocketFD = -1;
144    LOG("ServiceManagementLayer:: Shell socket closed.\n");
145}
146
147
148void
149ServiceManagementLayer::TransferRadioConfiguration()
150{
151}
152
153
154void
155ServiceManagementLayer::TransferExperience()
156{
157}
158
159
160void
161ServiceManagementLayer::ReceiveServices()
162{
163}
164
165
166void
167ServiceManagementLayer::SetActiveMission()
168{
169}
170
171
172void
173ServiceManagementLayer::ListServices()
174{
175}
176
177
178void
179ServiceManagementLayer::ReloadConfiguration()
180{
181    LOG("ServiceManagementLayer:: Reloading Configuration.\n");
182}
183
184
185void
186ServiceManagementLayer::LoadConfiguration()
187{
188    LOG("ServiceManagementLayer:: Loading Configuration.\n");
189}
190
Note: See TracBrowser for help on using the browser.