123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include "RemoteControllerFSM.h"
- CRemoteControllerFSM::CRemoteControllerFSM(void)
- :m_pConnection(NULL)
- {
- }
- CRemoteControllerFSM::~CRemoteControllerFSM(void)
- {
- }
- ErrorCodeEnum CRemoteControllerFSM::OnInit()
- {
- return Error_Succeed;
- }
- ErrorCodeEnum CRemoteControllerFSM::OnExit()
- {
- return Error_Succeed;
- }
- void CRemoteControllerFSM::s1_on_entry()
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("s1_on_entry")("enter to init state");
- auto pFunction = m_pEntity->GetFunction();
- pFunction->SetSysVar("RemoteMaintain", "N");
- }
- void CRemoteControllerFSM::s1_on_exit()
- {
- }
- unsigned int CRemoteControllerFSM::s1_on_event(FSMEvent* event)
- {
- //MessageBoxA(0,0,0,0);
- if (event->iEvt == Event_CreateChannel)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("s1_on_event")("recv Event_CreateChannel");
- auto rc = SecureClientConnect();
- if (rc == Error_Succeed && m_pConnection->IsConnectionOK())
- rc = m_pConnection->SendCreateRemoteChannelReq();
- if(rc == Error_Succeed)
- LOG_TRACE("send create remote channel succ");
- else
- LogError(Severity_Low, rc, 0, "send create remote channel fail");
- }
- return 0;
- }
- void CRemoteControllerFSM::s2_on_entry()
- {
- auto pFunction = m_pEntity->GetFunction();
- pFunction->SetSysVar("RemoteMaintain", "O");
- }
- void CRemoteControllerFSM::s2_on_exit()
- {
- }
- unsigned int CRemoteControllerFSM::s2_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_ReleaseChannel)
- {
- SecureClientRelease();
- }
- return 0;
- }
- void CRemoteControllerFSM::s3_on_entry()
- {
- auto pFunction = m_pEntity->GetFunction();
- pFunction->SetSysVar("RemoteMaintain", "M");
- }
- void CRemoteControllerFSM::s3_on_exit()
- {
- }
- unsigned int CRemoteControllerFSM::s3_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_ReleaseChannel)
- {
- SecureClientRelease();
- }
- return 0;
- }
- void CRemoteControllerFSM::s4_on_entry()
- {
- auto pFunction = m_pEntity->GetFunction();
- pFunction->SetSysVar("RemoteMaintain", "T");
- }
- void CRemoteControllerFSM::s4_on_exit()
- {
- }
- unsigned int CRemoteControllerFSM::s4_on_event(FSMEvent* event)
- {
- if (event->iEvt == Event_ReleaseChannel)
- {
- SecureClientRelease();
- }
- return 0;
- }
- ErrorCodeEnum CRemoteControllerFSM::SecureClientConnect()
- {
- if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
- return Error_Succeed;
- SecureClientRelease();
-
- m_pConnection = new CRemoteControllerCnn(m_pEntity, this);
- if (m_pConnection->ConnectFromCentralSetting() && m_pConnection->IsConnectionOK())
- return Error_Succeed;
- SecureClientRelease();
- return Error_PeerReject;
- }
- ErrorCodeEnum CRemoteControllerFSM::SecureClientRelease()
- {
- if (m_pConnection != NULL)
- {
- m_pConnection->Close();
- m_pConnection->DecRefCount();
- m_pConnection = NULL;
- }
- return Error_Succeed;
- }
|