mod_cardissuerStand.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. #include "CardIssuerStand_server_g.h"
  2. #include "CardIssuerStand_def_g.h"
  3. #include "CardIssuerStandFSM.h"
  4. #include "DevEntityCommBase.hpp"
  5. using namespace CardIssuerStand;
  6. class CCardIssuerEntity;
  7. class CardIssuerServerSession : public CardIssuerStandService_ServerSessionBase
  8. {
  9. public:
  10. CardIssuerServerSession(CCardIssuerEntity* pEntity):m_pEntity(pEntity){}
  11. virtual ~CardIssuerServerSession(){}
  12. virtual void Handle_Insert(SpReqAnsContext<CardIssuerStandService_Insert_Req, CardIssuerStandService_Insert_Ans>::Pointer ctx);
  13. virtual void Handle_Read(SpReqAnsContext<CardIssuerStandService_Read_Req, CardIssuerStandService_Read_Ans>::Pointer ctx);
  14. virtual void Handle_Capture(SpReqAnsContext<CardIssuerStandService_Capture_Req, CardIssuerStandService_Capture_Ans>::Pointer ctx);
  15. virtual void Handle_Eject(SpReqAnsContext<CardIssuerStandService_Eject_Req, CardIssuerStandService_Eject_Ans>::Pointer ctx);
  16. virtual void Handle_CancelInsert(SpOnewayCallContext<CardIssuerStandService_CancelInsert_Info>::Pointer ctx);
  17. virtual void Handle_InsertWaitMore(SpOnewayCallContext<CardIssuerStandService_InsertWaitMore_Info>::Pointer ctx);
  18. virtual void Handle_PreOnline(SpReqAnsContext<CardIssuerStandService_PreOnline_Req, CardIssuerStandService_PreOnline_Ans>::Pointer ctx);
  19. virtual void Handle_PostOnline(SpReqAnsContext<CardIssuerStandService_PostOnline_Req, CardIssuerStandService_PostOnline_Ans>::Pointer ctx);
  20. virtual void Handle_Exit(SpOnewayCallContext<CardIssuerStandService_Exit_Info>::Pointer ctx);
  21. virtual void Handle_QueryCardInfo(SpReqAnsContext<CardIssuerStandService_QueryCardInfo_Req, CardIssuerStandService_QueryCardInfo_Ans>::Pointer ctx);
  22. virtual void Handle_GetMaterialCountEx(SpReqAnsContext<CardIssuerStandService_GetMaterialCountEx_Req, CardIssuerStandService_GetMaterialCountEx_Ans>::Pointer ctx);
  23. virtual void Handle_SetMaterialCountEx(SpReqAnsContext<CardIssuerStandService_SetMaterialCountEx_Req, CardIssuerStandService_SetMaterialCountEx_Ans>::Pointer ctx);
  24. virtual void Handle_SetSomeFlag(SpReqAnsContext<CardIssuerStandService_SetSomeFlag_Req, CardIssuerStandService_SetSomeFlag_Ans>::Pointer ctx);
  25. virtual void Handle_IssueEx(SpReqAnsContext<CardIssuerStandService_IssueEx_Req, CardIssuerStandService_IssueEx_Ans>::Pointer ctx);
  26. virtual void Handle_QueryCIStatus(SpReqAnsContext<CardIssuerStandService_QueryCIStatus_Req, CardIssuerStandService_QueryCIStatus_Ans>::Pointer ctx);
  27. virtual void Handle_GetDevInfo(SpReqAnsContext<CardIssuerStandService_GetDevInfo_Req, CardIssuerStandService_GetDevInfo_Ans>::Pointer ctx);
  28. //JS接口定义
  29. virtual void Handle_ReadJS(SpReqAnsContext<CardIssuerStandService_ReadJS_Req, CardIssuerStandService_ReadJS_Ans>::Pointer ctx);
  30. virtual void Handle_PostOnlineJS(SpReqAnsContext<CardIssuerStandService_PostOnlineJS_Req, CardIssuerStandService_PostOnlineJS_Ans>::Pointer ctx);
  31. virtual void Handle_EjectJS(SpReqAnsContext<CardIssuerStandService_EjectJS_Req, CardIssuerStandService_EjectJS_Ans>::Pointer ctx);
  32. virtual void Handle_CaptureJS(SpReqAnsContext<CardIssuerStandService_CaptureJS_Req, CardIssuerStandService_CaptureJS_Ans>::Pointer ctx);
  33. virtual void Handle_QueryHasCardJS(SpReqAnsContext<CardIssuerStandService_QueryHasCardJS_Req, CardIssuerStandService_QueryHasCardJS_Ans>::Pointer ctx);
  34. virtual void Handle_IssueFromBoxJS(SpReqAnsContext<CardIssuerStandService_IssueFromBoxJS_Req, CardIssuerStandService_IssueFromBoxJS_Ans>::Pointer ctx);
  35. virtual void Handle_InsertJS(SpReqAnsContext<CardIssuerStandService_InsertJS_Req, CardIssuerStandService_InsertJS_Ans>::Pointer ctx);
  36. virtual void Handle_CancelInsertJS(SpOnewayCallContext<CardIssuerStandService_CancelInsertJS_Info>::Pointer ctx);
  37. private:
  38. CCardIssuerEntity* m_pEntity;
  39. };
  40. class CCardIssuerEntity : public CDevAdptEntityBase, public ISysVarListener
  41. {
  42. public:
  43. CCardIssuerEntity() :bInitialized(false)
  44. {
  45. }
  46. virtual ~CCardIssuerEntity(){}
  47. virtual const char *GetEntityName() const { return "CardIssuerStand"; }
  48. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  49. {
  50. LOG_FUNCTION();
  51. ErrorCodeEnum eStart = m_fsm.Init(this);
  52. if (eStart == Error_Succeed)
  53. {
  54. }
  55. GetFunction()->RegistSysVarEvent("UIState", this);
  56. pTransactionContext->SendAnswer(eStart);
  57. }
  58. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  59. {
  60. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  61. pTransactionContext->SendAnswer(Error);
  62. }
  63. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  64. {
  65. ErrorCodeEnum Error = __OnPause(Error_Succeed,pTransactionContext);
  66. pTransactionContext->SendAnswer(Error);
  67. }
  68. virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  69. {
  70. return Error_Succeed;
  71. }
  72. virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError, CSmartPointer<ITransactionContext> pTransactionContext)
  73. {
  74. return Error_Succeed;
  75. }
  76. virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  77. {
  78. return Error_Succeed;
  79. }
  80. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  81. {
  82. m_fsm.SelfTest(eTestType,pTransactionContext);
  83. }
  84. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  85. {
  86. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("A new connecting request arrived.");
  87. m_bNewSessionInit = true;
  88. return new CardIssuerServerSession(this);
  89. }
  90. void Insert(SpReqAnsContext<CardIssuerStandService_Insert_Req, CardIssuerStandService_Insert_Ans>::Pointer ctx)
  91. {
  92. LOG_FUNCTION();
  93. if(!m_fsm.GetDevInitFlag()){
  94. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  95. }else{
  96. m_bNewSessionInit = false;
  97. m_fsm.SetExitFlag(false);
  98. CardAcceptEvent *e = new CardAcceptEvent();
  99. e->ctx = ctx;
  100. m_fsm.PostEventFIFO(e);
  101. }
  102. }
  103. void Read(SpReqAnsContext<CardIssuerStandService_Read_Req, CardIssuerStandService_Read_Ans>::Pointer ctx)
  104. {
  105. LOG_FUNCTION();
  106. CardReadEvent* e = new CardReadEvent();
  107. e->ctx = ctx;
  108. m_fsm.PostEventFIFO(e);
  109. }
  110. void Capture(SpReqAnsContext<CardIssuerStandService_Capture_Req, CardIssuerStandService_Capture_Ans>::Pointer ctx)
  111. {
  112. LOG_FUNCTION();
  113. CardCaptureEvent* e = new CardCaptureEvent();
  114. e->ctx = ctx;
  115. m_fsm.PostEventFIFO(e);
  116. }
  117. void Eject(SpReqAnsContext<CardIssuerStandService_Eject_Req, CardIssuerStandService_Eject_Ans>::Pointer ctx)
  118. {
  119. LOG_FUNCTION();
  120. CardEjectEvent* e = new CardEjectEvent();
  121. e->ctx = ctx;
  122. m_fsm.PostEventFIFO(e);
  123. }
  124. void CancelInsert(SpOnewayCallContext<CardIssuerStandService_CancelInsert_Info>::Pointer ctx)
  125. {
  126. LOG_FUNCTION();
  127. CancelAcceptEvent *e = new CancelAcceptEvent();
  128. m_fsm.PostEventFIFO(e);
  129. }
  130. void InsertWaitMore(SpOnewayCallContext<CardIssuerStandService_InsertWaitMore_Info>::Pointer ctx)
  131. {
  132. LOG_FUNCTION();
  133. if (m_fsm.GetWaitFlag())
  134. m_fsm.SetWaitMore();
  135. }
  136. void PreOnline(SpReqAnsContext<CardIssuerStandService_PreOnline_Req, CardIssuerStandService_PreOnline_Ans>::Pointer ctx)
  137. {
  138. LOG_FUNCTION();
  139. if (!m_fsm.GetDevInitFlag()) {
  140. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  141. }
  142. else {
  143. PreOnlineEvent* e = new PreOnlineEvent();
  144. e->ctx = ctx;
  145. m_fsm.PostEventFIFO(e);
  146. }
  147. }
  148. void PostOnline(SpReqAnsContext<CardIssuerStandService_PostOnline_Req, CardIssuerStandService_PostOnline_Ans>::Pointer ctx)
  149. {
  150. LOG_FUNCTION();
  151. PostOnlineEvent* e = new PostOnlineEvent();
  152. e->ctx = ctx;
  153. m_fsm.PostEventFIFO(e);
  154. }
  155. void Exit(SpOnewayCallContext<CardIssuerStandService_Exit_Info>::Pointer ctx)
  156. {
  157. LOG_FUNCTION();
  158. m_bNewSessionInit = false;
  159. FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
  160. m_fsm.PostEventFIFO(evt);
  161. }
  162. void QueryCardInfo(SpReqAnsContext<CardIssuerStandService_QueryCardInfo_Req, CardIssuerStandService_QueryCardInfo_Ans>::Pointer ctx)
  163. {
  164. if (m_fsm.GetDevInitingFlag())
  165. {
  166. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DeviceOpening);
  167. return;
  168. }else if (!m_fsm.GetDevInitFlag()) {
  169. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  170. return;
  171. }
  172. if (m_bNewSessionInit)
  173. {
  174. FSMEvent *pEvt = new FSMEvent(USER_EVT_EXIT);
  175. m_fsm.PostEventFIFO(pEvt);
  176. ctx->Ans.position = CI_MEDIA_NOTPRESENT;
  177. ctx->Answer(Error_Succeed);
  178. }
  179. else
  180. {
  181. int ret = m_fsm.QueryCardPos();
  182. if (ret != 1)//query hardware ok
  183. ctx->Ans.position = ret;
  184. else
  185. {
  186. if (_stricmp(m_fsm.GetCurrStateName(), "Hold") == 0)
  187. ctx->Ans.position = 2;
  188. else
  189. ctx->Ans.position = 0;
  190. }
  191. ctx->Answer(Error_Succeed);
  192. }
  193. }
  194. void GetMaterialCountEx(SpReqAnsContext<CardIssuerStandService_GetMaterialCountEx_Req, CardIssuerStandService_GetMaterialCountEx_Ans>::Pointer ctx)
  195. {
  196. m_bNewSessionInit = false;
  197. GetMaterialExEvent *pEvt = new GetMaterialExEvent();
  198. pEvt->ctx = ctx;
  199. m_fsm.PostEventFIFO(pEvt);
  200. }
  201. void SetMaterialCountEx(SpReqAnsContext<CardIssuerStandService_SetMaterialCountEx_Req, CardIssuerStandService_SetMaterialCountEx_Ans>::Pointer ctx)
  202. {
  203. m_bNewSessionInit = false;
  204. SetMaterialExEvent *pEvt = new SetMaterialExEvent();
  205. pEvt->ctx = ctx;
  206. m_fsm.PostEventFIFO(pEvt);
  207. }
  208. void SetSomeFlag(SpReqAnsContext<CardIssuerStandService_SetSomeFlag_Req, CardIssuerStandService_SetSomeFlag_Ans>::Pointer ctx)
  209. {
  210. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set issue flag to %d", ctx->Req.IssueBusiness);
  211. if (ctx->Req.IssueBusiness == 1)
  212. m_fsm.FSMSetIssueFlag(1);
  213. else if (ctx->Req.IssueBusiness == 0)
  214. m_fsm.FSMSetIssueFlag(0);
  215. else if (ctx->Req.IssueBusiness == 2)//oilyang@20170621 query issue direction
  216. {
  217. ctx->Ans.reserved1.Init(1);
  218. ctx->Ans.reserved1[0] = (m_fsm.QueryIssueFlag() ? 0 : 1);//according to yzx
  219. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("issue direction:%d",ctx->Ans.reserved1[0]);//if 0 capture card eles eject card
  220. }
  221. else if (ctx->Req.IssueBusiness == 3)//oilyang@20181210
  222. {
  223. m_fsm.SetCancelByRFICFlag();
  224. }
  225. else if (ctx->Req.IssueBusiness == 4)//oilyang@20181220 get ic card account,for simple/lazy...
  226. {
  227. ctx->Ans.reserved2.Init(1);
  228. ctx->Ans.reserved2[0] = m_fsm.GetPreOnlineICCardNo();
  229. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetPreOnlineICCardNo:%d", ctx->Ans.reserved2[0].GetLength());
  230. }
  231. if (ctx->Req.reserved1.GetCount() > 0)
  232. {
  233. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set hopper num:%d",ctx->Req.reserved1[0]);
  234. if (ctx->Req.reserved1[0] == 1)
  235. m_fsm.SetHopperNum(1);
  236. else if (ctx->Req.reserved1[0] == 3)
  237. m_fsm.SetHopperNum(3);
  238. }
  239. ctx->Answer(Error_Succeed);
  240. }
  241. void IssueEx(SpReqAnsContext<CardIssuerStandService_IssueEx_Req, CardIssuerStandService_IssueEx_Ans>::Pointer ctx)
  242. {
  243. LOG_FUNCTION();
  244. if (!m_fsm.GetDevInitFlag()) {
  245. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  246. }
  247. else {
  248. m_bNewSessionInit = false;
  249. CardIssueExEvent* pEvt = new CardIssueExEvent();
  250. pEvt->ctx = ctx;
  251. m_fsm.PostEventFIFO(pEvt);
  252. }
  253. }
  254. void GetDevInfo(SpReqAnsContext<CardIssuerStandService_GetDevInfo_Req, CardIssuerStandService_GetDevInfo_Ans>::Pointer ctx)
  255. {
  256. LOG_FUNCTION();
  257. ctx->Ans.state = m_fsm.GetDevState();
  258. if (m_fsm.GetDevInitingFlag()) {
  259. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetDevInfo device is opening,state return 0");
  260. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  261. ctx->Answer(Error_NotInit, CardIssuer_UserErrorCode_DeviceOpening);
  262. }
  263. else {
  264. //设备未正常打开时,直接报state=0;
  265. if (!m_fsm.GetDevInitFlag()) {
  266. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetDevInfo device is not open,state return 0");
  267. ctx->Ans.state = DEVICE_STATUS_NOT_READY;
  268. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  269. }
  270. else {
  271. if (ctx->Ans.state != DEVICE_STATUS_NORMAL) {
  272. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetDevInfo state=%d", ctx->Ans.state);
  273. }
  274. ctx->Answer(Error_Succeed);
  275. }
  276. }
  277. }
  278. void QueryCIStatus(SpReqAnsContext<CardIssuerStandService_QueryCIStatus_Req, CardIssuerStandService_QueryCIStatus_Ans>::Pointer ctx)
  279. {
  280. m_fsm.QueryCIStatus(ctx);
  281. }
  282. virtual void OnSysVarEvent(const char* pszKey, const char* pszValue, const char* pszOldValue, const char* pszEntityName);
  283. virtual bool IsService()const{return true;}
  284. virtual bool IsMultiThread()const{return true;}
  285. //JS接口实现
  286. void ReadJS(SpReqAnsContext<CardIssuerStandService_ReadJS_Req, CardIssuerStandService_ReadJS_Ans>::Pointer ctx)
  287. {
  288. LOG_FUNCTION();
  289. if (!m_fsm.GetDevInitFlag())
  290. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  291. else
  292. {
  293. ReadJSEvent* pEvt = new ReadJSEvent();
  294. pEvt->ctx = ctx;
  295. m_fsm.PostEventFIFO(pEvt);
  296. }
  297. }
  298. void PostOnlineJS(SpReqAnsContext<CardIssuerStandService_PostOnlineJS_Req, CardIssuerStandService_PostOnlineJS_Ans>::Pointer ctx)
  299. {
  300. LOG_FUNCTION();
  301. if (!m_fsm.GetDevInitFlag())
  302. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  303. else
  304. {
  305. PostOnlineJSEvent* pEvt = new PostOnlineJSEvent();
  306. pEvt->ctx = ctx;
  307. m_fsm.PostEventFIFO(pEvt);
  308. }
  309. }
  310. void EjectJS(SpReqAnsContext<CardIssuerStandService_EjectJS_Req, CardIssuerStandService_EjectJS_Ans>::Pointer ctx)
  311. {
  312. LOG_FUNCTION();
  313. if (!m_fsm.GetDevInitFlag())
  314. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  315. else
  316. {
  317. EjectJSEvent* e = new EjectJSEvent();
  318. e->ctx = ctx;
  319. m_fsm.PostEventFIFO(e);
  320. }
  321. }
  322. void CaptureJS(SpReqAnsContext<CardIssuerStandService_CaptureJS_Req, CardIssuerStandService_CaptureJS_Ans>::Pointer ctx)
  323. {
  324. LOG_FUNCTION();
  325. if (!m_fsm.GetDevInitFlag())
  326. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  327. else
  328. {
  329. CaptureJSEvent* e = new CaptureJSEvent();
  330. e->ctx = ctx;
  331. m_fsm.PostEventFIFO(e);
  332. }
  333. }
  334. void QueryHasCardJS(SpReqAnsContext<CardIssuerStandService_QueryHasCardJS_Req, CardIssuerStandService_QueryHasCardJS_Ans>::Pointer ctx)
  335. {
  336. LOG_FUNCTION();
  337. if (!m_fsm.GetDevInitFlag())
  338. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  339. else
  340. m_fsm.QueryHasCardJS(ctx);
  341. }
  342. void IssueFromBoxJS(SpReqAnsContext<CardIssuerStandService_IssueFromBoxJS_Req, CardIssuerStandService_IssueFromBoxJS_Ans>::Pointer ctx)
  343. {
  344. LOG_FUNCTION();
  345. if (!m_fsm.GetDevInitFlag())
  346. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  347. else
  348. {
  349. IssueFromBoxJSEvent* pEvt = new IssueFromBoxJSEvent();
  350. pEvt->ctx = ctx;
  351. m_fsm.PostEventFIFO(pEvt);
  352. }
  353. }
  354. void InsertJS(SpReqAnsContext<CardIssuerStandService_InsertJS_Req, CardIssuerStandService_InsertJS_Ans>::Pointer ctx)
  355. {
  356. LOG_FUNCTION();
  357. if (!m_fsm.GetDevInitFlag())
  358. ctx->Answer(Error_DevNotAvailable, CardIssuer_UserErrorCode_DevOpen_Failed);
  359. else
  360. {
  361. InsertJSEvent* pEvt = new InsertJSEvent();
  362. pEvt->ctx = ctx;
  363. m_fsm.PostEventFIFO(pEvt);
  364. }
  365. }
  366. void CancelInsertJS(SpOnewayCallContext<CardIssuerStandService_CancelInsertJS_Info>::Pointer ctx)
  367. {
  368. LOG_FUNCTION();
  369. CancelInsertJSEvent* evt = new CancelInsertJSEvent();
  370. m_fsm.PostEventFIFO(evt);
  371. }
  372. protected:
  373. private:
  374. CCardIssuerFSM m_fsm;
  375. bool bInitialized,m_bNewSessionInit;
  376. };