Show
Ignore:
Timestamp:
05/17/10 03:14:03 (14 years ago)
Author:
nikhil
Message:
 
Location:
vtcross/branches/nikhil/crossmodel1
Files:
1 modified
1 copied

Legend:

Unmodified
Added
Removed
  • vtcross/branches/nikhil/crossmodel1/src/shell/CognitiveRadioShell.cpp

    r537 r554  
    183183        } 
    184184    } 
     185 
    185186     
    186187    /* Receive ACK for radio configuration */ 
     
    215216        return false; 
    216217    } 
     218 
    217219    return true; 
    218220} 
     
    252254} 
    253255 
    254  
    255 void 
    256 CognitiveRadioShell::RegisterPolicyEngine(int32_t socketFD) 
    257 { 
    258     LOG("Cognitive Radio Shell:: Received registration from Policy Engine on socket %d.\n", \ 
    259             socketFD); 
    260  
    261     PE_present = true; 
    262 } 
    263  
    264  
    265 void  
    266 CognitiveRadioShell::DeregisterPolicyEngine(int32_t socketFD) 
    267 { 
    268     LOG("Cognitive Radio Shell:: Received deregistration message from Policy Engine.\n"); 
    269  
    270     PE_present = false; 
    271      
    272     SendMessage(socketFD, "deregister_ack"); 
    273     shutdown(socketFD, 2); 
    274     close(socketFD); 
    275     LOG("Cognitive Radio Shell:: Socket %d closed.\n", socketFD); 
    276 } 
    277  
    278  
    279 void 
    280 CognitiveRadioShell::RegisterSML(int32_t socketFD) 
    281 { 
    282     LOG("Cognitive Radio Shell:: Received registration from SML on socket %d.\n", \ 
    283             socketFD); 
    284  
    285     SML_present = true; 
    286 } 
    287  
    288  
    289 void  
    290 CognitiveRadioShell::DeregisterSML(int32_t socketFD) 
    291 { 
    292     LOG("Cognitive Radio Shell:: Received deregistration message from SML.\n"); 
    293  
    294     SML_present = false; 
    295  
    296     SendMessage(socketFD, "deregister_ack"); 
    297     shutdown(socketFD, 2); 
    298     close(socketFD); 
    299     LOG("Cognitive Radio Shell:: Socket %d closed.\n", socketFD); 
    300 } 
    301  
    302 void  
    303 CognitiveRadioShell::SetActiveMission(int32_t socketFD) 
    304 { 
    305     char buffer[256]; 
    306  
    307     LOG("Cognitive Radio Shell:: Received Set Active Mission command from host.\n"); 
    308     
    309     /* Read the name of the active mission to be set from the host. */ 
    310     memset(buffer, 0, 256); 
    311     ReadMessage(commandSocketFD, buffer); 
    312  
    313     /* Send command to SML. */ 
    314     SendMessage(ceSocketFD, "set_active_mission"); 
    315     SendMessage(ceSocketFD, buffer); 
    316  
    317     /* Get ack from SML saying the mission was set properly */ 
    318     memset(buffer, 0, 256); 
    319     ReadMessage(ceSocketFD, buffer); 
    320  
    321     /* Forward ack to host */ 
    322     SendMessage(commandSocketFD, buffer); 
    323 } 
    324256 
    325257void  
     
    415347            } 
    416348 
    417             if(!match_found) {  
    418                 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
    419                     oList[item_count].name.c_str(), oUtilName); 
    420             } 
    421             else 
    422                 match_found = false;     
     349   
     350//////////////////WE are not looking for relationship between them..             
     351//            if(!match_found) {  
     352//                ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
     353//                    oList[item_count].name.c_str(), oUtilName); 
     354//            } 
     355//            else 
     356//                match_found = false;     
    423357        } 
    424358        oList[item_count].numAffects = affect_count;  
     
    476410            } 
    477411 
    478             if(!match_found) { 
    479                 ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
    480                     pList[item_count].name.c_str(), pUtilName); 
    481             } 
    482  
    483             match_found = false;     
     412//            if(!match_found) { 
     413//                ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
     414//                    pList[item_count].name.c_str(), pUtilName); 
     415//            } 
     416 
     417//            match_found = false;     
    484418        } 
    485419 
     
    536470        cp[i].value = atof(buffer); 
    537471    } 
     472////////////// NEW    INCLUSION /////////////////// 
     473 
     474/* Receive Set of Utilities */ 
     475    memset(buffer, 0, 256); 
     476    ReadMessage(commandSocketFD,buffer); 
     477    uint32_t numUtilities = atoi(buffer); 
     478 
     479    LOG("Cognitive Radio Shell:: Attempting to get %i utilities.\n",numUtilities); 
     480    Utility *u = new Utility[numUtilities]; 
     481 
     482    for (size_t i = 0;i < numUtilities; i++){ 
     483        memset(buffer, 0, 256); 
     484        ReadMessage(commandSocketFD,buffer); 
     485        u[i].name = std::string(buffer); 
     486 
     487        memset(buffer, 0, 256); 
     488        ReadMessage(commandSocketFD,buffer); 
     489        u[i].value = atof(buffer); 
     490    } 
     491 
     492/////////////////////////////////////// 
    538493 
    539494    /* Send to Cognitive Engine  
     
    541496     * to send this information 
    542497     */ 
     498    SendMessage(ceSocketFD,"request_optimization"); 
     499 
    543500    LOG("Cognitive Radio Shell:: Passing on observables.\n"); 
    544     SendMessage(ceSocketFD,"request_optimization"); 
    545501    sprintf(counter,"%i",numObservables); 
    546502    SendMessage(ceSocketFD,counter); 
     
    559515        SendMessage(ceSocketFD,var);  
    560516    } 
     517 
     518/////////////  NEW  //////////////////////////////////////////////////////// 
     519    LOG("Cognitive Radio Shell:: Passing on utilities.\n"); 
     520    sprintf(counter,"%i",numUtilities); 
     521    SendMessage(ceSocketFD,counter); 
     522    for(size_t i = 0; i < numUtilities; i++) { 
     523        SendMessage(ceSocketFD,u[i].name.c_str()); 
     524        sprintf(var,"%f",u[i].value); 
     525        SendMessage(ceSocketFD,var); 
     526    } 
     527 
     528////////////// END of NEW ///////////////////////////////////// 
    561529 
    562530    /* Receive Set of Parameters */ 
     
    591559 
    592560    delete [] o; 
     561    delete [] u; 
    593562    delete [] p; 
    594563} 
     
    634603        ReadMessage(commandSocketFD, buffer); 
    635604        o[i].value = atof(buffer); 
     605    } 
     606 
     607    /* Receive Set of Utilities */ 
     608    memset(buffer, 0, 256); 
     609    ReadMessage(commandSocketFD, buffer); 
     610    uint32_t numUtilities = atoi(buffer); 
     611 
     612    Utility *u = new Utility[numUtilities]; 
     613 
     614    for(size_t i = 0; i < numUtilities; i++) { 
     615        memset(buffer, 0, 256); 
     616        ReadMessage(commandSocketFD, buffer); 
     617        u[i].name = std::string(buffer); 
     618 
     619        memset(buffer, 0, 256); 
     620        ReadMessage(commandSocketFD, buffer); 
     621        u[i].value = atof(buffer); 
    636622    } 
    637623 
     
    650636     
    651637    /* Send Observables */ 
     638    memset(counter, 0, 55); 
    652639    sprintf(counter, "%i", numObservables); 
    653640    SendMessage(ceSocketFD, counter); 
     
    658645    }    
    659646 
     647     /* Send Utilities */ 
     648     memset(counter, 0, 55); 
     649     sprintf(counter, "%i", numUtilities); 
     650     SendMessage(ceSocketFD,counter); 
     651     for(size_t i = 0; i < numUtilities; i++) { 
     652        SendMessage(ceSocketFD, u[i].name.c_str()); 
     653        sprintf(var, "%f", u[i].value); 
     654        SendMessage(ceSocketFD, var); 
     655     } 
     656 
     657 
    660658    delete [] p; 
    661659    delete [] o; 
     660    delete [] u; 
    662661} 
    663662 
     
    678677    } else if(strcmp(buffer, "deregister_engine_cognitive") == 0) { 
    679678        DeregisterCognitiveEngine(socketFD); 
    680     } else if(strcmp(buffer, "register_engine_policy") == 0) { 
    681         RegisterPolicyEngine(socketFD); 
    682     } else if(strcmp(buffer, "deregister_engine_policy") == 0) { 
    683         DeregisterPolicyEngine(socketFD); 
    684     } else if(strcmp(buffer, "register_sml") == 0) { 
    685         RegisterSML(socketFD); 
    686     } else if(strcmp(buffer, "deregister_sml") == 0) { 
    687         DeregisterSML(socketFD); 
    688679    } else if(strcmp(buffer, "update_performance") == 0) { 
    689680        UpdateParameterPerformance(socketFD); 
     
    703694        /* Receive optimization request and current environment */ 
    704695        GetOptimalParameters(socketFD);   
    705     } else if(strcmp(buffer, "set_active_mission") == 0) { 
    706         SetActiveMission(socketFD);   
    707     } else if(strcmp(buffer, "request_optimization_service") == 0) { 
    708         /* Receive optimization request and current environment */ 
    709         //GetOptimalParametersService(socketFD);   
    710     } 
     696    }  
    711697 
    712698    return ret;