implemented single housekeeping thread for all message wait queues
[public/netxms.git] / src / client / libnxclient / main.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Client Library
4 ** Copyright (C) 2003-2014 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 by
8 ** 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: main.cpp
21 **
22 **/
23
24 #include "libnxclient.h"
25
26 /**
27 * Debug callback
28 */
29 static NXC_DEBUG_CALLBACK s_debugCallback = NULL;
30
31 /**
32 * Print debug messages
33 */
34 void DebugPrintf(const TCHAR *format, ...)
35 {
36 if (s_debugCallback == NULL)
37 return;
38
39 va_list args;
40 TCHAR buffer[4096];
41
42 va_start(args, format);
43 _vsntprintf(buffer, 4096, format, args);
44 va_end(args);
45 s_debugCallback(buffer);
46 }
47
48 /**
49 * Debug callback for crypto lib
50 */
51 static void CryptoLibDebugCallback(int level, const TCHAR *format, va_list args)
52 {
53 if (s_debugCallback == NULL)
54 return;
55
56 TCHAR buffer[4096];
57 _vsntprintf(buffer, 4096, format, args);
58 s_debugCallback(buffer);
59 }
60
61 /**
62 * Initialization function
63 */
64 bool LIBNXCLIENT_EXPORTABLE NXCInitialize()
65 {
66 return InitCryptoLib(0xFFFF, CryptoLibDebugCallback);
67 }
68
69 /**
70 * Shutdown function
71 */
72 void LIBNXCLIENT_EXPORTABLE NXCShutdown()
73 {
74 MsgWaitQueue::shutdown();
75 }
76
77 /**
78 * Get library version
79 */
80 UINT32 LIBNXCLIENT_EXPORTABLE NXCGetVersion()
81 {
82 return (NETXMS_VERSION_MAJOR << 24) | (NETXMS_VERSION_MINOR << 16) | NETXMS_VERSION_BUILD;
83 }
84
85 /**
86 * Set callback for debug messages
87 */
88 void LIBNXCLIENT_EXPORTABLE NXCSetDebugCallback(NXC_DEBUG_CALLBACK cb)
89 {
90 s_debugCallback = cb;
91 }
92
93 /**
94 * Get text for error
95 */
96 const TCHAR LIBNXCLIENT_EXPORTABLE *NXCGetErrorText(UINT32 error)
97 {
98 static const TCHAR *errorText[] =
99 {
100 _T("Request completed successfully"),
101 _T("Component locked"),
102 _T("Access denied"),
103 _T("Invalid request"),
104 _T("Request timed out"),
105 _T("Request is out of state"),
106 _T("Database failure"),
107 _T("Invalid object ID"),
108 _T("Object already exist"),
109 _T("Communication failure"),
110 _T("System failure"),
111 _T("Invalid user ID"),
112 _T("Invalid argument"),
113 _T("Duplicate DCI"),
114 _T("Invalid DCI ID"),
115 _T("Out of memory"),
116 _T("Input/Output error"),
117 _T("Incompatible operation"),
118 _T("Object creation failed"),
119 _T("Loop in object relationship detected"),
120 _T("Invalid object name"),
121 _T("Invalid alarm ID"),
122 _T("Invalid action ID"),
123 _T("Operation in progress"),
124 _T("Copy operation failed for one or more DCI(s)"),
125 _T("Invalid or unknown event code"),
126 _T("No interfaces suitable for sending magic packet"),
127 _T("No MAC address on interface"),
128 _T("Command not implemented"),
129 _T("Invalid trap configuration record ID"),
130 _T("Requested data collection item is not supported by agent"),
131 _T("Client and server versions mismatch"),
132 _T("Error parsing package information file"),
133 _T("Package with specified properties already installed on server"),
134 _T("Package file already exist on server"),
135 _T("Server resource busy"),
136 _T("Invalid package ID"),
137 _T("Invalid IP address"),
138 _T("Action is used in event processing policy"),
139 _T("Variable not found"),
140 _T("Server uses incompatible version of communication protocol"),
141 _T("Address already in use"),
142 _T("Unable to select cipher"),
143 _T("Invalid public key"),
144 _T("Invalid session key"),
145 _T("Encryption is not supported by peer"),
146 _T("Server internal error"),
147 _T("Execution of external command failed"),
148 _T("Invalid object tool ID"),
149 _T("SNMP protocol error"),
150 _T("Incorrect regular expression"),
151 _T("Parameter is not supported by agent"),
152 _T("File I/O operation failed"),
153 _T("MIB file is corrupted"),
154 _T("File transfer operation already in progress"),
155 _T("Invalid job ID"),
156 _T("Invalid script ID"),
157 _T("Invalid script name"),
158 _T("Unknown map name"),
159 _T("Invalid map ID"),
160 _T("Account disabled"),
161 _T("No more grace logins"),
162 _T("Server connection broken"),
163 _T("Invalid agent configuration ID"),
164 _T("Server has lost connection with backend database"),
165 _T("Alarm is still open in helpdesk system"),
166 _T("Alarm is not in \"outstanding\" state"),
167 _T("DCI data source is not a push agent"),
168 _T("Error parsing configuration import file"),
169 _T("Configuration cannot be imported because of validation errors"),
170 _T("Invalid graph ID"),
171 _T("Local cryptographic provider failure"),
172 _T("Unsupported authentication type"),
173 _T("Bad certificate"),
174 _T("Invalid certificate ID"),
175 _T("SNMP failure"),
176 _T("Node has no support for layer 2 topology discovery"),
177 _T("Invalid situation ID"),
178 _T("Named instance not found"),
179 _T("Invalid event ID"),
180 _T("Operation cannot be completed due to agent error"),
181 _T("Unknown variable"),
182 _T("Requested resource not available"),
183 _T("Job cannot be cancelled"),
184 _T("Invalid policy ID"),
185 _T("Unknown log name"),
186 _T("Invalid log handle"),
187 _T("New password is too weak"),
188 _T("Password was used before"),
189 _T("Invalid session handle"),
190 _T("Node already is a member of a cluster"),
191 _T("Job cannot be hold"),
192 _T("Job cannot be unhold"),
193 _T("Zone ID is already in use"),
194 _T("Invalid zone ID"),
195 _T("Cannot delete non-empty zone object"),
196 _T("No physical component data"),
197 _T("Invalid alarm note ID"),
198 _T("Encryption error"),
199 _T("Invalid mapping table ID"),
200 _T("No software package data"),
201 _T("Invalid DCI summary table ID"),
202 _T("User is logged in"),
203 _T("Error parsing XML"),
204 _T("SQL query cost is too high"),
205 _T("License violation"),
206 _T("Number of client licenses exceeded"),
207 _T("Object already exist"),
208 _T("No helpdesk link"),
209 _T("Helpdesk link communication failure"),
210 _T("Helpdesk link access denied"),
211 _T("Helpdesk link internal error"),
212 _T("LDAP connection error"),
213 _T("Routing table unavailable"),
214 _T("Switch forwarding database unavailable"),
215 _T("Location history not available"),
216 _T("Object is in use and cannot be deleted"),
217 _T("Script compilation error"),
218 _T("Script execution error")
219 };
220 return (error <= RCC_NXSL_EXECUTION_ERROR) ? errorText[error] : _T("No text message for this error");
221 }
222
223 #if defined(_WIN32) && !defined(UNDER_CE)
224
225 /**
226 * DLL entry point
227 */
228 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
229 {
230 if (dwReason == DLL_PROCESS_ATTACH)
231 DisableThreadLibraryCalls(hInstance);
232 return TRUE;
233 }
234
235 #endif /* _WIN32 */