NamedPipe class splitted into NAmedPipe and NamedPipeListener; nxapush switched to...
[public/netxms.git] / include / nxproc.h
CommitLineData
05f298fe
VK
1#ifndef _nxproc_h_
2#define _nxproc_h_
3
4#include <nms_common.h>
5
6/**
7 * Max pipe name length
8 */
b6883988 9#define MAX_PIPE_NAME_LEN 128
05f298fe 10
b6883988
VK
11/**
12 * Named pipe class
13 */
14class LIBNETXMS_EXPORTABLE NamedPipe
15{
16 friend class NamedPipeListener;
17
18private:
19 TCHAR m_name[MAX_PIPE_NAME_LEN];
20 HPIPE m_handle;
21 MUTEX m_writeLock;
22
23 NamedPipe(const TCHAR *name, HPIPE handle);
24
25public:
26 ~NamedPipe();
27
28 const TCHAR *name() const { return m_name; }
29 HPIPE handle() { return m_handle; }
30
31 bool write(const void *data, size_t size);
32
33 static NamedPipe *connect(const TCHAR *name, UINT32 timeout = 1000);
34};
05f298fe
VK
35
36/**
37 * Client request handler
38 */
39typedef void (*NamedPipeRequestHandler)(NamedPipe *pipe, void *userArg);
40
41/**
b6883988 42 * Named pipe listener (server)
05f298fe 43 */
b6883988 44class LIBNETXMS_EXPORTABLE NamedPipeListener
05f298fe
VK
45{
46private:
47 TCHAR m_name[MAX_PIPE_NAME_LEN];
48 HPIPE m_handle;
05f298fe
VK
49 NamedPipeRequestHandler m_reqHandler;
50 void *m_userArg;
51 THREAD m_serverThread;
52 bool m_stop;
53
05f298fe
VK
54 void serverThread();
55 static THREAD_RESULT THREAD_CALL serverThreadStarter(void *arg);
56
b6883988
VK
57 NamedPipeListener(const TCHAR *name, HPIPE handle, NamedPipeRequestHandler reqHandler, void *userArg);
58
05f298fe 59public:
b6883988 60 ~NamedPipeListener();
05f298fe
VK
61
62 const TCHAR *name() const { return m_name; }
05f298fe 63
b6883988
VK
64 void start();
65 void stop();
05f298fe 66
b6883988 67 static NamedPipeListener *create(const TCHAR *name, NamedPipeRequestHandler reqHandler, void *userArg);
05f298fe
VK
68};
69
70#endif /* _nxproc_h_ */