-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathipcpp.h
More file actions
71 lines (59 loc) · 1.27 KB
/
ipcpp.h
File metadata and controls
71 lines (59 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _DIPC_H_
#define _DIPC_H_
#include <vector>
#include <functional>
#include "ipc.h"
namespace dipc
{
class mutex
{
private:
volatile LONG interlock_;
public:
mutex();
~mutex();
private:
void lock();
void unlock();
friend class locker;
};
class locker
{
mutex& m_;
public:
locker(mutex& m);
~locker();
};
#ifdef _UNICODE
#define tstring wstring
#else
#define tstring string
#endif
class server {
struct router {
int cmd;
std::function<int(unsigned char*, int)> handler;
};
public:
server(const std::tstring& name = std::tstring(), int timeout = 1000);
~server();
void run();
void stop();
void route(int cmd, std::function<int(unsigned char*, int)> handler);
private:
bool stop_;
mutex mr_;
std::vector<router> routers_;
IpcServer* data_;
};
class client {
public:
client(const std::tstring& server_name = std::tstring(), int timeout = 1000);
~client();
std::string request(int cmd, const std::string& data = std::string());
private:
std::tstring server_name;
int timeout;
};
}
#endif