123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- #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_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()
- {
- bInitialized = false;
- }
- virtual ~CCardSwiperEntity(){}
- virtual const char *GetEntityName() const { return "CardSwiper"; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- //MessageBoxA(0,0,0,0);
- 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);
- pTransactionContext->SendAnswer(eStart);
- }
- 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 Init()
- {
- LOG_FUNCTION();
- if (CreateDevComponent((DeviceBaseClass *&)m_pCardIss) != Error_Succeed)
- {
- DbgWarn("创建cardiss设备模块失败");
- return;
- }
- bInitialized = true;
- }
- void Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if (!m_fsm.GetDevInitFlag())
- {
- ctx->Answer(Error_DevNotAvailable, CardSwiper_UserErrorCode_Read_OpenFailed);
- LogWarn(Severity_Middle, Error_DevNotAvailable, CardSwiper_UserErrorCode_Read_OpenFailed, "ReadCard but DevOpen failed.");
- }
- else if (m_fsm.GetCurrState()->id == 7) {
- ctx->Answer(Error_DevNotAvailable, CardSwiper_UserErrorCode_Read_DeviceOff);
- LogWarn(Severity_Middle, Error_DevNotAvailable, CardSwiper_UserErrorCode_Read_DeviceOff, "ReadCard but device is offline.");
- }
- else{
- 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();
- if (!m_fsm.GetDevInitFlag())
- {
- ctx->Answer(Error_DevNotAvailable, CardSwiper_UserErrorCode_PreOnline_OpenFailed);
- LogWarn(Severity_Middle, Error_DevNotAvailable, CardSwiper_UserErrorCode_PreOnline_OpenFailed, "PreOnline but DevOpen failed.");
- }
- else if (m_fsm.GetCurrState()->id == 7) {
- ctx->Answer(Error_DevNotAvailable, CardSwiper_UserErrorCode_PreOnline_DeviceOff);
- LogWarn(Severity_Middle, Error_DevNotAvailable, CardSwiper_UserErrorCode_PreOnline_DeviceOff, "PreOnline but device is offline.");
- }
- else{
- 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 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, const linkContext &pLinkInfo);
- virtual void OnSysVarEvent(const char* pszKey,const char* pszValue, const char* pszOldValue, const char* pszEntityName);
- protected:
- private:
- CardSwiperClass* m_pCardIss;
- CCardSwiperFSM m_fsm;
- BOOL bInitialized;
- 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;
- }
- DbgInfo(CSimpleStringA::Format("ConstructAPDU, lenAPDU:%d",m_lenAPDU));
- }
- };
|