IDCertFSM.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #ifndef IDCERTFSM_H
  2. #define IDCERTFSM_H
  3. #pragma once
  4. #include "SpFSM.h"
  5. #include "SpTest.h"
  6. #include "DevFSMCommBase.hpp"
  7. enum EvtType
  8. {
  9. USER_EVT_TEST = EVT_USER+1,
  10. USER_EVT_QUIT,
  11. USER_EVT_READ,
  12. USER_EVT_CANCEL_READ,
  13. USER_EVT_READ_FINISHED,
  14. USER_EVT_EXIT,
  15. USER_EVT_GET_DEVINFO,
  16. USER_EVT_ERROR,
  17. USER_EVT_READ_EX,
  18. USER_EVT_READ_EX_FINISHED,
  19. USER_EVT_EJECT,
  20. USER_EVT_WAIT_FETCH_IDCARD_FINISHED,
  21. USER_EVT_READ_AND_SCAN,
  22. USER_EVT_READ_AND_SCAN_FINISHED,
  23. USER_EVT_INIT_FINISHED,
  24. };
  25. enum BmpType
  26. {
  27. Bmp_ZP = 1,
  28. Bmp_SCAN = 2,
  29. };
  30. #include "IDCerClass.h"
  31. #include "IDCertificate_def_g.h"
  32. #pragma region forsonar
  33. typedef IDCertificate::IDCertService_Read_Req IDCert_Read_Req;
  34. typedef IDCertificate::IDCertService_Read_Ans IDCert_Read_Ans;
  35. typedef IDCertificate::IDCertService_CancelRead_Info IDCert_CancelRead_Info;
  36. typedef IDCertificate::IDCertService_ReadWaitMore_Info IDCert_ReadWaitMore_Info;
  37. typedef IDCertificate::IDCertService_Exit_Info IDCert_Exit_Info;
  38. typedef IDCertificate::IDCertService_ReadEx_Req IDCert_ReadEx_Req;
  39. typedef IDCertificate::IDCertService_ReadEx_Ans IDCert_ReadEx_Ans;
  40. typedef IDCertificate::IDCertService_Eject_Req IDCert_Eject_Req;
  41. typedef IDCertificate::IDCertService_Eject_Ans IDCert_Eject_Ans;
  42. typedef IDCertificate::IDCertService_ReadAndScan_Req IDCert_ReadAndScan_Req;
  43. typedef IDCertificate::IDCertService_ReadAndScan_Ans IDCert_ReadAndScan_Ans;
  44. typedef IDCertificate::IDCertService_CrossTermCall_Req IDCert_CrossTermCall_Req;
  45. typedef IDCertificate::IDCertService_CrossTermCall_Ans IDCert_CrossTermCall_Ans;
  46. typedef IDCertificate::IDCertService_CrossTermInvokeInfo_Info IDCert_CrossTermInvokeInfo_Info;
  47. typedef IDCertificate::IDCertService_GetDevInfo_Req IDCert_GetDevInfo_Req;
  48. typedef IDCertificate::IDCertService_GetDevInfo_Ans IDCert_GetDevInfo_Ans;
  49. #pragma endregion forsonar
  50. #include "mod_heartbeat/HeartBeat_client_g.h"
  51. using namespace HeartBeat;
  52. #include "DeviceCrossHelper.h"
  53. #include <map>
  54. using namespace std;
  55. typedef ErrorCodeEnum ( *lpCreateDevCom)(DeviceBaseClass *&baseObj);
  56. typedef ErrorCodeEnum ( *lpReleaseDevCom)(DeviceBaseClass *&pBaseObj);
  57. #include "DevErrorCode.h"
  58. #include "DevFSMCommBase.hpp"
  59. struct CtxInfo
  60. {
  61. int dataSize;
  62. LPVOID pCtx;
  63. };
  64. class ReadEvent : public FSMEvent
  65. {
  66. public:
  67. ReadEvent() : FSMEvent(USER_EVT_READ){}
  68. virtual ~ReadEvent(){}
  69. SpReqAnsContext<IDCert_Read_Req, IDCert_Read_Ans>::Pointer ctx;
  70. virtual void OnUnhandled()
  71. {
  72. if (ctx != NULL)
  73. ctx->Answer(Error_InvalidState);
  74. }
  75. };
  76. class CancelReadEvent : public FSMEvent
  77. {
  78. public:
  79. CancelReadEvent() : FSMEvent(USER_EVT_CANCEL_READ){}
  80. virtual ~CancelReadEvent(){}
  81. virtual void OnUnhandled()
  82. {
  83. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("idcer cancel read not handled");
  84. }
  85. };
  86. class GetDevInfoEvent : public FSMEvent
  87. {
  88. public:
  89. GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){}
  90. virtual ~GetDevInfoEvent(){}
  91. SpReqAnsContext<IDCert_GetDevInfo_Req, IDCert_GetDevInfo_Ans>::Pointer ctx;
  92. virtual void OnUnhandled()
  93. {
  94. if (ctx != NULL)
  95. ctx->Answer(Error_InvalidState);
  96. }
  97. };
  98. class ReadExEvent : public FSMEvent
  99. {
  100. public:
  101. ReadExEvent() : FSMEvent(USER_EVT_READ_EX){}
  102. virtual ~ReadExEvent(){}
  103. SpReqAnsContext<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::Pointer ctx;
  104. virtual void OnUnhandled()
  105. {
  106. if (ctx != NULL)
  107. ctx->Answer(Error_InvalidState);
  108. }
  109. };
  110. class EjectEvent : public FSMEvent
  111. {
  112. public:
  113. EjectEvent() : FSMEvent(USER_EVT_EJECT){}
  114. virtual ~EjectEvent(){}
  115. SpReqAnsContext<IDCert_Eject_Req, IDCert_Eject_Ans>::Pointer ctx;
  116. virtual void OnUnhandled()
  117. {
  118. if (ctx != NULL)
  119. ctx->Answer(Error_InvalidState);
  120. }
  121. };
  122. class ReadAndScanEvent : public FSMEvent
  123. {
  124. public:
  125. ReadAndScanEvent() : FSMEvent(USER_EVT_READ_AND_SCAN) {}
  126. virtual ~ReadAndScanEvent() {}
  127. SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer ctx;
  128. virtual void OnUnhandled()
  129. {
  130. if (ctx != NULL)
  131. ctx->Answer(Error_InvalidState);
  132. }
  133. };
  134. class CIDCertFSM : public CCommDevFSM<CIDCertFSM, IDCerClass>
  135. {
  136. public:
  137. enum {s0,s1,s2,s3,s4,s5};
  138. //ON_ENTITYT_TEST();
  139. BEGIN_FSM_STATE(CIDCertFSM)
  140. FSM_STATE_ENTRY(s0,"Normal",s0_on_entry,s0_on_exit,s0_on_event)
  141. FSM_STATE_ENTRY(s1,"Reading",s1_on_entry,s1_on_exit,s1_on_event)
  142. FSM_STATE_ENTRY(s2,"Fail",s2_on_entry,s2_on_exit,s2_on_event)
  143. FSM_STATE_ENTRY(s3, "Eject", s3_on_entry, s3_on_exit, s3_on_event)
  144. FSM_STATE_ENTRY(s4, "WaitingFetch", s4_on_entry, s4_on_exit, s4_on_event)
  145. FSM_STATE_ENTRY(s5, "Init", s5_on_entry, s5_on_exit, s5_on_event)
  146. END_FSM_STATE()
  147. BEGIN_FSM_RULE(CIDCertFSM, s5)
  148. FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0)
  149. FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  150. FSM_RULE_ENTRY(s0, s1, USER_EVT_READ, 0)
  151. FSM_RULE_ENTRY(s0, s1, USER_EVT_READ_EX, 0)
  152. FSM_RULE_ENTRY(s0, s1, USER_EVT_READ_AND_SCAN, 0)
  153. FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_FINISHED, 0)
  154. FSM_RULE_ENTRY(s1, s2, USER_EVT_READ_FINISHED, 1)
  155. FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_EX_FINISHED, 0)
  156. FSM_RULE_ENTRY(s1, s2, USER_EVT_READ_EX_FINISHED, 1)
  157. FSM_RULE_ENTRY(s1, s4, USER_EVT_READ_EX_FINISHED, 4)
  158. FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_FINISHED, 0)
  159. FSM_RULE_ENTRY(s1, s2, USER_EVT_READ_AND_SCAN_FINISHED, 1)
  160. FSM_RULE_ENTRY(s1, s4, USER_EVT_READ_AND_SCAN_FINISHED, 4)
  161. FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  162. FSM_RULE_ENTRY(s4, s0, USER_EVT_WAIT_FETCH_IDCARD_FINISHED, 0)
  163. FSM_RULE_ENTRY(s5, s0, USER_EVT_INIT_FINISHED, 0)
  164. FSM_RULE_ENTRY(s5, s2, USER_EVT_INIT_FINISHED, 2)
  165. END_FSM_RULE()
  166. CIDCertFSM():m_devInit(false),m_bCancelRead(false),m_bReading(false),m_bWaitReadMore(false),
  167. m_bExit(false),m_testResult(Error_Succeed), m_csMachineType(""), m_csSite(""), m_terminalNo(""), m_devSN("")
  168. ,m_devVendor(""), m_devVer(""), m_devBatch("") , m_bRVCIL(false), m_pHBClient(nullptr){
  169. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x201);
  170. m_FirstStart = TRUE;
  171. ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo));
  172. };
  173. virtual ~CIDCertFSM() {};
  174. virtual ErrorCodeEnum OnInit();
  175. virtual ErrorCodeEnum OnExit();
  176. virtual void s0_on_entry();
  177. virtual void s0_on_exit();
  178. virtual unsigned int s0_on_event(FSMEvent* e);
  179. virtual void s1_on_entry();
  180. virtual void s1_on_exit();
  181. virtual unsigned int s1_on_event(FSMEvent* e);
  182. virtual void s2_on_entry();
  183. virtual void s2_on_exit();
  184. virtual unsigned int s2_on_event(FSMEvent* e);
  185. virtual void s3_on_entry();
  186. virtual void s3_on_exit();
  187. virtual unsigned int s3_on_event(FSMEvent* e);
  188. virtual void s4_on_entry();
  189. virtual void s4_on_exit();
  190. virtual unsigned int s4_on_event(FSMEvent* e);
  191. virtual void s5_on_entry();
  192. virtual void s5_on_exit();
  193. virtual unsigned int s5_on_event(FSMEvent* e);
  194. int ReadInfo(SpReqAnsContext<IDCert_Read_Req, IDCert_Read_Ans>::Pointer ctx);
  195. int ReadInfoEx(SpReqAnsContext<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::Pointer ctx);
  196. int ReadAndScan(SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer ctx);
  197. int WaitFetchIDCard();
  198. void SetReadMore(){m_bWaitReadMore = true;}
  199. void SetExitFlag(){m_bExit = true;}
  200. bool GetReadFlag(){return m_bReading;}
  201. ErrorCodeEnum GetDevCatInfo(DevCategoryInfo &devInfo, CSimpleStringA& devType);
  202. void GetDevState(DevStateEnum &devState){ devState = m_devState; }
  203. int ReadHZCard(SpReqAnsContext<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::Pointer ctx);
  204. void DoExit(CSmartPointer<ITransactionContext> pTransactionContext)
  205. {
  206. pTransactionContext->SendAnswer(Error_Succeed);
  207. }
  208. int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay = false);
  209. bool GetDevInitFlag() { return m_devInit; }
  210. bool IsRVCIL() { /*return m_bRVCIL;*/return false; }//oilyang@20190123 方案改了,这里暂时不需要了
  211. void CrossTermCall(SpReqAnsContext<IDCert_CrossTermCall_Req, IDCert_CrossTermCall_Ans>::Pointer ctx);
  212. template <class TReq,class TAns>
  213. void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
  214. {
  215. m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
  216. }
  217. void SaveCtxAA(int methodID, SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer ctx)
  218. {
  219. m_readAndScanCtx = ctx;
  220. }
  221. LPVOID GetCtx(int methodID)
  222. {
  223. if (m_mapCtx.find(methodID) != m_mapCtx.end())
  224. return m_mapCtx[methodID].pCtx;
  225. else
  226. return NULL;
  227. }
  228. int Initial();
  229. void CrossTermInvokeInfo(SpOnewayCallContext<IDCert_CrossTermInvokeInfo_Info>::Pointer ctx);
  230. void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  231. protected:
  232. ErrorCodeEnum GetVendorDllPath(CSimpleStringA &strPath);
  233. ErrorCodeEnum GetPngBlob(CBlob &data,bool bClear=false);
  234. ErrorCodeEnum GetPngBlobEx(CBlob &data, CSimpleStringA fileNamePrefix,bool bClear=false);
  235. //type:1,delete img about zp; type:2,delete img about scan ID;type:3,delete both zp and scan ID
  236. void DeleteZP(int type);
  237. ErrorCodeEnum CheckDate(const char* date);
  238. ErrorCodeEnum CheckDate(const char* startDate, const char* endDate);
  239. void LogDate(IDCerInfo idInfo);
  240. void LogDateEx(IDCerInfoEx idInfo);
  241. //Delete bmp file in dep directory, you should just convey fileName only without paths -Joseph
  242. ErrorCodeEnum DeleteFileIfExisted(LPCTSTR fileName);
  243. bool GetAttachedTerminal(CSimpleStringA &csTerm);
  244. protected:
  245. bool m_devInit,m_bCancelRead,m_bReading,m_bWaitReadMore,m_bExit,m_bRVCIL;
  246. ErrorCodeEnum m_testResult;
  247. DevCategoryInfo m_devCatInfo;
  248. DevStateEnum m_devState;
  249. CSimpleStringA m_csMachineType, m_csSite, m_terminalNo, m_devSN;
  250. CSimpleStringA m_devVendor, m_devVer, m_devBatch;
  251. map<int, CtxInfo> m_mapCtx;
  252. HeartBeatService_ClientBase* m_pHBClient;
  253. SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer m_readAndScanCtx;
  254. CSimpleStringA m_csAlarmMsg;
  255. ErrorPackage m_errPkg;
  256. AdapterInfo m_adapterInfo;
  257. };
  258. struct ReadTask : public ITaskSp
  259. {
  260. CIDCertFSM* fsm;
  261. SpReqAnsContext<IDCert_Read_Req, IDCert_Read_Ans>::Pointer ctx;
  262. ReadTask(CIDCertFSM* f) : fsm(f) {}
  263. void Process()
  264. {
  265. FSMEvent *e = new FSMEvent(USER_EVT_READ_FINISHED);
  266. e->param1 = fsm->ReadInfo(ctx);
  267. fsm->PostEventFIFO(e);
  268. }
  269. };
  270. struct ReadExTask : public ITaskSp
  271. {
  272. CIDCertFSM* fsm;
  273. SpReqAnsContext<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::Pointer ctx;
  274. ReadExTask(CIDCertFSM* f) : fsm(f) {}
  275. void Process()
  276. {
  277. FSMEvent *e = new FSMEvent(USER_EVT_READ_EX_FINISHED);
  278. e->param1 = fsm->ReadInfoEx(ctx);
  279. fsm->PostEventFIFO(e);
  280. }
  281. };
  282. struct ReadAndScanTask : public ITaskSp
  283. {
  284. CIDCertFSM* fsm;
  285. SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer ctx;
  286. ReadAndScanTask(CIDCertFSM* f) : fsm(f) {}
  287. void Process()
  288. {
  289. FSMEvent *e = new FSMEvent(USER_EVT_READ_AND_SCAN_FINISHED);
  290. e->param1 = fsm->ReadAndScan(ctx);
  291. fsm->PostEventFIFO(e);
  292. }
  293. };
  294. struct WaitFetchIDCardTask : public ITaskSp
  295. {
  296. CIDCertFSM* fsm;
  297. WaitFetchIDCardTask(CIDCertFSM* f) : fsm(f) {}
  298. void Process()
  299. {
  300. FSMEvent *e = new FSMEvent(USER_EVT_WAIT_FETCH_IDCARD_FINISHED);
  301. e->param1 = fsm->WaitFetchIDCard();
  302. fsm->PostEventFIFO(e);
  303. }
  304. };
  305. struct InitTask : public ITaskSp
  306. {
  307. CIDCertFSM* fsm;
  308. InitTask(CIDCertFSM* f) : fsm(f) {}
  309. void Process()
  310. {
  311. FSMEvent* e = new FSMEvent(USER_EVT_INIT_FINISHED);
  312. e->param1 = fsm->Initial();
  313. fsm->PostEventFIFO(e);
  314. }
  315. };
  316. #endif //IDCERTFSM_H