Răsfoiți Sursa

#IQRV #comment [Merge]诗友去分行项目:集中配置实体合并

gifur 3 ani în urmă
părinte
comite
755bcb1654

+ 7 - 1
Module/mod_CenterSetting/CMakeLists.txt

@@ -13,10 +13,16 @@ add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 target_include_directories(${MODULE_NAME} PRIVATE
 	${RVC_TOOLKIT_INCLUDE_DIR}
 	${OTHER_LIB_BASE_DIR}/libpublicFun
+	${CONAN_INCLUDE_DIRS_JSONCPP}
+)
+
+target_link_directories(${MODULE_NAME} PRIVATE
+	${CONAN_LIB_DIRS_JSONCPP}
 )
 
 # 添加实体需要依赖的其他共享库(包括系统库)
 set(${MODULE_PREFIX}_LIBS ${MODULE_BASE_LIBS} ${RVCCOMM_LIB})
-target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} CONAN_PKG::OpenSSL libpublicFun)
+target_link_libraries(${MODULE_NAME} 
+	${${MODULE_PREFIX}_LIBS} CONAN_PKG::OpenSSL libpublicFun ${CONAN_PKG_LIBS_JSONCPP})
 
 deploy_module(${MODULE_PREFIX} ${MODULE_NAME})

+ 267 - 18
Module/mod_CenterSetting/CenterSettingConn.cpp

@@ -10,9 +10,64 @@ using std::regex;
 #include "fileutil.h"
 #include "iniutil.h"
 
+#if defined(RVC_OS_WIN)
+#pragma comment(lib, "crypt32.lib")
+#endif //RVC_OS_WIN
+
+
+bool CenterSettingResponse::Parse(string strData)
+{
+		Json::Value root;
+		Json::Reader reader;
+		reader.parse(strData, root, false);
+
+		bSuccess = root["success"].asBool();
+
+		if(bSuccess)
+		{
+			for(int i = 0; i < 2; ++i)
+			{
+				
+				if(root["data"][sites[i]].isNull())
+				{
+					Dbg("%s config is NULL.", sites[i].c_str());
+					continue;
+				}
+				configOfOneBranch.m_lastUpdateTime = root["data"][sites[i]]["lastUpdateTime"].asString();
+				configOfOneBranch.m_branchNo = root["data"][sites[i]]["branchNo"].asString();
+				if(sites[i] == "BIZ")
+					configOfOneBranch.m_site = "LAN";
+				else
+					configOfOneBranch.m_site = sites[i];
+				const string _site = configOfOneBranch.m_site;
+				configOfOneBranch.m_count = 0;
+				auto configArr = root["data"][sites[i]]["config"];
+				allConfigs[_site] = configOfOneBranch;
+				if(configArr.isArray()){
+					for(int j = 0; j < configArr.size(); j++)
+					{
+						allConfigs[_site].m_count++;
+						ConfigItem configItem;
+						
+						configItem.m_cnName = configArr[j]["cnName"].asString();
+						configItem.m_moudle = configArr[j]["moudle"].asString();
+						configItem.m_name = configArr[j]["name"].asString();
+						configItem.m_remark = configArr[j]["remark"].asString();
+						configItem.m_value = configArr[j]["value"].asString();
+						
+						allConfigs[_site].configSet.push_back(configItem);
+					}
+				}
+
+			}
+		}
+		return true;
+}
+
 CCenterSettingConn::CCenterSettingConn(CEntityBase *pEntity)
 	: SpSecureClient(pEntity)
 {
+	GetConfig();
 }
 
 
@@ -99,6 +154,15 @@ ErrorCodeEnum CCenterSettingConn::BeginPollConfig(const CSystemStaticInfo& info)
 	assert(pFunc != NULL);
 	CSimpleStringA strPath;
 	pFunc->GetPath("Cfg", strPath);
+
+	if(DeleteErrorFiles(strPath))
+	{
+		Dbg("delete error files succ.(hyc)");
+	}
+	else
+	{
+		Dbg("delete error files failed.(hyc)");
+	}
 	auto pPackage = CreateNewPackage("PollSM");
 	const int nArrayNum = pEntity->m_SyncFileInfo.size();
 	if (nArrayNum> 0)
