205 lines
4.6 KiB
C++
205 lines
4.6 KiB
C++
|
|
#include "StdAfx.h"
|
|||
|
|
#include "ServiceUnits.h"
|
|||
|
|
#include "ControlPacket.h"
|
|||
|
|
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|||
|
|
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
|||
|
|
CServiceUnits * CServiceUnits::g_pServiceUnits = NULL; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>캯<EFBFBD><ECBAAF>
|
|||
|
|
CServiceUnits::CServiceUnits()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ýӿ<C3BD>
|
|||
|
|
m_pIServiceUnitsSink=NULL;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|||
|
|
m_ServiceStatus=ServiceStatus_Stop;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>
|
|||
|
|
ASSERT(g_pServiceUnits == NULL);
|
|||
|
|
if (g_pServiceUnits == NULL) g_pServiceUnits = this;
|
|||
|
|
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
CServiceUnits::~CServiceUnits()
|
|||
|
|
{
|
|||
|
|
ConcludeService();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
bool CServiceUnits::StartService()
|
|||
|
|
{
|
|||
|
|
//Ч<><D0A7>״̬
|
|||
|
|
ASSERT(m_ServiceStatus==ServiceStatus_Stop);
|
|||
|
|
if (m_ServiceStatus!=ServiceStatus_Stop) return false;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>״̬
|
|||
|
|
SetServiceStatus(ServiceStatus_Config);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>
|
|||
|
|
if (InitializeService()==false)
|
|||
|
|
{
|
|||
|
|
ConcludeService();
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD>
|
|||
|
|
if (StartKernelService()==false)
|
|||
|
|
{
|
|||
|
|
ConcludeService();
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>״̬
|
|||
|
|
SetServiceStatus(ServiceStatus_Service);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
|||
|
|
bool CServiceUnits::ConcludeService()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|||
|
|
SetServiceStatus(ServiceStatus_Stop);
|
|||
|
|
|
|||
|
|
//ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
|
|||
|
|
if (m_TimerEngine.GetInterface()!=NULL) m_TimerEngine->ConcludeService();
|
|||
|
|
if (m_AttemperEngine.GetInterface()!=NULL) m_AttemperEngine->ConcludeService();
|
|||
|
|
if (m_TCPNetworkEngine.GetInterface()!=NULL) m_TCPNetworkEngine->ConcludeService();
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ýӿ<C3BD>
|
|||
|
|
bool CServiceUnits::SetServiceUnitsSink(IServiceUnitsSink * pIServiceUnitsSink)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|||
|
|
m_pIServiceUnitsSink=pIServiceUnitsSink;
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC>
|
|||
|
|
bool CServiceUnits::MaintainService(BYTE cbFlag)
|
|||
|
|
{
|
|||
|
|
BYTE cbTempFlag = cbFlag;
|
|||
|
|
//֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC>
|
|||
|
|
SendControlPacket(CT_MAINTAIN_SERVICE, &cbTempFlag, sizeof(BYTE));
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>Ϣ
|
|||
|
|
bool CServiceUnits::SendSystemMessage(CMD_CM_SystemMessage* pMsg)
|
|||
|
|
{
|
|||
|
|
SendControlPacket(CT_SEND_SYSTEM_MESSAGE, pMsg, sizeof(CMD_CM_SystemMessage));
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
bool CServiceUnits::InitializeService()
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>
|
|||
|
|
m_InitParameter.LoadInitParameter();
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if ((m_TimerEngine.GetInterface()==NULL)&&(m_TimerEngine.CreateInstance()==false)) return false;
|
|||
|
|
if ((m_AttemperEngine.GetInterface()==NULL)&&(m_AttemperEngine.CreateInstance()==false)) return false;
|
|||
|
|
if ((m_TCPNetworkEngine.GetInterface()==NULL)&&(m_TCPNetworkEngine.CreateInstance()==false)) return false;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|||
|
|
IUnknownEx * pIAttemperEngine=m_AttemperEngine.GetInterface();
|
|||
|
|
IUnknownEx * pITCPNetworkEngine=m_TCPNetworkEngine.GetInterface();
|
|||
|
|
|
|||
|
|
//<2F>ص<EFBFBD><D8B5>ӿ<EFBFBD>
|
|||
|
|
IUnknownEx * pIAttemperEngineSink=QUERY_OBJECT_INTERFACE(m_AttemperEngineSink,IUnknownEx);
|
|||
|
|
|
|||
|
|
//<2F>ӿ<F3B6A8BD>
|
|||
|
|
if (m_AttemperEngine->SetAttemperEngineSink(pIAttemperEngineSink)==false) return false;
|
|||
|
|
|
|||
|
|
//<2F>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (m_TimerEngine->SetTimerEngineEvent(pIAttemperEngine)==false) return false;
|
|||
|
|
if (m_AttemperEngine->SetNetworkEngine(pITCPNetworkEngine)==false) return false;
|
|||
|
|
if (m_TCPNetworkEngine->SetTCPNetworkEngineEvent(pIAttemperEngine)==false) return false;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>Ȼص<C8BB>
|
|||
|
|
m_AttemperEngineSink.m_pInitParameter=&m_InitParameter;
|
|||
|
|
m_AttemperEngineSink.m_pITimerEngine=m_TimerEngine.GetInterface();
|
|||
|
|
m_AttemperEngineSink.m_pITCPNetworkEngine=m_TCPNetworkEngine.GetInterface();
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
WORD wMaxConnect=m_InitParameter.m_wMaxConnect;
|
|||
|
|
WORD wServicePort=m_InitParameter.m_wServicePort;
|
|||
|
|
if (m_TCPNetworkEngine->SetServiceParameter(wServicePort,wMaxConnect,NULL)==false) return false;
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD>
|
|||
|
|
bool CServiceUnits::StartKernelService()
|
|||
|
|
{
|
|||
|
|
//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (m_TimerEngine->StartService()==false)
|
|||
|
|
{
|
|||
|
|
ASSERT(FALSE);
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (m_AttemperEngine->StartService()==false)
|
|||
|
|
{
|
|||
|
|
ASSERT(FALSE);
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (m_TCPNetworkEngine->StartService()==false)
|
|||
|
|
{
|
|||
|
|
ASSERT(FALSE);
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>״̬
|
|||
|
|
bool CServiceUnits::SetServiceStatus(enServiceStatus ServiceStatus)
|
|||
|
|
{
|
|||
|
|
//״̬<D7B4>ж<EFBFBD>
|
|||
|
|
if (m_ServiceStatus!=ServiceStatus)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>֪ͨ
|
|||
|
|
if ((m_ServiceStatus!=ServiceStatus_Service)&&(ServiceStatus==ServiceStatus_Stop))
|
|||
|
|
{
|
|||
|
|
LPCTSTR pszString=TEXT("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>");
|
|||
|
|
CTraceService::TraceString(pszString,TraceLevel_Exception);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>
|
|||
|
|
m_ServiceStatus=ServiceStatus;
|
|||
|
|
|
|||
|
|
//״̬֪ͨ
|
|||
|
|
ASSERT(m_pIServiceUnitsSink!=NULL);
|
|||
|
|
if (m_pIServiceUnitsSink!=NULL) m_pIServiceUnitsSink->OnServiceUnitsStatus(m_ServiceStatus);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD>
|
|||
|
|
bool CServiceUnits::SendControlPacket(WORD wControlID, VOID * pData, WORD wDataSize)
|
|||
|
|
{
|
|||
|
|
//״̬Ч<CCAC><D0A7>
|
|||
|
|
ASSERT(m_AttemperEngine.GetInterface() != NULL);
|
|||
|
|
if (m_AttemperEngine.GetInterface() == NULL) return false;
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD>Ϳ<EFBFBD><CDBF><EFBFBD>
|
|||
|
|
m_AttemperEngine->OnEventControl(wControlID, pData, wDataSize);
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
//////////////////////////////////////////////////////////////////////////////////
|