Changeset 194

Show
Ignore:
Timestamp:
03/23/09 21:29:50 (15 years ago)
Author:
bhilburn
Message:

Finished implementing basic structure of WaitForSignal?, added new
functions to components to allow proper response to component type
queries, modularized the connect & register step for engines, and added
a few TODOs in areas that need review. This is an abnormally large
commit.

Location:
vtcross/trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/include/vtcross/components.h

    r193 r194  
    4949        } 
    5050 
     51         
     52        /* Send an indentfying string for this object's component type in 
     53         * response to a GetRemoteComponentType query. 
     54         */ 
     55        virtual void SendComponentType() = 0; 
     56 
     57 
     58        /* Connect to the remote control component, which will always be either 
     59         * the VTCROSS shell or SML.  Based on the status of the SML_present 
     60         * bool, this function will also register the component or services. 
     61         * 
     62         * TODO I feel like the name of this function could be changed to be a 
     63         * little more descriptive? 
     64         */ 
     65        virtual void ConnectToRemoteComponent(const char* serverName, \ 
     66                const char* serverPort) = 0; 
    5167 
    5268        /* Wait for a command signal containing task instructions. 
     
    99115        ~ServiceManagementLayer(); 
    100116 
     117        void SendComponentType(); 
     118        void ConnectToRemoteComponent(const char* serverName, \ 
     119                const char* serverPort); 
    101120        void WaitForSignal(); 
    102121        void Shutdown(); 
     
    164183                const bool SML); 
    165184 
     185        void SendComponentType(); 
     186        void ConnectToRemoteComponent(const char* serverName, \ 
     187                const char* serverPort); 
    166188        void WaitForSignal(); 
    167189        void Shutdown(); 
     
    189211        /* Validate a set of transmission parameters received from the radio. 
    190212         */ 
    191         void ValidateParameters(struct Parameter pList[], \ 
    192                 struct CE_Info *ce_info, int decision_array[]); 
     213        void ValidateParameters(); 
    193214 
    194215 
     
    212233        ~CognitiveEngine(); 
    213234 
     235        void SendComponentType(); 
     236        void ConnectToRemoteComponent(const char* serverName, \ 
     237                const char* serverPort); 
    214238        void WaitForSignal(); 
    215239        void Shutdown(); 
  • vtcross/trunk/src/policy_engines/PolicyEngine.cpp

    r193 r194  
    4040 
    4141    SML_present = SML; 
    42  
     42     
     43    ConnectToRemoteComponent(serverName, serverPort); 
     44 
     45    LoadPolicies(); 
     46} 
     47 
     48 
     49void 
     50PolicyEngine::SendComponentType() 
     51{ 
     52    SendMessage(commandSocketFD, "response_engine_policy"); 
     53    LOG("Policy Engine responded to GetRemoteComponentType query.\n"); 
     54} 
     55 
     56 
     57void 
     58PolicyEngine::ConnectToRemoteComponent(const char* serverName, \ 
     59        const char* serverPort) 
     60{ 
    4361    commandSocketFD = ClientSocket(serverName, serverPort); 
    4462 
     
    5169        LOG("Policy Engine connected to shell at %s.\n", serverName); 
    5270    } 
    53  
    54     LoadPolicies(); 
    5571} 
    5672 
     
    5975PolicyEngine::WaitForSignal() 
    6076{ 
    61     LOG("Policy Engine:: Waiting for Policy Check Request.\n"); 
    62  
    63     int32_t decision_array[10]; 
    64     struct Parameter pList[10]; 
    65     struct CE_Info ce_info; 
    66  
    67     // TODO should this be a GetRequest call or something else? 
    68     if(GetRequest(commandSocketFD, pList, &ce_info)) { 
    69         LOG("Policy Engine:: Validating Transmission Parameters.\n"); 
    70         ValidateParameters(pList, &ce_info, decision_array);     
    71  
    72         LOG("Policy Engine:: Sending Policy decision to Server.\n"); 
    73         SendPEDecision(pList, &ce_info, decision_array); 
     77    char buffer[256]; 
     78 
     79    while(true) { 
     80        memset(buffer, 0, 256); 
     81        
     82        ReadMessage(commandSocketFD, buffer); 
     83 
     84        // TODO this is ugly... is there a better way? Doesn't strcmp compare the 
     85        // whole string?  We only need to compare until we find a single different 
     86        // byte... 
     87        if(strcmp(buffer, "validate_parameters") == 0) { 
     88            ValidateParameters(); 
     89        } 
     90        else if(strcmp(buffer, "query_component_type") == 0) { 
     91            SendComponentType(); 
     92        } 
     93        else if(strcmp(buffer, "connect_sml") == 0) { 
     94            /* This command implies that we are disconnecting from the shell and 
     95             * connecting to a SML component. */ 
     96            char serverName[256]; 
     97            char serverPort[256]; 
     98            // TODO is this going to end up being too slow? 
     99            memset(serverName, 0, 256); 
     100            memset(serverPort, 0, 256); 
     101 
     102            ReadMessage(commandSocketFD, serverName); 
     103            ReadMessage(commandSocketFD, serverPort); 
     104 
     105            /* Only continue if we are currently connected to a shell. */ 
     106            if(!SML_present) { 
     107                DeregisterComponent(); 
     108 
     109                shutdown(commandSocketFD, 2); 
     110                close(commandSocketFD); 
     111 
     112                SML_present = true; 
     113 
     114                ConnectToRemoteComponent(serverName, serverPort); 
     115            } 
     116        } 
     117        else if(strcmp(buffer, "disconnect_sml") == 0) { 
     118            /* This command implies that we are disconnecting from the SML and 
     119             * connecting to a shell component. */ 
     120            char serverName[256]; 
     121            char serverPort[256]; 
     122            // TODO is this going to end up being too slow? 
     123            memset(serverName, 0, 256); 
     124            memset(serverPort, 0, 256); 
     125 
     126            ReadMessage(commandSocketFD, serverName); 
     127            ReadMessage(commandSocketFD, serverPort); 
     128 
     129            /* We only want to do this if we are actually connected to an SML 
     130             * currently. */ 
     131            if(SML_present) { 
     132                DeregisterServices(); 
     133 
     134                shutdown(commandSocketFD, 2); 
     135                close(commandSocketFD); 
     136 
     137                SML_present = false; 
     138 
     139                ConnectToRemoteComponent(serverName, serverPort); 
     140            } 
     141        } 
     142        else if(strcmp(buffer, "relead_engine_configs") == 0) { 
     143            ReloadPolicies(); 
     144        } 
     145        else if(strcmp(buffer, "reset_engine_policy") == 0) { 
     146            Reset(); 
     147        } 
     148        else if(strcmp(buffer, "shutdown_engine_policy") == 0) { 
     149            Shutdown(); 
     150        } 
    74151    } 
    75152} 
     
    83160    else 
    84161        DeregisterComponent(); 
     162 
     163    // TODO should something else be happening here? 
    85164} 
    86165 
     
    100179{ 
    101180    SendMessage(commandSocketFD, "register_engine_policy"); 
    102     LOG("Policy Engine:: Registration message sent.\n"); 
     181    LOG("Policy Engine:: Registration message sent to shell.\n"); 
    103182 
    104183} 
     
    109188{ 
    110189    SendMessage(commandSocketFD, "deregister_engine_policy"); 
    111     LOG("Policy Engine:: Registration message sent.\n"); 
     190    LOG("Policy Engine:: Deregistration message sent to shell.\n"); 
    112191} 
    113192 
     
    163242 
    164243void  
    165 PolicyEngine::ValidateParameters(struct Parameter pList[], \ 
    166         struct CE_Info *ce_info, int decision_array[]) 
    167 { 
    168     LOG("Policy Engine:: Policies Validated.\n"); 
    169     for (size_t i = 0; i < ce_info->numParameters; i++) 
    170         decision_array[i] = 1; 
    171 } 
    172  
     244PolicyEngine::ValidateParameters() 
     245{ 
     246    LOG("Policy Engine:: Preparing to receive parameters for validation....\n"); 
     247 
     248    int32_t decision_array[10]; 
     249    struct Parameter pList[10]; 
     250    struct CE_Info ce_info; 
     251 
     252    if(GetRequest(commandSocketFD, pList, &ce_info)) { 
     253        LOG("Policy Engine:: Validating Transmission Parameters.\n"); 
     254        for (size_t i = 0; i < ce_info.numParameters; i++) 
     255            decision_array[i] = 1; 
     256 
     257        LOG("Policy Engine:: Sending Policy decision to Server.\n"); 
     258        SendPEDecision(pList, &ce_info, decision_array); 
     259 
     260        LOG("Policy Engine:: Policies Validated.\n"); 
     261    } 
     262    else 
     263        ERROR(1, "Call to GetRequest in ValidateParameters failed.\n"); 
     264 
     265} 
     266