@@ -170,10 +234,11 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
 		CSimpleStringA strCurStructName = CSimpleStringA::Format("PollSMA%d", nIndex);
 		
 		int nRetLen = pRecvPkg->GetStructLen(strCurStructName);
-        if (nRetLen == -1) {
-            Dbg("Get %s pkg struct failed !", strCurStructName.GetData());
-            break;
-        }
+		if (nRetLen == -1)
+		{
+			Dbg("Get %s pkg struct failed !", strCurStructName.GetData());
+			break;
+		}
 
 		nIndex++;
 
@@ -215,8 +280,15 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
 		pFunc->GetPath("Cfg", strPath);
 		CSimpleStringA strCurFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)pRet->FileName);
 
+		CSimpleString strRunInfoPath;
+		///**TODO(Gifur@9/16/2021): GetPath("RunCfg") implement! */
+		pFunc->GetPath("RunInfo", strRunInfoPath);
+		strRunInfoPath += SPLIT_SLASH_STR;
+		strRunInfoPath += "runcfg";
+		CSimpleStringA strNewPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strRunInfoPath, (const char*)pRet->FileName);
+
 		// 保存新配置文件
-		CSimpleStringA strNewFile = strCurFile + ".new";
+		CSimpleStringA strNewFile = strNewPath + ".new";
 		auto hFile = fopen(strNewFile, "wb");
 		int nLen = fwrite(pRet->FileContent, 1, nRetLen - sizeof(PollSMA), hFile);
 		fflush(hFile);
@@ -243,7 +315,9 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
 	
 		// 读出当前集中配置服务地址
 		memset(tmp, 0, 32);
-		inifile_read_str_s("CenterSetting", "Server", "", tmp, 32, strCurFile);
+		if (10 > inifile_read_str_s("CenterSetting", "Server", "", tmp, 32, strCurFile)) {
+			Dbg("read center setting service addr from exist file %s fail: (%d)", strCurFile.GetData(), GetLastError());
+		}
 		CSimpleStringA strCurServer = tmp;
 
 		// 写入同步信息
@@ -257,24 +331,24 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
 
 		// 保存原配置文件
 
-		time_t t = time(NULL);
-		tm* t1 = localtime(&t);
 
-		//SYSTEMTIME st = {};
-		//GetLocalTime(&st);
-		//CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
-		//	st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
-		CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
-			t1->tm_year + 1900, t1->tm_mon + 1, t1->tm_mday, t1->tm_hour, t1->tm_min);
+#if defined(RVC_OS_WIN)
+        SYSTEMTIME st = {};
+        GetLocalTime(&st);
+        CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
+                                                            st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
+#else
+        time_t t = time(NULL);
+        tm* t1 = localtime(&t);
+        CSimpleStringA strBackFile = CSimpleStringA::Format("%s.%04d%02d%02d%02d%02d", (const char*)strCurFile,
+                                                            t1->tm_year + 1900, t1->tm_mon + 1, t1->tm_mday, t1->tm_hour, t1->tm_min);
+#endif //RVC_OS_WIN
 		fileutil_copy_file(strBackFile, strCurFile);
-		//CopyFileA(strCurFile, strBackFile, FALSE);
 
 		// 替换当前配置文件
 		fileutil_copy_file(strCurFile, strNewFile);
-		//CopyFileA(strNewFile, strCurFile, FALSE);
 		fileutil_delete_file(strNewFile);
-		//DeleteFileA(strNewFile);
-		Dbg("Save config %s succ", (const char*)pRet->FileName);
+		Dbg("save config %s succ", (const char*)pRet->FileName);
 
 		// 保存同步信息
 		CCenterSettingEntity::ConfigFileInfo  info;
@@ -317,3 +391,178 @@ ErrorCodeEnum CCenterSettingConn::OnEndPollConfig(const CSmartPointer<IPackage>
 		return Error_NotExist;
 	}
 }
