Changeset 186

Show
Ignore:
Timestamp:
03/22/09 23:35:05 (15 years ago)
Author:
bhilburn
Message:

Made the remotecomponent struct public since information hiding doesn't
make any sense here, removed unneeded info from it, worked on a couple
of policy engine functions to be smart about start-up connections.

Location:
vtcross/trunk/src
Files:
5 modified

Legend:

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

    r185 r186  
    7878        virtual void RegisterServices(int32_t socketFD) = 0; 
    7979        virtual void DeregisterServices(int32_t socketFD) = 0; 
     80 
     81 
     82        /* The RemoteComponent struct represents either the VTCROSS shell or the 
     83         * VTCROSS SML.  If 'SML_present' is false, it is the former. Otherwise, 
     84         * it is the latter. 
     85         */ 
     86        bool SML_present; 
     87        struct RemoteComponent *control; 
    8088}; 
    8189 
     
    144152 
    145153 
    146         /* Overloaded constructor that creates a policy engine object with SML 
    147          * information pre-defined. 
    148          */ 
    149         PolicyEngine(const char* serverName, const char* portNumber); 
     154        /* Overloaded constructor that creates a policy engine object and 
     155         * connects it to either the shell or an SML, depening on the SML bool. 
     156         */ 
     157        PolicyEngine(const char* serverName, const char* portNumber, \ 
     158                const bool SML); 
    150159 
    151160        void GetRemoteComponentType(int32_t socketFD); 
     
    177186        void ValidateParameters(struct Parameter pList[], \ 
    178187                struct CE_Info *ce_info, int decision_array[]); 
    179  
    180  
    181         /* The RemoteComponent struct represents either the VTCROSS shell or the 
    182          * VTCROSS SML.  If 'SML_present' is false, it is the former. Otherwise, 
    183          * it is the latter. 
    184          */ 
    185         bool SML_present; 
    186         struct RemoteComponent *control; 
    187188}; 
    188189 
     
    244245         */ 
    245246        struct SML_Info *SML; 
    246  
    247  
    248         /* The RemoteComponent struct represents either the VTCROSS shell or the 
    249          * VTCROSS SML.  If 'SML_present' is false, it is the former. Otherwise, 
    250          * it is the latter. 
    251          */ 
    252         bool SML_present; 
    253         struct RemoteComponent *control; 
    254  
    255247}; 
    256248 
  • vtcross/trunk/src/include/vtcross/containers.h

    r184 r186  
    8686 */ 
    8787struct RemoteComponent { 
    88     struct hostent *server; 
    8988    std::string serverName; 
    9089    int32_t serverPort; 
  • vtcross/trunk/src/lib/socketcomm/socketcomm.cpp

    r184 r186  
    7878 
    7979/* TODO see notes in socketcomm.h. This function, and the RemoteComponent 
    80  * struct, need a code review. 
     80 * struct, need a code review to make sure it is ready to be used rather 
     81 * than ClientSocket() 
    8182 */ 
    8283void 
     
    9091        ERROR(1, "No server found by that hostname."); 
    9192         
    92     memcpy(serverInfo, server, sizeof(struct hostent)); 
    93  
    9493    serverInfo->socketFD = socket(AF_INET, SOCK_STREAM, 0); 
    9594    if(serverInfo->socketFD < 0)  
     
    232231    int32_t clientSocket = accept(serverSock, NULL, NULL); 
    233232    if(clientSocket < 0) 
    234         ERROR(1, "Could establish connection with client socket.\n"); 
     233        ERROR(1, "Could not establish connection with client socket.\n"); 
    235234    
    236235    LOG("Handling client %s\n", inet_ntoa(echoClientAddr.sin_addr)); 
  • vtcross/trunk/src/policy_engines/PolicyEngine.cpp

    r185 r186  
    3636 
    3737 
    38 PolicyEngine::PolicyEngine(const char* serverName, const char* portNumber) 
     38PolicyEngine::PolicyEngine(const char* serverName, const char* portNumber, \ 
     39        const bool SML) 
    3940{ 
    4041    LOG("Creating Policy Engine.\n"); 
    4142 
    42     SML_present = true; 
     43    SML_present = SML; 
    4344    control = new RemoteComponent; 
    4445    control->serverName = std::string(serverName); 
     
    4647 
    4748    control->socketFD = ClientSocket(serverName, portNumber); 
    48     RegisterServices(control->socketFD); 
    4949 
    50     LOG("Policy Engine connected to SML at %s.\n", serverName); 
     50    if(SML_present) { 
     51        RegisterServices(control->socketFD); 
     52        LOG("Policy Engine connected to SML at %s.\n", serverName); 
     53    } 
     54    else { 
     55        RegisterComponent(control->socketFD); 
     56        LOG("Policy Engine connected to shell at %s.\n", serverName); 
     57    } 
    5158 
    5259    LoadPolicies(); 
     
    8592    if(SML_present) 
    8693        DeregisterServices(control->socketFD); 
    87     // TODO otherwise, deregister from shell 
     94    else 
     95        DeregisterComponent(control->socketFD); 
    8896} 
    8997 
     
    92100PolicyEngine::Reset() 
    93101{ 
     102    LOG("Resetting Policy Engine.\n"); 
     103    SML_present = false; 
     104    control = new RemoteComponent; 
     105    LoadPolicies(); 
    94106} 
    95107 
  • vtcross/trunk/src/policy_engines/policy_demo.cpp

    r161 r186  
    3131       ERROR(1, "Usage: %s hostname port\n", argv[0]); 
    3232     
    33     LOG("Opening the client socket.\n"); 
    34     int32_t socketFD = ClientSocket(argv[1], argv[2]); 
    35  
    36     PolicyEngine policyEngine; 
    37     policyEngine.RegisterComponent(socketFD); 
     33    PolicyEngine policyEngine(argv[1], argv[2], false); 
    3834 
    3935    LOG("Waiting for signal...\n"); 
    4036    while(1) { 
    41         policyEngine.WaitForSignal(socketFD); 
     37        policyEngine.WaitForSignal(policyEngine.control->socketFD); 
    4238    } 
    4339