Service.h
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:4k
源码类别:

网格计算

开发平台:

Visual C++

  1. #ifndef _SERVICE_H
  2. #define _SERVICE_H
  3. #include "Thread.h"
  4. #include "Socket.h"
  5. #include "SafeVector.h"
  6. #include "....publictrfPublic.h"
  7. typedef struct _CLIENT_STATE {
  8. string clienthdid;
  9. int interval;
  10. }CLIENT_STATE, *PCLIENT_STATE;
  11. //update specialed client state.
  12. bool ModifyClientState(string clienthdid, bool state);
  13. //update the client state list.
  14. void UpdateClientState(void);
  15. //为以后扩充用---部门根据IP地址来划分
  16. int  GetClientDepart(string &clienthdid);
  17. class CClientThread;
  18. /********************************************************
  19.  *  Class Name : CService. *
  20.  * Purpose : Service objects manager class. *
  21.  *  File  Name : Service.h / Service.cpp *
  22.  *------------------------------------------------------*
  23.  * Author : Devia Lee. Date: 2004-06-01 *
  24.  ********************************************************/
  25. class CService
  26. {
  27. public:
  28. CService();
  29. virtual ~CService();
  30. friend class CServiceThread;
  31. bool Start(const int serverport = SVR_DIRPORT);
  32. void Stop();
  33. bool IsOpened(void);
  34. private:
  35. bool m_bopened;
  36. CServiceThread *m_omiservice;
  37. };
  38. /********************************************************
  39.  *  Class Name : CServiceSocket. *
  40.  * Purpose : Service socket object class. *
  41.  *  File  Name : Service.h / Service.cpp *
  42.  *------------------------------------------------------*
  43.  * Author : Devia Lee. Date: 2004-06-01 *
  44.  ********************************************************/
  45. class CServiceSocket : public CXWinServerSocket
  46. {
  47. public:
  48. CServiceSocket();
  49. virtual ~CServiceSocket();
  50. protected:
  51. //client event do here.
  52. void OnClientConnect(CXWinSocket *pClientSocket);
  53. void OnClientClose(CXWinSocket *pClientSocket);
  54. private:
  55. safe_vector<CClientThread*> m_omicltthreads;
  56. };
  57. /********************************************************
  58.  *  Class Name : CServiceThread. *
  59.  * Purpose : Main service thread class. *
  60.  *  File  Name : Service.h / Service.cpp *
  61.  *------------------------------------------------------*
  62.  * Author : Devia Lee. Date: 2004-06-01 *
  63.  ********************************************************/
  64. class CServiceThread : public CThread
  65. {
  66. public:
  67. CServiceThread();
  68. virtual ~CServiceThread();
  69. //create the acceptor socket listening thread.
  70. bool Create(CService *pService, bool bCreateAndSuspended = false, const uint unSvrPort = 8889);
  71. protected:
  72. //overrides execute function.
  73. void Execute();
  74. //start, stop, pause and resume event process functions.
  75. void OnStart();
  76. void OnStop();
  77. void OnSuspend();
  78. void OnResume();
  79. private:
  80. CService *m_service;
  81. CServiceSocket *m_svrsock;
  82. };
  83. /********************************************************
  84.  *  Class Name : CClientThread. *
  85.  * Purpose : Client processing thread class. *
  86.  *  File  Name : Service.h / Service.cpp *
  87.  *------------------------------------------------------*
  88.  * Author : Devia Lee. Date: 2004-06-01 *
  89.  ********************************************************/
  90. class CClientThread : public CThread
  91. {
  92. public:
  93. CClientThread(CXWinSocket *pClientSocket);
  94. virtual ~CClientThread();
  95. CXWinSocket *GetSockObj(void){return m_pcltsock;}
  96. protected:
  97. //overrides execute function.
  98. void Execute();
  99. void ProcessRAGState(RAGENTPACK &agrpack);
  100. void ProcessRAGAuthor(RAGENTPACK &agrpack);
  101. void ProcessRAGUsrSql(RAGENTPACK &agrpack);
  102. bool SendFile(LPCSTR lpszFile);
  103. //send answer to peer.
  104. bool SendAnswer(RAGPACKTYPE akp, bool bSuccessfully = true);
  105. public:
  106. string  m_sclienthdid;
  107. string  m_sremotehost;
  108. string  m_sremoteip;
  109. private:
  110. CXWinSocket *m_pcltsock;
  111. BOOL  m_bfirststate;
  112. };
  113. #endif //_SERVICE_H