mod_FingerPrint.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. //新增接口
  27. virtual void Handle_GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx);
  28. virtual void Handle_GenerateTemplateJS(SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx);
  29. virtual void Handle_CancelScanJS(SpReqAnsContext<FingerPrintService_CancelScanJS_Req, FingerPrintService_CancelScanJS_Ans>::Pointer ctx);
  30. private:
  31. CFingerPrintEntity* m_pEntity;
  32. };
  33. class CFingerPrintEntity : public CDevAdptEntityBase, public ISysVarListener
  34. {
  35. public:
  36. CFingerPrintEntity(){}
  37. virtual ~CFingerPrintEntity(){}
  38. virtual const char *GetEntityName() const { return "FingerPrint"; }
  39. virtual bool IsService() const {return true;}
  40. #ifdef RVC_OS_WIN
  41. #else
  42. virtual const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  43. ON_ENTITYT_TEST()
  44. #endif
  45. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  46. {
  47. LOG_FUNCTION();
  48. ErrorCodeEnum ec = m_fsm.Init(this);
  49. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnPreStart, Init:%d", ec);
  50. GetFunction()->RegistSysVarEvent("UIState", this);
  51. pTransactionContext->SendAnswer(ec);
  52. }
  53. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  54. {
  55. LOG_FUNCTION();
  56. pTransactionContext->SendAnswer(Error_Succeed);
  57. }
  58. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  59. {
  60. LOG_FUNCTION();
  61. pTransactionContext->SendAnswer(Error_Succeed);
  62. }
  63. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  64. {
  65. LOG_FUNCTION();
  66. m_fsm.OnExit();
  67. pTransactionContext->SendAnswer(Error_Succeed);
  68. }
  69. virtual void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  70. {
  71. //LOG_FUNCTION();
  72. m_fsm.SelfTest(eTestType, pTransactionContext);
  73. }
  74. virtual CServerSessionBase* OnNewSession(const char* , const char * )
  75. {
  76. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("A new connecting request arrived.");
  77. m_bNewSessionInit = true;
  78. return new FingerPrintServerSession(this);
  79. }
  80. //废弃
  81. void GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx)
  82. {
  83. //ScanEvent* e = new ScanEvent();
  84. //e->ctx = ctx;
  85. //m_fsm.PostEventFIFO(e);
  86. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke GetImageAndFeature request refuse");
  87. ctx->Answer(Error_Exception);
  88. }
  89. //废弃
  90. void GetImageAndFeatureEx(SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx)
  91. {
  92. //ScanExEvent* e = new ScanExEvent();
  93. //e->ctx = ctx;
  94. //m_fsm.PostEventFIFO(e);
  95. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke GetImageAndFeatureEx request refuse");
  96. ctx->Answer(Error_Exception);
  97. }
  98. //有用:扫描指纹(73294)
  99. void GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx)
  100. {
  101. if(!m_fsm.GetDevInitFlag()){
  102. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT);
  103. LogWarn(Severity_Middle, Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT, "GetFingerPrint but DevOpen failed.");
  104. }
  105. else{
  106. GetFingerEvent* e = new GetFingerEvent();
  107. e->ctx = ctx;
  108. m_fsm.PostEventFIFO(e);
  109. }
  110. }
  111. //有用:生成指纹模板(161)
  112. void GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx)
  113. {
  114. GenerateTemplateEvent* e = new GenerateTemplateEvent();
  115. e->ctx = ctx;
  116. m_fsm.PostEventFIFO(e);
  117. }
  118. //有用:取消注册(7066)
  119. void CancelRegister(SpOnewayCallContext<FingerPrintService_CancelRegister_Info>::Pointer ctx)
  120. {
  121. CancelRegisterEvent* e = new CancelRegisterEvent();
  122. m_fsm.PostEventFIFO(e);
  123. }
  124. //有用:取消对比(56)
  125. void CancelMatch(SpOnewayCallContext<FingerPrintService_CancelMatch_Info>::Pointer ctx)
  126. {
  127. CancelMatchEvent* e = new CancelMatchEvent();
  128. m_fsm.PostEventFIFO(e);
  129. }
  130. //废弃
  131. void CheckAndMatch(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx)
  132. {
  133. //MatchEvent* e = new MatchEvent();
  134. //e->ctx = ctx;
  135. //m_fsm.PostEventFIFO(e);
  136. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke CheckAndMatch request refuse");
  137. ctx->Answer(Error_Exception);
  138. }
  139. //设备安装状态使用
  140. void GetDevInfo(SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx)
  141. {
  142. LOG_FUNCTION();
  143. DevCategoryInfo devCatInfo;
  144. m_fsm.GetDevCatInfo(devCatInfo);
  145. ctx->Ans.model = devCatInfo.szModel;
  146. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo model is:%s", (const char*)ctx->Ans.model);
  147. ctx->Ans.state = (int)m_fsm.GetDevState();
  148. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("GetDevInfo %d", ctx->Ans.state);
  149. if (m_fsm.GetDevInitingFlag()) {
  150. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is opening,state return 0");
  151. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  152. ctx->Answer(Error_NotInit, FingerPrint_UserErrorCode_DevOpen_Failed);
  153. }
  154. else {
  155. if (!m_fsm.GetDevInitFlag()) {
  156. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is not open,state return 0");
  157. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  158. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DevOpen_Failed);
  159. }
  160. else {
  161. ctx->Answer(Error_Succeed);
  162. }
  163. }
  164. }
  165. //废弃
  166. void GetDevStatus(SpReqAnsContext<FingerPrintService_GetDevStatus_Req, FingerPrintService_GetDevStatus_Ans>::Pointer ctx)
  167. {
  168. int status = 0;
  169. m_fsm.GetCurDevState(status);
  170. ctx->Ans.status = status;
  171. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("FingerPrint state is:%d", status);
  172. ctx->Answer(Error_Succeed);
  173. }
  174. //废弃
  175. void Exit(SpOnewayCallContext<FingerPrintService_Exit_Info>::Pointer ctx)
  176. {
  177. FSMEvent* e = new FSMEvent(USER_EVT_EXIT);
  178. m_fsm.PostEventFIFO(e);
  179. }
  180. //js接口
  181. void GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx)
  182. {
  183. if (!m_fsm.GetDevInitFlag()) {
  184. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT);
  185. LogWarn(Severity_Middle, Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT, "GetFingerPrintJS but DevOpen failed.");
  186. }
  187. else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0) {
  188. //不符合请求调用,告知具体错误流程
  189. DWORD errCode = m_fsm.GetFsmStateErrCode();
  190. CSimpleStringA stateName = m_fsm.GetCurrStateName();
  191. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("GetFingerPrintJS req is unhandled ,CurrState=%d", stateName.GetData());
  192. ctx->Answer(Error_Unexpect, errCode);
  193. }
  194. else {
  195. GetFingerPrintJSEvent* e = new GetFingerPrintJSEvent();
  196. e->ctx = ctx;
  197. m_fsm.PostEventFIFO(e);
  198. }
  199. }
  200. void GenerateTemplateJS(SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx)
  201. {
  202. if (!m_fsm.GetDevInitFlag()) {
  203. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GenerateTemplate);
  204. LogWarn(Severity_Middle, Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GenerateTemplate, "GenerateTemplateJS but DevOpen failed.");
  205. }
  206. else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0) {
  207. //不符合请求调用,告知具体错误流程
  208. DWORD errCode = m_fsm.GetFsmStateErrCode();
  209. CSimpleStringA stateName = m_fsm.GetCurrStateName();
  210. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("GenerateTemplateJS req is unhandled ,CurrState=%d", stateName.GetData());
  211. ctx->Answer(Error_Unexpect, errCode);
  212. }
  213. else {
  214. GenerateTemplateJSEvent* e = new GenerateTemplateJSEvent();
  215. e->ctx = ctx;
  216. m_fsm.PostEventFIFO(e);
  217. }
  218. }
  219. void CancelScanJS(SpReqAnsContext<FingerPrintService_CancelScanJS_Req, FingerPrintService_CancelScanJS_Ans>::Pointer ctx)
  220. {
  221. if (!m_fsm.GetDevInitFlag()) {
  222. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_CANCELSCAN_FAIL);
  223. LogWarn(Severity_Middle, Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_CANCELSCAN_FAIL, "CancelScanJS but DevOpen failed.");
  224. }
  225. else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0 && _stricmp(m_fsm.GetCurrStateName(), "Scan") != 0) {
  226. //不符合请求调用,告知具体错误流程
  227. DWORD errCode = m_fsm.GetFsmStateErrCode();
  228. CSimpleStringA stateName = m_fsm.GetCurrStateName();
  229. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("CancelScanJS req is unhandled ,CurrState=%d", stateName.GetData());
  230. ctx->Answer(Error_Unexpect, errCode);
  231. }
  232. else {
  233. CancelScanJSEvent* e = new CancelScanJSEvent();
  234. e->ctx = ctx;
  235. m_fsm.PostEventFIFO(e);
  236. }
  237. }
  238. virtual void OnSysVarEvent(const char *pszKey,
  239. const char *pszValue, const char *pszOldValue, const char *pszEntityName);
  240. private:
  241. CFingerPrintFSM m_fsm;
  242. bool m_bNewSessionInit;
  243. };
  244. #endif