+
+
+bool CCenterSettingConn::DeleteErrorFiles(CSimpleStringA filePath)
+{
+    LOG_FUNCTION();
+    array_header_t* arr = fileutil_get_sub_files_a(filePath);
+    if (arr) {
+        for (int i = 0; i < arr->nelts; ++i) {
+			char* path = (char*)ARRAY_IDX(arr, i, char*);
+            regex reg("((DMZ)|(LAN))[^(\.ini)]");
+			if (regex_search(path, reg)) {
+                Dbg("delete: %s", path);
+				fileutil_delete_file(path);
+			}
+        }
+        toolkit_array_free2(arr);
+      }
+    return true;
+}
+
+bool CCenterSettingConn::InTerminalList()
+{
+	LOG_FUNCTION();
+    auto arrTerminalList = m_strTerminalList.Split('|');
+    Dbg("m_strTerminalList:%s", (const char*)m_strTerminalList);
+
+    for (int i = 0; i < arrTerminalList.GetCount(); ++i) {
+        if (info.strTerminalID == arrTerminalList[i]) {
+            Dbg("In terminalList.");
+            return true;
+        }
+    }
+    Dbg("Not in terminalList.");
+    return false;
+}
+
+void CCenterSettingConn::GetConfig()
+{
+    LOG_FUNCTION();
+
+    auto pFunc = m_pEntity->GetFunction();
+    assert(pFunc != NULL);
+	auto rc = pFunc->GetSystemStaticInfo(info);
+	assert(rc == Error_Succeed);
+	CSimpleStringA strCenterSetPath;
+	pFunc->GetPath("CenterSetting", strCenterSetPath);
+	m_strSite = "LAN";
+	if (strCenterSetPath.IsEndWith("DMZ.ini", true)) {
+		m_strSite = "DMZ";
+	}
+
+    CSmartPointer<IConfigInfo> spConfig;
+    ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
+    if (Error == Error_Succeed) 
+	{
+		spConfig->ReadConfigValue("Common", "GrayLaunchUrl", m_strGrayLaunchUrl);
+		spConfig->ReadConfigValue("Initializer", "SubBankNo", m_strCallRouteBranchNo);
+		spConfig->ReadConfigValue("CenterSetting", "CenterConfigUrl", m_strCenterSettingUrl);
+		spConfig->ReadConfigValue("CenterSetting", "LastUpdateTime", m_strLastTime);
+		spConfig->ReadConfigValue("CenterSetting", "Mode", m_strMode);
+		spConfig->ReadConfigValue("CenterSetting", "TerminalList", m_strTerminalList);
+    }
+}
+
+void CCenterSettingConn::WriteToConfig(const CenterSettings& configOfOneBranch)
+{
+    LOG_FUNCTION();
+    auto pFunc = m_pEntity->GetFunction();
+    assert(pFunc != NULL);
+    CSimpleStringA strPath;
+    pFunc->GetPath("Cfg", strPath);
+
+	///**TODO(Gifur@9/16/2021): GetPath("CenterSetting") 通过此接口来获取集中配置路径地址 */
+    CSimpleStringA fileName = CSimpleStringA::Format("CenterSetting.%s.ini", configOfOneBranch.m_site.c_str());
+    Dbg("fileName:%s", fileName.GetData());
+    CSimpleStringA strCurFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strPath, (const char*)fileName);
+
+    CSimpleString strRunInfoPath;
+    ///**TODO(Gifur@9/16/2021): GetPath("RunCfg") implement! */
+    pFunc->GetPath("RunInfo", strRunInfoPath);
+    strRunInfoPath += SPLIT_SLASH_STR;
+    strRunInfoPath += "runcfg";
+	CSimpleStringA strNewPath = strRunInfoPath + SPLIT_SLASH_STR;
+    CSimpleStringA strNewFile = strNewPath + fileName + ".new";
+
+	inifile_write_str(strNewFile, "CenterSetting", "LastUpdateTime", configOfOneBranch.m_lastUpdateTime.c_str());
+    for (int i = 0; i < configOfOneBranch.m_count; i++) {
+        string module = configOfOneBranch.configSet[i].m_moudle;
+        string name = configOfOneBranch.configSet[i].m_name;
+        string value = configOfOneBranch.configSet[i].m_value;
+        inifile_write_str(strNewFile, module.c_str(), name.c_str(), value.c_str());
+    }
+
+    // 替换当前配置文件
+	fileutil_copy_file(strCurFile, strNewFile);
+	fileutil_delete_file(strNewFile);
+
+    Dbg("save config %s succ", fileName.GetData());
+}
+
+ErrorCodeEnum CCenterSettingConn::GetCenterSetting()
+{
+    LOG_FUNCTION();
+    CenterSettingReq sReq;
+    sReq.m_url = m_strCenterSettingUrl;
+    sReq.m_last_update_time = m_strLastTime;
+
+    sReq.m_terminal_no = info.strTerminalID;
+    CenterSettingResponse sResponse;
+
+    Dbg("sReq.m_url:%s", sReq.m_url.c_str());
+
+    bool ret = m_pHttpFunc->Post(sReq, sResponse);
+
+    if (ret && sResponse.bSuccess) {
+        std::string tmp(m_strSite.GetData());
+        if (sResponse.allConfigs[tmp].m_lastUpdateTime == sReq.m_last_update_time) {
+            Dbg("Centersetting.%s.ini not changed.", m_strSite.GetData());
+            return Error_Succeed;
+        }
+        int cnt = 0;
+
+        for (auto iter = sResponse.allConfigs.cbegin(); iter != sResponse.allConfigs.cend(); iter++) {
+            cnt++;
+            WriteToConfig(iter->second);
+            CSimpleStringA msg = CSimpleString::Format("Update CenterSetting.%s.ini.", m_strSite.GetData());
+            LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_UPDATE, msg);
+        }
+
+        return Error_Succeed;
+    }
+    return Error_Unexpect;
+}
+
+ErrorCodeEnum CCenterSettingConn::GrayLaunch(BOOL& grayLaunch)
+{
+	LOG_FUNCTION();
+
+    m_pHttpFunc = create_http(HTTPLogCallback);
+    m_bGrayLaunch = false;
+
+    if (m_strGrayLaunchUrl.GetLength() != 0) {
+		GrayLaunchReq gReq;
+        gReq.m_url = m_strGrayLaunchUrl.GetData();
+        Dbg("gReq.m_url: %s", gReq.m_url.c_str());
+        gReq.m_terminal_no = info.strTerminalID;
+        gReq.m_branch_no = m_strCallRouteBranchNo;
+        gReq.m_modular = "centersetting";
+        GrayLaunchResponse gResponse;
+
+        bool ret = m_pHttpFunc->Get(gReq, gResponse);
+        if (ret) {
+            m_bGrayLaunch = gResponse.m_result;
+            grayLaunch = m_bGrayLaunch;
+
+            return Error_Succeed;
+        }
+    }
+    return Error_Unexpect;
+}
+
+void CCenterSettingConn::WriteIniFile(CSimpleStringA appName, CSimpleStringA keyName, CSimpleStringA value, CSimpleStringA newFile)
+{
+	if(-1 == inifile_write_str(newFile, appName, keyName, value)) {
+        LogWarn(Severity_Middle, Error_Unexpect, ERR_MOD_CENTERSETTING_WRITE_FAILED, "集中配置写入失败");
+        Dbg("Write config to %s fail(%d): appName=%s, keyName=%s, value=%s", newFile, GetLastError(), appName, keyName, value);
+    }
+}
+
+bool CCenterSettingConn::GetMode() 
+{
+	LOG_FUNCTION();
+	Dbg("m_strMode:%s", (const char*)m_strMode);
+	return (m_strMode == "1");
+}

