#ifndef SERVICE_UNITS_HEAD_FILE
#define SERVICE_UNITS_HEAD_FILE

#pragma once

#include "Stdafx.h"
#include "InitParameter.h"
#include "AttemperEngineSink.h"
#include "DataBaseEngineSink.h"

//////////////////////////////////////////////////////////////////////////////////

//ʾ
#define NETWORK_CORRESPOND			1									//¼

//Ϣ
#define WM_UICONTROL_REQUEST		(WM_USER+100)						//

//////////////////////////////////////////////////////////////////////////////////
//öٶ

//״̬
enum enServiceStatus
{
	ServiceStatus_Stop,				//ֹͣ״̬
	ServiceStatus_Config,			//״̬
	ServiceStatus_Service,			//״̬
};

//////////////////////////////////////////////////////////////////////////////////

//״̬ӿ
interface IServiceUnitsSink
{
	//ӿڶ
public:
	//״̬
	virtual VOID OnServiceUnitsStatus(enServiceStatus ServiceStatus)=NULL;
};

//////////////////////////////////////////////////////////////////////////////////

//Ԫ
class CServiceUnits : public CWnd
{
	//Ԫ
	friend class CAttemperEngineSink;
	friend class CDataBaseEngineSink;

	//״̬
protected:
	enServiceStatus					m_ServiceStatus;					//״̬

	//
public:
	CInitParameter					m_InitParameter;					//ò

	//
private:
	CWHDataQueue					m_DataQueue;						//ݶ
	CCriticalSection				m_CriticalSection;					//ͬ

	//
protected:
	CAttemperEngineSink				m_AttemperEngineSink;				//ȹ
	CDataBaseEngineSink				m_DataBaseEngineSink[4];			//ݹ

	//ں
protected:
	CTimerEngineHelper				m_TimerEngine;						//ʱ
	CAttemperEngineHelper			m_AttemperEngine;					//
	CDataBaseEngineHelper			m_DataBaseEngine;					//
	CTCPNetworkEngineHelper			m_TCPNetworkEngine;					//
	CTCPSocketServiceHelper			m_TCPSocketService;					//Э

	//ӿڱ
protected:
	IServiceUnitsSink *				m_pIServiceUnitsSink;				//״̬ӿ

	//̬
public:
	static CServiceUnits *			g_pServiceUnits;					//ָ

	//
public:
	//캯
	CServiceUnits();
	//
	virtual ~CServiceUnits();

	//Ϣ
public:
	//ȡ״̬
	enServiceStatus GetServiceStatus() { return m_ServiceStatus; }

	//
public:
	//
	bool StartService();
	//ֹͣ
	bool ConcludeService();
	//ýӿ
	bool SetServiceUnitsSink(IServiceUnitsSink * pIServiceUnitsSink);
	//Ͷ
	bool PostControlRequest(WORD wIdentifier, VOID * pData, WORD wDataSize);

	//
protected:
	//
	bool InitializeService();
	//ں
	bool StartKernelService();
	//
	bool StartNetworkService();

	//ڲ
private:
	//״̬
	bool SetServiceStatus(enServiceStatus ServiceStatus);
	//Ϳ
	bool SendControlPacket(WORD wControlID, VOID * pData, WORD wDataSize);

	//Ϣӳ
protected:
	//Ϣ
	LRESULT OnUIControlRequest(WPARAM wParam, LPARAM lParam);

	DECLARE_MESSAGE_MAP()
};

//////////////////////////////////////////////////////////////////////////////////

#endif