| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- #ifndef RVC_MOD_CENTERSETTING_H__
- #define RVC_MOD_CENTERSETTING_H__
- #pragma once
- #include <map>
- #include <string>
- #include "CenterSetting_server_g.h"
- using namespace CenterSetting;
- #include "modVer.h"
- #include "CenterSettingConn.h"
- #include "SpTest.h"
- enum ConnectServerType
- {
- DEFAULT = 0,
- BACKUP = 1,
- PARAM = 2,
- DEBRANCH = 3
- };
- #define WEBURL_ENV_DEV 1
- #define WEBURL_ENV_ST 2
- #define WEBURL_ENV_UAT 3
- #define WEBURL_ENV_ALL 0
- #define WEBURL_CONFIG_CENTESETTING 0
- #define WEBURL_CONFIG_CUSTOM 1
- #define WEBURL_STATUS_PROVIDE 0
- #define WEBURL_STATUS_DEFAULT 1
- #define WEBURL_STATUS_USING 2
- #define WEBURL_STATUS_DEPRECATE 3
- #define WEBURL_ITEM_COUNT_MAX 100
- #define WEBURL_ITEM_INDEX_CENTERSETTING (WEBURL_ITEM_COUNT_MAX + 1)
- struct CustomWebUrlConfig
- {
- CSimpleStringA strFutureUrl;
- CSimpleStringA strAdUrl;
- CSimpleStringA strRemark;
- int useEnv;
- int configFrom;
- int curStatus;
- int index;
- bool IsValid()
- {
- return (!strFutureUrl.IsNullOrEmpty() && curStatus != WEBURL_STATUS_DEPRECATE);
- }
- };
- 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;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("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_CenterFileNotExists(false), m_nConnectFailCount(0), m_bUseBackupNow(false)
- , m_spDownloadCall(NULL), m_spDownloadCallEx(NULL){}
- 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()
- void OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext);
- virtual void OnStarted();
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext);
- virtual void OnTimeout(DWORD dwTimerID);
- virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszClass*/);
- ErrorCodeEnum GetSyncInfo(unsigned int &dwSyncTime, CSimpleStringA &strSyncHash, CSimpleStringA &strSyncFile);
- ErrorCodeEnum DownloadCenterSetting(SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer sp);
- void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext);
- void EditWebUrl(SpReqAnsContext<CenterSettingService_EditWebUrl_Req, CenterSettingService_EditWebUrl_Ans>::Pointer ctx);
- void GetWebUrlList(SpReqAnsContext<CenterSettingService_GetWebUrlList_Req, CenterSettingService_GetWebUrlList_Ans>::Pointer ctx);
- void GetActiveCustomUrl(SpReqAnsContext<CenterSettingService_GetActiveCustomUrl_Req, CenterSettingService_GetActiveCustomUrl_Ans>::Pointer ctx);
- void EditTerminalBackupInfo(SpReqAnsContext<CenterSettingService_EditTerminalBackupInfo_Req, CenterSettingService_EditTerminalBackupInfo_Ans>::Pointer ctx);
- void GetTerminalBackupInfoList(SpReqAnsContext<CenterSettingService_GetTerminalBackupInfoList_Req, CenterSettingService_GetTerminalBackupInfoList_Ans>::Pointer ctx);
- void DownloadCenterFiles(SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer ctx);
- private:
- ErrorCodeEnum BeginDownloadCenterSetting(LPCTSTR serverIP = NULL, int port = 0);
- ErrorCodeEnum EndDownloadCenterSetting(ErrorCodeEnum rc);
-
- bool ConnectToServiceWithType(ConnectServerType type, LPCTSTR serverIP = NULL, int port = 0);
- void DisconnectForSure();
- bool ParseIPAddress(const char *str, CSimpleStringA &ip, int &port);
- bool TryExtractSiteFromFileName(const char *pszPath, CSimpleStringA &strFileName, CSimpleStringA &strSite);
-
- ErrorCodeEnum GetWebUrlInfoFromCenterSettings(CustomWebUrlConfig& config);
- bool IsServerConnectedNow() const
- {
- return (m_pConnection != nullptr && m_pConnection->IsConnectionOK());
- }
- virtual void OnSysVarEvent(const char *pszKey,
- const char *pszValue, const char *pszOldValue, const char *pszEntityName);
- bool CheckServerIPIsExist();
- ErrorCodeEnum UpdateTerminalInfoAtChange(const CSimpleStringA& newTerminalInfo);
- ErrorCodeEnum ConfirmCenterSettingsFileAndUpdateIfNecessary(const CSimpleStringA& serverIP);
- bool IsParamCurrentUsed(const CSimpleStringA& strTerminalInfo, const CSimpleStringA& strServerIP, DWORD& outMask);
- ErrorCodeEnum GetParamCurrentUseing(CustomWebUrlConfig& config);
- bool IsDownloadPending()
- {
- if (m_spDownloadCall != NULL) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Download Call Pending!");
- return true;
- }
- if (m_spDownloadCallEx != NULL) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Download Call Ex Pending!");
- return true;
- }
- return false;
- }
- void ReturnAndClearDownloadContext(ErrorCodeEnum ec)
- {
- if (m_spDownloadCall != NULL) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DownloadCall return %s", SpStrError(ec));
- m_spDownloadCall->Answer(ec);
- m_spDownloadCall.Clear();
- m_spDownloadCall = NULL;
- }
- if (m_spDownloadCallEx != NULL) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DownloadCallEx return %s", SpStrError(ec));
- m_spDownloadCallEx->Answer(ec);
- m_spDownloadCallEx.Clear();
- m_spDownloadCallEx = NULL;
- }
- }
- void RemoveAllCenterSettingFiles();
- CSimpleStringA GetCenterSettingsACSTypeDownloadUrl();
- private:
- struct ConfigFileInfo
- {
- CSimpleStringA strFileHash;
- CSimpleStringA strFileName;
- DWORD dwSyncTime;
- };
- std::map<std::string, ConfigFileInfo> m_SyncFileInfo;
- CSimpleStringA m_strCurSiteExtName; // 当前场所集中配置扩展名:LAN或DMZ
- CSimpleStringA m_strRvcWebVersion; // 当前RVCWeb版本
- bool m_CenterFileNotExists;
- bool m_bUseBackupNow;
- int m_nConnectFailCount;
- CCenterSettingConn *m_pConnection;
- SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer m_spDownloadCall;
- SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer m_spDownloadCallEx;
- friend class CCenterSettingConn;
- };
- struct DownloadCenterSettingsTask : public ITaskSp
- {
- DownloadCenterSettingsTask(CCenterSettingEntity* entity) :pEntity(entity) {}
- void Process()
- {
- pEntity->DownloadCenterSetting(NULL);
- }
- CCenterSettingEntity* pEntity;
- };
- class CCenterSettingService : public CenterSettingService_ServerSessionBase
- {
- public:
- CCenterSettingService(CCenterSettingEntity *pEntity) :m_pEntity(pEntity){}
- virtual ~CCenterSettingService(){}
- virtual void Handle_Download(SpReqAnsContext<CenterSettingService_Download_Req, CenterSettingService_Download_Ans>::Pointer ctx)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("%s: %s, %d", __FUNCTION__, ctx->Req.strAddr.GetData(), ctx->Req.nPort);
- if (ctx->Req.strAddr.IsNullOrEmpty() || ctx->Req.nPort < 0) {
- ctx->Answer(Error_Param);
- } else {
- m_pEntity->DownloadCenterSetting(ctx);
- }
- }
- virtual void Handle_GetSyncInfo(SpReqAnsContext<CenterSettingService_GetSyncInfo_Req, CenterSettingService_GetSyncInfo_Ans>::Pointer ctx)
- {
- auto rc = m_pEntity->GetSyncInfo(ctx->Ans.nSyncTime, ctx->Ans.strFileHash, ctx->Ans.strFileName);
- ctx->Answer(rc);
- }
- void Handle_EditWebUrl(SpReqAnsContext<CenterSettingService_EditWebUrl_Req, CenterSettingService_EditWebUrl_Ans>::Pointer ctx);
- void Handle_GetWebUrlList(SpReqAnsContext<CenterSettingService_GetWebUrlList_Req, CenterSettingService_GetWebUrlList_Ans>::Pointer ctx);
- void Handle_GetActiveCustomUrl(SpReqAnsContext<CenterSettingService_GetActiveCustomUrl_Req, CenterSettingService_GetActiveCustomUrl_Ans>::Pointer ctx);
- void Handle_EditTerminalBackupInfo(SpReqAnsContext<CenterSettingService_EditTerminalBackupInfo_Req, CenterSettingService_EditTerminalBackupInfo_Ans>::Pointer ctx);
- void Handle_GetTerminalBackupInfoList(SpReqAnsContext<CenterSettingService_GetTerminalBackupInfoList_Req, CenterSettingService_GetTerminalBackupInfoList_Ans>::Pointer ctx);
- void Handle_DownloadCenterFiles(SpReqAnsContext<CenterSettingService_DownloadCenterFiles_Req, CenterSettingService_DownloadCenterFiles_Ans>::Pointer ctx);
- private:
- CCenterSettingEntity *m_pEntity;
- };
- #endif /*RVC_MOD_CENTERSETTING_H__*/
|