+ 64 - 1
Module/mod_CenterSetting/CenterSettingConn.h

@@ -4,7 +4,12 @@
 #pragma once
 
 #include "SpSecureClient.h"
-
+#include "SpIni.h"
+#include "IHttpFunc.h"
+#include "json/json.h"
+#include "EventCode.h"
+#include <vector>
+#include <string>
 #pragma pack(1)
 // 变更查询 {PollCfg}
 // 新终端版本上送 {PollCfg2}
@@ -66,13 +71,60 @@ struct PollSMA
 };
 #pragma pack()
 
+struct CenterSettingReq : CHTTPReq{
+	CenterSettingReq(){m_timeOut = 5;}
+	string m_terminal_no;
+	string m_last_update_time;
+	virtual string ToJson(){
+		char reqcontent[512];
+		sprintf(reqcontent, "{\"terminal_no\":\"%s\",\"last_update_time\":\"%s\"}", m_terminal_no.c_str(), 
+			m_last_update_time.c_str());
+		return reqcontent;
+	}
+};
+
+struct ConfigItem{
+	string m_cnName;
+	string m_moudle;
+	string m_name;
+	string m_remark;
+	string m_value;
+};
+
+struct CenterSettings{
+	int m_count;
+	string m_lastUpdateTime;
+	string m_branchNo;
+	string m_site;
+	vector<ConfigItem>configSet;
+};
+
+static string sites[] = {"DMZ","BIZ"};
+
+struct CenterSettingResponse : CHTTPRet{
+	CenterSettingResponse(){}
+	CenterSettings configOfOneBranch;
+	map<string, CenterSettings> allConfigs;
+	bool bSuccess;
 
+	virtual bool Parse(string strData);
+};
 
 class CCenterSettingConn : public SpSecureClient
 {
 public:
 	CCenterSettingConn(CEntityBase *pEntity);
 	ErrorCodeEnum BeginPollConfig(const CSystemStaticInfo& info);
+	ErrorCodeEnum GetCenterSetting();
+	ErrorCodeEnum GrayLaunch(BOOL &grayLaunch);
+	CSystemStaticInfo info;
+	bool GetMode();
+	void GetConfig();
+	bool InTerminalList();
+	CSimpleStringA m_strTerminalList;
+	CSimpleStringA m_strMode;
+
+	bool DeleteErrorFiles(CSimpleStringA filePath);
 
 private:
 	virtual ~CCenterSettingConn(void);
@@ -84,6 +136,17 @@ private:
 	UINT64 ConvertBytesToUINT64(byte bytesData[8]);
 	bool IsServiceAvailable(const char *pszServiceAddr);
 	bool ParseIPAddress(const char *str, CSimpleStringA &ip, int &port);
+
+	void WriteToConfig(const CenterSettings& configOfOneBranch);
+	void WriteIniFile(CSimpleStringA appName, CSimpleStringA keyName, CSimpleStringA value, CSimpleStringA newFile);
+
+	IHttpFunc *m_pHttpFunc;
+	BOOL m_bGrayLaunch;
+	CSimpleStringA m_strGrayLaunchUrl;
+	CSimpleStringA m_strCallRouteBranchNo;
+	CSimpleStringA m_strCenterSettingUrl;
+	CSimpleStringA m_strLastTime;
+	CSimpleStringA m_strSite;
 };
 
 #endif //RVC_MOD_CENTERSETTING_CONN_H_

