123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- #ifndef __MOD_PINPAD_H
- #define __MOD_PINPAD_H
- #include "SpBase.h"
- #include "PinPadFSM.h"
- #include "DevEntityCommBase.hpp"
- class PinPadServerSession : public PinPad::PinPadService_ServerSessionBase
- {
- public:
- PinPadServerSession(CPinPadEntity* pEntity):m_pEntity(pEntity){}
- virtual ~PinPadServerSession(){}
- void Handle_InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx);
- void Handle_InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx);
- void Handle_Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx);
- void Handle_GetInputJS(SpReqAnsContext<PinPadService_GetInputJS_Req, PinPadService_GetInputJS_Ans>::Pointer ctx);
- void Handle_InputCancelJS(SpReqAnsContext<PinPadService_InputCancelJS_Req, PinPadService_InputCancelJS_Ans>::Pointer ctx);
- void Handle_GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx);
- void Handle_GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx);
- void Handle_LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
- void Handle_EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
- void Handle_QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx);
- void Handle_GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
- private:
- CPinPadEntity* m_pEntity;
- };
- class CPinPadEntity : public CDevAdptEntityBase, public ISysVarListener
- {
- public:
- CPinPadEntity():m_state(-1){}
- virtual ~CPinPadEntity(){}
- virtual const char *GetEntityName() const { return "PinPad"; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- GetFunction()->RegistSysVarEvent("UIState", this);
- pTransactionContext->SendAnswer(Error);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- //ErrorCodeEnum Error = __OnClose(Error_Succeed);
- //MessageBoxA(0,0,0,0);
- //m_fsm.OnExit();
- m_fsm.PostExitEvent();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnPause(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
- {
- ErrorCodeEnum Error = m_fsm.Init(this);
- return Error;
- }
- virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
- {
- return Error_Succeed;
- }
- virtual CServerSessionBase* OnNewSession(const char*,const char*)
- {
- return new PinPadServerSession(this);
- }
- void InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- InputWaitingMoreEvent *e = new InputWaitingMoreEvent();
- m_fsm.PostEventFIFO(e);
- }
- void InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- InputCancelEvent *e = new InputCancelEvent();
- m_fsm.PostEventFIFO(e);
- }
- void Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx)
- {
- FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
- m_fsm.PostEventFIFO(evt);
- }
- void GetInputJS(SpReqAnsContext<PinPadService_GetInputJS_Req, PinPadService_GetInputJS_Ans>::Pointer ctx)
- {
- if (!m_fsm.GetDevInitFlag())
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- else {
- m_fsm.SetJSCtx(ctx);
- GetInputJSEvent* e = new GetInputJSEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- void InputCancelJS(SpReqAnsContext<PinPadService_InputCancelJS_Req, PinPadService_InputCancelJS_Ans>::Pointer ctx)
- {
- if (!m_fsm.GetDevInitFlag())
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- else if (_stricmp(m_fsm.GetCurrStateName(), "Input") != 0)
- ctx->Answer(Error_Unexpect, PinPad_UserErrorCode_NotInGetInput);
- else
- {
- InputCancelEvent* e = new InputCancelEvent();
- m_fsm.PostEventFIFO(e);
- }
- }
- void GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx)
- {
- if (!m_fsm.GetDevInitFlag())
- {
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- LogWarn(Severity_Middle, Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed, "Open PinPad failed(GetInputSM)");
- }else{
- m_fsm.SetCtx(ctx);
- GetInputSMEvent* e = new GetInputSMEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- void LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if(!m_fsm.GetDevInitFlag())
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- else{
- LoadKeySMEvent *evt = new LoadKeySMEvent();
- evt->ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- }
- }
- void EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- if(!m_fsm.GetDevInitFlag())
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- else{
- EncryptSMEvent *evt = new EncryptSMEvent();
- evt->ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- }
- }
- void QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx)
- {
- if (m_fsm.GetDevInitFlag())
- {
- m_fsm.GetEncryptKey(ctx->Ans.encryptkey, ctx->Ans.reserved1);
- ctx->Answer(Error_Succeed);
- }
- else{
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- }
- }
- void GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx)
- {
- if(!m_fsm.GetDevInitFlag())
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- else{
- GetCheckCodeEvent *evt = new GetCheckCodeEvent();
- evt->ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- }
- }
- void GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx)
- {
- if (m_fsm.GetDevInitingFlag())
- ctx->Answer(Error_NotInit, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- else if (m_fsm.GetDevInitFlag())
- {
- DevCategoryInfo devInfo;
- memset(&devInfo, 0, sizeof(devInfo));
- ErrorCodeEnum eGetDevInfo = m_fsm.GetDevInfo(devInfo);
- if (eGetDevInfo == Error_Succeed)
- {
- //oiltmp@20240823 纪林的与业务组的初始化优化完成之后,是不是不要再拼接了?
- CSimpleStringA tmpAddStr("");
- tmpAddStr = tmpAddStr + "Vendor=" + devInfo.szVendor;
- if (devInfo.szModel[strlen(devInfo.szModel) - 1] == '#')
- ctx->Ans.model = CSimpleStringA(devInfo.szModel) + tmpAddStr;
- else
- ctx->Ans.model = CSimpleStringA(devInfo.szModel) + "#" + tmpAddStr;
- ctx->Ans.type = devInfo.szType;
- }
- ctx->Ans.state = eGetDevInfo;
- ctx->Answer(Error_Succeed);
- }
- else
- ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
- }
- void DoInputCancelJS(SpReqAnsContext<PinPadService_InputCancelJS_Req, PinPadService_InputCancelJS_Ans>::Pointer ctx);
- virtual void OnSysVarEvent(const char *pszKey,
- const char *pszValue, const char *pszOldValue, const char *pszEntityName);
- virtual bool IsService()const{return true;}
- virtual bool IsMultiThread()const{return true;}
- virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType,pTransactionContext);
- }
- protected:
- private:
- CPinPadFSM m_fsm;
- int m_state;
- };
- struct InputCancelJSTask : public ITaskSp
- {
- CPinPadEntity* pEntity;
- SpReqAnsContext<PinPadService_InputCancelJS_Req, PinPadService_InputCancelJS_Ans>::Pointer ctx;
- InputCancelJSTask(CPinPadEntity* entity) : pEntity(entity) {}
- void Process()
- {
- pEntity->DoInputCancelJS(ctx);
- }
- };
- #endif //__MOD_PINPAD_H
|