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

129 lines
2.9 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include "../stdlib/locker.hpp"
#include "../stdlib/noncopyable.hpp"
2017-06-02 14:47:24 +08:00
#include "ipc_server.hpp"
2014-11-19 00:25:21 +08:00
struct acl_pthread_pool_t;
namespace acl {
class ipc_client;
class ACL_CPP_API ipc_request : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
ipc_request();
virtual ~ipc_request();
/**
*
* IO
2014-11-19 00:25:21 +08:00
*/
virtual void run(ipc_client* ipc);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
*
* _WIN32
2014-11-19 00:25:21 +08:00
*/
virtual void run(HWND hWnd);
/**
* _WIN32
* @param hWnd {HWND}
2014-11-19 00:25:21 +08:00
*/
void set_hwnd(HWND hWnd)
{
hWnd_ = hWnd;
}
/**
* _WIN32
* @return {HWND}
2014-11-19 00:25:21 +08:00
*/
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:
/**
*
* @param nthread {int} > 1 线
* 线
* @param ipc_keep {bool} IPC
*
2014-11-19 00:25:21 +08:00
*/
ipc_service(int nthread, bool ipc_keep = true);
virtual ~ipc_service();
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
* _WIN32
*
* @param hWnd {HWND}
* @param msg {UINT}
* @param wParam {WPARAM}
* @param lParam {LPARAM}
2014-11-19 00:25:21 +08:00
*/
virtual void win32_proc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam);
#endif
/**
* ipc
* @return {ipc_client*} NULL
2014-11-19 00:25:21 +08:00
*/
ipc_client* peek_conn();
/**
* ipc
* @param conn {ipc_client*} ipc
2014-11-19 00:25:21 +08:00
*/
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
/**
*
2014-11-19 00:25:21 +08:00
* @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_;
/**
* Windows
2014-11-19 00:25:21 +08:00
*/
virtual bool create_window(void);
/**
* Windows
2014-11-19 00:25:21 +08:00
*/
virtual void close_window(void);
#endif
locker lock_;
std::list<ipc_client*> conn_pool_;
};
} // namespace acl