fixed make dist
[public/netxms.git] / src / agent / libnxtux / nxtux.cpp
CommitLineData
c7c6ce77
VK
1/*
2** NetXMS Tuxedo helper library
3** Copyright (C) 2014-2016 Raden Solutions
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nxtux.cpp
20**
21**/
22
23#include <nxtux.h>
24
25/**
26 * Connect count
27 */
28static int s_connectCount = 0;
29static MUTEX s_connectLock = MutexCreate();
30
31/**
32 * Connect to Tuxedo app
33 */
34bool LIBNXTUX_EXPORTABLE TuxedoConnect()
35{
36 bool success = true;
37 MutexLock(s_connectLock);
38 if (s_connectCount == 0)
39 {
40 if (tpinit(NULL) != -1)
41 {
42 s_connectCount++;
43 }
44 else
45 {
46 nxlog_debug(3, _T("tpinit() call failed (%hs)"), tpstrerrordetail(tperrno, 0));
47 success = false;
48 }
49 }
50 else
51 {
52 s_connectCount++;
53 }
54 MutexUnlock(s_connectLock);
55 return success;
56}
57
58/**
59 * Disconnect from Tuxedo app
60 */
61void LIBNXTUX_EXPORTABLE TuxedoDisconnect()
62{
63 MutexLock(s_connectLock);
64 if (s_connectCount > 0)
65 {
66 s_connectCount--;
67 if (s_connectCount == 0)
68 tpterm();
69 }
70 MutexUnlock(s_connectLock);
71}
72
73/**
74 * Helper function to get string field
75 */
76bool LIBNXTUX_EXPORTABLE CFgetString(FBFR32 *fb, FLDID32 fieldid, FLDOCC32 oc, char *buf, size_t size)
77{
78 FLDLEN32 len = (FLDLEN32)size;
79 if (CFget32(fb, fieldid, oc, buf, &len, FLD_STRING) == -1)
80 {
81 buf[0] = 0;
82 return false;
83 }
84 return true;
85}
86
87#ifdef _WIN32
88
89/**
90 * DLL entry point
91 */
92BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
93{
94 if (dwReason == DLL_PROCESS_ATTACH)
95 DisableThreadLibraryCalls(hInstance);
96 return TRUE;
97}
98
99#endif