#include "rcdu.h" #include "parammanager.h" #include "Config.h" #include CParamManager::CParamManager( ) :m_mode(0), m_depth(0) { } CParamManager::~CParamManager( ) { } int CParamManager::inputparamAnalysis( int argc, char * const argv[] ) { int o; string cofigpath = DEFAULT_CONFIG_FILE; // parse command line arguments while ((o = getopt(argc, argv, "vhc:m:i:d:")) >= 0) { switch (o) { case 'h': // help cerr << "usage: " << PROG_NAME << " [-vhc] [-m mode] [-i service id] [-d depth] " << endl; cerr << " " << PROG_NAME << " -m reg [-i service id] [-d depth] " << endl; cerr << " " << PROG_NAME << " -m sync [-i service id]" << endl; cerr << "options are: " << endl; cerr << " -h help" << endl; cerr << " -v print current version" << endl; cerr << " -c config path" << endl; cerr << " -m job mode [reg|sync]" << endl; cerr << " default sync" << endl; cerr << " -i service id" << endl; cerr << " If you do not enter all the services registered" << endl; cerr << " -d to calculate the depth of the path" << endl; return 1; break; case 'v': // version cerr << "[info] " << PROG_NAME << " Version :" << PROG_VERSION << endl; return 1; break; case 'c': // config file cofigpath = optarg; break; case 'm': // mode if( strcmp(optarg, "reg") == 0 ) m_mode = 1; else if ( strcmp(optarg, "sync") == 0 ) m_mode = 0; else m_mode = -1; break; case 'i': // service id m_serviceid = optarg; break; case 'd': // depth m_depth = atoi(optarg); break; } } #ifdef _DEBUG cout << "mode = "<< m_mode <<", service id = " << m_serviceid << ", depth = " << m_depth << endl; #endif // _DEBUG // ÀԷ°ª üũ if( !correctinput() ) return 1; // load config file if( !loadconfig( cofigpath.c_str() ) ) return 1; return 0; } bool CParamManager::correctinput( void ) { if( m_mode < 0 ) { cerr << "[error] Wrong mode." << endl; return false; } switch (m_mode) { case 1: // reg if(m_depth < 0) { cerr << "[error] Wrong Parameter(depth)." << endl; return false; } break; case 0: // sync default: break; } return true; } static bool CheckValue(std::string& szValue, Config& conf, const std::string& defsection, const std::string& defkey) { if( szValue.size() > 0 ) return true; if( defsection.size() <= 0 || defkey.size() <= 0 ) return false; conf.GetConfig( defsection, defkey, szValue ); if( szValue.size() > 0 ) return true; return false; } bool CParamManager::loadconfig( const char * path ) { Config conf; // Config File open if( conf.Open( path) == false ) { return false; } string szValue; // log path if( conf.GetConfig( PROG_NAME, "DEFAULT_LOG_DIR", szValue ) == false ) { if( !CheckValue(szValue, conf, "COMMON", "DEFAULT_LOG_DIR") ) { cerr << "[error] Config info get failed. [" << PROG_NAME << "]->LOG_DIR" <LOG_LEVEL" <RCDB_IP" <RCDB_PORT" <RCDB_DB_NAME" <RCDB_DB_NAME" <RCDB_DB_NAME" <