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 | |
---|
23 | ServiceManagementLayer::ServiceManagementLayer() |
---|
24 | { |
---|
25 | LOG("Creating Service Management Layer.\n"); |
---|
26 | shellSocketFD = -1; |
---|
27 | LoadConfiguration(); |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | ServiceManagementLayer::~ServiceManagementLayer() |
---|
32 | { |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | ServiceManagementLayer::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 | |
---|
47 | void |
---|
48 | ServiceManagementLayer::SendComponentType() |
---|
49 | { |
---|
50 | SendMessage(shellSocketFD, "response_sml"); |
---|
51 | LOG("SML responded to GetRemoteComponentType query.\n"); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void |
---|
56 | ServiceManagementLayer::ConnectToShell(const char* serverName, \ |
---|
57 | const char* serverPort) |
---|
58 | { |
---|
59 | shellSocketFD = ClientSocket(serverName, serverPort); |
---|
60 | |
---|
61 | RegisterComponent(); |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void |
---|
66 | ServiceManagementLayer::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 | |
---|
112 | void |
---|
113 | ServiceManagementLayer::Shutdown() |
---|
114 | { |
---|
115 | DeregisterComponent(); |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | void |
---|
120 | ServiceManagementLayer::Reset() |
---|
121 | { |
---|
122 | DeregisterComponent(); |
---|
123 | LoadConfiguration(); |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | void |
---|
128 | ServiceManagementLayer::RegisterComponent() |
---|
129 | { |
---|
130 | SendMessage(shellSocketFD, "register_sml"); |
---|
131 | LOG("ServiceManagementLayer:: Registration message sent.\n"); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | void |
---|
136 | ServiceManagementLayer::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 | |
---|
148 | void |
---|
149 | ServiceManagementLayer::TransferRadioConfiguration() |
---|
150 | { |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | void |
---|
155 | ServiceManagementLayer::TransferExperience() |
---|
156 | { |
---|
157 | } |
---|
158 | |
---|
159 | |
---|
160 | void |
---|
161 | ServiceManagementLayer::ReceiveServices() |
---|
162 | { |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | void |
---|
167 | ServiceManagementLayer::SetActiveMission() |
---|
168 | { |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | void |
---|
173 | ServiceManagementLayer::ListServices() |
---|
174 | { |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | void |
---|
179 | ServiceManagementLayer::ReloadConfiguration() |
---|
180 | { |
---|
181 | LOG("ServiceManagementLayer:: Reloading Configuration.\n"); |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | void |
---|
186 | ServiceManagementLayer::LoadConfiguration() |
---|
187 | { |
---|
188 | LOG("ServiceManagementLayer:: Loading Configuration.\n"); |
---|
189 | } |
---|
190 | |
---|