mod_FingerPrint.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. }
  104. else{
  105. GetFingerEvent* e = new GetFingerEvent();
  106. e->ctx = ctx;
  107. m_fsm.PostEventFIFO(e);
  108. }
  109. }
  110. //有用:生成指纹模板(161)
  111. void GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx)
  112. {
  113. GenerateTemplateEvent* e = new GenerateTemplateEvent();
  114. e->ctx = ctx;
  115. m_fsm.PostEventFIFO(e);
  116. }
  117. //有用:取消注册(7066)
  118. void CancelRegister(SpOnewayCallContext<FingerPrintService_CancelRegister_Info>::Pointer ctx)
  119. {
  120. CancelRegisterEvent* e = new CancelRegisterEvent();
  121. m_fsm.PostEventFIFO(e);
  122. }
  123. //有用:取消对比(56)
  124. void CancelMatch(SpOnewayCallContext<FingerPrintService_CancelMatch_Info>::Pointer ctx)
  125. {
  126. CancelMatchEvent* e = new CancelMatchEvent();
  127. m_fsm.PostEventFIFO(e);
  128. }
  129. //废弃
  130. void CheckAndMatch(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx)
  131. {
  132. //MatchEvent* e = new MatchEvent();
  133. //e->ctx = ctx;
  134. //m_fsm.PostEventFIFO(e);
  135. LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke CheckAndMatch request refuse");
  136. ctx->Answer(Error_Exception);
  137. }
  138. //设备安装状态使用
  139. void GetDevInfo(SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx)
  140. {
  141. LOG_FUNCTION();
  142. DevCategoryInfo devCatInfo;
  143. m_fsm.GetDevCatInfo(devCatInfo);
  144. ctx->Ans.model = devCatInfo.szModel;
  145. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo model is:%s", (const char*)ctx->Ans.model);
  146. ctx->Ans.state = (int)m_fsm.GetDevState();
  147. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("GetDevInfo %d", ctx->Ans.state);
  148. if (m_fsm.GetDevInitingFlag()) {
  149. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is opening,state return 0");
  150. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  151. ctx->Answer(Error_NotInit, FingerPrint_UserErrorCode_DevOpen_Failed);
  152. }
  153. else {
  154. if (!m_fsm.GetDevInitFlag()) {
  155. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is not open,state return 0");
  156. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  157. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DevOpen_Failed);
  158. }
  159. else {
  160. ctx->Answer(Error_Succeed);
  161. }
  162. }
  163. }
  164. //废弃
  165. void GetDevStatus(SpReqAnsContext<FingerPrintService_GetDevStatus_Req, FingerPrintService_GetDevStatus_Ans>::Pointer ctx)
  166. {
  167. int status = 0;
  168. m_fsm.GetCurDevState(status);
  169. ctx->Ans.status = status;
  170. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("FingerPrint state is:%d", status);
  171. ctx->Answer(Error_Succeed);
  172. }
  173. //废弃
  174. void Exit(SpOnewayCallContext<FingerPrintService_Exit_Info>::Pointer ctx)
  175. {
  176. FSMEvent* e = new FSMEvent(USER_EVT_EXIT);
  177. m_fsm.PostEventFIFO(e);
  178. }
  179. //js接口
  180. void GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx)
  181. {
  182. if (!m_fsm.GetDevInitFlag()) {
  183. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT);
  184. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetFingerPrintJS but DevOpen failed.");
  185. }
  186. else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0) {
  187. //不符合请求调用,告知具体错误流程
  188. DWORD errCode = m_fsm.GetFsmStateErrCode();
  189. CSimpleStringA stateName = m_fsm.GetCurrStateName();
  190. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("GetFingerPrintJS req is unhandled ,CurrState=%d", stateName.GetData());
  191. ctx->Answer(Error_Unexpect, errCode);
  192. }
  193. else {
  194. GetFingerPrintJSEvent* e = new GetFingerPrintJSEvent();
  195. e->ctx = ctx;
  196. m_fsm.PostEventFIFO(e);
  197. }
  198. }
  199. void GenerateTemplateJS(SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx)
  200. {
  201. if (!m_fsm.GetDevInitFlag()) {
  202. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GenerateTemplate);
  203. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GenerateTemplateJS but DevOpen failed.");
  204. }
  205. else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0) {
  206. //不符合请求调用,告知具体错误流程
  207. DWORD errCode = m_fsm.GetFsmStateErrCode();
  208. CSimpleStringA stateName = m_fsm.GetCurrStateName();
  209. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("GenerateTemplateJS req is unhandled ,CurrState=%d", stateName.GetData());
  210. ctx->Answer(Error_Unexpect, errCode);
  211. }
  212. else {
  213. GenerateTemplateJSEvent* e = new GenerateTemplateJSEvent();
  214. e->ctx = ctx;
  215. m_fsm.PostEventFIFO(e);
  216. }
  217. }
  218. void CancelScanJS(SpReqAnsContext<FingerPrintService_CancelScanJS_Req, FingerPrintService_CancelScanJS_Ans>::Pointer ctx)
  219. {
  220. if (!m_fsm.GetDevInitFlag()) {
  221. ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_CANCELSCAN_FAIL);
  222. }
  223. else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0 && _stricmp(m_fsm.GetCurrStateName(), "Scan") != 0) {
  224. //不符合请求调用,告知具体错误流程
  225. DWORD errCode = m_fsm.GetFsmStateErrCode();
  226. CSimpleStringA stateName = m_fsm.GetCurrStateName();
  227. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("CancelScanJS req is unhandled ,CurrState=%d", stateName.GetData());
  228. ctx->Answer(Error_Unexpect, errCode);
  229. }
  230. else {
  231. CancelScanJSEvent* e = new CancelScanJSEvent();
  232. e->ctx = ctx;
  233. m_fsm.PostEventFIFO(e);
  234. }
  235. }
  236. virtual void OnSysVarEvent(const char *pszKey,
  237. const char *pszValue, const char *pszOldValue, const char *pszEntityName);
  238. private:
  239. CFingerPrintFSM m_fsm;
  240. bool m_bNewSessionInit;
  241. };
  242. #endif