+ 96 - 5
Module/mod_CenterSetting/mod_centersetting.cpp

@@ -94,6 +94,9 @@ void CCenterSettingEntity::OnStarted()
 
 	 // 立刻同步配置
 	 GetFunction()->PostEntityTaskFIFO(new DownloadCenterSettingsTask(this));
+	 
+	 //订阅首页状态
+	 GetFunction()->RegistSysVarEvent("UIState", this);
 
 	 // 启动轮询定时器 5min
 	 GetFunction()->SetTimer(DOWNLOAD_CENTERSETTINGS_TIMER_ID, this, DOWNLOAD_CENTERSETTINGS_TIMER_INTERVAL);
@@ -114,17 +117,37 @@ void CCenterSettingEntity::OnStarted()
  ErrorCodeEnum CCenterSettingEntity::BeginDownloadCenterSetting(LPCTSTR serverIP, int port)
  {
 	 LOG_FUNCTION();
+	 //TODO
+	 m_pConnection = new CCenterSettingConn(this);
+
+	 if (!GetServerIP())
+	 {
+		 Dbg("Centersetting may be lost.");
+		 //return Error_Unexpect;
+	 }
 
 	 if (serverIP != NULL && strlen(serverIP) > 0 && port > 0) {
 		 if (!SecureClientConnect(ConnectServerType::PARAM, serverIP, port)) {
 			 return Error_NetBroken;
 		 }
-	 } else {
-         if (!SecureClientConnect(ConnectServerType::DEFAULT)) {
-                 return Error_NetBroken;
-         }
+	 }
+	 else {
+		 if (!SecureClientConnect(ConnectServerType::DEFAULT)) {
+			 return Error_NetBroken;
+		 }
 	 }
 
+	 if (m_bGrayLaunch) {
+         ErrorCodeEnum rc = m_pConnection->GetCenterSetting(); //新模式
+         if (rc != Error_Succeed)
+             LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_CONNECT_FAILED, "Get centersetting failed.");
+         else
+             LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_CONNECT_SUCC, "Get centersetting succ.");
+		 ReturnAndClearDownloadContext(rc);
+		 return rc;
+	 }
+
+	 
 	 m_nConnectFailCount = 0;
 	 LOG_ASSERT(IsServerConnectedNow());
 
