Prechádzať zdrojové kódy

#IQRV #comment [Module] Download 实体添加日志

gifur 4 rokov pred
rodič
commit
fee983e422
1 zmenil súbory, kde vykonal 26 pridanie a 133 odobranie
  1. 26 133
      Module/mod_download/DownloadFSM.cpp

+ 26 - 133
Module/mod_download/DownloadFSM.cpp

@@ -9,9 +9,6 @@
 #include "SpIni.h"
 #include "EventCode.h"
 
-
-
-
 static ErrorCodeEnum ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
 {
 	ErrorCodeEnum Error = Error_Unexpect;
@@ -49,7 +46,9 @@ static ErrorCodeEnum ParseBoolean(const char *str, BOOL &bValue)
 }
 
 
-DownloadFSM::DownloadFSM() : m_pConnection(NULL), m_arr_downlist(NULL), m_current(NULL), m_last_filelist(NULL),m_DFlist(NULL),m_currentFileTask(NULL)
+DownloadFSM::DownloadFSM() 
+	: m_pConnection(NULL), m_arr_downlist(NULL), m_current(NULL)
+	, m_last_filelist(NULL),m_DFlist(NULL),m_currentFileTask(NULL)
 {
 	isStartUp =false;
 }
@@ -132,7 +131,7 @@ bool DownloadFSM::checkFileStr(CSimpleStringA strFile,int count)
 ErrorCodeEnum DownloadFSM::LoadDownloadFileList()
 {	//时间戳|文件名$
 	//lwt 修改成日志文件互备模式:当运行时文件破坏时,用备份文件替代,当运行文件正常时,覆盖更新下备份文件,以防止备份文件之前是错误的。
-	CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();;
+	CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();
 	CSmartPointer<IConfigInfo> spConfig;
 	ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
 	if (Error != Error_Succeed) {
@@ -235,77 +234,6 @@ ErrorCodeEnum DownloadFSM::LoadDownloadFileList()
 		Dbg("initial load task: expiretime[%d],expiredate[%s],filename[%s]",pTask->ExpireTime, expire.ToTimeString().GetData(), pTask->FileName.GetData());
 	}
 	return Error_Succeed;
-
-	//CSmartPointer<IEntityFunction> spFunction = m_pEntity->GetFunction();;
-	//CSmartPointer<IConfigInfo> spConfig;
-	//ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
-	//bool breset= false;
-	//if (Error == Error_Succeed) {
-	//	int count=0;
-	//	Error = spConfig->ReadConfigValueInt("downloadFile", "count", count);
-	//	if(Error == Error_Succeed){
-	//		Dbg("downloadFile count is %d",count);
-	//		if(count == 0){
-	//			//因可能文件不存在,也返回0,默认初始化下文件,保证文件创建和字段创建
-	//			spConfig->WriteConfigValueInt("downloadFile", "count", 0);
-	//			spConfig->WriteConfigValue("downloadFile", "fileList", "");
-	//		}
-	//		CSimpleStringA fileList ="";
-	//		Error = spConfig->ReadConfigValue("downloadFile", "fileList", fileList);	
-	//		if(Error == Error_Succeed){
-	//			Dbg("downloadFile fileList is [%s]",fileList.GetData());
-	//			CAutoArray<CSimpleStringA> fList = fileList.Split('$');
-	//			if(fList.GetCount() == count){
-	//				for(int i=0; i<fList.GetCount(); i++){
-	//					CAutoArray<CSimpleStringA> info = fList[i].Split('|');
-	//					if(info.GetCount() == 2){
-	//						CSimpleStringA expireTime = info[0];
-	//						CSimpleStringA fileName= info[1];
-	//						//加入任务队列
-	//						DownloadFileTask *pTask = new DownloadFileTask(); 
-	//						pTask->FileName=fileName;
-	//						pTask->ExpireTime = (DWORD)atoi(expireTime.GetData()); 
-	//						m_DFlist->push_back(pTask);
-	//						Dbg("initial load task: expiretime[%d], filename[%s]",pTask->ExpireTime,pTask->FileName.GetData());
-	//					}else{
-	//						//报错
-	//						Dbg("downloadFile.ini fileList fileInfo param is error, fileInfo is [%s]",info[i].GetData());
-	//						breset=true;
-	//						break;
-	//					}
-	//				}
-	//			}else{
-	//				//报错
-	//				Dbg("downloadFile.ini fileList param is error, flist not equal count");
-	//				breset=true;
-	//			}
-	//		}else{
-	//			Dbg("read downloadFile.ini param fileList fail!");
-	//		}
-	//	}else{
-	//		Dbg("read downloadFile.ini param count fail!");
-	//	}	
-	//}else{
-	//	Dbg("open downloadFile.ini fail, please check out downloadFile.ini!");
-	//}
-	//if(breset){	
-	//	//重置下载列表
-	//	std::list<DownloadFileTask*>::iterator iter; 
-	//	for(iter=m_DFlist->begin();iter!=m_DFlist->end();++iter){
-	//		delete *iter;
-	//	}
-	//	m_DFlist->clear();
-	//	//保存队列到文件
-	//	ErrorCodeEnum rc = SaveDownloadFileList();
-	//	if(rc==Error_Succeed){
-	//		Dbg("downloadFile.ini param reset is success");
-	//	}else{
-	//		Error=Error_CheckSum;
-	//		Dbg("downloadFile.ini param reset is fail");
-	//	}	
-	//}
-	//return Error;
-	
 }
 
 //保存运行时文件任务
