Server core implemented as DLL/shared library
[public/netxms.git] / src / server / core / debug.cpp
1 /*
2 ** Project X - Network Management System
3 ** Copyright (C) 2003 Victor Kirhenshtein
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 ** $module: debug.cpp
20 **
21 **/
22
23 #include "nxcore.h"
24
25
26 //
27 // Test mutex state and print to stdout
28 //
29
30 void DbgTestMutex(MUTEX hMutex, TCHAR *szName)
31 {
32 _tprintf(_T(" %s: "), szName);
33 if (MutexLock(hMutex, 100))
34 {
35 _tprintf(_T("unlocked\n"));
36 MutexUnlock(hMutex);
37 }
38 else
39 {
40 _tprintf(_T("locked\n"));
41 }
42 }
43
44
45 //
46 // Test read/write lock state and print to stdout
47 //
48
49 void DbgTestRWLock(RWLOCK hLock, TCHAR *szName)
50 {
51 _tprintf(_T(" %s: "), szName);
52 if (RWLockWriteLock(hLock, 100))
53 {
54 _tprintf(_T("unlocked\n"));
55 RWLockUnlock(hLock);
56 }
57 else
58 {
59 if (RWLockReadLock(hLock, 100))
60 {
61 _tprintf(_T("locked for reading\n"));
62 RWLockUnlock(hLock);
63 }
64 else
65 {
66 _tprintf(_T("locked for writing\n"));
67 }
68 }
69 }
70
71
72 //
73 // Debug printf - write text to stdout if in standalone mode
74 // and specific application flag(s) is set
75 //
76
77 void DbgPrintf(DWORD dwFlags, TCHAR *szFormat, ...)
78 {
79 va_list args;
80 TCHAR szBuffer[1024];
81
82 if (!(g_dwFlags & dwFlags))
83 return; // Required application flag(s) not set
84
85 va_start(args, szFormat);
86 _vsntprintf(szBuffer, 1024, szFormat, args);
87 va_end(args);
88 WriteLog(MSG_DEBUG, EVENTLOG_INFORMATION_TYPE, _T("s"), szBuffer);
89 }