| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #include <iostream>
- #include <string>
- #include <thread>
- #include <vector>
- #include <list>
- #include "Buffer.h"
- #include "CDiscHelper.h"
- #include "TSysThread.h"
- #include "CAppLife.h"
- #include "CTimer.h"
- #include "AnyCleaner.h"
- #define FRAME_CACHESIZE 1024*1024*1024
- #define GB(x) ((x.HighPart << 2) + (x.LowPart >> 20) / 1024.0) // 转换为GB单位显示
- typedef void (*FRAMEDATACALLBACK)(char* frame_data, int frame_size, \
- unsigned int frame_timesec, unsigned int frame_timeusec, bool is_iframe, \
- void* user_data);
- typedef struct tagRTPFILEDESC {
- char file_name[256];
- int file_size;
- char name[256];
- char folder[256];
- ULONGLONG file_number;
- unsigned int start_timesec; // recording time_sec
- unsigned int start_timeusec;
- unsigned int end_timesec;
- unsigned int end_timeusec;
- unsigned int duration_sec;
- } RTPFILEDESC;
- typedef struct tagTIME_SPAN {
- unsigned int start_timesec;
- //unsigned int start_timeusec;
- unsigned int end_timesec;
- //unsigned int end_timeusec;
- //unsigned int duration_sec;
- } TIME_SPAN;
- class CAppLifeThread : public TSysThreadImpl
- {
- public:
- CAppLifeThread() : m_AppLife(nullptr) {}
- ~CAppLifeThread()
- {
- Stop();
- if (m_AppLife) {
- delete m_AppLife;
- m_AppLife = nullptr;
- }
- }
- void PostQuit() { if (m_AppLife) m_AppLife->PostQuit(); }
- void Action()
- {
- m_AppLife = new CAppLife();
- //注意NVS_WATCHDOG_EVENT,NVS_EXIT_EVENT需要和软件狗里的cfg文件里的值相同
- #define NVS_INSTANCE_MUTEX "E3F9C076-84E6-4AF7-996A-1A0486BEBD79"
- #define NVS_WATCHDOG_EVENT "E3F9C076-84E6-4AF7-996A-1A0486BEBD79-heart"
- #define NVS_EXIT_EVENT "E3F9C076-84E6-4AF7-996A-1A0486BEBD79-quit"
- //"385222EF-7909-4D58-83B0-2FB8E5EA0960"
- if (m_AppLife->Begin((char*)NVS_INSTANCE_MUTEX, (char*)NVS_WATCHDOG_EVENT, (char*)NVS_EXIT_EVENT)) {
- //LOG4CXX_ERROR(app_logger, "failed to initialize life events.");
- return;
- }
- m_AppLife->WaitForQuit();
- OutputDebugStringA("Close m_AppLife");
- }
- private:
- CAppLife* m_AppLife;
- };
- class ClearRtpFiles : public TSysThreadImpl
- {
- public:
- ClearRtpFiles();
- ~ClearRtpFiles();
- void Action();
- CAppLifeThread* life_worker;
- int retension_day;
- int checktime;//最小单位min
- int remaining_memory;//最小单位GB字节
- std::string src_path;
- std::string backup_path;
- TIME_SPAN src_time_span;
- TIME_SPAN back_time_span;
- std::vector<char*> vec_src_foldernames;
- std::vector<char*> vec_back_foldernames;
- std::vector<char*> vec_src_date_folder;
- std::vector<char*> vec_back_date_folder;
- std::list<RTPFILEDESC*> list_src_rtpfiles;
- std::list<RTPFILEDESC*> list_localDay_rtpfiles;
- std::list<RTPFILEDESC*> list_lastDay_rtpfiles;
- std::list<RTPFILEDESC*> list_nextDay_rtpfiles;
- std::list<RTPFILEDESC*> list_backup_rtpfiles;
- void Is_NextSame_Times(std::list<RTPFILEDESC*>* list_rtpfiles, RTPFILEDESC* paramer, unsigned int starttime, unsigned int endtime);
- void Is_LastSame_Times(std::list<RTPFILEDESC*>* list_rtpfiles, RTPFILEDESC* paramer, unsigned int starttime, unsigned int endtime);
- void Is_Same_Times(std::list<RTPFILEDESC*>* list_rtpfiles, RTPFILEDESC* paramer,unsigned int starttime, unsigned int endtime,bool &check_last,bool &check_next);
- void Delete_file(std::string filename);
- void Check_Channels(std::string src,std::string backup);
- BOOL SHDeleteFolder(std::string pstrFolder, BOOL bAllowUndo);
- int Get_Date_List(std::vector<char*>* pVecFolderName, char* folder_name);
- void Get_DateFiles(std::vector<char*>* vec_foldernames, const char* src_folder);
- bool LoadDeviceInfo();
- void Get_Channels(const char* backup_folder, const char* src_folder);
- void Get_Folder(std::vector<char*>* vec_foldernames, const char* src_folder);
- int Get_Folder_List(std::vector<char*>* pVecFolderName, char* folder_name);
- void init();
- int Rtp_Listfile(std::list<RTPFILEDESC*>* list_rtpfiles, const char* src_folder);
- int Get_Disk_Free(std::string serial);
- void File_Sort(std::list<RTPFILEDESC*>* src_rtpfiles, std::list<RTPFILEDESC*>* dst_rtpfiles);
- void Folder_Sort(std::vector<char*>* src_folder, std::vector<char*>* dst_folder);
- std::string Get_Filename_Time(std::string src);
- int Get_MaxSize_File(std::list<RTPFILEDESC*>* list_rtpfiles);
- void Clear_EmptyDirectory(std::vector<char*>::iterator it_char);
- void Free_Rtpfiles();
- };
|