Browse Source

Z991239-635 #comment other: 没改动逻辑,主要是适应编码规范

gifur 5 years ago
parent
commit
a8565384f0

+ 63 - 26
Module/include/DevEntityCommBase.hpp

@@ -21,7 +21,8 @@ struct VendorLibInfo
 
 	VendorLibInfo() :strDevice(true), strVendor(true), strVersion(true), strBatch(true) {}
 
-	bool IsValid() const {
+	bool IsValid() const
+	{
 		return (!strDevice.IsNullOrEmpty()
 			&& !strVendor.IsNullOrEmpty()
 			&& !strVersion.IsNullOrEmpty()
@@ -31,16 +32,20 @@ struct VendorLibInfo
 	int GetVersionInt() const 
 	{
 		int result = 0;
-		if (!strVersion.IsNullOrEmpty()) {
+
+		if (!strVersion.IsNullOrEmpty()) 
+		{
 			result = atoi(strVersion.GetData());
 		}
+
 		return result;
 	}
 
 	int GetBatchInt() const 
 	{
 		int result = 0;
-		if (!strBatch.IsNullOrEmpty()) {
+		if (!strBatch.IsNullOrEmpty()) 
+		{
 			result = atoi(strBatch.GetData());
 		}
 		return result;
@@ -49,29 +54,35 @@ struct VendorLibInfo
 	CSimpleStringA toLibNameString() const
 	{
 		CSimpleStringA strFullLibName(true);
-		if (!strDevice.IsNullOrEmpty()) {
+		if (!strDevice.IsNullOrEmpty()) 
+		{
 			strFullLibName = strDevice;
-			if (!strVendor.IsNullOrEmpty()) {
+			if (!strVendor.IsNullOrEmpty()) 
+			{
 				strFullLibName += ".";
 				strFullLibName += strVendor;
 			}
-			if (!strVersion.IsNullOrEmpty()) {
+
+			if (!strVersion.IsNullOrEmpty()) 
+			{
 				strFullLibName += ".";
 				strFullLibName += strVersion;
 			}
-			if (!strBatch.IsNullOrEmpty()) {
+
+			if (!strBatch.IsNullOrEmpty()) 
+			{
 				strFullLibName += ".";
 				strFullLibName += strBatch;
 			}
 
-#ifdef _WIN32
+#ifdef RVC_OS_WIN
 			strFullLibName += ".dll";
 #else
 			CSimpleStringA strPrefix("lib");
 			strPrefix += strFullLibName;
 			strPrefix += ".so";
 			strFullLibName = strPrefix;
-#endif //_WIN32
+#endif //RVC_OS_WIN
 		}
 
 		return strFullLibName;
@@ -84,11 +95,12 @@ class CDevAdptEntityBase : public CEntityBase
 
 public:
 
-	CDevAdptEntityBase(){}
+	CDevAdptEntityBase() { }
 
 	virtual CSimpleStringA GetVendorLibName()
 	{
-		if (!vendorLibInfo.IsValid()) {
+		if (!vendorLibInfo.IsValid()) 
+		{
 			ExtractVendorLibName();
 		}
 		return vendorLibInfo.toLibNameString();
@@ -99,19 +111,21 @@ public:
 
 	virtual ~CDevAdptEntityBase() {}
 
+public:
+
+	VendorLibInfo vendorLibInfo;
+
 private:
 
 	ErrorCodeEnum ExtractVendorLibName();
-
-public:
-	VendorLibInfo vendorLibInfo;
 };
 
 inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibName()
 {
 	CSmartPointer<IConfigInfo> spRootConfig;
 	ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Root, spRootConfig);
-	if (IS_SUCCEED(erroCode)) {
+	if (IS_SUCCEED(erroCode)) 
+	{
 		CSimpleStringA strSection = CSimpleStringA("Device.") + GetEntityName();
 		vendorLibInfo.strDevice = GetEntityName();
 		spRootConfig->ReadConfigValue(strSection, "Vendor", vendorLibInfo.strVendor);
@@ -119,15 +133,19 @@ inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibName()
 		spRootConfig->ReadConfigValue(strSection, "Batch", vendorLibInfo.strBatch);
 
 		if (!vendorLibInfo.IsValid())
+		{
 			erroCode = Error_NotConfig;
+		}
 	}
+
 	return erroCode;
 }
 
 inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA& csLibFullPath)
 {
 	CSimpleStringA strLibName = GetVendorLibName();
-	if (strLibName.IsNullOrEmpty()) {
+	if (strLibName.IsNullOrEmpty()) 
+	{
 		return Error_Unexpect;
 	}
 	
@@ -140,18 +158,21 @@ inline ErrorCodeEnum CDevAdptEntityBase::ExtractVendorLibFullPath(CSimpleStringA
 
 inline void CDevAdptEntityBase::InitializeVendorLogSwitch()
 {
-	CSystemStaticInfo sysInfo;
-	GetFunction()->GetSystemStaticInfo(sysInfo);
+
 	if (!vendorLibInfo.IsValid())
+	{
 		ExtractVendorLibName();
+	}
 
 	struct VendorLogConfig {
+
 		CSimpleStringA strLevel;
 		CSimpleStringA strType;
 		CSimpleStringA strDllName;
 		CSimpleStringA strLogPath;
 
-		void Settle() {
+		void Settle() 
+		{
 			toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
 			toolkit_setenv("VENDOR_RECODE_TYPE", strType);
 			toolkit_setenv("VENDOR_DLL_NAME", strDllName);
@@ -165,32 +186,48 @@ inline void CDevAdptEntityBase::InitializeVendorLogSwitch()
 
 	CSimpleStringA str;
 	centerConfig->ReadConfigValue(GetEntityName(), vendorLibInfo.strVendor, str);
-	if (str.IsNullOrEmpty()) {
+	if (str.IsNullOrEmpty()) 
+	{
 		centerConfig->ReadConfigValue(GetEntityName(), "All", str);
 	}
+
 	if (!str.IsNullOrEmpty())
+	{
 		stLogConfig.strLevel = str;
+	}
+
+	if (stLogConfig.strLevel.Compare("OFF", true) != 0)
+	{
+		CSystemStaticInfo sysInfo;
+		GetFunction()->GetSystemStaticInfo(sysInfo);
 
-	if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
 		CSimpleStringA strWhiteNameSheet;
 		centerConfig->ReadConfigValue(GetEntityName(), "AllowTerminals", strWhiteNameSheet);
-		if (!strWhiteNameSheet.IsNullOrEmpty()) {
+		if (!strWhiteNameSheet.IsNullOrEmpty()) 
+		{
 			bool bWhiteNameSheet = false;
+			
 			CAutoArray<CSimpleStringA> arrayWhiteNameSheet = strWhiteNameSheet.Split(',');
-			for (int i = 0; i < arrayWhiteNameSheet.GetCount(); i++) {
+			for (int i = 0; i < arrayWhiteNameSheet.GetCount(); i++) 
+			{
 				std::regex pattern(arrayWhiteNameSheet[i]);
-				if (std::regex_match(sysInfo.strTerminalID.GetData(), pattern)) {
+				if (std::regex_match(sysInfo.strTerminalID.GetData(), pattern)) 
+				{
 					bWhiteNameSheet = true;
 					break;
 				}
 			}
+
 			//if this terminal is not at WhiteNameSheet,set level with "OFF".
-			if (!bWhiteNameSheet)
+			if (!bWhiteNameSheet) 
+			{
 				stLogConfig.strLevel = "OFF";
+			}
 		}
 	}
 
-	if (stLogConfig.strLevel.Compare("OFF", true) != 0) {
+	if (stLogConfig.strLevel.Compare("OFF", true) != 0) 
+	{
 		str.Clear();
 		centerConfig->ReadConfigValue(GetEntityName(), "Type", str);
 		if (!str.IsNullOrEmpty())

+ 84 - 43
Module/include/DevFSMCommBase.hpp

@@ -37,7 +37,8 @@ assert(DeviceBaseHelper::GetCurVendorType("chinavision") == Vendor_ChinaVision);
 
 */
 
-enum VendorNameType {
+enum VendorNameType 
+{
 	Vendor_Invalide,
 	Vendor_Sankyo,
 	Vendor_ChinaVision,
@@ -74,27 +75,36 @@ static const char* VendorNameStr[] = {
 	"hx"
 };
 
+
 inline static VendorNameType GetCurVendorType(LPCTSTR vendorName)
 {
-	if (vendorName == NULL || strlen(vendorName) == 0) {
+	if (vendorName == NULL || strlen(vendorName) == 0) 
+	{
 		return Vendor_Invalide;
 	}
+
 	int idx = -1;
-	for (int i = 0; i < sizeof(VendorNameStr) / sizeof(VendorNameStr[0]); ++i) {
-		if (strnicmp(vendorName, VendorNameStr[i], strlen(VendorNameStr[i])) == 0) {
+
+	for (int i = 0; i < sizeof(VendorNameStr) / sizeof(VendorNameStr[0]); ++i) 
+	{
+		if (strnicmp(vendorName, VendorNameStr[i], strlen(VendorNameStr[i])) == 0) 
+		{
 			idx = i;
 			break;
 		}
 	}
-	if (idx == -1) {
+
+	if (idx == -1)
+	{
 		/*历史遗留原因,怡化厂商有两个适配器名字*/
 		if (strnicmp(vendorName, "yihua", strlen("yihua")) == 0) {
 			idx = Vendor_YiHua;
-		}
-		else {
+		
+		} else {
 			idx = Vendor_Invalide;
 		}
 	}
+
 	return (VendorNameType)idx;
 }
 
@@ -106,6 +116,7 @@ struct DevAdptLibHelper
 		ErrorCodeEnum erroCode = Error_Succeed;
 
 		do {
+
 			int res = toolkit_dlopen(strFullLibPath, &m_lib);
 			if (res != 0) {
 				Dbg("toolkit_dlopen[%s] failed with error %s.", strFullLibPath.GetData(), toolkit_dlerror(&m_lib));
@@ -113,12 +124,15 @@ struct DevAdptLibHelper
 				break;
 			}
 
-			if ((res = toolkit_dlsym(&m_lib, "CreateDevComponent", (void**)&pFuncCreateAdapt)) != 0) {
+			if ((res = toolkit_dlsym(&m_lib, "CreateDevComponent", (void**)&pFuncCreateAdapt)) != 0) 
+			{
 				Dbg("Get 'CreateDevComponent' Func address failed with error: %s", toolkit_dlerror(&m_lib));
 				erroCode = Error_DevLoadFileFailed;
 				break;
 			}
-			if ((res = toolkit_dlsym(&m_lib, "ReleaseDevComponent", (void**)&pFuncReleaseAdapt)) != 0) {
+
+			if ((res = toolkit_dlsym(&m_lib, "ReleaseDevComponent", (void**)&pFuncReleaseAdapt)) != 0) 
+			{
 				Dbg("Get 'ReleaseDevComponent' Func address failed with error: %s", toolkit_dlerror(&m_lib));
 				erroCode = Error_DevLoadFileFailed;
 				break;
@@ -126,7 +140,8 @@ struct DevAdptLibHelper
 
 		} while (false);
 
-		if (IS_FAILURED(erroCode)) {
+		if (IS_FAILURED(erroCode)) 
+		{
 			TearDown();
 		}
 
@@ -142,8 +157,7 @@ struct DevAdptLibHelper
 			return Error_NotInit;
 		}
 
-		ErrorCodeEnum erroCode = Error_Succeed;
-		erroCode = pFuncCreateAdapt((DeviceBaseClass*&)m_AdptObjPtr);
+		ErrorCodeEnum erroCode = pFuncCreateAdapt((DeviceBaseClass*&)m_AdptObjPtr);
 		if (IS_FAILURED(erroCode)) {
 			Dbg("Create device adapter object failed! EC=%s", SpStrError(erroCode));
 			return erroCode;
@@ -166,9 +180,11 @@ struct DevAdptLibHelper
 
 	void TearDown()
 	{
-		if (m_AdptObjPtr != nullptr) {
+		if (m_AdptObjPtr != nullptr) 
+		{
 			m_AdptObjPtr->DevClose();
-			if (nullptr != pFuncReleaseAdapt) {
+			if (nullptr != pFuncReleaseAdapt)
+			{
 				DeviceBaseClass* devBasePtr = static_cast<DeviceBaseClass*>(m_AdptObjPtr);
 #if DEVICE_BASE_INTERFACE_FILE_VERSION == 2
 				pFuncReleaseAdapt(0, devBasePtr);
@@ -189,11 +205,9 @@ struct DevAdptLibHelper
 
 	TSubAdpt* operator->()
 	{ 
-		
 		if (m_AdptObjPtr == nullptr) {
 			throw std::runtime_error("the dev class pointer is nullptr!!");
 		}
-
 		return m_AdptObjPtr; 
 	}
 
@@ -208,12 +222,13 @@ struct DevAdptLibHelper
 		TearDown();
 	}
 
-	DevAdptLibHelper(const DevAdptLibHelper&) = delete; /** forbid copy*/
-	DevAdptLibHelper& operator=(const DevAdptLibHelper&) = delete; /** forbid assignment*/
+	DevAdptLibHelper(const DevAdptLibHelper&) = delete; 
+	DevAdptLibHelper& operator=(const DevAdptLibHelper&) = delete;
 
 private:
 
 	toolkit_lib_t m_lib;
+
 	DevAdaptObjCreateFunc pFuncCreateAdapt;
 	DevAdaptObjReleaseFunc pFuncReleaseAdapt;
 
@@ -246,11 +261,13 @@ struct DevEntityErrorCode {
 		dwVendorId = dwVendorID;
 	}
 
-	DWORD GetCompleteErrorCode() const {
+	DWORD GetCompleteErrorCode() const 
+	{
 		return MAKE_SLV_ERRORCODE(dwEntityId, dwVendorId, dwVendorErroCode);
 	}
 
-	DWORD GetCompleteErrorCode2Business() const {
+	DWORD GetCompleteErrorCode2Business() const 
+	{
 		return MAKE_SLV_ERRORCODE_TO_BUSINESS(dwEntityId, dwVendorErroCode, dwReserved);
 	}
 
@@ -259,9 +276,12 @@ struct DevEntityErrorCode {
 template<class TFSM, class TDevClass>
 class CCommDevFSM : public FSMImpl<TFSM>
 {
+
 public:
-	ErrorCodeEnum GetAndSplitDevErrInfo(CSimpleStringA& csErrMsg, 
-		WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay = "");
+
+	ErrorCodeEnum GetAndSplitDevErrInfo(
+		CSimpleStringA& csErrMsg, WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay = "");
+
 	ErrorCodeEnum LogDevErrInfo(LPCTSTR lpszFuncName = "")
 	{
 		CSimpleStringA csMsg;
@@ -274,10 +294,13 @@ public:
 		ErrorCodeEnum eRet = GetAndSplitDevErrInfo(csMsg, wdErrorCode);
 		return (eRet == Error_Succeed);
 	}
+	 
 protected:
+
 	DevAdptLibHelper<TDevClass> m_hDevHelper;
 
 	DevEntityErrorCode m_entCode;
+
 	CSimpleStringA m_csAlarmMsg = "No more information";
 
 	void UpdateEntityID()
@@ -285,6 +308,7 @@ protected:
 		CEntityStaticInfo esi = { 0 };
 		ErrorCodeEnum ec = this->GetEntityBase()->GetFunction()->GetEntityStaticInfo(
 			this->GetEntityBase()->GetEntityName(), esi);
+
 		if (ec == Error_Succeed) {
 			Dbg("wEntityDevelopID: 0x%X", esi.wEntityDevelopID);
 			m_entCode.ResetWithEntityID(esi.wEntityDevelopID);
@@ -301,45 +325,55 @@ protected:
 		m_entCode.SetDevCode(dwVal, reserved);
 		return GetDEC();
 	}
+
 	DWORD GetDEC() const
 	{
 		return m_entCode.GetCompleteErrorCode();
 	}
-	//DWORD AlarmDEC() const {
-	//	return GetDEC();
-	//}
-	DWORD AlarmDECToBusiness(DWORD dwVal = 0) {
-		if (dwVal > 0)
+
+	DWORD AlarmDECToBusiness(DWORD dwVal = 0) 
+	{
+		if (dwVal > 0) {
 			UpdateDEC(dwVal);
+		}
+
 		//oilyang@20200528 according the meeting result,throw a LogError while answering ctx
 		//oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
 		DWORD dwCode = 0;
-		if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId)
+		if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId) {
 			dwCode = m_entCode.dwVendorErroCode;
-		else
+
+		} else {
 			dwCode = m_entCode.GetCompleteErrorCode2Business();
+		}
+
 		LogError(Severity_Middle, Error_Unexpect, dwCode, "TODO:");
+		
 		return dwCode;
 	}
+
 	void ClearRelatedDEC()
 	{
 		UpdateDEC();
 		m_csAlarmMsg = "No more information";
 	}
+
 	void LogErrMsg(const char* pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode = 0, BOOL bAlarm = FALSE);
 };
 
 
 template<class TFSM, class TDevClass>
 inline ErrorCodeEnum CCommDevFSM<TFSM, TDevClass>::GetAndSplitDevErrInfo(
-	CSimpleStringA& csErrMsg, WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay)
+		CSimpleStringA& csErrMsg, WORD& wdDevErrCode, LPCTSTR lpszFuncNameForDisplay)
 {
 	csErrMsg = "";
 	wdDevErrCode = 0;
 
 	BOOL bDisplayFunName = TRUE;
 	if (lpszFuncNameForDisplay == NULL || strlen(lpszFuncNameForDisplay) == 0)
+	{
 		bDisplayFunName = FALSE;
+	}
 
 	if (!m_hDevHelper) {
 		Dbg("inst occurs nullptr !!!");
@@ -349,7 +383,8 @@ inline ErrorCodeEnum CCommDevFSM<TFSM, TDevClass>::GetAndSplitDevErrInfo(
 	DevErrorInfo devErrInfo;
 	ZeroMemory(&devErrInfo, sizeof(DevErrorInfo));
 	ErrorCodeEnum erroCode = m_hDevHelper->GetLastErr(devErrInfo);
-	if (erroCode == Error_Succeed) {
+	if (erroCode == Error_Succeed)
+	{
 		if (strlen(devErrInfo.szErrMsg) > 0) {
 			csErrMsg = devErrInfo.szErrMsg;
 		}
@@ -358,25 +393,26 @@ inline ErrorCodeEnum CCommDevFSM<TFSM, TDevClass>::GetAndSplitDevErrInfo(
 			//oiltmp@20200520 comment the following line
 			//wdDevErrCode = (WORD)((devErrInfo.dwErrMsgLen >> 16) & 0x0000FFFF);
 		}
+
 		if (bDisplayFunName) {
 			Dbg("Invoke <%s> failed, Dev_GLE: DevErrCode[%d], ErrMsg[%s]",
-				lpszFuncNameForDisplay, wdDevErrCode, (LPCTSTR)csErrMsg);
-		}
-		else {
+					lpszFuncNameForDisplay, wdDevErrCode, (LPCTSTR)csErrMsg);
+		
+		} else {
 			Dbg("Dev_GLE: DevErrCode[%d], ErrMsg[%s]", wdDevErrCode, (LPCTSTR)csErrMsg);
 		}
-	}
-	else {
+	
+	} else {
 		if (bDisplayFunName) {
 			Dbg("Invoke <%s> failed, and unfortunately Dev_GLE failed returned EC: %d(0x%X)",
-				lpszFuncNameForDisplay, erroCode, erroCode);
+					lpszFuncNameForDisplay, erroCode, erroCode);
 			csErrMsg = CSimpleStringA::Format("Invoke <%s> failed", lpszFuncNameForDisplay);
-		}
-		else {
-			Dbg("Dev_GLE failed returned EC: %d(0x%X)",
-				erroCode, erroCode);
+		
+		} else {
+			Dbg("Dev_GLE failed returned EC: %d(0x%X)", erroCode, erroCode);
 		}
 	}
+
 	return erroCode;
 }
 
@@ -385,24 +421,29 @@ inline void CCommDevFSM<TFSM, TDevClass>::LogErrMsg(
 	const char* pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode, BOOL bAlarm)
 {
 	Dbg("%s failed, EC = %s(0x%x)", pMsgHead, SpStrError(eErrCode), eErrCode);
+	
 	WORD wdErrCode = 0;
 	CSimpleStringA csErrMsg(true);
 	ErrorCodeEnum ec = GetAndSplitDevErrInfo(csErrMsg, wdErrCode);
+	
 	if (ec == Error_Succeed && wdErrCode != 0) {
 		//oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
 		if ((defaultDevCode >> 20) == m_entCode.dwEntityId)
 			UpdateDEC(defaultDevCode);
 		else
 			UpdateDEC(wdErrCode);
-	}
-	else if (defaultDevCode != 0) {
+	
+	} else if (defaultDevCode != 0) {
 		UpdateDEC(defaultDevCode);
 	}
+	
 	m_csAlarmMsg = CSimpleStringA::Format("%s failed EC= %s : %s",
 		pMsgHead, SpStrError(eErrCode), (LPCTSTR)csErrMsg);
+	
 	if (bAlarm) {
 		LogWarn(Severity_High, eErrCode, AlarmDECToBusiness(), (LPCTSTR)m_csAlarmMsg);
 	}
+
 	return;
 }
 

+ 3 - 1
Module/mod_CenterSetting/CenterSettingConn.cpp

@@ -297,8 +297,10 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
 		info.strFileName = pRet->FileName;
 		
 		CSimpleStringA str1, str2;
-		if (pEntity->ExtractSiteFromFileName(info.strFileName, str1, str2))
+		if (pEntity->TryExtractSiteFromFileName(info.strFileName, str1, str2))
+		{
 			pEntity->m_SyncFileInfo[(const char*)str2] = info;
+		}
 
 		delete[] pBuf;
 		pBuf = NULL;

+ 23 - 15
Module/mod_CenterSetting/mod_centersetting.cpp

@@ -9,6 +9,10 @@
 #include <regex>
 using namespace std;
 
+
+#define DOWNLOAD_CENTERSETTINGS_TIMER_ID 1
+#define DOWNLOAD_CENTERSETTINGS_TIMER_INTERVAL (5 * 60 * 1000)
+
 CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/)
 {
 	return new CCenterSettingService(this);
@@ -29,7 +33,7 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
 			 char *pszFile = ARRAY_IDX(arr, i, char*);
 
 			 CSimpleStringA strSite;
-			 if (ExtractSiteFromFileName(pszFile, info.strFileName, strSite))
+			 if (TryExtractSiteFromFileName(pszFile, info.strFileName, strSite))
 			 {
 				 char szTmp[64];
 				 inifile_read_str_s("Main", "SyncHash", "", szTmp, 64, pszFile);
@@ -48,8 +52,8 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
 
 	 CSimpleStringA strFilePath;
 	 GetFunction()->GetPath("CenterSetting", strFilePath);
-	 CSimpleStringA strFileName;
-	 ExtractSiteFromFileName(strFilePath, strFileName, m_strCurSiteExtName);
+	 CSimpleStringA strNoUsed;
+	 TryExtractSiteFromFileName(strFilePath, strNoUsed, m_strCurSiteExtName);
 
 	 // 缓存当前RVCWeb版本
 	 char szVersion[64] = {};
@@ -57,16 +61,23 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
 	 m_strRvcWebVersion = szVersion;
 
 	 // 立刻同步配置
-	 BeginDownloadCenterSetting();
+	 //BeginDownloadCenterSetting();
+	 pFunc->PostEntityTaskFIFO(new DownloadCenterSettingsTask(this));
 
-	 // 启动轮询定时器
-	 GetFunction()->SetTimer(1, this, 60000);
+	 // 启动轮询定时器 5min
+	 GetFunction()->SetTimer(DOWNLOAD_CENTERSETTINGS_TIMER_ID, this, DOWNLOAD_CENTERSETTINGS_TIMER_INTERVAL);
+ }
+
+
+ void CCenterSettingEntity::OnTimeout(DWORD dwTimerID)
+ {
+	 BeginDownloadCenterSetting();
  }
 
  void CCenterSettingEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  {
 	 SecureClientRelease();
-	 GetFunction()->KillTimer(1);
+	 GetFunction()->KillTimer(DOWNLOAD_CENTERSETTINGS_TIMER_ID);
 	 pTransactionContext->SendAnswer(Error_Succeed);
  }
 
@@ -110,9 +121,10 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
 	 return rc;
  }
 
- ErrorCodeEnum CCenterSettingEntity::DownloadCenterSetting(SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer sp)
+ ErrorCodeEnum CCenterSettingEntity::DownloadCenterSetting(
+	  SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer sp)
  {
-	 if (m_spDownloadCall != NULL)
+	 if (m_spDownloadCall != nullptr)
 	 {
 		 Dbg("last download call not complet");
 		 sp->Answer(Error_Duplication);
@@ -138,11 +150,6 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
 	 return Error_Unexpect;
  }
 
- void CCenterSettingEntity::OnTimeout(DWORD dwTimerID)
- {	 
-	 BeginDownloadCenterSetting();
- }
-
  bool CCenterSettingEntity::ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
  {
 	 if (str)
@@ -161,7 +168,8 @@ CServerSessionBase *CCenterSettingEntity::OnNewSession(const char* /*pszRemoteEn
 	 return false;
  }
  
- bool CCenterSettingEntity::ExtractSiteFromFileName(const char *pszPath, CSimpleStringA &strFileName, CSimpleStringA &strSite)
+ bool CCenterSettingEntity::TryExtractSiteFromFileName(
+	 const char *pszPath, CSimpleStringA &strFileName, CSimpleStringA &strSite)
  {
 	 const regex re("(CenterSetting\.(.+)\.ini$)");
 

+ 21 - 7
Module/mod_CenterSetting/mod_centersetting.h

@@ -2,20 +2,28 @@
 
 #include "CenterSetting_server_g.h"
 using namespace CenterSetting;
-#include "CenterSettingConn.h"
 
+#include "modVer.h"
+#include "CenterSettingConn.h"
+#include "SpTest.h"
 #include <map>
 #include <string>
+
 using namespace std;
 
 class CCenterSettingEntity : public CEntityBase, public ITimerListener
 {
 public:
-	CCenterSettingEntity() : /*m_dwLastSyncTime(0),*/ m_pConnection(NULL), m_nConnectFailCount(0), m_bUseBackupNow(false){}
+	CCenterSettingEntity() : /*m_dwLastSyncTime(0),*/
+		m_pConnection(nullptr), m_nConnectFailCount(0), m_bUseBackupNow(false){}
 	virtual ~CCenterSettingEntity() {}
 	virtual const char *GetEntityName() const { return "CenterSetting"; }
+	const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
+
 	virtual bool IsService()const{return true;}
 
+	ON_ENTITYT_TEST()
+
 	virtual void OnStarted();
 	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
 	virtual void OnTimeout(DWORD dwTimerID);		
@@ -31,7 +39,7 @@ private:
 	bool SecureClientConnect(bool bUseBackup);
 	void SecureClientRelease();
 	bool ParseIPAddress(const char *str, CSimpleStringA &ip, int &port);
-	bool ExtractSiteFromFileName(const char *pszPath, CSimpleStringA &strFileName, CSimpleStringA &strSite);
+	bool TryExtractSiteFromFileName(const char *pszPath, CSimpleStringA &strFileName, CSimpleStringA &strSite);
 	
 private:
 	struct ConfigFileInfo
@@ -44,10 +52,6 @@ private:
 	CSimpleStringA m_strCurSiteExtName;		// 当前场所集中配置扩展名:LAN或DMZ
 	CSimpleStringA m_strRvcWebVersion;		// 当前RVCWeb版本
 
-	//CSimpleStringA m_strSyncFileHash;
-	//CSimpleStringA m_strSyncFileName;
-	//DWORD m_dwLastSyncTime;
-
 	bool m_bUseBackupNow;
 	int m_nConnectFailCount;
 	CCenterSettingConn *m_pConnection;
@@ -56,6 +60,16 @@ private:
 	friend class CCenterSettingConn;
 };
 
+struct DownloadCenterSettingsTask : public ITaskSp
+{
+	DownloadCenterSettingsTask(CCenterSettingEntity* entity) :pEntity(entity) {}
+	void Process()
+	{
+		pEntity->DownloadCenterSetting(nullptr);
+	}
+	CCenterSettingEntity* pEntity;
+};
+
 class CCenterSettingService : public CenterSettingService_ServerSessionBase
 {
 public:

+ 3 - 0
Module/mod_CenterSetting/test/testCenterSettingEntity.cpp

@@ -0,0 +1,3 @@
+
+#include "mod_centersetting.h"
+

+ 53 - 26
Module/mod_cardswiper/mod_cardswiper.cpp

@@ -10,86 +10,113 @@
 #include "EventCode.h"
 
 
-void CardSwiperServerSession::Handle_Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx)
+void CardSwiperServerSession::Handle_Read(
+	SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->Read(ctx);
 }
 
-void CardSwiperServerSession::Handle_PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx)
+void CardSwiperServerSession::Handle_PreOnline(
+	SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->PreOnline(ctx);
 }
-void CardSwiperServerSession::Handle_PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_PostOnline(
+	SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->PostOnline(ctx);
 }
+
 void CardSwiperServerSession::Handle_Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->Exit(ctx);
 }
 
-void CardSwiperServerSession::Handle_GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx)
+void CardSwiperServerSession::Handle_GetDevInfo(
+	SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->GetDevInfo(ctx);
 }
-void CardSwiperServerSession::Handle_CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_CancelInsert(
+	SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->CancelInsert(ctx);
 }
-void CardSwiperServerSession::Handle_Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_Eject(
+	SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->Eject(ctx);
 }
-void CardSwiperServerSession::Handle_QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_QueryCardInfo(
+	SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->QueryCardInfo(ctx);
 }
-void CardSwiperServerSession::Handle_MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx)
+
+
+ErrorCodeEnum ConvertFromSiteType(CSimpleStringA const& src, CSimpleStringA& dst)
+{
+
+	return Error_Succeed;
+}
+
+void CardSwiperServerSession::Handle_MagTransferInit(
+	SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->MagTransferInit(ctx);
 }
-void CardSwiperServerSession::Handle_QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_QueryConnInfo(
+	SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx)
 {
 	m_pEntity->QueryConnInfo(ctx);
 }
-void CardSwiperServerSession::Handle_InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_InsertWaitMore(
+	SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->InsertWaitMore(ctx);
 }
-void CardSwiperServerSession::Handle_QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_QueryFWBList(
+	SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->QueryFWBList(ctx);
 }
-void CardSwiperServerSession::Handle_BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx)
+
+void CardSwiperServerSession::Handle_BindFWB(
+	SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
 	m_pEntity->BindFWB(ctx);
 }
-void CCardSwiperEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
-	const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
+void CCardSwiperEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, 
+	const SeverityLevelEnum eLevel, const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
 	const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage)
 {
 	switch (dwUserCode)
 	{
 	case EVENT_ACCESSAUTH_SUCCEED:
-	{
-		//Dbg("access auth succeed.");
-		//FSMEvent *pEvt = new FSMEvent(USER_EVT_MAGDATA_TRANSFER_INIT_V2);
-		//m_fsm.PostEventFIFO(pEvt);
-		m_fsm.SetAAState(0);
-	}
+		{
+			m_fsm.SetAAState(0);
+		}
 		break;
+
 	case EVENT_ACCESSAUTH_FAILED:
 	case EVENT_ACCESSAUTH_TIMEOUT:
 		Dbg("access auth failed.");
@@ -98,23 +125,23 @@ void CCardSwiperEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogI
 		break;
 	}
 }
-void CCardSwiperEntity::OnSysVarEvent(const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName)
+void CCardSwiperEntity::OnSysVarEvent(
+	const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName)
 {
 	if ((_strnicmp(pszKey, "UIState", strlen("UIState")) == 0))
 	{
 		if (_strnicmp(pszValue, "M", strlen("M")) == 0)
 		{
 			m_fsm.SetMainPageFlag(true);
-		}
-		else
+		
+		} else {
 			m_fsm.SetMainPageFlag(false);
-
-
+		}
 	}
 }
 
 
 SP_BEGIN_ENTITY_MAP()
 	SP_ENTITY(CCardSwiperEntity)
-	SP_END_ENTITY_MAP()
+SP_END_ENTITY_MAP()
 

+ 25 - 49
Module/mod_cardswiper/mod_cardswiper.h

@@ -3,6 +3,7 @@
 #include "CardSwiperClass.h"
 #include "CardSwiperFSM.h"
 #include "DevEntityCommBase.hpp"
+#include "modVer.h"
 
 using namespace CardSwiper;
 
@@ -26,7 +27,9 @@ public:
 	virtual void Handle_InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx);
 	virtual void Handle_QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx);
 	virtual void Handle_BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx);
+
 private:
+
 	CCardSwiperEntity* m_pEntity;
 };
 
@@ -38,7 +41,14 @@ public:
 
 	}
 	virtual ~CCardSwiperEntity(){}
+	
 	virtual const char *GetEntityName() const { return "CardSwiper"; }
+
+	virtual const char* GetEntityVersion() const
+	{
+		return MODULE_VERSION_FULL;
+	}
+
 	virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext) 
 	{ 
 		LOG_FUNCTION();
@@ -49,23 +59,8 @@ public:
 		GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
 			Log_Event, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
 		GetFunction()->RegistSysVarEvent("UIState", this);
-		if (eStart == Error_Succeed)
-		{
-			//oiltest no gpio for current
-			//m_pGpioClient = new GpioService_ClientBase(this);
-			//ErrorCodeEnum ErrorConn = m_pGpioClient->Connect();
-			//if (ErrorConn != Error_Succeed) {
-			//	m_pGpioClient->SafeDelete();
-			//	m_pGpioClient = NULL;
-			//}
-			//else
-			//	Dbg("gpio connected.");
-
-		}
 
 		pTransactionContext->SendAnswer(eStart);
-		//ErrorCodeEnum Error = __OnStart(Error_Succeed);
-		//pTransactionContext->SendAnswer(Error);
 	}
 
 	virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext) 
@@ -79,23 +74,28 @@ public:
 		ErrorCodeEnum Error = __OnPause(Error_Succeed);
 		pTransactionContext->SendAnswer(Error); 
 	}
+
 	virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
 	{	
 		return Error_Succeed;
 	}
+
 	virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
 	{
 		m_fsm.QueryFWBList(NULL, 2);//oiltest
 		return Error_Succeed;
 	}
+
 	virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
 	{
 		return Error_Succeed;
 	}
+
 	virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
 	{
 		m_fsm.SelfTest(eTestType,pTransactionContext);
 	}
+
 	virtual CServerSessionBase* OnNewSession(const char*,const char*)
 	{
 		return new CardSwiperServerSession(this);
@@ -117,6 +117,7 @@ public:
 		e->ctx = ctx;
 		m_fsm.PostEventFIFO(e);
 	}
+
 	void PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx)
 	{
 		LOG_FUNCTION();
@@ -124,24 +125,27 @@ public:
 		e->ctx = ctx;
 		m_fsm.PostEventFIFO(e);
 	}
+
 	void Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx)
 	{
-		//LOG_FUNCTION();
 		FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
 		m_fsm.PostEventFIFO(evt);
 	}
+
 	void CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx)
 	{
 		m_fsm.SetAcceptWaitMore(false);
 		FSMEvent *evt = new FSMEvent(USER_EVT_CANCELINSERT);
 		m_fsm.PostEventFIFO(evt);
 	}
+
 	void Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx)
 	{
 		ctx->Answer(Error_Succeed);
 		FSMEvent *pEvt = new FSMEvent(USER_EVT_EJECT);
 		m_fsm.PostEventFIFO(pEvt);
 	}
+
 	void QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx)
 	{
 		LOG_FUNCTION();
@@ -182,48 +186,20 @@ public:
 		ctx->Ans.state = m_fsm.GetDevState();
 		ctx->Answer(Error_Succeed);
 	}
+
 	virtual bool IsService()const{return true;}
+
 	virtual bool IsMultiThread()const{return true;}
+
 	virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
 		const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
 		const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage);
+
 	virtual void OnSysVarEvent(const char* pszKey,const char* pszValue, const char* pszOldValue, const char* pszEntityName);
-protected:
+
 private:
 	CardSwiperClass* m_pCardIss;
 	CCardSwiperFSM m_fsm;
 
-	LONG m_lenAPDU;
-	BYTE m_APDUsendBuf[512];
 	CUUID m_uuidAccessAuth;
-
-private:
-	void ConstructAPDU(BYTE cls,BYTE ins,BYTE p1,BYTE p2,BYTE lc,LPBYTE data,LPBYTE le)
-	{
-		LOG_FUNCTION();
-		m_lenAPDU = 0;
-		m_APDUsendBuf[0] = cls;
-		m_APDUsendBuf[1] = ins;
-		m_APDUsendBuf[2] = p1;
-		m_APDUsendBuf[3] = p2;
-		m_lenAPDU = 4;
-		if (lc != NULL && data != NULL)
-		{
-			m_APDUsendBuf[4] = lc;
-			m_lenAPDU++;
-			if (lc != 0)
-			{
-				memcpy(m_APDUsendBuf+m_lenAPDU,data,lc);
-				m_lenAPDU += lc;
-			}
-		}
-		if (le != NULL)
-			m_APDUsendBuf[m_lenAPDU++] = (*le);
-		if (!data)
-		{
-			delete[] data;
-			data = NULL;
-		}
-		Dbg("cmd len[%d]",m_lenAPDU);
-	}
 };