PageRenderTime 33ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TServerMS/Service/ServiceImpHost.h

http://awoe.googlecode.com/
C++ Header | 82 lines | 43 code | 17 blank | 22 comment | 0 complexity | 411d912c1af790cc87550423ac09c12e MD5 | raw file
 1#ifndef		___DATA_HOST_IMP___
 2#define		___DATA_HOST_IMP___
 3
 4#include "Service/ServiceImp.h"
 5#include "ServiceDataSMS.h"
 6#include "Service/Session.h"
 7#include "Message/MsgBuilderIf.h"
 8
 9//
10//	Network Service 
11//
12//
13class ServiceImpHost : public ServiceImp
14{
15public:
16	enum
17	{
18		num_working_thread	=	4,
19		num_session_mgrs	=	2,
20	};
21
22
23	ServiceImpHost();
24	virtual ~ServiceImpHost();
25
26	virtual void init(ServiceData& data);
27
28	//
29	//	session recycle & reuse
30	//
31	virtual bool	createSession(Session*& pSes);
32	virtual	bool	releaseSession(Session*  pSes);
33
34	//
35	//	get session by session/entity id
36	//
37	Session*	getSession(int sid);
38	void		rmvSession(int sid);
39
40	//
41	//	session start & end
42	//
43	virtual void onSessionStart(Session* pSes, const boost::system::error_code& error);
44	virtual void onSessionEnd(Session* pSes);
45protected:
46	virtual void onStart();
47	virtual void onStop();
48
49	//
50	//	callbacks
51	//
52	virtual void onTimer();
53	virtual void onDispatchMsg(IMsg* pMsg);
54	//
55	//	handle control message
56	//
57	virtual void onControlMsg(IMsg* pMsg);
58
59	void post_accept();
60protected:
61
62	boost::asio::io_service::work	m_theEmptyWork;
63	boost::asio::ip::tcp::endpoint	m_theEndPoint;
64	boost::asio::ip::tcp::acceptor	m_theAcceptor;
65
66	typedef stdext::hash_map<int, Session*>	SessionMap;
67	SessionMap		m_mapSID2Session;
68	int				m_nCurrentSessionID;
69
70	Service*	m_wpSvcLgc;
71
72	MsgBufferFactory	m_theMsgBuffFact;
73
74	IMsgBuilder*		m_pMsgBuilder;
75
76	//
77	//	configurations from properties file
78	//
79	short		m_nPort;
80};
81
82#endif