mod_FingerPrint.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #ifndef MOD_FINGERPRINT_H
  2. #define MOD_FINGERPRINT_H
  3. #include "FingerPrintFSM.h"
  4. #include "FingerPrint_server_g.h"
  5. #include "modVer.h"
  6. #ifdef RVC_OS_WIN
  7. #else
  8. #include "SpTest.h"
  9. #endif
  10. class CFingerPrintEntity;
  11. class FingerPrintServerSession : public FingerPrint::FingerPrintService_ServerSessionBase
  12. {
  13. public:
  14. FingerPrintServerSession(CFingerPrintEntity* pEntity) : m_pEntity(pEntity){}
  15. virtual ~FingerPrintServerSession(){}
  16. virtual void Handle_GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx);
  17. virtual void Handle_GetImageAndFeatureEx(SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx);
  18. virtual void Handle_GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx);
  19. virtual void Handle_GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx);
  20. virtual void Handle_CancelRegister(SpOnewayCallContext<FingerPrintService_CancelRegister_Info>::Pointer ctx);
  21. virtual void Handle_CancelMatch(SpOnewayCallContext<FingerPrintService_CancelMatch_Info>::Pointer ctx);
  22. virtual void Handle_GetDevInfo(SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx);
  23. virtual void Handle_GetDevStatus(SpReqAnsContext<FingerPrintService_GetDevStatus_Req, FingerPrintService_GetDevStatus_Ans>::Pointer ctx);
  24. virtual void Handle_Match(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx);
  25. virtual void Handle_Exit(SpOnewayCallContext<FingerPrintService_Exit_Info>::Pointer ctx);
  26. private:
  27. CFingerPrintEntity* m_pEntity;
  28. };
  29. class CFingerPrintEntity : public CDevAdptEntityBase, public ISysVarListener
  30. {
  31. public:
  32. CFingerPrintEntity(){}
  33. virtual ~CFingerPrintEntity(){}
  34. virtual const char *GetEntityName() const { return "FingerPrint"; }
  35. virtual bool IsService() const {return true;}
  36. #ifdef RVC_OS_WIN
  37. #else
  38. virtual const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  39. ON_ENTITYT_TEST()
  40. #endif
  41. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  42. {
  43. LOG_FUNCTION();
  44. ErrorCodeEnum ec = m_fsm.Init(this);
  45. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnPreStart, Init:%d", ec);
  46. GetFunction()->RegistSysVarEvent("UIState", this);
  47. pTransactionContext->SendAnswer(ec);
  48. }
  49. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  50. {
  51. LOG_FUNCTION();
  52. pTransactionContext->SendAnswer(Error_Succeed);
  53. }
  54. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  55. {
  56. LOG_FUNCTION();
  57. pTransactionContext->SendAnswer(Error_Succeed);
  58. }
  59. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  60. {
  61. LOG_FUNCTION();
  62. m_fsm.OnExit();
  63. pTransactionContext->SendAnswer(Error_Succeed);
  64. }
  65. virtual void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  66. {
  67. //LOG_FUNCTION();
  68. m_fsm.SelfTest(eTestType, pTransactionContext);
  69. }
  70. virtual CServerSessionBase* OnNewSession(const char* , const char * )
  71. {
  72. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("A new connecting request arrived.");
  73. m_bNewSessionInit = true;
  74. return new FingerPrintServerSession(this);
  75. }
  76. //废弃
  77. void GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx)
  78. {
  79. //ScanEvent* e = new ScanEvent();
  80. //e->ctx = ctx;
  81. //m_fsm.PostEventFIFO(e);
  82. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke GetImageAndFeature request refuse");
  83. ctx->Answer(Error_Exception);
  84. }
  85. //废弃
  86. void GetImageAndFeatureEx(SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx)
  87. {
  88. //ScanExEvent* e = new ScanExEvent();
  89. //e->ctx = ctx;
  90. //m_fsm.PostEventFIFO(e);
  91. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke GetImageAndFeatureEx request refuse");
  92. ctx->Answer(Error_Exception);
  93. }
  94. //有用:扫描指纹(73294)
  95. void GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx)
  96. {
  97. if(!m_fsm.GetDevInitFlag()){
  98. ctx->Answer(Error_DevNotAvailable);
  99. LogWarn(Severity_Middle, Error_DevNotAvailable, FingerPrint_UserErrorCode_DevOpen_Failed_Registe, "GetFingerPrint but DevOpen failed.");
  100. }
  101. else{
  102. GetFingerEvent* e = new GetFingerEvent();
  103. e->ctx = ctx;
  104. m_fsm.PostEventFIFO(e);
  105. }
  106. }
  107. //有用:生成指纹模板(161)
  108. void GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx)
  109. {
  110. GenerateTemplateEvent* e = new GenerateTemplateEvent();
  111. e->ctx = ctx;
  112. m_fsm.PostEventFIFO(e);
  113. }
  114. //有用:取消注册(7066)
  115. void CancelRegister(SpOnewayCallContext<FingerPrintService_CancelRegister_Info>::Pointer ctx)
  116. {
  117. CancelRegisterEvent* e = new CancelRegisterEvent();
  118. m_fsm.PostEventFIFO(e);
  119. }
  120. //有用:取消对比(56)
  121. void CancelMatch(SpOnewayCallContext<FingerPrintService_CancelMatch_Info>::Pointer ctx)
  122. {
  123. CancelMatchEvent* e = new CancelMatchEvent();
  124. m_fsm.PostEventFIFO(e);
  125. }
  126. //废弃
  127. void CheckAndMatch(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx)
  128. {
  129. //MatchEvent* e = new MatchEvent();
  130. //e->ctx = ctx;
  131. //m_fsm.PostEventFIFO(e);
  132. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke CheckAndMatch request refuse");
  133. ctx->Answer(Error_Exception);
  134. }
  135. //设备安装状态使用
  136. void GetDevInfo(SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx)
  137. {
  138. LOG_FUNCTION();
  139. DevCategoryInfo devCatInfo;
  140. m_fsm.GetDevCatInfo(devCatInfo);
  141. ctx->Ans.model = devCatInfo.szModel;
  142. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo model is:%s", (const char*)ctx->Ans.model);
  143. ctx->Ans.state = (int)m_fsm.GetDevState();
  144. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("GetDevInfo %d", ctx->Ans.state);
  145. if (m_fsm.GetDevInitingFlag()) {
  146. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is opening,state return 0");
  147. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  148. ctx->Answer(Error_NotInit, FingerPrint_UserErrorCode_DevOpen_Failed);
  149. }
  150. else {
  151. if (!m_fsm.GetDevInitFlag()) {
  152. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is not open,state return 0");
  153. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  154. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DevOpen_Failed);
  155. }
  156. else {
  157. ctx->Answer(Error_Succeed);
  158. }
  159. }
  160. }
  161. //废弃
  162. void GetDevStatus(SpReqAnsContext<FingerPrintService_GetDevStatus_Req, FingerPrintService_GetDevStatus_Ans>::Pointer ctx)
  163. {
  164. int status = 0;
  165. m_fsm.GetCurDevState(status);
  166. ctx->Ans.status = status;
  167. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("FingerPrint state is:%d", status);
  168. ctx->Answer(Error_Succeed);
  169. }
  170. //废弃
  171. void Exit(SpOnewayCallContext<FingerPrintService_Exit_Info>::Pointer ctx)
  172. {
  173. FSMEvent* e = new FSMEvent(USER_EVT_EXIT);
  174. m_fsm.PostEventFIFO(e);
  175. }
  176. virtual void OnSysVarEvent(const char *pszKey,
  177. const char *pszValue, const char *pszOldValue, const char *pszEntityName);
  178. private:
  179. CFingerPrintFSM m_fsm;
  180. bool m_bNewSessionInit;
  181. };
  182. #endif