change log updated
[public/netxms.git] / include / nxproc.h
... / ...
CommitLineData
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 */
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 TCHAR m_user[64];
23
24 NamedPipe(const TCHAR *name, HPIPE handle, const TCHAR *user);
25
26public:
27 ~NamedPipe();
28
29 const TCHAR *name() const { return m_name; }
30 HPIPE handle() { return m_handle; }
31 const TCHAR *user();
32
33 bool write(const void *data, size_t size);
34
35 static NamedPipe *connect(const TCHAR *name, UINT32 timeout = 1000);
36};
37
38/**
39 * Client request handler
40 */
41typedef void (*NamedPipeRequestHandler)(NamedPipe *pipe, void *userArg);
42
43/**
44 * Named pipe listener (server)
45 */
46class LIBNETXMS_EXPORTABLE NamedPipeListener
47{
48private:
49 TCHAR m_name[MAX_PIPE_NAME_LEN];
50 HPIPE m_handle;
51 NamedPipeRequestHandler m_reqHandler;
52 void *m_userArg;
53 THREAD m_serverThread;
54 bool m_stop;
55 TCHAR m_user[64];
56
57 void serverThread();
58 static THREAD_RESULT THREAD_CALL serverThreadStarter(void *arg);
59
60 NamedPipeListener(const TCHAR *name, HPIPE handle, NamedPipeRequestHandler reqHandler, void *userArg, const TCHAR *user);
61
62public:
63 ~NamedPipeListener();
64
65 const TCHAR *name() const { return m_name; }
66
67 void start();
68 void stop();
69
70 static NamedPipeListener *create(const TCHAR *name, NamedPipeRequestHandler reqHandler, void *userArg, const TCHAR *user = NULL);
71};
72
73#endif /* _nxproc_h_ */