/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. #include "Service/ServiceImp.h"
  4. #include "ServiceDataSMS.h"
  5. #include "Service/Session.h"
  6. #include "Message/MsgBuilderIf.h"
  7. //
  8. // Network Service
  9. //
  10. //
  11. class ServiceImpHost : public ServiceImp
  12. {
  13. public:
  14. enum
  15. {
  16. num_working_thread = 4,
  17. num_session_mgrs = 2,
  18. };
  19. ServiceImpHost();
  20. virtual ~ServiceImpHost();
  21. virtual void init(ServiceData& data);
  22. //
  23. // session recycle & reuse
  24. //
  25. virtual bool createSession(Session*& pSes);
  26. virtual bool releaseSession(Session* pSes);
  27. //
  28. // get session by session/entity id
  29. //
  30. Session* getSession(int sid);
  31. void rmvSession(int sid);
  32. //
  33. // session start & end
  34. //
  35. virtual void onSessionStart(Session* pSes, const boost::system::error_code& error);
  36. virtual void onSessionEnd(Session* pSes);
  37. protected:
  38. virtual void onStart();
  39. virtual void onStop();
  40. //
  41. // callbacks
  42. //
  43. virtual void onTimer();
  44. virtual void onDispatchMsg(IMsg* pMsg);
  45. //
  46. // handle control message
  47. //
  48. virtual void onControlMsg(IMsg* pMsg);
  49. void post_accept();
  50. protected:
  51. boost::asio::io_service::work m_theEmptyWork;
  52. boost::asio::ip::tcp::endpoint m_theEndPoint;
  53. boost::asio::ip::tcp::acceptor m_theAcceptor;
  54. typedef stdext::hash_map<int, Session*> SessionMap;
  55. SessionMap m_mapSID2Session;
  56. int m_nCurrentSessionID;
  57. Service* m_wpSvcLgc;
  58. MsgBufferFactory m_theMsgBuffFact;
  59. IMsgBuilder* m_pMsgBuilder;
  60. //
  61. // configurations from properties file
  62. //
  63. short m_nPort;
  64. };
  65. #endif