| 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 |
#ifndef _VJDebug_h_ |
|---|
| 36 |
#define _VJDebug_h_ |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
#include <vjConfig.h> |
|---|
| 41 |
#include <stdlib.h> |
|---|
| 42 |
|
|---|
| 43 |
#include <Sync/vjMutex.h> |
|---|
| 44 |
#include <Sync/vjGuard.h> |
|---|
| 45 |
#include <Kernel/vjStreamLock.h> |
|---|
| 46 |
#include <Utils/vjSingleton.h> |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
#define vjDBG_BASE 0 |
|---|
| 50 |
#define vjDBG_ALL (vjDBG_BASE+0) |
|---|
| 51 |
const std::string vjDBG_ALLstr("DBG_ALL"); |
|---|
| 52 |
#define vjDBG_ERROR (vjDBG_BASE+1) |
|---|
| 53 |
const std::string vjDBG_ERRORstr("DBG_ERROR"); |
|---|
| 54 |
#define vjDBG_KERNEL (vjDBG_BASE+2) |
|---|
| 55 |
const std::string vjDBG_KERNELstr("DBG_KERNEL"); |
|---|
| 56 |
#define vjDBG_INPUT_MGR (vjDBG_BASE+3) |
|---|
| 57 |
const std::string vjDBG_INPUT_MGRstr("DBG_INPUT_MGR"); |
|---|
| 58 |
#define vjDBG_DRAW_MGR (vjDBG_BASE+4) |
|---|
| 59 |
const std::string vjDBG_DRAW_MGRstr("DBG_DRAW_MGR"); |
|---|
| 60 |
#define vjDBG_DISP_MGR (vjDBG_BASE+5) |
|---|
| 61 |
const std::string vjDBG_DISP_MGRstr("DBG_DISP_MGR"); |
|---|
| 62 |
#define vjDBG_ENV_MGR (vjDBG_BASE+6) |
|---|
| 63 |
const std::string vjDBG_ENV_MGRstr("DBG_ENV_MGR"); |
|---|
| 64 |
#define vjDBG_PERFORMANCE (vjDBG_BASE+7) |
|---|
| 65 |
const std::string vjDBG_PERFORMANCEstr("DBG_PERFORMANCE"); |
|---|
| 66 |
#define vjDBG_CONFIG (vjDBG_BASE+8) |
|---|
| 67 |
const std::string vjDBG_CONFIGstr("DBG_CONFIGDB"); |
|---|
| 68 |
|
|---|
| 69 |
#define vjDBG_USER 100 |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
#define vjDBG_CRITICAL_LVL 0 |
|---|
| 82 |
#define vjDBG_CONFIG_LVL 1 |
|---|
| 83 |
#define vjDBG_WARNING_LVL 2 |
|---|
| 84 |
#define vjDBG_STATE_LVL 3 |
|---|
| 85 |
#define vjDBG_VERB_LVL 4 |
|---|
| 86 |
#define vjDBG_HVERB_LVL 5 |
|---|
| 87 |
#define vjDBG_DETAILED_LVL 6 |
|---|
| 88 |
#define vjDBG_HEX_LVL 7 |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
#define clrNONE "00" |
|---|
| 96 |
#define clrBOLD "01" |
|---|
| 97 |
#define clrBLACK "30" |
|---|
| 98 |
#define clrRED "31" |
|---|
| 99 |
#define clrGREEN "32" |
|---|
| 100 |
#define clrYELLOW "33" |
|---|
| 101 |
#define clrBLUE "34" |
|---|
| 102 |
#define clrMAGENTA "35" |
|---|
| 103 |
#define clrCYAN "36" |
|---|
| 104 |
#define clrWHITE "37" |
|---|
| 105 |
|
|---|
| 106 |
#ifdef VJ_OS_Win32 |
|---|
| 107 |
# define clrESC "" |
|---|
| 108 |
# define clrCONTROL_CHARS(font, color) "" |
|---|
| 109 |
# define clrSetNORM(color) "" |
|---|
| 110 |
# define clrSetBOLD(color) "" |
|---|
| 111 |
# define clrRESET "" |
|---|
| 112 |
# define clrOutBOLD(color,text) text |
|---|
| 113 |
# define clrOutNORM(color,text) text |
|---|
| 114 |
#else |
|---|
| 115 |
# define clrESC char(27) |
|---|
| 116 |
# define clrCONTROL_CHARS(font, color) clrESC << "[" << font << ";" << color << "m" |
|---|
| 117 |
# define clrSetNORM(color) clrESC << "[" << color << "m" |
|---|
| 118 |
# define clrSetBOLD(color) clrCONTROL_CHARS(clrBOLD, color) |
|---|
| 119 |
# define clrRESET clrESC << "[" << clrNONE << "m" |
|---|
| 120 |
# define clrOutBOLD(color,text) clrSetBOLD(color) << text << clrRESET |
|---|
| 121 |
# define clrOutNORM(color,text) clrSetNORM(color) << text << clrRESET |
|---|
| 122 |
#endif |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
#ifdef VJ_DEBUG |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
# define LOCK_DEBUG_STREAM |
|---|
| 130 |
# define MAX_DBG_LEVEL 100 |
|---|
| 131 |
#else |
|---|
| 132 |
# define LOCK_DEBUG_STREAM |
|---|
| 133 |
# define MAX_DBG_LEVEL vjDBG_WARNING_LVL |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
#endif |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
#define vjDEBUG(cat,val) if (val>MAX_DBG_LEVEL) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, true) |
|---|
| 151 |
#define vjDEBUGlg(cat,val,show_thread,use_indent,lockIt) if (val>MAX_DBG_LEVEL) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, show_thread, use_indent, 0, lockIt) |
|---|
| 152 |
#define vjDEBUG_BEGIN(cat,val) if (val>MAX_DBG_LEVEL) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, true, true, 1) |
|---|
| 153 |
#define vjDEBUG_BEGINlg(cat,val,show_thread,use_indent,lockIt) if (val>MAX_DBG_LEVEL) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, show_thread, use_indent, 1, lockIt) |
|---|
| 154 |
#define vjDEBUG_END(cat,val) if (val>MAX_DBG_LEVEL) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, true, true, -1) |
|---|
| 155 |
#define vjDEBUG_ENDlg(cat,val,show_thread,use_indent,lockIt) if (val>MAX_DBG_LEVEL) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, show_thread, use_indent, -1, lockIt) |
|---|
| 156 |
|
|---|
| 157 |
#define vjDEBUG_CONT(cat,val) vjDEBUGlg(cat,val,false,false,true) |
|---|
| 158 |
#define vjDEBUG_CONT_END(cat,val) vjDEBUG_ENDlg(cat,val,false,false,true) |
|---|
| 159 |
#define vjDEBUG_NEXT(cat,val) vjDEBUGlg(cat,val,false,true,true) |
|---|
| 160 |
#define vjDEBUG_NEXT_BEGIN(cat,val) vjDEBUG_BEGINlg(cat,val,false,true,true) |
|---|
| 161 |
#define vjDEBUG_NEXT_END(cat,val) vjDEBUG_ENDlg(cat,val,false,true,true) |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
#define vjDEBUGnl(cat,val) vjDEBUGlg(cat,val,true,true,false) |
|---|
| 166 |
#define vjDEBUG_ENDnl(cat,val) vjDEBUG_ENDlg(cat,val,true,true,false) |
|---|
| 167 |
#define vjDEBUG_BEGINnl(cat,val) vjDEBUG_BEGINlg(cat,val,true,true,false) |
|---|
| 168 |
#define vjDEBUG_CONTnl(cat,val) vjDEBUGlg(cat,val,false,false,false) |
|---|
| 169 |
#define vjDEBUG_CONT_ENDnl(cat,val) vjDEBUG_ENDlg(cat,val,false,false,false) |
|---|
| 170 |
#define vjDEBUG_NEXTnl(cat,val) vjDEBUGlg(cat,val,false,true,false) |
|---|
| 171 |
#define vjDEBUG_NEXT_BEGINnl(cat,val) vjDEBUG_BEGINlg(cat,val,false,true,false) |
|---|
| 172 |
#define vjDEBUG_NEXT_ENDnl(cat,val) vjDEBUG_ENDlg(cat,val,false,true,false) |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
#ifdef LOCK_DEBUG_STREAM |
|---|
| 176 |
# define vjDEBUG_STREAM_LOCK vjStreamLock(vjDebug::instance()->debugLock()) |
|---|
| 177 |
# define vjDEBUG_STREAM_UNLOCK vjStreamUnLock(vjDebug::instance()->debugLock()) |
|---|
| 178 |
# define vjDEBUG_FLUSH vjDEBUG_STREAM_UNLOCK << std::flush |
|---|
| 179 |
#else |
|---|
| 180 |
# define vjDEBUG_STREAM_LOCK std::flush |
|---|
| 181 |
# define vjDEBUG_STREAM_UNLOCK std::flush |
|---|
| 182 |
# define vjDEBUG_FLUSH std::flush |
|---|
| 183 |
#endif |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
#include <Kernel/vjAssert.h> |
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
class vjDebug |
|---|
| 195 |
{ |
|---|
| 196 |
private: |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
vjDebug(); |
|---|
| 201 |
|
|---|
| 202 |
public: |
|---|
| 203 |
|
|---|
| 204 |
std::ostream& getStream(int cat, int level, bool show_thread_info = true, |
|---|
| 205 |
bool use_indent = true, int indentChange = 0, bool lockStream = true); |
|---|
| 206 |
|
|---|
| 207 |
int getLevel() |
|---|
| 208 |
{ return debugLevel; } |
|---|
| 209 |
|
|---|
| 210 |
vjMutex& debugLock() |
|---|
| 211 |
{ return mDebugLock; } |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
void addCategoryName(std::string name, int cat); |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
void addAllowedCategory(int cat); |
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
bool isCategoryAllowed(int cat); |
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
void setDefaultCategoryNames(); |
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
void getAllowedCatsFromEnv(); |
|---|
| 227 |
|
|---|
| 228 |
void growAllowedCategoryVector(int newSize); |
|---|
| 229 |
|
|---|
| 230 |
private: |
|---|
| 231 |
int debugLevel; |
|---|
| 232 |
int indentLevel; |
|---|
| 233 |
|
|---|
| 234 |
vjMutex mDebugLock; |
|---|
| 235 |
|
|---|
| 236 |
std::vector<bool> mAllowedCategories; |
|---|
| 237 |
std::map<std::string,int> mCategoryNames; |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
vjSingletonHeader(vjDebug); |
|---|
| 257 |
}; |
|---|
| 258 |
|
|---|
| 259 |
#endif |
|---|