NamedPipe class splitted into NAmedPipe and NamedPipeListener; nxapush switched to...
[public/netxms.git] / include / nxproc.h
1 #ifndef _nxproc_h_
2 #define _nxproc_h_
3
4 #include <nms_common.h>
5
6 /**
7 * Max pipe name length
8 */
9 #define MAX_PIPE_NAME_LEN 128
10
11 /**
12 * Named pipe class
13 */
14 class LIBNETXMS_EXPORTABLE NamedPipe
15 {
16 friend class NamedPipeListener;
17
18 private:
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
25 public:
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 };
35
36 /**
37 * Client request handler
38 */
39 typedef void (*NamedPipeRequestHandler)(NamedPipe *pipe, void *userArg);
40
41 /**
42 * Named pipe listener (server)
43 */
44 class LIBNETXMS_EXPORTABLE NamedPipeListener
45 {
46 private:
47 TCHAR m_name[MAX_PIPE_NAME_LEN];
48 HPIPE m_handle;
49 NamedPipeRequestHandler m_reqHandler;
50 void *m_userArg;
51 THREAD m_serverThread;
52 bool m_stop;
53
54 void serverThread();
55 static THREAD_RESULT THREAD_CALL serverThreadStarter(void *arg);
56
57 NamedPipeListener(const TCHAR *name, HPIPE handle, NamedPipeRequestHandler reqHandler, void *userArg);
58
59 public:
60 ~NamedPipeListener();
61
62 const TCHAR *name() const { return m_name; }
63
64 void start();
65 void stop();
66
67 static NamedPipeListener *create(const TCHAR *name, NamedPipeRequestHandler reqHandler, void *userArg);
68 };
69
70 #endif /* _nxproc_h_ */