--- projects/cms/source/host/c++/Config.cpp 2001/03/01 20:10:53 1.4 +++ projects/cms/source/host/c++/Config.cpp 2001/03/27 00:06:11 1.6 @@ -3,17 +3,16 @@ Config::Config( string serverName, int serverPort, int printDebug ){ // the constructor for the class - configConnectionRetryTime = 1; // one second debug = printDebug; - MAX_CONNECTION_ATTEMPTS = 10; // + MAX_CONNECTION_ATTEMPTS = 10; configName = serverName; configPort = serverPort; if ( debug == 1 ){ std::cout << "Config Constructor\n"; - } + } // if // make a reference to smallnet @@ -21,37 +20,26 @@ Config::Config( string serverName, int serverPort, int std::cout << "Config::Constructor::Constructing SmallNet\n"; } net = new SmallNet(debug); - // net->setDebug(1); - - // read the values which we want to retrieve from the - // config manager from the "config.values.txt" file - //propertyNames = new string[20]; - //propertyValues = new string[20]; - - // FIX ME + // sod that we are using defined values now.. propertyNames[0] = "UDPUpdateTime"; propertyNames[1] = "TCPUpdateTime"; propertyNames[2] = "FilterRetryTime"; propertyNames[3] = "ConfigRetryTime"; - numProperties = 4; + propertyNames[4] = "AVERAGERUpdateTime"; + propertyNames[5] = "MAXTCPFilterRetries"; + numProperties = 5; - // read the Chat dialog we 'expect' to have with the config - // manager from disk. This is a new idea so that the client - // won't have to be hard coded with the dialog (incase it changes) - - // FIX ME - if ( loadConfig() == 0 ){ // successful just continue if ( debug == 1 ){ std::cout << "Config::Constructor::loadConfig() Successful\n"; - } - } - else { + } // if + } else { if ( debug == 1 ){ std::cout << "Config::Constructor::loadConfig() failed-retrying\n"; - } + } // if + // woops something went wrong. we'll just keep retrying // and increasing the time between trys int loadConfigResult = -1; @@ -62,8 +50,7 @@ Config::Config( string serverName, int serverPort, int while ( loadConfigResult != 0 ){ if ( retrys > MAX_CONNECTION_ATTEMPTS ){ std::cout << "Maxium number of retries reached, Quitting"; - // exit("Failed to connect"); - } + } // if // make the connection retry time greater configConnectionRetryTime = configConnectionRetryTime * 2; std::cout << "Waiting " << configConnectionRetryTime << " seconds before retrying\n"; @@ -72,13 +59,11 @@ Config::Config( string serverName, int serverPort, int retrys++; loadConfigResult = loadConfig(); } // while - - } // if if ( debug == 1 ){ std::cout << "Config::Constructor - Finished!\n"; - } + } // if } // Config @@ -88,35 +73,36 @@ int Config::loadConfig(){ if ( debug == 1 ){ std::cout << "Config::loadConfig()\n"; - } + } // if // make a connection if ( debug == 1 ){ std::cout << "Config::loadConfig::establishing config connection\n"; - } + } // if + int established = establishConfig(); if ( established != 0 ){ + destroyConfig(); return established; - } + } // if // do the talk ;) if ( debug == 1 ){ std::cout << "Config::loadConfig::Processing chat script\n"; - } + } // if + int chat = chatConfig(); if ( chat != 0 ){ // and close the connection destroyConfig(); - // return chat; - } + } // if // and close the connection - if ( debug == 1 ){ std::cout << "Config::loadConfig::closing config connection\n"; - } + } // if destroyConfig(); // return everything ok @@ -128,30 +114,83 @@ int Config::establishHeartbeat(){ // just an interface onto smallnet if ( debug == 1 ){ std::cout << "Config::establishHeartbeat()\n"; - } + } // if - int establish = net->connectHeartBeat(configName, configPort); - + int establish = net->connectHeartBeat(configName, configPort); + if ( debug == 1 ){ std::cout << "->" << establish << "\n"; - } + } // if return establish; } // establishHeartBeat - int Config::destroyHeartbeat(){ // just hooks into the smallnet interface if ( debug == 1 ){ std::cout << "Config::destroyHeartbeat()\n"; - } + } // if net->closeHeartBeatConnection(); } // destroyHeartBeat +int Config::chatHeartBeat(){ + + string response; + + response = net->heartBeatSend("HEARTBEAT"); + if ( response != "OK" ){ + // something went wrong + if ( debug == 1 ){ + std::cout << "Config::chatHeartBeat::ERROR in HEARTBEAT\n"; + } // if + return -1; + } // if + + response = net->heartBeatSend("CONFIG"); + if ( response != "OK" ){ + // something went wrong + if ( debug == 1 ){ + std::cout << "Config::chatHeartBeat::ERROR in CONFIG\n"; + } // if + return -1; + } // if + + response = net->heartBeatSend(fileList); + if ( response != "OK" ){ + // something went wrong + if ( debug == 1 ){ + std::cout << "Config::chatHeartBeat::ERROR in fileList\n"; + } // if + return -1; + } // if + + response = net->heartBeatSend(lastModified); + if ( response != "OK" ){ + // something went wrong + if ( debug == 1 ){ + std::cout << "Config::chatHeartBeat::ERROR in lastModified\n"; + } // if + return -1; + } // if + + response = net->heartBeatSend("ENDHEARTBEAT"); + if ( response != "OK" ){ + // something went wrong + if ( debug == 1 ){ + std::cout << "Config::chatHeartBeat::ERROR in ENDHEARTBEAT\n"; + } // if + return -1; + } // if + + // seems ok to me + return 0; + +} // chat Heart Beat + int Config::establishConfig(){ // ask smallnet to make a connection to the filtermanager so we can get some config // details @@ -159,13 +198,11 @@ int Config::establishConfig(){ std::cout << "Config::establishConfig()\n"; } - - /* MODIFY THIS */ int response = net->connectConfig(configName, configPort); if ( debug == 1 ){ std::cout << "->" << response << "\n"; - } + } // if return response; @@ -176,31 +213,31 @@ int Config::chatConfig(){ // do some funky jibble.. ;) if ( debug == 1 ){ std::cout << "Config::chatConfig()\n"; - } + } // if string response; - - + // hard coeded for the moment if ( debug == 1 ){ std::cout << "Config::chatConfig::STARTCONFIG\n"; - } + } // if + response = net->heartBeatSend("STARTCONFIG"); if ( response != "OK" ){ // something went wrong - return -1; if ( debug == 1 ){ std::cout << "Config::chatConfig::ERROR\n"; - } - } + } // if + return -1; + } // if if ( debug == 1 ){ std::cout << "Config::chatConfig::LASTMODIFIED\n"; - } + } // if lastModified = net->heartBeatSend("LASTMODIFIED"); if ( debug == 1 ){ std::cout << "Config::chatConfig::FILELIST\n"; - } + } // if fileList = net->heartBeatSend("FILELIST"); fQDN = net->heartBeatSend("FQDN"); @@ -209,27 +246,28 @@ int Config::chatConfig(){ if ( debug == 1 ){ std::cout << "Config::chatConfig::requesting properties\n"; - } + } // if if ( numProperties > 0 ){ // we actually need to look for some properties for ( int i=0; i < numProperties; i++ ){ // lets hope that this works! ;) if ( debug == 1 ){ std::cout << "Config::chatConfig::" << propertyNames[i] << "\n"; - } + } // if propertyValues[i] = net->heartBeatSend(propertyNames[i]); } // for } // if if ( debug == 1 ){ std::cout << "Config::chatConfig::ENDCONFIG\n"; - } + } // if response = net->heartBeatSend("ENDCONFIG"); // doesn't matter what it returns if ( debug == 1 ){ std::cout << "Config::chatConfig::FILTER\n"; - } + } // if + response = net->heartBeatSend("FILTER"); // now we need to pull repsonse apart to get the filter information out int first = response.find(";",0); @@ -240,7 +278,7 @@ int Config::chatConfig(){ if ( debug == 1 ){ std::cout << "Config::chatConfig::END\n"; - } + } // if response = net->heartBeatSend("END"); return 0; @@ -250,7 +288,7 @@ int Config::chatConfig(){ int Config::destroyConfig(){ if ( debug == 1 ){ std::cout << "Config::destroyConfig()\n"; - } + } // if net->closeConfigConnection(); @@ -261,7 +299,7 @@ string Config::getStrProperty(string propertyName){ if ( debug == 1 ){ std::cout << "Config::getProperty()\n"; - } + } // if for ( int i=0; i<20; i++ ){ if ( propertyName == propertyNames[i] ){ @@ -280,7 +318,7 @@ int Config::getIntProperty( string propertyName ){ if ( debug == 1 ){ std::cout << "Config::getProperty()\n"; - } + } // if string response = getStrProperty( propertyName ); if ( response == "ERROR" ){ @@ -290,8 +328,9 @@ int Config::getIntProperty( string propertyName ){ int i = atoi(response.c_str()); if ( i > 0 ){ + // valid return i; - } + } // if // otherwise return ERROR return -1;