summaryrefslogtreecommitdiff
path: root/TAO/tao/debug.h
blob: 83b4e55c726612aaa3139333a4209f79e6ffd377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// This may look like C, but it's really -*- C++ -*-

// ============================================================================
//
// = LIBRARY
//    TAO
// 
// = FILENAME
//    debug.h
//
// = DESCRIPTION
//     debug/trace support.
//
// = AUTHOR
//     Copyright 1994-1995 by Sun Microsystems Inc.
// 
// ============================================================================

#if !defined (TAO_DEBUG_H)
#define	TAO_DEBUG_H

// These are global to simplify is use by other code, very much in
// particular by getopt and related argument-parsing code
//
// THREADING NOTE: don't set them except in an unthreaded environment
// such as process initialization.  They're treated as immutable.

// 0 to ??; higher == more
extern u_int TAO_Export TAO_debug_level;	

// set by getopt
extern char * TAO_Export TAO_debug_filter;

// These are just simple 0, 1, and 2 argument messages that will
// appear when debugging's enabled, regardless of category.  They also
// just compile out painlessly.

#if defined (DEBUG)
#include <stdio.h>
#include <errno.h>
#include <string.h>

// 1, 2, 3 argument messages -- generic
#define dmsg(s)		{ if (TAO_debug_level) dmsg_v (s); }
#define dmsg1(s,a1)	{ if (TAO_debug_level) dmsg_v (s, a1); }
#define dmsg2(s,a1,a2)	{ if (TAO_debug_level) dmsg_v (s, a1, a2); }

// dump CORBA_Exception, if any, with id tag
#define dexc(env,s)	{ if (TAO_debug_level && env.exception ()) \
				_dmsg_x (env, s); }

// dump POSIX error indication, if any, with ID tag
#define dperror(str)	{ if (TAO_debug_level) dmsg_v ("%s: %s", \
				str, strerror (errno)); }

// dump socket error indication, if any, with ID tag
#if defined (_WINSOCKAPI_)
#define	dsockerr(s)	{ if (TAO_debug_level) dmsg_v ("%s:  winsock error %d", \
				s, WSAGetLastError()); }
#else
#define	dsockerr(s)	dperror(s)
#endif /* _WINSOCKAPI_ */

#else	/* !DEBUG */
#define dmsg(s)		{ }
#define dmsg1(s,a1)	{ }
#define dmsg2(s,a1,a2)	{ }

#define dexc(env, s)	{ }
#define	dperror(s)	{ }
#define	dsockerr(s)	{ }
#endif	/* DEBUG */

// These don't compile out; you must #ifdef them.  This is done
// intentionally since CPP macros have severe limits, and varargs _(or
// lack thereof) is one of them.

#if defined (DEBUG)

// This is like an fprintf statement except the filter is a set of
// characters (string).  If TAO_debug_level is nonzero and any
// characters in that string are in the "TAO_debug_filter" string, the
// message is then printed.  Assign thosee characters as needed.

extern void TAO_Export dmsg_filter (const char *_FAR filter,
                                        const char *_FAR fmt, ...);

// Filter according to TAO_debug_level instead of category.  (For
// speed, test against TAO_debug_level directly.)

extern void TAO_Export dmsg_filter (u_int level, 
                                        const char *_FAR fmt, ...);

// General varargs debug message printer, no filtering

extern void TAO_Export dmsg_v (const char *_FAR fmt, ...);
extern void TAO_Export _dmsg_x (CORBA_Environment _FAR &env,
                                    const char *_FAR info);
extern void TAO_Export dmsg_opaque (char *_FAR label,
                                        u_char *_FAR buffer,
                                        u_long len);
extern void TAO_Export dmsg_opaque_full (char *_FAR label,
                                             const u_char *_FAR buffer,
                                             u_long len);
#endif /* DEBUG */

#endif /* TAO_DEBUG_H */