Changeset 250 for vtcross/branches
- Timestamp:
- 05/13/09 17:06:09 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/wrodgers/ServiceManagementLayer.cpp
r249 r250 7 7 /* DESCRIPTION OF FILE. 8 8 */ 9 test10 9 11 10 #include <cstdlib> … … 38 37 #include <sys/wait.h> 39 38 40 #include "tinyxml/tinyxml.h" 41 #include "tinyxml/tinystr.h" 42 43 #include <sqlite3.h> 44 #include <sqlite3ext.h> 45 46 uint32_t Current_ID = 0; 47 uint32_t numCogEnginesPresent = 0; 48 bool cogEnginePresent = false; 39 #include "../../trunk/src/include/tinyxml/tinyxml.h" 40 #include "../../trunk/src/include/tinyxml/tinystr.h" 41 42 49 43 50 44 … … 53 47 LOG("Creating Service Management Layer.\n"); 54 48 shellSocketFD = -1; 49 numberOfCognitiveEngines = 0; 50 CE_Present = false; 51 cogEngSrv = 1; 52 53 Current_ID = 0; 55 54 LoadConfiguration(); 56 numberOfCognitiveEngines = 0;57 55 } 58 56 … … 150 148 } 151 149 152 void153 ServiceManagementLayer::RegisterCognitiveEngine(int32_t ID)154 {155 LOG("Cognitive Radio Shell:: Received registration message from Cognitive Engine.\n");156 157 TransferRadioConfiguration(ID);158 TransferExperience(ID);159 160 numberOfCognitiveEngines++;161 CE_present = true;162 }163 164 165 void166 ServiceManagementLayer::DeregisterCognitiveEngine(int32_t socketFD)167 {168 LOG("Cognitive Radio Shell:: Received deregistration message from Cognitive Engine.\n");169 170 numberOfCognitiveEngines--;171 if(numberOfCognitiveEngines == 0)172 CE_present = false;173 174 SendMessage(socketFD, "deregister_ack");175 shutdown(socketFD, 2);176 close(socketFD);177 LOG("Cognitive Radio Shell:: Socket closed.\n");178 }179 150 180 151 … … 261 232 ServiceManagementLayer::RegisterCognitiveEngine(int32_t socketFD) 262 233 { 263 SendMessage( commandSocketFD, "register_engine_cognitive");234 SendMessage(shellSocketFD, "register_engine_cognitive"); 264 235 LOG("Cognitive Engine:: Registration message sent to shell.\n"); 265 236 … … 268 239 269 240 numberOfCognitiveEngines++; 270 CE_ present = true;241 CE_Present = true; 271 242 } 272 243 … … 279 250 numberOfCognitiveEngines--; 280 251 if(numberOfCognitiveEngines == 0) 281 CE_ present = false;252 CE_Present = false; 282 253 283 254 SendMessage(socketFD, "deregister_ack"); … … 295 266 int32_t desc_ready = 1; 296 267 int32_t timeout = 10; 297 fd_set sockSet [1];268 fd_set sockSet; 298 269 299 270 cogEngSrv = CreateTCPServerSocket(CEPort); 300 271 int32_t maxDescriptor = cogEngSrv; 301 272 302 if(Initia numberOfCognitiveEngineslizeTCPServerPort(cogEngSrv) == -1)273 if(InitializeTCPServerPort(cogEngSrv) == -1) 303 274 ERROR(1,"Error initializing primary port\n"); 304 275 … … 325 296 char buffer[256]; 326 297 memset(buffer, 0, 256); 327 sockaddr_in sock_addr = new sockaddr_in; 298 struct sockaddr_in sock_addr; 299 memset((void *) &sock_addr, 0, sizeof(sock_addr)); 328 300 //Peak at the next message on the socket to determine its address of orgin 329 recvfrom(cogEngSrv, buffer, 256, MSG_PE AK, (struct sockaddr*) &sock_addr, NULL);301 recvfrom(cogEngSrv, buffer, 256, MSG_PEEK, (struct sockaddr*) &sock_addr, NULL); 330 302 bool found = false; 331 303 //Is it from a previously logged address? 332 304 for(int i = 0; i < Current_ID; i++){ 333 if( CE_List[i].(*sock_ptr).sin_addr.s_addr == sock_addr.sin_addr.s_addr){305 if((*CE_List[i].sock_ptr).sin_addr.s_addr == sock_addr.sin_addr.s_addr){ 334 306 //If so, pass the ID number of that component into the signal handler to process the message 307 found=true; 335 308 CESignalHandler(i); 336 found=true;337 309 } 338 310 } … … 342 314 CE_List[Current_ID].ID_num = Current_ID; 343 315 CESignalHandler(Current_ID); 344 Current ID++;316 Current_ID++; 345 317 } 346 318 }