--- projects/cms/source/host/c++/Config.cpp 2001/02/26 14:59:54 1.3 +++ projects/cms/source/host/c++/Config.cpp 2002/05/18 18:15:56 1.7 @@ -1,19 +1,37 @@ +/* + * i-scream central monitoring system + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + #include "Config.h" 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 +39,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 +69,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 +78,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 +92,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 +133,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 +217,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,58 +232,61 @@ 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"); + // now send the properties we want 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); @@ -238,7 +297,7 @@ int Config::chatConfig(){ if ( debug == 1 ){ std::cout << "Config::chatConfig::END\n"; - } + } // if response = net->heartBeatSend("END"); return 0; @@ -248,7 +307,7 @@ int Config::chatConfig(){ int Config::destroyConfig(){ if ( debug == 1 ){ std::cout << "Config::destroyConfig()\n"; - } + } // if net->closeConfigConnection(); @@ -259,7 +318,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] ){ @@ -278,7 +337,7 @@ int Config::getIntProperty( string propertyName ){ if ( debug == 1 ){ std::cout << "Config::getProperty()\n"; - } + } // if string response = getStrProperty( propertyName ); if ( response == "ERROR" ){ @@ -288,8 +347,9 @@ int Config::getIntProperty( string propertyName ){ int i = atoi(response.c_str()); if ( i > 0 ){ + // valid return i; - } + } // if // otherwise return ERROR return -1;