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.

RevLine 
[163]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{
[164]25    LOG("Creating Service Management Layer.\n");
[204]26    shellSocketFD = -1;
[164]27    LoadConfiguration();
[163]28}
29
30
31ServiceManagementLayer::~ServiceManagementLayer()
32{
33}
34
35
[204]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
[163]47void
[200]48ServiceManagementLayer::SendComponentType()
[163]49{
[204]50    SendMessage(shellSocketFD, "response_sml");
51    LOG("SML responded to GetRemoteComponentType query.\n");
[163]52}
53
54
55void
[204]56ServiceManagementLayer::ConnectToShell(const char* serverName, \
57        const char* serverPort)
[200]58{
[204]59    shellSocketFD = ClientSocket(serverName, serverPort);
60
61    RegisterComponent();
[200]62}
[164]63
[200]64
65void
66ServiceManagementLayer::WaitForSignal()
67{
[206]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    }
[163]109}
110
111
112void
113ServiceManagementLayer::Shutdown()
114{
[204]115    DeregisterComponent();
[163]116}
117
118
119void
120ServiceManagementLayer::Reset()
121{
[204]122    DeregisterComponent();
123    LoadConfiguration();
[163]124}
125
126
127void
[200]128ServiceManagementLayer::RegisterComponent()
[163]129{
[200]130    SendMessage(shellSocketFD, "register_sml");
[164]131    LOG("ServiceManagementLayer:: Registration message sent.\n");
[163]132}
133
134
135void
[200]136ServiceManagementLayer::DeregisterComponent()
[163]137{
[204]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");
[163]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{
[204]181    LOG("ServiceManagementLayer:: Reloading Configuration.\n");
[163]182}
183
184
185void
186ServiceManagementLayer::LoadConfiguration()
187{
[164]188    LOG("ServiceManagementLayer:: Loading Configuration.\n");
[163]189}
190
Note: See TracBrowser for help on using the browser.