@@ -736,7 +759,19 @@ void CCenterSettingEntity::OnStarted()
 	 m_bUseBackupNow = (type == ConnectServerType::BACKUP);
 
 	 m_pConnection = new CCenterSettingConn(this);
-	 
+
+     //TerminalList中或Mode=1的终端走新模式,否则走旧模式
+	 if (m_pConnection->InTerminalList() || m_pConnection->GetMode()) {
+		ErrorCodeEnum rc = m_pConnection->GrayLaunch(m_bGrayLaunch);
+        if (Error_Succeed != rc) {
+            LogWarn(Severity_Middle, rc, ERR_MOD_CENTERSETTING_GRAY_CONNECT_FAILED, "Get grayLaunch failed.");
+			return false;
+        } else if(m_bGrayLaunch) {
+            LogWarn(Severity_Middle, Error_Succeed, EVENT_MOD_CENTERSETTING_GRAY_CONNECT_SUCC, "Get grayLaunch succ.");
+			return true;
+        }
+	 }
+
 	 if (m_bUseBackupNow)
 	 {
 		 CSmartPointer<IConfigInfo> pConfig;
@@ -779,8 +814,60 @@ void CCenterSettingEntity::OnStarted()
 		 m_pConnection->DecRefCount();
 		 m_pConnection = NULL;
 	 }
+	 m_bGrayLaunch = FALSE;
+ }
+
+ void CCenterSettingEntity::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) {
+             Dbg("enter main page");
+             CSimpleStringA strCurFile;
+             GetFunction()->GetPath("CenterSetting", strCurFile);
+
+             CSimpleStringA strBackFile = CSimpleStringA::Format("%s.backup", strCurFile.GetData());
+             if (!fileutil_copy_file(strBackFile, strCurFile)) {
+                 Dbg("Copy curFile to backFile failed: %d", GetLastError());
+             }
+             GetFunction()->UnregistSysVarEvent("UIState");
+         } else {
+             Dbg("not main page[%s]", pszValue);
+         }
+     }
  }
 
+ bool CCenterSettingEntity::GetServerIP()
+ {
+	 LOG_FUNCTION();
+
+     CSmartPointer<IConfigInfo> pConfig;
+     auto rc = GetFunction()->OpenConfig(Config_CenterSetting, pConfig);
+
+     assert(rc == Error_Succeed);
+
+     CSimpleStringA strServer;
+
+     rc = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
+     if (rc != Error_Succeed || strServer.IsNullOrEmpty()) {
+         Dbg("read strServer from center setting fail.");
+         Dbg("use backup center setting...");
+
+         CSimpleStringA strBackFile, strCurFile;
+         GetFunction()->GetPath("CenterSetting", strCurFile);
+         strBackFile = CSimpleStringA::Format("%s.backup", strCurFile.GetData());
+		 if(-1 == fileutil_copy_file(strCurFile, strBackFile)) {
+             Dbg("Copy backFile to curFile failed: %d", GetLastError());
+             return false;
+		 } else {
+             rc = pConfig->ReadConfigValue("CenterSetting", "Server", strServer);
+			 if (rc != Error_Succeed || strServer.IsNullOrEmpty()) {
+				 return false;
+			 }
+		 }
+     }
+     return true;
+ }
 
  ErrorCodeEnum CCenterSettingEntity::UpdateTerminalInfoAtChange(const CSimpleStringA& newTerminalInfo)
  {
@@ -897,6 +984,10 @@ void CCenterSettingEntity::OnStarted()
 		 }
          toolkit_array_free2(subs);
      }
