123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #include "CardSwiper_server_g.h"
- #include "CardSwiper_def_g.h"
- #include "CardSwiperClass.h"
- #include "CardSwiperFSM.h"
- #include "DevEntityCommBase.hpp"
- using namespace CardSwiper;
- class CCardSwiperEntity;
- class CardSwiperServerSession : public CardSwiperService_ServerSessionBase
- {
- public:
- CardSwiperServerSession(CCardSwiperEntity* pEntity):m_pEntity(pEntity){}
- virtual ~CardSwiperServerSession(){}
- virtual void Handle_Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx);
- virtual void Handle_PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx);
- virtual void Handle_PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx);
- virtual void Handle_Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx);
- virtual void Handle_CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx);
- virtual void Handle_Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx);
- virtual void Handle_QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx);
- virtual void Handle_MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx);
- virtual void Handle_QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx);
- virtual void Handle_InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx);
- virtual void Handle_QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx);
- virtual void Handle_BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx);
- private:
- CCardSwiperEntity* m_pEntity;
- };
- class CCardSwiperEntity : public CDevAdptEntityBase, public ILogListener, public ISysVarListener
- {
- public:
- CCardSwiperEntity()
- {
- }
- virtual ~CCardSwiperEntity(){}
- virtual const char *GetEntityName() const { return "CardSwiper"; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- GetVendorLibName();
- ErrorCodeEnum eStart = m_fsm.Init(this);
- GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
- Log_Error, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
- GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
- Log_Event, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
- GetFunction()->RegistSysVarEvent("UIState", this);
- if (eStart == Error_Succeed)
- {
- //oiltest no gpio for current
- //m_pGpioClient = new GpioService_ClientBase(this);
- //ErrorCodeEnum ErrorConn = m_pGpioClient->Connect();
- //if (ErrorConn != Error_Succeed) {
- // m_pGpioClient->SafeDelete();
- // m_pGpioClient = NULL;
- //}
- //else
- // Dbg("gpio connected.");
- }
- pTransactionContext->SendAnswer(eStart);
- //ErrorCodeEnum Error = __OnStart(Error_Succeed);
- //pTransactionContext->SendAnswer(Error);
- }
- 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)
- {
- m_fsm.QueryFWBList(NULL, 2);//oiltest
- return Error_Succeed;
- }
- virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
- {
- return Error_Succeed;
- }
- virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType,pTransactionContext);
- }
- virtual CServerSessionBase* OnNewSession(const char*,const char*)
- {
- return new CardSwiperServerSession(this);
- }
- void Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- m_fsm.SetAcceptWaitMore(false);
- CardReadEvent* e = new CardReadEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- PreOnlineEvent* e = new PreOnlineEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- PostOnlineEvent* e = new PostOnlineEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx)
- {
- //LOG_FUNCTION();
- FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
- m_fsm.PostEventFIFO(evt);
- }
- void CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx)
- {
- m_fsm.SetAcceptWaitMore(false);
- FSMEvent *evt = new FSMEvent(USER_EVT_CANCELINSERT);
- m_fsm.PostEventFIFO(evt);
- }
- void Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx)
- {
- ctx->Answer(Error_Succeed);
- FSMEvent *pEvt = new FSMEvent(USER_EVT_EJECT);
- m_fsm.PostEventFIFO(pEvt);
- }
- void QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- QueryCardInfoEvent* e = new QueryCardInfoEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- MagDataTransferInitEvent * e = new MagDataTransferInitEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx)
- {
- ctx->Ans.connect = m_fsm.QueryConnStatus();
- ctx->Answer(Error_Succeed);
- }
- void InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx)
- {
- m_fsm.SetAcceptWaitMore(true);
- }
- void QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx)
- {
- QueryFWBListEvent* pEvt = new QueryFWBListEvent();
- pEvt->ctx = ctx;
- m_fsm.PostEventFIFO(pEvt);
- }
- void BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx)
- {
- BindFWBEvent* pEvt = new BindFWBEvent();
- pEvt->ctx = ctx;
- m_fsm.PostEventFIFO(pEvt);
- }
- void GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx)
- {
- ctx->Ans.state = m_fsm.GetDevState();
- ctx->Answer(Error_Succeed);
- }
- virtual bool IsService()const{return true;}
- virtual bool IsMultiThread()const{return true;}
- virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage);
- virtual void OnSysVarEvent(const char* pszKey,const char* pszValue, const char* pszOldValue, const char* pszEntityName);
- protected:
- private:
- CardSwiperClass* m_pCardIss;
- CCardSwiperFSM m_fsm;
- LONG m_lenAPDU;
- BYTE m_APDUsendBuf[512];
- CUUID m_uuidAccessAuth;
- private:
- void ConstructAPDU(BYTE cls,BYTE ins,BYTE p1,BYTE p2,BYTE lc,LPBYTE data,LPBYTE le)
- {
- LOG_FUNCTION();
- m_lenAPDU = 0;
- m_APDUsendBuf[0] = cls;
- m_APDUsendBuf[1] = ins;
- m_APDUsendBuf[2] = p1;
- m_APDUsendBuf[3] = p2;
- m_lenAPDU = 4;
- if (lc != NULL && data != NULL)
- {
- m_APDUsendBuf[4] = lc;
- m_lenAPDU++;
- if (lc != 0)
- {
- memcpy(m_APDUsendBuf+m_lenAPDU,data,lc);
- m_lenAPDU += lc;
- }
- }
- if (le != NULL)
- m_APDUsendBuf[m_lenAPDU++] = (*le);
- if (!data)
- {
- delete[] data;
- data = NULL;
- }
- Dbg("cmd len[%d]",m_lenAPDU);
- }
- };
|