Changeset 207
- Timestamp:
- 03/26/09 10:40:14 (15 years ago)
- Location:
- vtcross/trunk/src
- Files:
-
- 2 added
- 1 removed
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/include/vtcross/components.h
r203 r207 295 295 }; 296 296 297 /* Cognitive Radio Shell class declaration. 298 */ 299 class CognitiveRadioShell 300 { 301 public: 302 CognitiveRadioShell(); 303 ~CognitiveRadioShell(); 304 305 306 /* Overloaded constructor that creates a CR Shell object */ 307 CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \ 308 int16_t policyPort, int16_t commandPort); 309 310 void SendComponentType(int32_t socketFD); 311 void Shutdown(); 312 void Reset(); 313 314 /* Start all the socket servers */ 315 void StartShellServer(); 316 int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \ 317 Utility* &uList, Observable* &oList, Radio_Info* radioInfo); 318 private: 319 /* Parse and load/reload policies into the policy engine. 320 */ 321 void LoadPolicies(); 322 void ReloadPolicies(); 323 324 /* Register and Deregister the different components */ 325 void RegisterCognitiveEngine(int32_t socketFD); 326 void DeregisterCognitiveEngine(int32_t socketFD); 327 void RegisterPolicyEngine(int32_t socketFD); 328 void DeregisterPolicyEngine(int32_t socketFD); 329 void RegisterSML(int32_t socketFD); 330 void DeregisterSML(int32_t socketFD); 331 332 /* Handle a message that is received from a component */ 333 void HandleMessage(int32_t socketFD); 334 335 /* Send optimization request to primary port FD*/ 336 void GetOptimalParameters(int32_t socketFD); 337 338 void SendRadioConfiguration(int32_t socketFD); 339 void SendRadioExperience(int32_t socketFD); 340 341 bool SML_present; 342 bool PE_present; 343 bool CE_present; 344 345 int32_t numberOfCognitiveEngines; 346 int16_t primaryPort; 347 int16_t policyPort; 348 int16_t commandPort; 349 350 Utility * u; 351 Parameter * p; 352 Observable * o; 353 struct Radio_Info * radio_info; 354 }; 355 297 356 #endif -
vtcross/trunk/src/include/vtcross/socketcomm.h
r195 r207 60 60 Observable* oList[], Radio_Info* radio_info); 61 61 62 int32_t InitializeTCPServerPort(int32_t servSock); 63 62 64 #endif -
vtcross/trunk/src/lib/socketcomm/socketcomm.cpp
r195 r207 12 12 #include <cstdlib> 13 13 #include <cstring> 14 #include <iostream> 15 #include <fcntl.h> 16 #include <sys/ioctl.h> 14 17 #include <netdb.h> 15 18 #include <netinet/in.h> … … 34 37 ReadMessage(int32_t socketFD, char* msgBuffer) 35 38 { 39 40 // Peek at the buffer to get real message length. 41 // Messages are termination with a "\0" to denote EOM. 36 42 ssize_t msgLength = recv(socketFD, msgBuffer, 256, MSG_PEEK); 37 43 … … 42 48 } 43 49 50 // Read the message into msgBuffer 44 51 msgLength = recv(socketFD, msgBuffer, i + 1, 0); 45 52 if (msgLength < 0) … … 202 209 203 210 int32_t clientSocket = accept(serverSock, NULL, NULL); 204 if(clientSocket < 0) 205 ERROR(1, "Could not establish connection with client socket.\n"); 206 207 LOG("Handling client %s\n", inet_ntoa(echoClientAddr.sin_addr)); 211 if(clientSocket < 0) { 212 //ERROR(1, "Could not establish connection with client socket.\n"); 213 return -1; 214 } 215 //LOG("Handling client %s\n", inet_ntoa(echoClientAddr.sin_addr)); 208 216 209 217 return clientSocket; … … 238 246 } 239 247 248 int32_t 249 InitializeTCPServerPort(int32_t servSock) 250 { 251 252 int32_t rc, on = 1; 253 254 rc = setsockopt(servSock, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)); 255 if(rc < 0) 256 { 257 ERROR(1,"setsockopt() failed\n"); 258 close(servSock); 259 return -1; 260 } 261 262 rc = ioctl(servSock, FIONBIO, (char*)&on); 263 if(rc < 0) 264 { 265 ERROR(1,"ioctl() failed\n"); 266 close(servSock); 267 return -1; 268 } 269 270 return 1; 271 } -
vtcross/trunk/src/shell/Makefile.am
r168 r207 5 5 bin_PROGRAMS = shell_demo 6 6 7 shell_demo_SOURCES = cr_shell.cpp7 shell_demo_SOURCES = CognitiveRadioShell.cpp shell_demo.cpp 8 8 shell_demo_LDADD = ../lib/tinyxml/libtinyxml.a ../lib/socketcomm/libsocketcomm.a 9 9