root/juggler/branches/1.0/Kernel/vjDebug.h

Revision 8789, 10.2 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34
35 #ifndef _VJDebug_h_
36 #define _VJDebug_h_
37 //#pragma once
38
39 // #define VJ_DEBUG  Defined in vjConfig.h
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 // Debug output categories
49 #define vjDBG_BASE 0
50 #define vjDBG_ALL (vjDBG_BASE+0)         /* Use if you always want it ouput */
51 const std::string vjDBG_ALLstr("DBG_ALL");
52 #define vjDBG_ERROR (vjDBG_BASE+1)       /* Error output */
53 const std::string vjDBG_ERRORstr("DBG_ERROR");
54 #define vjDBG_KERNEL (vjDBG_BASE+2)      /* Kernel output */
55 const std::string vjDBG_KERNELstr("DBG_KERNEL");
56 #define vjDBG_INPUT_MGR (vjDBG_BASE+3)       /* Input output */
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 // Suggested use of val/debugLevel
72 //
73 // 0 - Critical messages (always need to be seen)
74 // 1 - Configuration of system
75 // 2 - Warnings and potential problems
76 // 3 - State changes & who is doing what
77 // 4 - Verbose (don't need source) ex
78 // 5 - Highly verbose (may need source)
79 // 6 - Very detailed: i.e. Function entry and exit
80 // 7 - You will be reading hexidecimal
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 // COLOR CONTROL CODES
92 // TODO: Make the work for windows
93 // 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
94 // 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
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 //#   define vjDEBUG(cat,val) if (0) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val)
127 //#   define vjDEBUG_BEGIN(cat,val) if (0) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, true, 1)
128 //#   define vjDEBUG_END(cat,val) if (0) ; else if((val <= vjDebug::instance()->getLevel()) && (vjDebug::instance()->isCategoryAllowed(cat))) vjDebug::instance()->getStream(cat, val, true, -1)
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 //#   define vjDEBUG(cat,val) if (1) ; else std::cout
135 //#   define vjDEBUG_BEGIN(cat,val) if (1) ; else std::cout
136 //#   define vjDEBUG_END(cat,val) if (1) ; else std::cout
137 #endif
138
139 // #undef LOCK_DEBUG_STREAM
140
141 // Define the actual macros to use
142 // vjDEBUG - Outputs debug info
143 // vjDEBUG_BEGIN - Starts some indenting of the thread information
144 // vjDEBUG_END - Ends the indenting level of the information
145 // vjDEBUG_CONT - Continue on the same line (no thread info, no indent)
146 // vjDEBUG_CONT_END - Continue on the same line AND decrease indent one level (no thread info, no indent)
147 // vjDEBUG_NEXT - Outputing more info on next line (no thread info)
148 // vjDEBUG_NEXT_BEGIN - Output more infor on next line AND indent one level more
149 // vjDEBUG_NEXT_END - Ouput more info on the next line AND decrease indent one level
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 // Versions that don't lock the stream
164 // NOTE: USE WITH EXTREME RISK
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 //: Class to support debug output
191 //
192 //!PUBLIC_API:
193 //-----------------------------------------
194 class vjDebug
195 {
196 private:
197    // Set default values
198    // Set up default categories
199    // Get debug config from environment
200    vjDebug();
201
202 public:
203    // Get the debug stream to use
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    // Add a category name
214    void addCategoryName(std::string name, int cat);
215
216    // Allow the given category
217    void addAllowedCategory(int cat);
218
219    // Are we allowed to print this category??
220    bool isCategoryAllowed(int cat);
221
222    // Setup the default categories
223    void setDefaultCategoryNames();
224
225    // Configure the allowed categories from the users environment
226    void getAllowedCatsFromEnv();
227
228    void growAllowedCategoryVector(int newSize);
229
230 private:
231    int debugLevel;      // Debug level to use
232    int indentLevel;     // Amount to indent
233
234    vjMutex          mDebugLock;
235
236    std::vector<bool> mAllowedCategories;      //: The categories we allow
237    std::map<std::string,int> mCategoryNames; //: The names and id of allowed catagories
238
239 /*
240 public:
241    static vjDebug* instance()
242    {
243       if(_instance == NULL)                     // First check
244       {
245          vjGuard<vjMutex> guard(_inst_lock);    // Serial critical section
246          if (_instance == NULL)                 // Second check
247             _instance = new vjDebug;
248       }
249       vjASSERT(_instance != NULL && "vjDEBUG has NULL _instance");
250       return _instance;
251    }
252 private:
253    static vjDebug* _instance;
254    static vjMutex _inst_lock;
255    */
256 vjSingletonHeader(vjDebug);
257 };
258
259 #endif
Note: See TracBrowser for help on using the browser.