f2ea049ae114481cfa4afb1a0c98a7ed19f34411
[public/netxms.git] / src / libnetxms / nxproc.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** NetXMS Foundation Library
4 ** Copyright (C) 2003-2017 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published
8 ** by the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: nxproc.cpp
21 **
22 **/
23
24 #include "libnetxms.h"
25 #include <nxproc.h>
26
27 /**
28 * Start named pipe server
29 */
30 void NamedPipe::startServer()
31 {
32 if (m_serverThread != INVALID_THREAD_HANDLE)
33 return; // already started
34
35 m_stop = false;
36 m_serverThread = ThreadCreateEx(NamedPipe::serverThreadStarter, 0, this);
37 }
38
39 /**
40 * Stop named pipe server
41 */
42 void NamedPipe::stopServer()
43 {
44 m_stop = true;
45 ThreadJoin(m_serverThread);
46 m_serverThread = INVALID_THREAD_HANDLE;
47 }
48
49 /**
50 * Named pipe server thread starter
51 */
52 THREAD_RESULT THREAD_CALL NamedPipe::serverThreadStarter(void *arg)
53 {
54 static_cast<NamedPipe*>(arg)->serverThread();
55 return THREAD_OK;
56 }