/*************************************************************************** Log File Process Base Trhead ----------------------------------------- begin : 2015/10/07 copyright : (C) 2010 SolutionBox Inc. author : Service 1 Team email : svc1@solbox.com version : 1.0 CopyRight(C) 2010 SolutionBox Inc. All Rights reserved. Redistribution and use in source and binary forms, with or with out modification, are not permitted in outside of SolutionBox Inc. ***************************************************************************/ #ifndef __CASH_GENERATOR_H__ #define __CASH_GENERATOR_H__ #include #include #include #include "Logger.h" #include "Signal_handle.h" using namespace std; /// @brief class CLogFileProcessThread { public: /// @brief 생성자 CLogFileProcessThread(string myname); ~CLogFileProcessThread(); /// @brief Thread를 생성하고, 이를 시작한다. /// @param none /// @return 성공은 return true 실패는 return false bool Start(); /// @brief ProcessStatus 내의 RCDB 관련 설정값을 이용해 DB Connection을 한다. /// @param sighandle 쓰레드에서 signal에 따라 정상 종료하도록 signal handle을 전달한다. /// @param pshmemNetworStat 공유메모리 포인터 /// @return 성공하면 return true 실패하면 return false bool ThreadInit(const sig_atomic_t *sighandle); // Attributes private: // 쓰레드 핸들 pthread_t m_threadHandle; const sig_atomic_t *m_sighandle; ///@brief 작업 시간 구간을 저장하는 구조체. typedef struct LOG_FILE_PROCESS_TIME_SCOPE { int begin; int end; } LogFileProcessTimeScope; ///@brief 상태값. typedef enum LOG_FILE_PROCESS_STATUS { LFP_READY = 0, LFP_SLEEP, LFP_WORKING, LFP_DONE } LogFileProcessStatus; ///@brief 오늘 날자를 저장. struct tm 구조체의 tm_mday 값.(1~31) int m_nToday; ///@brief 현재 상태를 저장. LogFileProcessStatus m_nStatus; ///@brief 작업 시간 구간을 저장. LogFileProcessTimeScope m_TimeScope; bool bFirst; string m_szMyName; // Operations private: ///@brief 상태를 설정하는 함수. ///@param status [in] 설정할 상태값. ///@return none. void SetStatus( LogFileProcessStatus status ); ///@brief 현재 상태를 얻는 함수. ///@param none. ///@return 현재 상태를 반환. LogFileProcessStatus GetStatus() { return m_nStatus; }; ///@brief 정수형의 상태를 입력 받아서 문자열로 반환하는 함수. ///@param status [in] 상태값. ///@return status에 해당하는 문자열을 반환. /// "LFP_READY", "LFP_SLEEP", "LFP_WORKING", "LFP_DONE" , "UNKOWN" 중 하나. std::string GetStrStatus( LogFileProcessStatus status ); ///@brief 작업 시작 여부를 판단하는 함수. ///@param now [in] 현재 시각을 저장하고 있는 tm 구조체. ///@return 현재 상태에 따라 아래의 값을 반환. /// - LFP_READY : 현재 시각이 작업 시간 구간에 있는지 확인해서 작업 시간 구간이면 true, 그렇지 않으면 false 반환. /// - LFP_DONE : false 반환 /// - LFP_SLEEP : false 반환 /// - LFP_WORKING : false 반환 bool IsBeginWork( struct tm& now ); ///@brief 주어진 시간이 작업 시간 구간인지 판단하는 함수. ///@param hour [in] 시간값 (0~23) ///@return 4 <= hour < 7이면 true, 그렇지 않으면 false 반환. bool IsInWorkTimeScope( int hour ); ///@brief 날자가 변경 되었는지를 확인하는 함수. ///@param day [in] 날자값 (1~31) ///@return 주어진 day가 m_nToday와 같으면 false, 다르면 true 반환. bool IsChangedDay( int day ); ///@brief 작업 시간 구간 내에서 실제로 작업을 시작할 때까지 대기할 수 있는 최대 시간을 초 단위로 계산하는 함수. ///@param now [in] 현재 시각을 저장하고 있는 tm 구조체. ///@return 주어진 시간에서 작업 시간 구간의 마지막 시간까지의 남은 초를 반환. /// 주어진 시간이 작업 구간 내에 있지 않거나 시간 정보가 올바르지 않으면 -1 반환. int GetMaxSleepSecond( struct tm& now ); ///@brief 오늘 날자를 구하는 함수 ///@param none. ///@return 오늘 날자를 반환한다.(1~31) int GetToday(); int Rand( uint32_t max, uint32_t key ); // Functions private: // 쓰레드 시작 루틴이다. static void* EntryPoint(void* arg); // 해당 함수의 내용은 수정하지 말것. void Execute(); protected: ///@brief 실제 로그 파일을 처리하는 함수. ///@ 가상 함수로 CLogFileProcessThread 클래스를 상속받는 자식 클래스에서 구현해야 한다. virtual bool DoWork() { return false; }; ///@brief 주어진 경로가 디렉토리인지 아닌지를 판단하는 함수. ///@param path [in] 경로. ///@return path가 존재하지 않거나 파일이면 false, 그렇지 않으면 true 반환. bool IsDirectory( std::string path ); ///@brief 파일을 unlink 시키는 함수. ///@param filename [in] 삭제할 파일명 ///@return unlink 성공하면 true, 그렇지 않으면 false 반환. bool Unlink( std::string filename ); }; #endif //__CASH_GENERATOR_H__