File: gsDebug.h

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (198 lines) | stat: -rw-r--r-- 7,069 bytes parent folder | download | duplicates (2)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef __GSIDEBUG_H__
#define __GSIDEBUG_H__
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//  Advanced debug logging for GameSpy SDKs
//
//  Usage:
//      1) #define GSI_COMMON_DEBUG to enable debug output
//      2) Set target output (file or console or custom func)
//		3) Use Debug macros to log output
//
//  Todo:
//      Allow user to specify IP to send debug output to (remote log for PS2)
//#include "nonport.h"
#include <stdarg.h>

#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
extern "C" {
#endif

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Input levels (text is reported at one of these levels)
typedef gsi_u8 GSIDebugLevel;
#define GSIDebugLevel_HotError   (GSIDebugLevel)(1<<0)   //  1 Unexpected Error
#define GSIDebugLevel_WarmError  (GSIDebugLevel)(1<<1)   //  2 Expected Error
#define GSIDebugLevel_Warning    (GSIDebugLevel)(1<<2)   //  4 Warnings and Errors
#define GSIDebugLevel_Notice     (GSIDebugLevel)(1<<3)   //  8 Usefull debug info
#define GSIDebugLevel_Comment    (GSIDebugLevel)(1<<4)   // 16 Debug spam
#define GSIDebugLevel_RawDump    (GSIDebugLevel)(1<<5)   // 32 e.g. MemoryBuffer
#define GSIDebugLevel_StackTrace (GSIDebugLevel)(1<<6)   // 64 Important function entries
// add new ones here (update string table in gsiDebug.c!)
#define GSIDebugLevel_Count      7   // 7 reporting levels

// Output levels (a mask for the levels you want to receive)
// (update string table in gsiDebug.c!)
#define GSIDebugLevel_None       (GSIDebugLevel)(0)    //    No output
#define GSIDebugLevel_Normal     (GSIDebugLevel)(0x07) //    Warnings and above
#define GSIDebugLevel_Debug      (GSIDebugLevel)(0x0F) //    Notice and above
#define GSIDebugLevel_Verbose    (GSIDebugLevel)(0x1F) //    Comment and above
#define GSIDebugLevel_Hardcore   (GSIDebugLevel)(0xFF) //    Recv all


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Output types
typedef enum 
{
	GSIDebugType_Network,  // Network activity
	GSIDebugType_File,     // File output
	GSIDebugType_Memory,   // Memory allocations
	GSIDebugType_State,    // State update
	GSIDebugType_Misc,     // None of the above
	// add new ones here (update string table in gsiDebug.c!)

	GSIDebugType_Count,
	GSIDebugType_All = GSIDebugType_Count
} GSIDebugType;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Debug categories (SDKs)
typedef enum
{
	GSIDebugCat_App,
	GSIDebugCat_GP,
	GSIDebugCat_Peer,
	GSIDebugCat_QR2,
	GSIDebugCat_SB,
	GSIDebugCat_Voice,
	GSIDebugCat_AD,
	GSIDebugCat_NatNeg,
	GSIDebugCat_HTTP,
	GSIDebugCat_CDKey,
	// Add new ones here (update string table in gsiDebug.c!)


	GSIDebugCat_Common, // Common should be last to prevent display weirdness
	                    // resulting from initialization order
	GSIDebugCat_Count,
	GSIDebugCat_All = GSIDebugCat_Count
} GSIDebugCategory;

extern char* gGSIDebugCatStrings[GSIDebugCat_Count];
extern char* gGSIDebugTypeStrings[GSIDebugType_Count];
extern char* gGSIDebugLevelStrings[GSIDebugLevel_Count];

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Only include static data and functions if GSI_COMMON_DEBUG is defined
#ifndef GSI_COMMON_DEBUG
	// not using GSI debug!  Define functions to <blank>
	// (put these here so VisualAssist will resolve the definitions below)
	#if !defined(_WIN32) && !defined(__MWERKS__)
		// WIN32 doesn't like "..." in a macro
		#define gsDebugFormat(c,t,l,f,...)
		#define gsDebugVaList(c,t,l,f,v)
		#define gsDebugBinary(c,t,l,b,n)
		#define gsSetDebugLevel(c,t,l)
		#define gsSetDebugFile(f)
		#define gsOpenDebugFile(f)
		#define gsGetDebugFile
		#define gsSetDebugCallback(c)
	#elif defined(_NITRO)
		#define gsDebugFormat(...)
		#define gsDebugVaList(c,t,l,f,v)
		#define gsDebugBinary(c,t,l,b,n)
		#define gsSetDebugLevel(c,t,l)
		#define gsSetDebugFile(f)
		#define gsOpenDebugFile(f)
		#define gsGetDebugFile
		#define gsSetDebugCallback(c)
	#else
		#define gsDebugFormat
		#define gsDebugVaList
		#define gsDebugBinary
		#define gsSetDebugLevel
		#define gsSetDebugFile
		#define gsOpenDebugFile
		#define gsGetDebugFile
		#define gsSetDebugCallback
	#endif
#else


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// User supplied debug function, will receive debug text
typedef void (*GSIDebugCallback)(GSIDebugCategory,GSIDebugType,GSIDebugLevel,
                                   const char*, va_list);


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Global debug instance
typedef struct GSIDebugInstance
{
#if !defined(_NITRO)
	FILE* mGSIDebugFile;
#endif
	GSIDebugCallback mDebugCallback;
	gsi_i32 mInitialized;

#if !defined(GSI_NO_THREADS)
	GSICriticalSection mDebugCrit;
#endif

	GSIDebugLevel mGSIDebugLevel[GSIDebugCat_Count][GSIDebugType_Count];
} GSIDebugInstance;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Logging functions
void gsDebugFormat(GSIDebugCategory theCat, GSIDebugType theType, 
             GSIDebugLevel theLevel, const char* theTokenStr, ...);  

void gsDebugVaList(GSIDebugCategory theCat, GSIDebugType theType, 
             GSIDebugLevel theLevel, const char* theTokenStr, 
			 va_list theParams);  

void gsDebugBinary(GSIDebugCategory theCat, GSIDebugType theType,
             GSIDebugLevel theLevel, const char* theBuffer, gsi_i32 theLength);


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Output functions
void  gsSetDebugLevel(GSIDebugCategory theCat, GSIDebugType theType, 
					  GSIDebugLevel theLevel);

#if !defined(_NITRO)

// Set the output file (NULL for no file)
void  gsSetDebugFile(FILE* theFile);

// Open and set the debug file
FILE* gsOpenDebugFile(const char* theFileName);

// Retrieve the debug file
FILE* gsGetDebugFile();

#endif

// Set a callback to be triggered with debug output
void  gsSetDebugCallback(GSIDebugCallback theCallback);


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#endif // GSI_COMMON_DEBUG

#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
}
#endif

#endif // __GSIDEBUG_H__