--- projects/cms/source/host/c++/Config.cpp 2001/03/05 12:41:06 1.5 +++ projects/cms/source/host/c++/Config.cpp 2002/05/21 16:47:11 1.8 @@ -1,19 +1,38 @@ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * 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,14 +40,7 @@ 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"; @@ -38,22 +50,16 @@ Config::Config( string serverName, int serverPort, int 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; @@ -64,8 +70,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"; @@ -74,13 +79,11 @@ Config::Config( string serverName, int serverPort, int retrys++; loadConfigResult = loadConfig(); } // while - - } // if if ( debug == 1 ){ std::cout << "Config::Constructor - Finished!\n"; - } + } // if } // Config @@ -90,35 +93,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 @@ -130,24 +134,23 @@ 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(); @@ -160,47 +163,47 @@ int Config::chatHeartBeat(){ response = net->heartBeatSend("HEARTBEAT"); if ( response != "OK" ){ // something went wrong - return -1; 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 - return -1; 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 - return -1; 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 - return -1; 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 - return -1; if ( debug == 1 ){ std::cout << "Config::chatHeartBeat::ERROR in ENDHEARTBEAT\n"; - } - } + } // if + return -1; + } // if // seems ok to me return 0; @@ -215,13 +218,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; @@ -232,31 +233,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"); @@ -265,27 +266,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); @@ -296,7 +298,7 @@ int Config::chatConfig(){ if ( debug == 1 ){ std::cout << "Config::chatConfig::END\n"; - } + } // if response = net->heartBeatSend("END"); return 0; @@ -306,7 +308,7 @@ int Config::chatConfig(){ int Config::destroyConfig(){ if ( debug == 1 ){ std::cout << "Config::destroyConfig()\n"; - } + } // if net->closeConfigConnection(); @@ -317,7 +319,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] ){ @@ -336,7 +338,7 @@ int Config::getIntProperty( string propertyName ){ if ( debug == 1 ){ std::cout << "Config::getProperty()\n"; - } + } // if string response = getStrProperty( propertyName ); if ( response == "ERROR" ){ @@ -346,8 +348,9 @@ int Config::getIntProperty( string propertyName ){ int i = atoi(response.c_str()); if ( i > 0 ){ + // valid return i; - } + } // if // otherwise return ERROR return -1;