acl/lib_acl_cpp/include/acl_cpp/ipc/ipc_service.hpp

128 lines
2.5 KiB
C++
Raw Normal View History

2014-11-19 00:25:21 +08:00
#pragma once
#include "acl_cpp/acl_cpp_define.hpp"
#include "acl_cpp/stdlib/locker.hpp"
#include "acl_cpp/ipc/ipc_server.hpp"
struct acl_pthread_pool_t;
namespace acl {
class ipc_client;
class ACL_CPP_API ipc_request
{
public:
ipc_request();
virtual ~ipc_request();
/**
* <EFBFBD><EFBFBD><EFBFBD>ӿڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񣬸ýӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD> IO <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ģʽ
*/
virtual void run(ipc_client* ipc);
#if defined(WIN32) || defined(WIN64)
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ӿڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>񣬸ýӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD> WIN32 <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ģʽ
*/
virtual void run(HWND hWnd);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> WIN32 <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
* @param hWnd {HWND} <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
*/
void set_hwnd(HWND hWnd)
{
hWnd_ = hWnd;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> WIN32 <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
* @return {HWND} <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
*/
HWND get_hwnd(void) const
{
return (hWnd_);
}
#endif
private:
#if defined(WIN32) || defined(WIN64)
2014-11-19 00:25:21 +08:00
HWND hWnd_;
#endif
};
class ACL_CPP_API ipc_service : public ipc_server
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param nthread {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ > 1 <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳߳أ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
* @param ipc_keep {bool} <EFBFBD>ڲ<EFBFBD> IPC <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>Ƿ񱣳ֳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>Ч<EFBFBD><EFBFBD>
*/
ipc_service(int nthread, bool ipc_keep = true);
virtual ~ipc_service();
#if defined(WIN32) || defined(WIN64)
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WIN32 <EFBFBD><EFBFBD>Ϣģʽʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʵ<EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ָýӿ<EFBFBD>
* @param hWnd {HWND} <EFBFBD><EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
* @param msg {UINT} <EFBFBD>û<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
* @param wParam {WPARAM} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param lParam {LPARAM} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
virtual void win32_proc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam);
#endif
/**
* <EFBFBD><EFBFBD> ipc <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {ipc_client*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ʾ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
ipc_client* peek_conn();
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ipc <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ӷŻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>
* @param conn {ipc_client*} ipc <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void push_conn(ipc_client* conn);
protected:
#if defined(WIN32) || defined(WIN64)
2014-11-19 00:25:21 +08:00
__int64 magic_;
#else
long long int magic_;
#endif
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param req {ipc_request*}
*/
void request(ipc_request* req);
private:
bool ipc_keep_;
acl_pthread_pool_t* thread_pool_;
#if defined(WIN32) || defined(WIN64)
2014-11-19 00:25:21 +08:00
HWND hWnd_;
HINSTANCE hInstance_;
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Windows <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ʽ<EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
*/
virtual bool create_window(void);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Windows <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ʽ<EFBFBD>£<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD>ھ<EFBFBD><EFBFBD><EFBFBD>
*/
virtual void close_window(void);
#endif
locker lock_;
std::list<ipc_client*> conn_pool_;
};
} // namespace acl