+
+	 if (m_pConnection != NULL) {
+		 m_pConnection->DeleteErrorFiles(strEntityCfgPath);
+	 }
  }
 
  ErrorCodeEnum CCenterSettingEntity::ConfirmCenterSettingsFileAndUpdateIfNecessary(const CSimpleStringA& serverIP)

+ 42 - 2
Module/mod_CenterSetting/mod_centersetting.h

@@ -52,11 +52,44 @@ struct CustomWebUrlConfig
 		return (!strFutureUrl.IsNullOrEmpty() && curStatus != WEBURL_STATUS_DEPRECATE);
 	}
 };
-class CCenterSettingEntity : public CEntityBase, public ITimerListener
+
+
+struct GrayLaunchReq : CHTTPReq{
+	GrayLaunchReq(){m_timeOut = 5;}
+	string m_terminal_no;
+	string m_branch_no;
+    string m_modular;
+	virtual string ToJson(){
+		char reqcontent[512];
+		sprintf(reqcontent, "{\"terminal_no\":\"%s\",\"branch_no\":\"%s\",\"modular\":\"%s\"}", m_terminal_no.c_str(), 
+			m_branch_no.c_str(), m_modular.c_str());
+		return reqcontent;
+	}
+};
+
+struct GrayLaunchResponse : CHTTPRet{
+	GrayLaunchResponse():m_result(false){}
+	bool m_result;
+	virtual bool Parse(string strData){
+		Json::Value root;
+		Json::Reader reader;
+		Dbg("GrayLaunchResponse.Parse");
+		reader.parse(strData, root, false);
+		if (root["data"].isBool()) {
+			m_result = root["data"].asBool();
+		}
+		
+		return true;
+	}
+};
+
+static void HTTPLogCallback(const char* msg){}
+
+class CCenterSettingEntity : public CEntityBase, public ITimerListener, public ISysVarListener
 {
 public:
 	CCenterSettingEntity() : /*m_dwLastSyncTime(0),*/
-		m_pConnection(nullptr), m_nConnectFailCount(0), m_bUseBackupNow(false)
+		m_pConnection(nullptr), m_nConnectFailCount(0), m_bUseBackupNow(false), m_bStartUp(false)
 		, m_spDownloadCall(NULL), m_spDownloadCallEx(NULL){}
 	virtual ~CCenterSettingEntity() {}
 	virtual const char *GetEntityName() const { return "CenterSetting"; }
@@ -100,6 +133,10 @@ private:
 	{
 		return (m_pConnection != nullptr && m_pConnection->IsConnectionOK());
 	}
+	virtual void OnSysVarEvent(const char *pszKey,
+		const char *pszValue, const char *pszOldValue, const char *pszEntityName);
+	bool GetServerIP();
+
 	ErrorCodeEnum UpdateTerminalInfoAtChange(const CSimpleStringA& newTerminalInfo);
 	ErrorCodeEnum ConfirmCenterSettingsFileAndUpdateIfNecessary(const CSimpleStringA& serverIP);
 	bool IsParamCurrentUsed(const CSimpleStringA& strTerminalInfo, const CSimpleStringA& strServerIP, DWORD& outMask);
@@ -139,6 +176,7 @@ private:
 
 	void RemoveAllCenterSettingFiles();
 
+
 private:
 	struct ConfigFileInfo
 	{
@@ -153,6 +191,8 @@ private:
 	bool m_bUseBackupNow;
 	int m_nConnectFailCount;
 	CCenterSettingConn *m_pConnection;
+	BOOL m_bGrayLaunch;
+	bool m_bStartUp;
 	
 	SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer m_spDownloadCall;
     SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer m_spDownloadCallEx;