Changeset 175

Show
Ignore:
Timestamp:
03/21/09 17:06:47 (15 years ago)
Author:
bhilburn
Message:

Got the shell over to using the proper SendMessage?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/shell/cr_shell.cpp

    r169 r175  
    4343{ 
    4444        for(size_t i = 0; i < ce_info->numUtilities ; i++) { 
    45         LOG("Shell:: Utility: %s\n\tUnits: %s\n\tGoal: %s\n\tTarget: %s\n", \ 
    46                 uList[i]->name, uList[i]->units, uList[i]->goal, \ 
    47                 uList[i]->target); 
     45        LOG("Shell:: Utility: %s\n\tUnits: %s\n\tGoal: %s\n\tTarget: %f\n", \ 
     46                uList[i]->name.c_str(), uList[i]->units.c_str(), \ 
     47                uList[i]->goal.c_str(), uList[i]->target); 
    4848        } 
    4949 
    5050        for(size_t i = 0; i < ce_info->numParameters; i++) { 
    5151            LOG("Shell:: Radio Operation Profile has been sucessfully sent.\n"); 
    52         LOG("Shell:: Parameter: %s\n\tUnits: %s\n\tMin: %s\n\t", \ 
    53                 pList[i]->name, pList[i]->units, pList[i]->min); 
    54         LOG("\tMax: %s\n\tStep: %s\n", pList[i]->max, pList[i]->step); 
     52        LOG("Shell:: Parameter: %s\n\tUnits: %s\n\tMin: %f\n\t", \ 
     53                pList[i]->name.c_str(), pList[i]->units.c_str(), \ 
     54                pList[i]->min); 
     55        LOG("\tMax: %f\n\tStep: %f\n", pList[i]->max, pList[i]->step); 
    5556 
    5657                for(size_t j = 0; j < pList[i]->numAffects; j++) { 
    57                         LOG("\t\tAffect %s -> %s\n", pList[i]->affection_list[j].u->name, \ 
    58                     pList[i]->affection_list[j].relation); 
     58                        LOG("\t\tAffect %s -> %s\n", pList[i]->affection_list[j].u->name.c_str(), \ 
     59                    pList[i]->affection_list[j].relation.c_str()); 
    5960                } 
    6061        } 
    6162         
    6263    for(size_t i = 0; i < ce_info->numObservables; i++) { 
    63                 LOG("Observable: %s\n", oList[i]->name); 
     64                LOG("Observable: %s\n", oList[i]->name.c_str()); 
    6465 
    6566                for(size_t j = 0; j < oList[i]->numAffects; j++) { 
    66                         LOG("\t\tAffect %s -> %s ", oList[i]->affection_list[j].u->name, \ 
    67                     oList[i]->affection_list[j].relation); 
     67                        LOG("\t\tAffect %s -> %s ", oList[i]->affection_list[j].u->name.c_str(), \ 
     68                    oList[i]->affection_list[j].relation.c_str()); 
    6869                } 
    6970        } 
     
    7172 
    7273 
     74// TODO should this function really be called parse 'ce' config?  Seems like it 
     75// affects the entire radio? 
     76// TODO Why are we always returning 1? Is this just a success variable? It's not 
     77// even being used when we call it... 
     78// TODO this function needs some serious comments 
    7379int32_t 
    7480parse_ce_config(TiXmlDocument* doc, Utility* u[], Parameter* p[], \ 
     
    116122            u[item_count]->goal = uGoal; 
    117123 
    118                 if(pChild->QueryFloatAttribute("target", &u[i]->target) != TIXML_SUCCESS)  
    119             u[i]->target = -1; 
     124                if(pChild->QueryFloatAttribute("target", &u[item_count]->target) != TIXML_SUCCESS)  
     125            u[item_count]->target = -1; 
    120126 
    121127                item_count++; 
     
    143149                        const char *oUtilName = pSecondChild->Attribute("utility"); 
    144150                        if(oUtilName) { 
    145                                 for(attribute_count = 0; u[attribute_count]! = NULL; attribute_count++ ) { 
     151                                for(attribute_count = 0; u[attribute_count] != NULL; attribute_count++ ) { 
    146152                                        if(u[attribute_count]->name == oUtilName) { 
    147                                                 o[i]->affection_list[affect_count].u = u[attribute_count]; 
     153                                                o[item_count]->affection_list[affect_count].u = u[attribute_count]; 
    148154 
    149155                                                const char *oRelate = pSecondChild->Attribute("relationship"); 
     
    158164                        } 
    159165 
    160                         if(!match_found)  
     166                        if(!match_found) {  
    161167                ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
    162                         o[i]->name, oUtilName); 
     168                        o[item_count]->name.c_str(), oUtilName); 
     169            } 
    163170            else 
    164171                match_found = false;     
     
    189196            p[item_count]->units = pUnits; 
    190197 
    191                 if(pChild->QueryFloatAttribute("min", &p[i]->min) != TIXML_SUCCESS)  
     198                if(pChild->QueryFloatAttribute("min", &p[item_count]->min) != TIXML_SUCCESS)  
    192199            p[item_count]->min = -1; 
    193200 
    194                 if(pChild->QueryFloatAttribute("max", &p[i]->max) != TIXML_SUCCESS)  
     201                if(pChild->QueryFloatAttribute("max", &p[item_count]->max) != TIXML_SUCCESS)  
    195202            p[item_count]->max = -1; 
    196203 
    197                 if(pChild->QueryFloatAttribute("step", &p[i]->step) != TIXML_SUCCESS)  
     204                if(pChild->QueryFloatAttribute("step", &p[item_count]->step) != TIXML_SUCCESS)  
    198205            p[item_count]->step = -1; 
    199206                 
     
    223230                        if(!match_found) { 
    224231                ERROR(1, "Error: %s: %s is not a valid utility.\n", \ 
    225                         p[item_count]->name, pUtilName); 
     232                        p[item_count]->name.c_str(), pUtilName); 
    226233            } 
    227234 
     
    237244 
    238245        return 1; 
    239 } 
    240  
    241  
    242 int32_t  
    243 ReceiveMessage(int32_t socket, char* buffer)  
    244 { 
    245     int32_t i,n; 
    246     
    247     n = recv(socket,buffer,256,MSG_PEEK); 
    248      
    249     for(i=0;i<256;i++){ 
    250         if(strcmp(&buffer[i],"\0") == 0) break; 
    251     } 
    252     n = recv(socket,buffer,i+1,0); 
    253     if (n < 0) 
    254         ERROR(1, "Error reading from socket!\n"); 
    255     //    printf("ReadMessage:%s %d\n",buffer,n); 
    256  
    257     return n; 
    258 } 
    259  
    260  
    261 int32_t 
    262 SendMessage(int32_t socketfd, string message)  
    263 { 
    264         int32_t n; 
    265  
    266         message.append("\0");    
    267         // Write message back to client 
    268     n = send(socketfd,message.c_str(),(message.size()+1),0); 
    269     if (n<0) 
    270         ERROR(1, "Error sending to client\n"); 
    271     if(n == 0) 
    272         printf("Client closed the socket.\n"); 
    273  
    274         //printf("SendMessage:%s %d\n",message.c_str(),n);       
    275     return n; 
    276246} 
    277247 
     
    292262        // send utility  
    293263    for(i = 0; i < ce_info->numUtilities; i++) { 
    294                 SendMessage(socketfd,uList[i]->name); 
    295                 SendMessage(socketfd,uList[i]->units); 
    296                 SendMessage(socketfd,uList[i]->goal); 
    297                 sprintf(var,"%f",uList[i]->target); 
     264                SendMessage(socketfd, uList[i]->name.c_str()); 
     265                SendMessage(socketfd, uList[i]->units.c_str()); 
     266                SendMessage(socketfd, uList[i]->goal.c_str()); 
     267                sprintf(var,"%f", uList[i]->target); 
    298268                SendMessage(socketfd,var); 
    299269        } 
     
    303273        SendMessage(socketfd,counter); 
    304274        for(i = 0; i < ce_info->numParameters; i++) { 
    305                 SendMessage(socketfd,pList[i]->name); 
    306                 SendMessage(socketfd,pList[i]->units); 
     275                SendMessage(socketfd,pList[i]->name.c_str()); 
     276                SendMessage(socketfd,pList[i]->units.c_str()); 
    307277                sprintf(var,"%f",pList[i]->min); 
    308278                SendMessage(socketfd,var); 
     
    315285                SendMessage(socketfd,counter); 
    316286                for(j = 0; j < pList[i]->numAffects; j++) { 
    317                         SendMessage(socketfd,pList[i]->affection_list[j].u->name); 
    318                         SendMessage(socketfd,pList[i]->affection_list[j].relation); 
     287                        SendMessage(socketfd,pList[i]->affection_list[j].u->name.c_str()); 
     288                        SendMessage(socketfd,pList[i]->affection_list[j].relation.c_str()); 
    319289                } 
    320290        } 
     
    324294        SendMessage(socketfd,counter); 
    325295        for(i = 0; i < ce_info->numObservables; i++) { 
    326                 SendMessage(socketfd,oList[i]->name); 
     296                SendMessage(socketfd,oList[i]->name.c_str()); 
    327297                 
    328298                sprintf(counter,"%i",oList[i]->numAffects);  
    329299                SendMessage(socketfd,counter); 
    330300                for(j = 0; j < oList[i]->numAffects; j++) { 
    331                         SendMessage(socketfd,oList[i]->affection_list[j].u->name); 
    332                         SendMessage(socketfd,oList[i]->affection_list[j].relation); 
     301                        SendMessage(socketfd,oList[i]->affection_list[j].u->name.c_str()); 
     302                        SendMessage(socketfd,oList[i]->affection_list[j].relation.c_str()); 
    333303                } 
    334304        } 
     
    337307    char buffer[256]; 
    338308        string message; 
    339         n = ReceiveMessage(socketfd, buffer); 
     309        ReadMessage(socketfd, buffer); 
    340310    //printf("%s\n", buffer); 
    341311        //cout << message << endl; 
     
    399369        char var[50]; 
    400370    int32_t i; 
    401     string control_msg; 
     371    char* control_msg = "val"; 
    402372     
    403373    int32_t socketfd = ce_info->policy_socket; 
    404374 
    405375    // Control message that validation request is coming 
    406     control_msg = "val"; 
    407376        SendMessage(socketfd,control_msg); 
    408377 
     
    413382        SendMessage(socketfd,counter); 
    414383        for(i = 0; i < ce_info->numParameters; i++) { 
    415                 SendMessage(socketfd,pList[i]->name); 
    416                 SendMessage(socketfd,pList[i]->units); 
     384                SendMessage(socketfd,pList[i]->name.c_str()); 
     385                SendMessage(socketfd,pList[i]->units.c_str()); 
    417386                sprintf(var,"%f",pList[i]->min); 
    418387                SendMessage(socketfd,var); 
     
    449418    for (i = 0; i < ce_info->numParameters; i++){ 
    450419        bzero(buffer,256); 
    451         ReceiveMessage(sockfd,buffer); 
     420        ReadMessage(sockfd,buffer); 
    452421        var = atof(buffer); 
    453422        pList[i]->value = var; 
     
    594563    /* Receive message from client */ 
    595564    bzero(buffer,256); 
    596     ReceiveMessage(socketfd,buffer); 
     565    ReadMessage(socketfd,buffer); 
    597566 
    598567    printf("Cognitive Radio:: Message Received - %s.\n\n", buffer);