This commit is contained in:
biosvos
2026-08-07 17:38:18 +09:00
commit 873193a243
9613 changed files with 2755992 additions and 0 deletions
+440
View File
@@ -0,0 +1,440 @@
#include "ServiceConfig.h"
#include <stdlib.h>
#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;
}