123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "SpHelper.h"
- // 柜员上下文 0x30A
- #include "CounterContext_msg_g.h"
- using namespace CounterContext;
- #include "AssistantChannel_client_g.h"
- using namespace AssistantChannel;
- #include "chan_protocol.h"
- #include "EventCode.h"
- class CCounterContextEntity;
- class ChannelClient : public ChannelService_ClientBase
- {
- public:
- ChannelClient(CCounterContextEntity *pEntity);
- virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
- };
- class CCounterContextEntity : public CEntityBase,public ILogListener, public ITimerListener
- {
- public:
- CCounterContextEntity() : m_pChannelClient(NULL), m_bConnectAssist(false) {}
- virtual ~CCounterContextEntity() {}
- virtual const char *GetEntityName() const { return "CounterContext"; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- 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)
- {
- if (LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS == dwUserCode)
- {
- Sleep(900);
- if (m_pChannelClient != NULL){
- m_pChannelClient->GetFunction()->CloseSession();
- m_pChannelClient = NULL;
- m_bConnectAssist = false;
- }
- if (Error_Succeed == ConnectAssistChannel()) {
- m_bConnectAssist = true;
- }
- else {
- GetFunction()->SetTimer(1, this, 3150);
- }
- }
- }
- ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
- {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- int i = 0;
- m_arrListener.Init(1);
- pFunc->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS, NULL, false);
- if (preOperationError != Error_Succeed)
- return preOperationError;
- return Error_Succeed;
- }
- void OnStarted()
- {
- m_pChannelClient = new ChannelClient(this);
- if (Error_Succeed == ConnectAssistChannel()) {
- m_bConnectAssist = true;
- }
- else {
- GetFunction()->SetTimer(1, this, 3150);
- }
- }
- ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
- {
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- for (int i = 0; i < m_arrListener.GetCount(); ++i)
- {
- spFunction->UnsubscribeLog(m_arrListener[i]);
- }
- m_pChannelClient->GetFunction()->CloseSession();
- m_pChannelClient = NULL;
- return Error_Succeed;
- }
- void OnReceivePkt(int sub_type, const char *buffer, int size)
- {
- if (sub_type == ACM_AGENTCTX_INFO) {
- CounterBasicInfo evt;
- SpBuffer buf;
- buf.OpenRead(buffer, size);
- #if defined(RVC_OS_WIN)
- evt.Serialize(buf);
- #else
- CSimpleString16Bit name16;
- buf& name16;
- evt.name = CSimpleString16Bit2A(name16);
- CSimpleString16Bit workNumber16;
- buf& workNumber16;
- evt.workNumber = CSimpleString16Bit2A(workNumber16);
- CSimpleString16Bit callid16;
- buf& callid16;
- evt.callid = CSimpleString16Bit2A(callid16);
- CSimpleString16Bit skillCode16;
- buf& skillCode16;
- evt.skillCode = CSimpleString16Bit2A(skillCode16);
- CSimpleString16Bit skillDesc16;
- buf& skillDesc16;
- evt.skillDesc = CSimpleString16Bit2A(skillDesc16);
- CSimpleString16Bit level16;
- buf& level16;
- evt.level = CSimpleString16Bit2A(level16);
- #endif //RVC_OS_WIN
- SpSendBroadcast(GetFunction(), SP_MSG_OF(CounterBasicInfo), SP_MSG_SIG_OF(CounterBasicInfo), evt);
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unknown sub_type %d from agent!", sub_type);
- }
- }
- ErrorCodeEnum ConnectAssistChannel()
- {
- if (NULL == m_pChannelClient) {
- m_pChannelClient = new ChannelClient(this);
- }
-
- ErrorCodeEnum Error = m_pChannelClient->Connect();
- if (Error_Succeed != Error) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect assistant channel failed!");
- m_pChannelClient->SafeDelete();
- m_pChannelClient = NULL;
- return Error;
- }
-
- ChannelService_BeginRecv_Sub Sub;
- Sub.type = ACM_TYPE_AGENTCTX;
- Error = (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
- if (Error != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Register ACM_TYPE_AGENTCTX failed!");
- m_pChannelClient->GetFunction()->CloseSession();
- m_pChannelClient = NULL;
- return Error;
- }
- return Error;
- }
- void OnTimeout(DWORD dwTimerID)
- {
- if (1 == dwTimerID) {
- if (!m_bConnectAssist) {
- if (Error_Succeed == ConnectAssistChannel()) {
- m_bConnectAssist = true;
- }
- }
- if (m_bConnectAssist) {
- GetFunction()->KillTimer(1);
- }
- }
- }
- private:
- ChannelClient *m_pChannelClient;
- CAutoArray<CUUID> m_arrListener;
- bool m_bConnectAssist;
- };
- ChannelClient::ChannelClient( CCounterContextEntity *pEntity ) : ChannelService_ClientBase(pEntity)
- {
- }
- void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
- {
- if (Error == Error_Succeed) {
- CCounterContextEntity *pEntity = static_cast<CCounterContextEntity*>(m_pEntityBase);
- pEntity->OnReceivePkt(Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
- }
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CCounterContextEntity)
- SP_END_ENTITY_MAP()
|