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