OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gsDebug.h
1#ifndef __GSIDEBUG_H__
2#define __GSIDEBUG_H__
5// Advanced debug logging for GameSpy SDKs
6//
7// Usage:
8// 1) #define GSI_COMMON_DEBUG to enable debug output
9// 2) Set target output (file or console or custom func)
10// 3) Use Debug macros to log output
11//
12// Todo:
13// Allow user to specify IP to send debug output to (remote log for PS2)
14//#include "nonport.h"
15#include <stdarg.h>
16
17#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
18extern "C" {
19#endif
20
23// Input levels (text is reported at one of these levels)
24typedef gsi_u8 GSIDebugLevel;
25#define GSIDebugLevel_HotError (GSIDebugLevel)(1<<0) // 1 Unexpected Error
26#define GSIDebugLevel_WarmError (GSIDebugLevel)(1<<1) // 2 Expected Error
27#define GSIDebugLevel_Warning (GSIDebugLevel)(1<<2) // 4 Warnings and Errors
28#define GSIDebugLevel_Notice (GSIDebugLevel)(1<<3) // 8 Usefull debug info
29#define GSIDebugLevel_Comment (GSIDebugLevel)(1<<4) // 16 Debug spam
30#define GSIDebugLevel_RawDump (GSIDebugLevel)(1<<5) // 32 e.g. MemoryBuffer
31#define GSIDebugLevel_StackTrace (GSIDebugLevel)(1<<6) // 64 Important function entries
32// add new ones here (update string table in gsiDebug.c!)
33#define GSIDebugLevel_Count 7 // 7 reporting levels
34
35// Output levels (a mask for the levels you want to receive)
36// (update string table in gsiDebug.c!)
37#define GSIDebugLevel_None (GSIDebugLevel)(0) // No output
38#define GSIDebugLevel_Normal (GSIDebugLevel)(0x07) // Warnings and above
39#define GSIDebugLevel_Debug (GSIDebugLevel)(0x0F) // Notice and above
40#define GSIDebugLevel_Verbose (GSIDebugLevel)(0x1F) // Comment and above
41#define GSIDebugLevel_Hardcore (GSIDebugLevel)(0xFF) // Recv all
42
43
46// Output types
47typedef enum
48{
49 GSIDebugType_Network, // Network activity
50 GSIDebugType_File, // File output
51 GSIDebugType_Memory, // Memory allocations
52 GSIDebugType_State, // State update
53 GSIDebugType_Misc, // None of the above
54 // add new ones here (update string table in gsiDebug.c!)
55
56 GSIDebugType_Count,
57 GSIDebugType_All = GSIDebugType_Count
58} GSIDebugType;
59
60
63// Debug categories (SDKs)
64typedef enum
65{
66 GSIDebugCat_App,
67 GSIDebugCat_GP,
68 GSIDebugCat_Peer,
69 GSIDebugCat_QR2,
70 GSIDebugCat_SB,
71 GSIDebugCat_Voice,
72 GSIDebugCat_AD,
73 GSIDebugCat_NatNeg,
74 GSIDebugCat_HTTP,
75 GSIDebugCat_CDKey,
76 // Add new ones here (update string table in gsiDebug.c!)
77
78
79 GSIDebugCat_Common, // Common should be last to prevent display weirdness
80 // resulting from initialization order
81 GSIDebugCat_Count,
82 GSIDebugCat_All = GSIDebugCat_Count
83} GSIDebugCategory;
84
85extern char* gGSIDebugCatStrings[GSIDebugCat_Count];
86extern char* gGSIDebugTypeStrings[GSIDebugType_Count];
87extern char* gGSIDebugLevelStrings[GSIDebugLevel_Count];
88
91// Only include static data and functions if GSI_COMMON_DEBUG is defined
92#ifndef GSI_COMMON_DEBUG
93 // not using GSI debug! Define functions to <blank>
94 // (put these here so VisualAssist will resolve the definitions below)
95 #if !defined(_WIN32) && !defined(__MWERKS__)
96 // WIN32 doesn't like "..." in a macro
97 #define gsDebugFormat(c,t,l,f,...)
98 #define gsDebugVaList(c,t,l,f,v)
99 #define gsDebugBinary(c,t,l,b,n)
100 #define gsSetDebugLevel(c,t,l)
101 #define gsSetDebugFile(f)
102 #define gsOpenDebugFile(f)
103 #define gsGetDebugFile
104 #define gsSetDebugCallback(c)
105 #elif defined(_NITRO)
106 #define gsDebugFormat(...)
107 #define gsDebugVaList(c,t,l,f,v)
108 #define gsDebugBinary(c,t,l,b,n)
109 #define gsSetDebugLevel(c,t,l)
110 #define gsSetDebugFile(f)
111 #define gsOpenDebugFile(f)
112 #define gsGetDebugFile
113 #define gsSetDebugCallback(c)
114 #else
115 #define gsDebugFormat
116 #define gsDebugVaList
117 #define gsDebugBinary
118 #define gsSetDebugLevel
119 #define gsSetDebugFile
120 #define gsOpenDebugFile
121 #define gsGetDebugFile
122 #define gsSetDebugCallback
123 #endif
124#else
125
126
129// User supplied debug function, will receive debug text
130typedef void (*GSIDebugCallback)(GSIDebugCategory,GSIDebugType,GSIDebugLevel,
131 const char*, va_list);
132
133
136// Global debug instance
137typedef struct GSIDebugInstance
138{
139#if !defined(_NITRO)
140 FILE* mGSIDebugFile;
141#endif
142 GSIDebugCallback mDebugCallback;
143 gsi_i32 mInitialized;
144
145#if !defined(GSI_NO_THREADS)
146 GSICriticalSection mDebugCrit;
147#endif
148
149 GSIDebugLevel mGSIDebugLevel[GSIDebugCat_Count][GSIDebugType_Count];
150} GSIDebugInstance;
151
152
155// Logging functions
156void gsDebugFormat(GSIDebugCategory theCat, GSIDebugType theType,
157 GSIDebugLevel theLevel, const char* theTokenStr, ...);
158
159void gsDebugVaList(GSIDebugCategory theCat, GSIDebugType theType,
160 GSIDebugLevel theLevel, const char* theTokenStr,
161 va_list theParams);
162
163void gsDebugBinary(GSIDebugCategory theCat, GSIDebugType theType,
164 GSIDebugLevel theLevel, const char* theBuffer, gsi_i32 theLength);
165
166
169// Output functions
170void gsSetDebugLevel(GSIDebugCategory theCat, GSIDebugType theType,
171 GSIDebugLevel theLevel);
172
173#if !defined(_NITRO)
174
175// Set the output file (NULL for no file)
176void gsSetDebugFile(FILE* theFile);
177
178// Open and set the debug file
179FILE* gsOpenDebugFile(const char* theFileName);
180
181// Retrieve the debug file
182FILE* gsGetDebugFile();
183
184#endif
185
186// Set a callback to be triggered with debug output
187void gsSetDebugCallback(GSIDebugCallback theCallback);
188
189
192#endif // GSI_COMMON_DEBUG
193
194#if defined(__LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
195}
196#endif
197
198#endif // __GSIDEBUG_H__