Changeset 209
- Timestamp:
- 03/26/09 12:53:27 (15 years ago)
- Location:
- vtcross/trunk/src
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/include/vtcross/components.h
r208 r209 49 49 } 50 50 51 52 51 /* Send an indentfying string for this object's component type in 53 52 * response to a GetRemoteComponentType query. … … 55 54 virtual void SendComponentType() = 0; 56 55 57 58 56 /* Wait for a command signal containing task instructions. 59 57 */ 60 58 virtual void WaitForSignal() = 0; 61 59 62 63 60 /* Completely shutdown the radio and all operations. 64 61 */ 65 62 virtual void Shutdown() = 0; 66 67 63 68 64 /* Reset the radio and reload all configuration files. … … 71 67 */ 72 68 virtual void Reset() = 0; 73 74 69 75 70 /* Register or deregister a component with the primary radio shell. … … 97 92 const char* serverPort, const bool SML) = 0; 98 93 99 100 94 /* Register or deregister services that this engine provides with the 101 95 * service management layer. … … 140 134 void TransferRadioConfiguration(); 141 135 142 143 136 /* Receive information regarding a completed 'experience' and pass it on 144 137 * to the appropriate cognitive engine. 145 138 */ 146 139 void TransferExperience(); 147 148 140 149 141 /* Listen for other components registering their available services with … … 152 144 void ReceiveServices(); 153 145 154 155 146 /* Change the active mission of the radio to a new one and adjust radio 156 147 * behavoir appropriately. … … 158 149 void SetActiveMission(); 159 150 160 161 151 /* List all services provided to the radio by registered components. 162 152 */ 163 153 void ListServices(); 164 165 154 166 155 /* Load/Relead the XML configuration file. … … 169 158 void LoadConfiguration(); 170 159 171 172 160 /* The socket file descriptor information for the shell which this SML 173 161 * is connected to. … … 185 173 PolicyEngine(); 186 174 ~PolicyEngine(); 187 188 175 189 176 /* Overloaded constructor that creates a policy engine object and … … 211 198 void ReloadPolicies(); 212 199 213 214 200 /* Return a decision made by the policy engine regarding a certain set 215 201 * of transmission parameters. … … 218 204 int32_t decision_array[]); 219 205 220 221 206 /* Validate a set of transmission parameters received from the radio. 222 207 */ 223 208 void ValidateParameters(); 224 225 209 226 210 /* The SML_present bool reflects whether or not the remote component … … 261 245 void ReceiveRadioConfiguration(); 262 246 263 264 247 /* Receive an 'experience' report from the radio. 265 248 */ 266 249 void ReceiveExperience(); 267 268 250 269 251 /* Find the most optimal set of transmission parameters given certain … … 273 255 void GetSolution(Observable *observables); 274 256 void GetSolution(Observable *observables, std::string service); 275 276 257 277 258 /* Receive a feedback from the radio regarding the performance of a … … 303 284 ~CognitiveRadioShell(); 304 285 305 306 /* Overloaded constructor that creates a CR Shell object */ 286 /* Overloaded constructor that creates a CR Shell object and loads the 287 * passed radio configuration XML file. 288 */ 307 289 CognitiveRadioShell(const char* radioConfig, int16_t primaryPort, \ 308 290 int16_t policyPort, int16_t commandPort); … … 314 296 /* Start all the socket servers */ 315 297 void StartShellServer(); 298 316 299 int32_t LoadRadioConfiguration(const char* radioConfig, Parameter* &pList, \ 317 300 Utility* &uList, Observable* &oList, Radio_Info* radioInfo); … … 322 305 void ReloadPolicies(); 323 306 324 /* Register and Deregister the different components */ 307 /* Register and Deregister the different components. 308 */ 325 309 void RegisterCognitiveEngine(int32_t socketFD); 326 310 void DeregisterCognitiveEngine(int32_t socketFD); … … 330 314 void DeregisterSML(int32_t socketFD); 331 315 332 /* Handle a message that is received from a component */ 316 /* Handle a message that is received from a component. 317 */ 333 318 void HandleMessage(int32_t socketFD); 334 319 335 /* Send optimization request to primary port FD*/ 320 /* Send optimization request to primary port FD. 321 */ 336 322 void GetOptimalParameters(int32_t socketFD); 337 323 -
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);