mod_selfchecker.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef __MOD_SELFCHECKER_H
  2. #define __MOD_SELFCHECKER_H
  3. #pragma once
  4. #include "SpBase.h"
  5. #include "SelfCheckerFSM.h"
  6. #include "SelfChecker_server_g.h"
  7. #include "AssistantChannel_client_g.h"
  8. #include "chan_protocol.h"
  9. using namespace SelfChecker;
  10. using namespace AssistantChannel;
  11. struct EntityProcessInfo
  12. {
  13. int restartTimes;
  14. EntityProcessInfo(){restartTimes = 0;}
  15. };
  16. class CSelfCheckerEntity;
  17. class SelfCheckerSession : public SelfCheckerService_ServerSessionBase
  18. {
  19. public:
  20. SelfCheckerSession(CSelfCheckerEntity *pEntity):m_pEntity(pEntity){}
  21. virtual ~SelfCheckerSession(){};
  22. virtual void Handle_RealCheck(SpReqAnsContext<SelfCheckerService_RealCheck_Req, SelfCheckerService_RealCheck_Ans>::Pointer ctx);
  23. virtual void Handle_GetEntityErrorList(SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx);
  24. private:
  25. CSelfCheckerEntity *m_pEntity;
  26. };
  27. class AssistChannelSelfCheckerClient : public ChannelService_ClientBase
  28. {
  29. public:
  30. AssistChannelSelfCheckerClient(CSelfCheckerEntity *pEntity);
  31. virtual ~AssistChannelSelfCheckerClient(){}
  32. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  33. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  34. };
  35. class CSelfCheckerEntity : public CEntityBase,public IEntityLifeListener,public IEntityStateListener
  36. ,public ILogListener
  37. {
  38. public:
  39. CSelfCheckerEntity():m_bIEIdle(false),m_pAssChanClient(NULL){ }
  40. virtual ~CSelfCheckerEntity() {}
  41. virtual const char *GetEntityName() const { return "SelfChecker"; }
  42. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  43. {
  44. LOG_FUNCTION();
  45. ErrorCodeEnum errCode = Error_Succeed;
  46. m_fsm.Init(this);
  47. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  48. CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
  49. if (pFuncPrivilege != NULL) {
  50. errCode = pFuncPrivilege->RegistEntityLifeEvent(this); // NULL to register for all
  51. if (errCode != Error_Succeed)
  52. {
  53. Dbg("RegistEntityLife failed(%d).",errCode);
  54. pTransactionContext->SendAnswer(errCode);
  55. return;
  56. }
  57. } else {
  58. errCode = Error_NoPrivilege;
  59. Dbg("NoPrivilege");
  60. pTransactionContext->SendAnswer(errCode);
  61. return;
  62. }
  63. errCode = pFuncPrivilege->RegistEntityStateEvent(NULL,this);
  64. if (errCode != Error_Succeed)
  65. {
  66. Dbg("RegistEntityState failed(%d).",errCode);
  67. pTransactionContext->SendAnswer(errCode);
  68. return;
  69. }
  70. Dbg("regist entity event ok.");
  71. GetFunction()->SubscribeLog(m_uuidCardIsuuer,this,Log_Error,Severity_High,Error_IgnoreAll,-1,NULL,false);
  72. GetFunction()->SubscribeLog(m_uuidCardSwiper,this,Log_Event,Severity_High,Error_IgnoreAll,-1,"CardSwiper",false);
  73. GetFunction()->SubscribeLog(m_uuidCardSwiper, this, Log_Error, Severity_Middle, Error_IgnoreAll, -1, "CardSwiper");
  74. //GetFunction()->SubscribeLog(m_uuidPinPad,this,Log_Error,Severity_High,Error_IgnoreAll,-1,"PinPad",false);
  75. //GetFunction()->SubscribeLog(m_uuidIDCertificate,this,Log_Error,Severity_High,Error_IgnoreAll,-1,"IDCertificate",false);
  76. //GetFunction()->SubscribeLog(m_uuidMedia,this,Log_Error,Severity_High,Error_IgnoreAll,-1,"MediaController",false);
  77. CSmartPointer<IConfigInfo> spConfig;
  78. ErrorCodeEnum eCfg = pFunc->OpenConfig(Config_Software, spConfig);
  79. if (eCfg != Error_Succeed) {
  80. Dbg("open cfg file failed()!",eCfg);
  81. }
  82. else
  83. {
  84. spConfig->ReadConfigValue("init","QueryStateEntity",m_csQueryStateEntity);
  85. }
  86. auto list = m_csQueryStateEntity.Split(',');
  87. for (int i = 0; i < list.GetCount(); ++i)
  88. {
  89. CSimpleStringA entity = list[i];
  90. m_vQueryStateEntity.push_back(entity);
  91. }
  92. //ConnectToAssistChannel();
  93. //ConnectToHealthManager();
  94. pTransactionContext->SendAnswer(errCode);
  95. }
  96. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  97. {
  98. pTransactionContext->SendAnswer(Error_Succeed);
  99. }
  100. virtual void OnCreated(const char *pszEntityName,ErrorCodeEnum eOnStartErrorCode,const char *pszCallerEntity);
  101. virtual void OnClosed(const char *pszEntityName,EntityCloseCauseEnum eCloseCause,ErrorCodeEnum eOnCloseErrorCode,const char *pszCallerEntity);
  102. virtual void OnException(const char *pszEntityName,const char *pszFunctionName,EntityStateEnum eState,EntityStateEnum eLastState,ErrorCodeEnum eErrorCode);
  103. virtual void OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState);
  104. virtual void OnUserStateHook(const char *pszEntityName,DWORD dwState,DWORD dwLastState);
  105. virtual void OnCeateConnection(const char *pszCallerEntity,const char *pszServiceEntity);
  106. virtual void OnCloseConnection(const char *pszCallerEntity,const char *pszServiceEntity);
  107. //int GetActiveCount(){return m_activeEntity.size();}
  108. ErrorCodeEnum GetLiveEntityList(CAutoArray<CSimpleString> &LiveEntitys);
  109. ErrorCodeEnum GetEntityTestCode(const char *pszEntityName,ErrorCodeEnum &LastTestError, TestActionEnum &eLastAction);
  110. ErrorCodeEnum ExamineEntity(const char *pszEntityName);
  111. bool GetIEIdleFlag() {return m_bIEIdle;}
  112. void RealCheck(SpReqAnsContext<SelfCheckerService_RealCheck_Req, SelfCheckerService_RealCheck_Ans>::Pointer ctx);
  113. void GetEntityErrorList(SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx);
  114. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  115. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  116. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage);
  117. ErrorCodeEnum MsgPushedByAssChannel(const int type,const int sub_type,const char *pszEntityName="",const char *msg="");
  118. ErrorCodeEnum GetEntityStatusStr(CSimpleStringA &result);
  119. ErrorCodeEnum ConnectToAssistChannel();
  120. //ErrorCodeEnum ConnectToHealthManager();
  121. //ErrorCodeEnum AddEntity(vector<CSimpleStringA> &entityVec,const char *pszEntityName);
  122. //ErrorCodeEnum RemoveEntity(vector<CSimpleStringA> &entityVec,const char *pszEntityName);
  123. //ErrorCodeEnum CheckEntity();
  124. virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  125. {
  126. return new SelfCheckerSession(this);
  127. }
  128. virtual bool IsService()const{return true;}
  129. virtual bool IsMultiThread()const{return true;}
  130. private:
  131. CSelfCheckerFSM m_fsm;
  132. map<CSimpleStringA,EntityProcessInfo> m_entityProcInfo;
  133. bool m_bIEIdle;
  134. CUUID m_uuidCardIsuuer,m_uuidCardSwiper,m_uuidPinPad,m_uuidIDCertificate,m_uuidMedia;
  135. AssistChannelSelfCheckerClient *m_pAssChanClient;
  136. CSimpleStringA m_csQueryStateEntity;
  137. vector<CSimpleStringA> m_vQueryStateEntity;
  138. ErrorCodeEnum RestartModule(const char* pEntityName);
  139. };
  140. AssistChannelSelfCheckerClient::AssistChannelSelfCheckerClient(CSelfCheckerEntity *pEntity):ChannelService_ClientBase(pEntity)
  141. {
  142. }
  143. #endif // __MOD_SELFCHECKER_H