123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #ifndef _MOD_CONTACTLESS_H
- #define _MOD_CONTACTLESS_H
- #pragma once
- #include "stdafx.h"
- #include "ContactlessFSM.h"
- #include "DevEntityCommBase.hpp"
- #include "modVer.h"
- class CContactlessCardEntity;
- class ContactlessCardServerSession : public ContactlessCardService_ServerSessionBase
- {
- public:
- ContactlessCardServerSession(CContactlessCardEntity* pEntity):m_pEntity(pEntity){}
- virtual ~ContactlessCardServerSession(){}
- virtual void Handle_Insert(SpReqAnsContext<ContactlessCardService_Insert_Req, ContactlessCardService_Insert_Ans>::Pointer ctx);
- virtual void Handle_CancelInsert(SpOnewayCallContext<ContactlessCardService_CancelInsert_Info>::Pointer ctx);
- virtual void Handle_InsertWaitMore(SpOnewayCallContext<ContactlessCardService_InsertWaitMore_Info>::Pointer ctx);
- virtual void Handle_PreOnline(SpReqAnsContext<ContactlessCardService_PreOnline_Req, ContactlessCardService_PreOnline_Ans>::Pointer ctx);
- virtual void Handle_PostOnline(SpReqAnsContext<ContactlessCardService_PostOnline_Req, ContactlessCardService_PostOnline_Ans>::Pointer ctx);
- virtual void Handle_Eject(SpReqAnsContext<ContactlessCardService_Eject_Req, ContactlessCardService_Eject_Ans>::Pointer ctx);
- virtual void Handle_Exit(SpOnewayCallContext<ContactlessCardService_Exit_Info>::Pointer ctx);
- virtual void Handle_QueryCardInfo(SpReqAnsContext<ContactlessCardService_QueryCardInfo_Req, ContactlessCardService_QueryCardInfo_Ans>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<ContactlessCardService_GetDevInfo_Req, ContactlessCardService_GetDevInfo_Ans>::Pointer ctx);
- private:
- CContactlessCardEntity* m_pEntity;
- };
- class CContactlessCardEntity : public CDevAdptEntityBase
- {
- public:
- CContactlessCardEntity()
- {
- }
- virtual ~CContactlessCardEntity(){}
- virtual const char *GetEntityName() const { return "ContactlessCard"; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum eStart = m_fsm.Init(this);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnPause(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
- {
- return Error_Succeed;
- }
- virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
- {
- return Error_Succeed;
- }
- virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
- {
- return Error_Succeed;
- }
- void Insert(SpReqAnsContext<ContactlessCardService_Insert_Req, ContactlessCardService_Insert_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if(!m_fsm.GetDevInitFlag()){
- ctx->Answer(Error_DevNotAvailable, ContactlessCard_UserErrorCode_Read_OpenFailed);
- LogWarn(Severity_Middle, Error_DevNotAvailable, ContactlessCard_UserErrorCode_Read_OpenFailed, "ReadCard but DevOpen failed.");
- }
- else{
- m_fsm.SetExitFlag(false);
- CardAcceptEvent* e = new CardAcceptEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- void CancelInsert(SpOnewayCallContext<ContactlessCardService_CancelInsert_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- if(!m_fsm.GetDevInitFlag()){
- LogWarn(Severity_Middle, Error_DevNotAvailable, ContactlessCard_UserErrorCode_Cancel_OpenFailed, "CancelInsert but DevOpen failed.");
- }else{
- FSMEvent *evt = new FSMEvent(USER_EVT_ACCEPT_CANCEL);
- m_fsm.PostEventFIFO(evt);
- }
- }
- void InsertWaitMore(SpOnewayCallContext<ContactlessCardService_InsertWaitMore_Info>::Pointer ctx)
- {
- if (m_fsm.GetWaitFlag())
- m_fsm.SetWaitMore();
- }
- void PreOnline(SpReqAnsContext<ContactlessCardService_PreOnline_Req, ContactlessCardService_PreOnline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- PreOnlineEvent* e = new PreOnlineEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void PostOnline(SpReqAnsContext<ContactlessCardService_PostOnline_Req, ContactlessCardService_PostOnline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- PostOnlineEvent* e = new PostOnlineEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void Eject(SpReqAnsContext<ContactlessCardService_Eject_Req, ContactlessCardService_Eject_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- CardEjectEvent* e = new CardEjectEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void Exit(SpOnewayCallContext<ContactlessCardService_Exit_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- if(!m_fsm.GetDevInitFlag()){
- LogWarn(Severity_Middle, Error_DevNotAvailable, ContactlessCard_UserErrorCode_Exit_OpenFailed, "Exit but DevOpen failed.");
- }else{
- FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
- m_fsm.PostEventFIFO(evt);
- }
- }
- void QueryCardInfo(SpReqAnsContext<ContactlessCardService_QueryCardInfo_Req, ContactlessCardService_QueryCardInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- QueryCardInfoEvent* e = new QueryCardInfoEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void GetDevInfo(SpReqAnsContext<ContactlessCardService_GetDevInfo_Req, ContactlessCardService_GetDevInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ctx->Ans.state = m_fsm.GetDevState();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("GetDevInfo %d", ctx->Ans.state);
- ctx->Answer(Error_Succeed);
- }
- virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType,pTransactionContext);
- }
- virtual CServerSessionBase* OnNewSession(const char*,const char*)
- {
- return new ContactlessCardServerSession(this);
- }
- virtual bool IsService()const{return true;}
- virtual bool IsMultiThread()const{return true;}
- protected:
- private:
- CContactlessCardFSM m_fsm;
- private:
- };
- #endif //_MOD_CONTACTLESS_H
|