reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ResipAssert.h
Go to the documentation of this file.
1
2
#ifndef __ASSERTION_H
3
#define __ASSERTION_H
4
29
#include <assert.h>
30
31
#ifdef HAVE_CONFIG_H
32
#include "config.h"
33
#endif
34
35
// Uncomment or define on the compiler command line to have
36
// assertion failures logged to the Windows event logger
37
//#define LOG_EVENT_AND_ASSERT
38
39
#if defined(WIN32) && defined(LOG_EVENT_AND_ASSERT)
40
41
#ifndef WIN32_LEAN_AND_MEAN
42
#define WIN32_LEAN_AND_MEAN
43
#endif
44
#include <windows.h>
45
#include <Winreg.h>
46
#include <winnt.h>
47
#include <tchar.h>
48
#include <crtdbg.h>
49
50
#define SysLogAssertEvent(x) \
51
{ \
52
HKEY key; \
53
long errorCode = \
54
RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services\\EventLog\\Application\\reSIProcate"), \
55
0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &key, NULL); \
56
if (ERROR_SUCCESS == errorCode) \
57
{ \
58
HANDLE eventLogHandle; \
59
RegCloseKey(key); \
60
eventLogHandle = RegisterEventSource(NULL, _T("reSIProcate")); \
61
if (eventLogHandle != NULL) \
62
{ \
63
TCHAR appPath[MAX_PATH]; \
64
TCHAR moduleInfo[1024]; \
65
TCHAR fileInfo[1024]; \
66
TCHAR lineInfo[1024]; \
67
TCHAR assertInfo[1024]; \
68
const TCHAR* lines[4] = { moduleInfo, fileInfo, lineInfo, assertInfo }; \
69
GetModuleFileName(0, appPath, MAX_PATH); \
70
_sntprintf_s(moduleInfo, 1024, _TRUNCATE, _T("\r\nModule : %s"), appPath); \
71
_sntprintf_s(fileInfo, 1024, _TRUNCATE, _T("\r\nFile : %s"), _T(__FILE__)); \
72
_sntprintf_s(lineInfo, 1024, _TRUNCATE, _T("\r\nLine : %d"), __LINE__); \
73
_sntprintf_s(assertInfo, 1024, _TRUNCATE, _T("\r\nAssert: %s"), _T(#x)); \
74
ReportEvent(eventLogHandle, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 4, 0, lines, NULL); \
75
DeregisterEventSource(eventLogHandle); \
76
} \
77
} \
78
}
79
80
#define resip_assert(x) \
81
{ \
82
if ( !(x) ) \
83
{ \
84
SysLogAssertEvent( (x) ); \
85
} \
86
{ \
87
assert( (x) ); \
88
} \
89
}
90
91
#else
92
93
#ifdef RESIP_ASSERT_SYSLOG
94
#include <syslog.h>
95
#define RESIP_ASSERT_SYSLOG_PRIORITY (LOG_DAEMON | LOG_CRIT)
96
#define resip_assert(x) \
97
{ \
98
if ( !(x) ) \
99
{ \
100
syslog( RESIP_ASSERT_SYSLOG_PRIORITY, "assertion failed: %s:%d: %s", __FILE__, __LINE__, #x ); \
101
} \
102
{ \
103
assert( (x) ); \
104
} \
105
}
106
#else
107
#define resip_assert(x) assert(x)
108
#endif
109
110
#endif
// defined(WIN32) && defined(LOG_EVENT_AND_ASSERT)
111
112
/* Need to use resip_assert_not_null() due to the compiler warning
113
*
114
* warning: the compiler can assume that the
115
* address of 'rhs' will never be NULL [-Waddress]
116
*
117
* Tried to suppress the warning with _Pragma("GCC diagnostic ignored...")
118
* but that didn't make the warning go away.
119
*
120
* Therefore, using the cast to void* to suppress that warning.
121
*/
122
123
#define resip_assert_not_null(x) \
124
{ \
125
resip_assert(((void*)(x)) != 0); \
126
}
127
128
#endif
// __ASSERTION_H
129
130
/* ====================================================================
131
*
132
* Copyright (c) 2014 Daniel Pocock All rights reserved.
133
*
134
* Redistribution and use in source and binary forms, with or without
135
* modification, are permitted provided that the following conditions
136
* are met:
137
*
138
* 1. Redistributions of source code must retain the above copyright
139
* notice, this list of conditions and the following disclaimer.
140
*
141
* 2. Redistributions in binary form must reproduce the above copyright
142
* notice, this list of conditions and the following disclaimer in
143
* the documentation and/or other materials provided with the
144
* distribution.
145
*
146
* 3. Neither the name of the author(s) nor the names of any contributors
147
* may be used to endorse or promote products derived from this software
148
* without specific prior written permission.
149
*
150
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
151
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
153
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
154
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
155
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
156
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
157
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
158
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
159
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
160
* SUCH DAMAGE.
161
*
162
* ====================================================================
163
*
164
*
165
*/
166
rutil
ResipAssert.h
Generated by
1.9.8