@@ -365,21 +293,6 @@ ErrorCodeEnum DownloadFSM::addDownLoadFileWork(CSimpleStringA fileName,DWORD exp
 		//先删除再加入
 		std::list<DownloadFileTask*>::iterator iter; 
 
-		//bool isInsert = true;
-		//for(iter=m_DFlist->begin();iter!=m_DFlist->end();++iter){
-		//	DownloadFileTask* p = *iter;
-		//	if(p->FileName==fileName){
-		//		isInsert=false;
-		//		break;
-		//	}
-		//}
-		//if(isInsert){
-		//	//加入任务
-		//	DownloadFileTask *pTask= new DownloadFileTask();
-		//	pTask->FileName = fileName;
-		//	pTask->ExpireTime = expireTime;
-		//	m_DFlist->push_back(pTask);
-		//}
 		//删除所有文件名相同的文件
 		for(iter=m_DFlist->begin();iter!=m_DFlist->end();){
 			DownloadFileTask* p = *iter;
@@ -419,12 +332,6 @@ ErrorCodeEnum DownloadFSM::deleteDownLoadFileWork(CSimpleStringA fileName)
 		std::list<DownloadFileTask*>::iterator iter; 
 		for(iter=m_DFlist->begin();iter!=m_DFlist->end();++iter){
 			DownloadFileTask* p = *iter;
-			//if(p->FileName==fileName){
-			//	Dbg("deleteDownLoadFileWork file [%s] is  deleted",fileName.GetData());
-			//	delete p;
-			//	iter = m_DFlist->erase(iter);
-			//	break;
-			//}
 			//尝试修改先移除后delete,看是否还出现问题
 			if(strcmp(p->FileName.GetData(),fileName.GetData())==0){
 				Dbg("deleteDownLoadFileWork file [%s] is  deleted",fileName.GetData());
@@ -611,8 +518,6 @@ void DownloadFSM::OnStateTrans( int iSrcState, int iDstState )
 
 void DownloadFSM::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
 {
-	
-
 	if(strcmp("CallState",pszKey)==0){
 		Dbg("rx sysvar %s from %s, %s to %s", pszKey, pszEntityName, pszOldValue, pszValue);
 		if (pszValue[0] == 'O') {
@@ -732,10 +637,10 @@ ErrorCodeEnum DownloadFSM::OnExit()
 	return Error_Succeed;
 }
 
-
-
 void DownloadFSM::s0_on_entry()
 {
+	LOG_FUNCTION();
+
 	//通过直接获取变量值来判断是否进入了启动界面
 	if(!isStartUp){
 		CSimpleStringA strState;
@@ -763,6 +668,8 @@ void DownloadFSM::s0_on_entry()
 
 void DownloadFSM::s0_on_exit()
 {
+	LOG_FUNCTION();
+
 	CancelTimer(1);
 }
 
@@ -798,11 +705,16 @@ unsigned int DownloadFSM::s0_on_event(FSMEvent* event)
 
 void DownloadFSM::s1_on_entry()
 {
+    LOG_FUNCTION();
+
 	ScheduleTimer(1, 30000); 
 }
 
 void DownloadFSM::s1_on_exit()
 {
+
+    LOG_FUNCTION();
+
 	CancelTimer(1);
 }
 
@@ -813,6 +725,9 @@ unsigned int DownloadFSM::s1_on_event(FSMEvent* event)
 
 void DownloadFSM::s2_on_entry()
 {	
+
+	LOG_FUNCTION();
+
 	//过滤任务列表中超过时效任务
 	ErrorCodeEnum error = checkWorkExpireTime();
 
@@ -820,20 +735,6 @@ void DownloadFSM::s2_on_entry()
 	if(m_DFlist->size()>0){
 		if (!m_pConnection) {
 			m_pConnection = new DownloadConnection(m_pEntity, this);
-			/*if (!m_pConnection->Connect(m_server1, m_server1_port, 3)) {
-				m_pConnection->Close();
-				m_pConnection->DecRefCount();
-				m_pConnection = NULL;
-				if ((m_server2!=NULL)&&(m_server2_port!=0)&&((m_server2 != m_server1)||(m_server2_port != m_server1_port))) 
-				{
-					m_pConnection = new DownloadConnection(m_pEntity, this);
-					if (!m_pConnection->Connect(m_server2, m_server2_port, 3)) {
-						m_pConnection->Close();
-						m_pConnection->DecRefCount();
-						m_pConnection = NULL;
-					}
-				}
-			}*/
 			if(m_pConnection->ConnectFromCentralSetting() && m_pConnection->IsConnectionOK()){
 				//创建成功
 			}else{
@@ -865,20 +766,6 @@ unsigned int DownloadFSM::s2_on_event(FSMEvent* event)
 		//当有任务时创建连接
 		if(m_DFlist->size()>0){
 			m_pConnection = new DownloadConnection(m_pEntity, this);
-			//if (!m_pConnection->Connect(m_server1, m_server1_port, 3)) {
-			//	m_pConnection->Close();
-			//	m_pConnection->DecRefCount();
-			//	m_pConnection = NULL;
-			//	if((m_server2!=NULL)&&(m_server2_port!=0)&&((m_server2 != m_server1)||(m_server2_port != m_server1_port))) 
-			//	{
-			//		m_pConnection = new DownloadConnection(m_pEntity, this);
-			//		if (!m_pConnection->Connect(m_server2, m_server2_port, 3)) {
-			//			m_pConnection->Close();
-			//			m_pConnection->DecRefCount();
-			//			m_pConnection = NULL;
-			//		}
-			//	}
-			//}
 			if(m_pConnection->ConnectFromCentralSetting() && m_pConnection->IsConnectionOK()){
 				//创建成功
 			}else{
@@ -900,9 +787,10 @@ unsigned int DownloadFSM::s2_on_event(FSMEvent* event)
 
 void DownloadFSM::s3_on_entry()
 {
+	LOG_FUNCTION();
+
 	m_arr_downlist = NULL;
 		
-	
 	//复制任务
 	EnterCriticalSection(&m_cs);
 		std::list<download_file_t*>::iterator fIter;
@@ -939,6 +827,8 @@ void DownloadFSM::s3_on_entry()
 
 void DownloadFSM::s3_on_exit()
 {
+	LOG_FUNCTION();
+
 	//释放m_arr_downlist;
 	if(m_arr_downlist!=NULL){
 		download_free_filelist(m_arr_downlist);
@@ -1052,6 +942,8 @@ void DownloadFSM::s4_on_entry()
 
 void DownloadFSM::s4_on_exit()
 {
+	LOG_FUNCTION();
+
 	if (m_pConnection) {
 		m_pConnection->Close();
 		m_pConnection->DecRefCount();
@@ -1148,6 +1040,8 @@ unsigned int DownloadFSM::s4_on_event(FSMEvent* event)
 
 void DownloadFSM::s5_on_entry()
 {
+	LOG_FUNCTION();
+
 	//清理临时文件
 	array_header_t *arr = fileutil_get_sub_files_a(m_base_path);
 	if (arr) {
@@ -1160,8 +1054,6 @@ void DownloadFSM::s5_on_entry()
 #else
 				remove(path);
 #endif // RVC_OS_WIN
-
-				
 			}
 		}
 		toolkit_array_free2(arr);
@@ -1173,6 +1065,8 @@ void DownloadFSM::s5_on_entry()
 
 void DownloadFSM::s5_on_exit()
 {
+	LOG_FUNCTION();
+
 	CancelTimer(5);
 }
 
@@ -1185,7 +1079,6 @@ unsigned int DownloadFSM::s5_on_event(FSMEvent* event)
 	return 0;
 }
 
-
 void DownloadFSM::nextTask(){
 
 	download_file_t *file=NULL;