c643fed8474b7bd45471868c5e99a4f7825b716a
[public/netxms.git] / src / db / libnxdb / main.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Server Library
4 ** Copyright (C) 2003, 2004, 2005, 2006, 2007 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 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 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 "libnxdb.h"
25
26
27 //
28 // Static data
29 //
30
31 static void (*s_dbgPrintCb)(int, const TCHAR *, va_list) = NULL;
32
33
34 //
35 // Write log
36 //
37
38 void __DBWriteLog(WORD level, const TCHAR *format, ...)
39 {
40 TCHAR buffer[4096];
41 va_list args;
42
43 va_start(args, format);
44 _vsntprintf(buffer, 4096, format, args);
45 va_end(args);
46 nxlog_write(g_logMsgCode, level, "s", buffer);
47 }
48
49
50 //
51 // Debug output
52 //
53
54 void __DBDbgPrintf(int level, const TCHAR *format, ...)
55 {
56 if (s_dbgPrintCb != NULL)
57 {
58 va_list args;
59
60 va_start(args, format);
61 s_dbgPrintCb(level, format, args);
62 va_end(args);
63 }
64 }
65
66
67 //
68 // Set debug print callback
69 //
70
71 void LIBNXDB_EXPORTABLE DBSetDebugPrintCallback(void (*cb)(int, const TCHAR *, va_list))
72 {
73 s_dbgPrintCb = cb;
74 }
75
76
77 //
78 // DLL entry point
79 //
80
81 #ifdef _WIN32
82
83 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
84 {
85 if (dwReason == DLL_PROCESS_ATTACH)
86 DisableThreadLibraryCalls(hInstance);
87 return TRUE;
88 }
89
90 #endif /* _WIN32 */