- #ifndef _SERVICE_H
- #define _SERVICE_H
- #include "Thread.h"
- #include "Socket.h"
- #include "SafeVector.h"
- #include "....publictrfPublic.h"
- typedef struct _CLIENT_STATE {
- string clienthdid;
- int interval;
- }CLIENT_STATE, *PCLIENT_STATE;
- //update specialed client state.
- bool ModifyClientState(string clienthdid, bool state);
- //update the client state list.
- void UpdateClientState(void);
- //为以后扩充用---部门根据IP地址来划分
- int GetClientDepart(string &clienthdid);
- class CClientThread;
- /********************************************************
- * Class Name : CService. *
- * Purpose : Service objects manager class. *
- * File Name : Service.h / Service.cpp *
- *------------------------------------------------------*
- * Author : Devia Lee. Date: 2004-06-01 *
- ********************************************************/
- class CService
- {
- public:
- CService();
- virtual ~CService();
- friend class CServiceThread;
- bool Start(const int serverport = SVR_DIRPORT);
- void Stop();
- bool IsOpened(void);
- private:
- bool m_bopened;
- CServiceThread *m_omiservice;
- };
- /********************************************************
- * Class Name : CServiceSocket. *
- * Purpose : Service socket object class. *
- * File Name : Service.h / Service.cpp *
- *------------------------------------------------------*
- * Author : Devia Lee. Date: 2004-06-01 *
- ********************************************************/
- class CServiceSocket : public CXWinServerSocket
- {
- public:
- CServiceSocket();
- virtual ~CServiceSocket();
- protected:
- //client event do here.
- void OnClientConnect(CXWinSocket *pClientSocket);
- void OnClientClose(CXWinSocket *pClientSocket);
- private:
- safe_vector<CClientThread*> m_omicltthreads;
- };
- /********************************************************
- * Class Name : CServiceThread. *
- * Purpose : Main service thread class. *
- * File Name : Service.h / Service.cpp *
- *------------------------------------------------------*
- * Author : Devia Lee. Date: 2004-06-01 *
- ********************************************************/
- class CServiceThread : public CThread
- {
- public:
- CServiceThread();
- virtual ~CServiceThread();
- //create the acceptor socket listening thread.
- bool Create(CService *pService, bool bCreateAndSuspended = false, const uint unSvrPort = 8889);
- protected:
- //overrides execute function.
- void Execute();
- //start, stop, pause and resume event process functions.
- void OnStart();
- void OnStop();
- void OnSuspend();
- void OnResume();
- private:
- CService *m_service;
- CServiceSocket *m_svrsock;
- };
- /********************************************************
- * Class Name : CClientThread. *
- * Purpose : Client processing thread class. *
- * File Name : Service.h / Service.cpp *
- *------------------------------------------------------*
- * Author : Devia Lee. Date: 2004-06-01 *
- ********************************************************/
- class CClientThread : public CThread
- {
- public:
- CClientThread(CXWinSocket *pClientSocket);
- virtual ~CClientThread();
- CXWinSocket *GetSockObj(void){return m_pcltsock;}
- protected:
- //overrides execute function.
- void Execute();
- void ProcessRAGState(RAGENTPACK &agrpack);
- void ProcessRAGAuthor(RAGENTPACK &agrpack);
- void ProcessRAGUsrSql(RAGENTPACK &agrpack);
- bool SendFile(LPCSTR lpszFile);
- //send answer to peer.
- bool SendAnswer(RAGPACKTYPE akp, bool bSuccessfully = true);
- public:
- string m_sclienthdid;
- string m_sremotehost;
- string m_sremoteip;
- private:
- CXWinSocket *m_pcltsock;
- BOOL m_bfirststate;
- };
- #endif //_SERVICE_H