#include "ServiceConfig.h" #include #include "Logger.h" // static º¯¼ö ÃʱâÈ­ CServiceConfig * CServiceConfig::m_pInstance = NULL; // »ý¼ºÀÚ CServiceConfig::CServiceConfig() { // default °ª ¼³Á¤. // ÁöÁ¤µÈ conf ÆÄÀÏ¿¡ ÇØ´ç ¼³Á¤ÀÌ ¾ø¾îµµ µ¿À۵ǵµ·Ï ó¸®ÇÒ °ª¿¡ ´ëÇØ¼­¸¸ default °ªÀ» Á¤ÀÇÇÑ´Ù. } // ¼Ò¸êÀÚ CServiceConfig::~CServiceConfig() { // °´Ã¼ ¼Ò¸ê½Ã... // ¸¸¾à static GetInstance() ÇÔ¼ö°¡ °¡¸£Å°´Â °´Ã¼°¡ ÀÚ±â ÀÚ½ÅÀ̶ó¸é... // ¼Ò¸ê 󸮿¡ ÀÇÇØ ¹®Á¦°¡ ¹ß»ýÇÒ ¼ö ÀÖÀ¸¹Ç·Î... ÀÌ¿¡ ´ëÇÑ Ã³¸®¸¦ ÇØ ÁØ´Ù. if( CServiceConfig::GetInstance() == this ) { CServiceConfig::m_pInstance = NULL; } } bool CServiceConfig::Init( const std::string strProgramName, const std::string & strConfFileName, std::string & strErrorMessage ) { // 1. Àӽà 󸮿ë Instance ¸¦ »ý¼ºÇÑ´Ù. CServiceConfig * pTempInstance = new CServiceConfig(); // 2. Àü´Þ ¹ÞÀº Config Á¤º¸¸¦ Àӽà Instance ·Î ·ÎµùÇÑ´Ù. // - ¸¸¾à ·ÎµùÀÌ ½ÇÆÐÇÒ °æ¿ì... Àӽà Instance °´Ã¼¸¦ »èÁ¦ ó¸®ÇÑ´Ù. if( pTempInstance->Load( strProgramName, strConfFileName, strErrorMessage ) == false ) { delete pTempInstance; pTempInstance = NULL; return false; // »ý¼º ½ÇÆÐ »çÀ¯´Â Error String °ü·Ã ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© È®ÀÎ. } // 3. Àü´Þ¹ÞÀº Conf Á¤º¸ ·Îµù¿¡ ¼º°øÇÑ °æ¿ì... // - ±âÁ¸ Instance °´Ã¼°¡ Á¸ÀçÇÏ´Â °æ¿ì.. ±³Ã¼ ó¸®.. // - ±âÁ¸ Instance °´Ã¼°¡ ¾ø´Â °æ¿ì´Â ½Å±Ô Instance »ç¿ëÅä·Ï ó¸®. if( CServiceConfig::GetInstance() == NULL ) { CServiceConfig::m_pInstance = pTempInstance; } else { // Instance replace... CServiceConfig * pPreviosInstance = CServiceConfig::m_pInstance; CServiceConfig::m_pInstance = pTempInstance; delete pPreviosInstance; } return true; } CServiceConfig * CServiceConfig::GetInstance( ) { return CServiceConfig::m_pInstance; } bool CServiceConfig::Load( const std::string & strProgramName, const std::string & strConfFileName, std::string & strErrorMessage ) { // º¯¼ö À¯È¿¼º È®ÀÎ if( strProgramName.size() <= 0 ) { strErrorMessage = "Config Program Name[" + strProgramName + "] not valid."; return false; } // Config class (lib ÇÏÀ§) ¸¦ ÀÌ¿ëÇÏ¿© config ÆÄÀÏ »óÀÇ Á¤º¸¸¦ ·Îµù ó¸® Config conf; if( conf.Open( strConfFileName ) == false ) { strErrorMessage = "Config file[" + strConfFileName + "] open failed."; return false; } // Config ¸ðµâ¿¡ ·ÎµùµÈ Á¤º¸ Áß ÇÊ¿äÇÑ Á¤º¸¸¸ °¡Á®¿Â´Ù... // - ¸¸¾à ¿À·ù°¡ ¹ß»ýÇÒ °æ¿ì... ÇØ´ç ³»¿ªÀº Error String ¿¡ ÀúÀå ó¸®... std::string strValue; int nValue; std::vector< std::string > vecValue; // Log path if( GetConfigValue( conf, strProgramName, "DEFAULT_LOG_DIR", strValue, strErrorMessage ) == false ) return false; else { m_strLogPath = strValue; strValue.clear(); } // Log Level if( GetConfigValue( conf, strProgramName, "LOG_LEVEL", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue < 0 || nValue > MAX_LOG_LEVEL ) { strErrorMessage = "Config [LOG_LEVEL] value[" + strValue + "] is not valid"; return false; } else m_nLogLevel = nValue; strValue.clear(); } // RC ID if( GetConfigValue( conf, strProgramName, "RC_ID", strValue, strErrorMessage ) == false ) return false; else { m_strRcId = strValue; strValue.clear(); } // RCDB IP if( GetConfigValue( conf, strProgramName, "RCDB_IP", strValue, strErrorMessage ) == false ) return false; else { m_strRcdbIp = strValue; strValue.clear(); } // RCDB PORT if( GetConfigValue( conf, strProgramName, "RCDB_PORT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue <= 0 || nValue > 65535 ) { strErrorMessage = "Config [RCDB_PORT] value[" + strValue + "] is not valid"; return false; } else m_nRcdbPort = nValue; strValue.clear(); } // RCDB DB NAME if( GetConfigValue( conf, strProgramName, "RCDB_DB_NAME", strValue, strErrorMessage ) == false ) return false; else { m_strRcdbName = strValue; strValue.clear(); } // RCDB ACCOUNT if( GetConfigValue( conf, strProgramName, "RCDB_ACCT", strValue, strErrorMessage ) == false ) return false; else { m_strRcdbAcct = strValue; strValue.clear(); } // RCDB ACCOUNT PASSWORD if( GetConfigValue( conf, strProgramName, "RCDB_ACCT_PW", strValue, strErrorMessage ) == false ) return false; else { m_strRcdbAcctPw = strValue; strValue.clear(); } // FHS FTSD (File TranSfer Daemon) Service Port if( GetConfigValue( conf, strProgramName, "FHS_TRANSFER_DAEMON_PORT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue <= 0 || nValue > 65535 ) { strErrorMessage = "Config [FHS_TRANSFER_DAEMON_PORT] value[" + strValue + "] is not valid"; return false; } else m_nFhsTransferDaemonPort = nValue; strValue.clear(); } // Max Queue Count(size) limit ( 0: infinite ) if( GetConfigValue( conf, strProgramName, "MAX_QUEUE_COUNT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue < 0 ) { strErrorMessage = "Config [MAX_QUEUE_COUNT] value[" + strValue + "] is not valid"; return false; } else m_nMaxQueueSize = nValue; strValue.clear(); } // Max Retry Count if file processing failed. if( GetConfigValue( conf, strProgramName, "MAX_RETRY_COUNT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue < 0 ) { strErrorMessage = "Config [MAX_RETRY_COUNT] value[" + strValue + "] is not valid"; return false; } else m_nMaxRetryCount = nValue; strValue.clear(); } // File Hash Check Level: 0:Not use hash, 1:Partitial hash(Default), 2:Full Hash if( GetConfigValue( conf, strProgramName, "FILE_HASH_CHECK_LEVEL", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue < 0 || nValue > 2) { strErrorMessage = "Config [FILE_HASH_CHECK_LEVEL] value[" + strValue + "] is not valid"; return false; } else m_nHashCheckLevel = nValue; strValue.clear(); } // Max count of file replication request thread if( GetConfigValue( conf, strProgramName, "MAX_REPLICATION_THREAD", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue <= 0 ) { strErrorMessage = "Config [MAX_REPLICATION_THREAD] value[" + strValue + "] is not valid"; return false; } else m_nMaxReplicationThread = nValue; strValue.clear(); } // FHS Hot contents Á¤º¸ ¼ö½ÅÀ» À§ÇÑ TCP Listen Port if( GetConfigValue( conf, strProgramName, "FHS_HOTCONTENT_LISTEN_TCP_PORT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue <= 0 || nValue > 65535 ) { strErrorMessage = "Config [FHS_HOTCONTENT_LISTEN_TCP_PORT] value[" + strValue + "] is not valid"; return false; } else m_nFhsHotContentListenPort = nValue; strValue.clear(); } // Hot content cache »ý¼ºÀ» À§ÇÑ ÃÖ¼Ò µ¿Á¢ fd ¼³Á¤°ª. if( GetConfigValue( conf, strProgramName, "HOTCONTENT_CREATE_MINIMUM_FD_COUNT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi( strValue.c_str() ); if( nValue < 0 ) { strErrorMessage = "Config [HOTCONTENT_CREATE_MINIMUM_FD_COUNT] value[" + strValue + "] is not valid"; return false; } else m_nCacheCreateMinimumFdCount = nValue; strValue.clear(); } // Cache File Timeout (sec) (Default: 24Hour) if( GetConfigValue( conf, strProgramName, "CACHE_FILE_TIMEOUT", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue <= 0 ) { strErrorMessage = "Config [CACHE_FILE_TIMEOUT] value[" + strValue + "] is not valid"; return false; } else m_nCacheFileTimeout = nValue; strValue.clear(); } // Max count of file cache request thread if( GetConfigValue( conf, strProgramName, "MAX_CACHE_THREAD", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue <= 0 ) { strErrorMessage = "Config [MAX_CACHE_THREAD] value[" + strValue + "] is not valid"; return false; } else m_nMaxCacheThread = nValue; strValue.clear(); } // Target select interval on running if( GetConfigValue( conf, strProgramName, "TARGET_SELECT_INTERVAL", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue < 0 ) { strErrorMessage = "Config [TARGET_SELECT_INTERVAL] value[" + strValue + "] is not valid"; return false; } else m_nTargetSelectInterval = nValue; strValue.clear(); } // Target select interval on starting if( GetConfigValue( conf, strProgramName, "TARGET_SELECT_INTERVAL_ON_STARTING", strValue, strErrorMessage ) == false ) return false; else { nValue = atoi(strValue.c_str()); if( nValue < 0 ) { strErrorMessage = "Config [TARGET_SELECT_INTERVAL_ON_STARTING] value[" + strValue + "] is not valid"; return false; } else m_nTargetSelectIntervalOnStarting = nValue; strValue.clear(); } // Skip keyword : h|path (head) or m|path(middle) or t|path(tail) // - º» ¼³Á¤°©Àº ¾ø¾îµµ µ¿ÀÛÇϵµ·Ï ó¸®ÇÑ´Ù. // CHG 2014-09-02 huibong // program -> common section º¯°æ¿¡ µû¸¥ ±â´É Ãß°¡ ó¸® ( #20201 ) if( conf.GetConfig( strProgramName, "SKIP_KEYWORD", vecValue ) == true ) { // ÇØ´ç °ªÀÌ Á¸ÀçÇÒ °æ¿ì.. // Multi value À̹ǷΠ°¹¼ö °Ë»ç if( vecValue.size() > 0 ) { m_vecSkipWord = vecValue; } vecValue.clear(); } else { // program section ¿¡ Á¸ÀçÇÏÁö ¾ÊÀ» °æ¿ì... COMMON ¼¼¼Ç È®ÀÎ if( conf.GetConfig( "COMMON", "SKIP_KEYWORD", vecValue ) == true ) { // ÇØ´ç °ªÀÌ Á¸ÀçÇÒ °æ¿ì.. // Multi value À̹ǷΠ°¹¼ö °Ë»ç if( vecValue.size() > 0 ) { m_vecSkipWord = vecValue; } vecValue.clear(); } } // conf Á¤º¸ ·ÎµùÀÌ ¸ðµÎ Á¤»óÀûÀ¸·Î ¿Ï·áµÈ °æ¿ì... // ¸¶Áö¸·À¸·Î Àü´Þ¹ÞÀº config ¸í, section Á¤º¸¸¦ ÀúÀåÇÑ´Ù. m_strConfigFileName = strConfFileName; m_strProgramName = strProgramName; return true; } bool CServiceConfig::GetConfigValue( Config & conf, const std::string & strProgramName, const std::string strKey, std::string & strValue, std::string & strErrorMessage ) { // conf get value if( conf.GetConfig( strProgramName, strKey, strValue) == false ) { if( conf.GetConfig( "COMMON", strKey, strValue) == false ) { strErrorMessage = "Config [" + strKey + "] value is not exist"; return false; } } // value check. if( strValue.empty() == true ) { strErrorMessage = "Config [" + strKey + "] value is not valid"; return false; } return true; }