Changeset 209 for vtcross/trunk/src/shell/CognitiveRadioShell.cpp
- Timestamp:
- 03/26/09 12:53:27 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/shell/CognitiveRadioShell.cpp
r208 r209 62 62 radio_info = new Radio_Info; 63 63 64 65 64 LoadRadioConfiguration(radioConfig,p,u,o,radio_info); 66 65 … … 78 77 } 79 78 79 80 80 void 81 81 CognitiveRadioShell::Shutdown() … … 98 98 } 99 99 100 100 101 void 101 102 CognitiveRadioShell::SendRadioExperience(int32_t socketFD) … … 104 105 LOG("Cognitive Radio Shell:: Sending radio experience to Cognitive Engine.\n"); 105 106 } 107 106 108 107 109 void … … 117 119 } 118 120 121 119 122 void 120 123 CognitiveRadioShell::DeregisterCognitiveEngine(int32_t socketFD) … … 124 127 numberOfCognitiveEngines--; 125 128 if(numberOfCognitiveEngines == 0) 126 CE_present = false;129 CE_present = false; 127 130 128 131 SendMessage(socketFD, "deregister_ack"); … … 132 135 } 133 136 137 134 138 void 135 139 CognitiveRadioShell::RegisterPolicyEngine(int32_t socketFD) … … 138 142 PE_present = true; 139 143 } 144 140 145 141 146 void … … 152 157 } 153 158 159 154 160 void 155 161 CognitiveRadioShell::RegisterSML(int32_t socketFD) … … 159 165 SML_present = true; 160 166 } 167 161 168 162 169 void … … 173 180 } 174 181 182 175 183 int32_t 176 CognitiveRadioShell::LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \ 177 Utility* &uList, Observable* &oList, Radio_Info * radioInfo) 184 CognitiveRadioShell::LoadRadioConfiguration(const char* radioConfig, \ 185 Parameter* &pList, Utility* &uList, Observable* &oList, \ 186 Radio_Info* radioInfo) 178 187 { 179 188 TiXmlElement *pElem; … … 193 202 TiXmlDocument doc( radioConfig ); 194 203 bool loadOkay = doc.LoadFile(); 195 if(!loadOkay) 196 { 204 if(!loadOkay) { 197 205 ERROR(1,"Loading radio configuration failed: %s\n", radioConfig); 198 206 return -1; … … 212 220 213 221 for(pChild = pChild1->FirstChildElement("utility"); pChild; \ 214 pChild = pChild->NextSiblingElement()) 215 { 222 pChild = pChild->NextSiblingElement()) { 223 216 224 const char *uName = pChild->Attribute("name"); 217 225 if(uName) … … 240 248 241 249 for(pChild = pChild1->FirstChildElement("observable"); pChild; \ 242 pChild = pChild->NextSiblingElement()) 243 { 250 pChild = pChild->NextSiblingElement()) { 251 244 252 const char *oName = pChild->Attribute("name"); 245 253 if(oName) … … 248 256 affect_count = 0; 249 257 for(pSecondChild = pChild->FirstChildElement("affect"); pSecondChild; \ 250 pSecondChild = pSecondChild->NextSiblingElement()) 251 { 258 pSecondChild = pSecondChild->NextSiblingElement()) { 259 252 260 const char *oUtilName = pSecondChild->Attribute("utility"); 253 if(oUtilName) 254 { 255 for(attribute_count = 0; attribute_count < radio_info->numUtilities; attribute_count++ ) 256 { 257 if(uList[attribute_count].name == oUtilName) 258 { 261 if(oUtilName) { 262 for(attribute_count = 0; attribute_count < radio_info->numUtilities; attribute_count++ ) { 263 if(uList[attribute_count].name == oUtilName) { 264 259 265 oList[item_count].affection_list[affect_count].u = &uList[attribute_count]; 260 266 const char *oRelate = pSecondChild->Attribute("relationship"); 261 267 if(oRelate) 262 268 oList[item_count].affection_list[affect_count].relation = oRelate; 269 263 270 affect_count++; 264 271 match_found = true; … … 287 294 item_count = 0; 288 295 for(pChild = pChild1->FirstChildElement("parameter"); pChild; \ 289 pChild = pChild->NextSiblingElement()) 290 { 296 pChild = pChild->NextSiblingElement()) { 297 291 298 const char *pName = pChild->Attribute("name"); 292 299 if(pName) … … 308 315 affect_count = 0; 309 316 for(pSecondChild = pChild->FirstChildElement("affect"); pSecondChild; \ 310 pSecondChild = pSecondChild->NextSiblingElement()) 311 {317 318 pSecondChild = pSecondChild->NextSiblingElement()) { 312 319 const char *pUtilName = pSecondChild->Attribute("utility"); 313 if(pUtilName) 314 { 315 for(attribute_count = 0; attribute_count < radio_info->numUtilities; attribute_count++) 316 { 317 if(uList[attribute_count].name == pUtilName) 318 { 320 if(pUtilName) { 321 for(attribute_count = 0; attribute_count < radio_info->numUtilities; attribute_count++) { 322 if(uList[attribute_count].name == pUtilName) { 319 323 pList[item_count].affection_list[affect_count].u = &uList[attribute_count]; 320 324 … … 332 336 } 333 337 334 if(!match_found) 335 { 338 if(!match_found) { 336 339 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 337 340 pList[item_count].name.c_str(), pUtilName); … … 352 355 } 353 356 357 354 358 void 355 359 CognitiveRadioShell::GetOptimalParameters(int32_t socketFD) 356 360 { 357 358 359 } 361 } 362 360 363 361 364 void … … 384 387 } 385 388 389 386 390 void 387 391 CognitiveRadioShell::StartShellServer() … … 421 425 } 422 426 423 while (running) 424 { 427 while (running) { 425 428 /* Zero socket descriptor vector and set for server sockets */ 426 429 /* This must be reset every time select() is called */ … … 437 440 /* Suspend program until descriptor is ready or timeout */ 438 441 rc = select(maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout); 439 if 442 if(rc == 0) 440 443 LOG("No echo requests for %i secs...Server still alive\n", timeout); 441 else 442 { 444 else { 443 445 desc_ready = rc; 444 446 445 for (port = 0; port <= maxDescriptor && desc_ready > 0; port++) { 446 if (FD_ISSET(port, &sockSet)) 447 { 448 desc_ready -= 1; 447 for(port = 0; port <= maxDescriptor && desc_ready > 0; port++) { 448 if(FD_ISSET(port, &sockSet)) { 449 desc_ready -= 1; 449 450 450 451 /* Check if request is new or on an existing open descriptor */ 451 if( (port == servSock[primary]) || (port == servSock[policy]) || (port == servSock[command])) { 452 do 453 { 452 if((port == servSock[primary]) || (port == servSock[policy]) || (port == servSock[command])) { 453 do { 454 454 new_sd = AcceptTCPConnection(port); 455 455 if(new_sd < 0) 456 {457 456 break; 458 }459 457 460 458 HandleMessage(new_sd); … … 464 462 //LOG("New incoming connection - %i\n\n",new_sd); 465 463 } while(new_sd != -1); 466 } else {467 464 } 465 else { 468 466 //LOG("Request on already open descriptor.\n\n"); 469 467 HandleMessage(port);