root/juggler/tags/1.0.5/Kernel/vjDebug.cpp

Revision 7539, 5.9 kB (checked in by anonymous, 7 years ago)

This commit was manufactured by cvs2svn to create tag
'RELENG_1_0_5_RELEASE'.

  • 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 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  * -----------------------------------------------------------------
26  * File:          $RCSfile$
27  * Date modified: $Date$
28  * Version:       $Revision$
29  * -----------------------------------------------------------------
30  *
31  *************** <auto-copyright.pl END do not edit this line> ***************/
32
33 #include <vjConfig.h>
34
35 #include <Kernel/vjDebug.h>
36
37 #include <Sync/vjMutex.h>
38 #include <Kernel/vjStreamLock.h>
39
40 /*
41 vjDebug* vjDebug::_instance = NULL;
42 vjMutex  vjDebug::_inst_lock;
43 */
44
45 vjSingletonImp(vjDebug);
46
47 #include <vjConfig.h>
48 #include <stdlib.h>
49
50 #include <Sync/vjMutex.h>
51 #include <Threads/vjThread.h>
52 #include <Kernel/vjStreamLock.h>
53
54
55
56 vjDebug::vjDebug()
57 {
58    indentLevel = 0;     // Initialy don't indent
59    debugLevel = 1;      // Should actually try to read env variable
60
61    char* debug_lev = getenv("VJ_DEBUG_NFY_LEVEL");
62    if(debug_lev != NULL)
63    {
64       debugLevel = atoi(debug_lev);
65       std::cout << "VJ_DEBUG_NFY_LEVEL: Set to " << debugLevel << std::endl
66                 << std::flush;
67    } else {
68       std::cout << "VJ_DEBUG_NFY_LEVEL: Not found. " << std::endl << std::flush;
69       std::cout << "VJ_DEBUG_NFY_LEVEL: Defaults to " << debugLevel
70                 << std::endl << std::flush;
71    }
72
73    setDefaultCategoryNames();
74    getAllowedCatsFromEnv();
75 }
76
77 std::ostream& vjDebug::getStream(int cat, int level, bool show_thread_info,
78                                  bool use_indent, int indentChange, bool lockStream)
79 {
80    if(indentChange < 0)                // If decreasing indent
81       indentLevel += indentChange;
82
83    //cout << "VJ " << level << ": ";
84
85    // Lock the stream
86 #ifdef LOCK_DEBUG_STREAM
87    if(lockStream)
88    {
89       debugLock().acquire();     // Get the lock
90    }
91 #endif
92
93    // --- Create stream header --- //
94    /*
95    if(show_thread_info)
96       std::cout << vjDEBUG_STREAM_LOCK << vjThread::self() << " VJ:";
97    else
98       std::cout << vjDEBUG_STREAM_LOCK << "              ";
99    */
100
101    // Ouput thread info
102    // If not, then output space if we are also using indent (assume this means new line used)
103    if(show_thread_info)
104       std::cout << "[" << vjThread::self() << "] VJ: ";
105    else if(use_indent)
106       std::cout << "                  ";
107
108
109       // Insert the correct number of tabs into the stream for indenting
110    if(use_indent)
111    {
112       for(int i=0;i<indentLevel;i++)
113          std::cout << "\t";
114    }
115
116    if(indentChange > 0)             // If increasing indent
117       indentLevel += indentChange;
118
119    return std::cout;
120 }
121
122 void vjDebug::addCategoryName(std::string name, int cat)
123 {
124    mCategoryNames[name] = cat;
125 }
126
127 void vjDebug::addAllowedCategory(int cat)
128 {
129    if((int)mAllowedCategories.size() < (cat+1))
130       growAllowedCategoryVector(cat+1);
131
132    mAllowedCategories[cat] = true;
133 }
134
135 // Are we allowed to print this category??
136 bool vjDebug::isCategoryAllowed(int cat)
137 {
138    // If no entry for cat, grow the vector
139    if((int)mAllowedCategories.size() < (cat+1))
140       growAllowedCategoryVector(cat+1);
141
142    // If I specified to listen to all OR
143    // If it has category of ALL
144    if((mAllowedCategories[vjDBG_ALL]) || (cat == vjDBG_ALL))
145       return true;
146    else
147       return mAllowedCategories[cat];
148 }
149
150 void vjDebug::setDefaultCategoryNames()
151 {
152    ///* XXX: Removed for insure checking
153    addCategoryName(vjDBG_ALLstr,vjDBG_ALL);
154    addCategoryName(vjDBG_ERRORstr,vjDBG_ERROR);
155    addCategoryName(vjDBG_KERNELstr,vjDBG_KERNEL);
156    addCategoryName(vjDBG_INPUT_MGRstr,vjDBG_INPUT_MGR);
157    addCategoryName(vjDBG_DRAW_MGRstr,vjDBG_DRAW_MGR);
158    addCategoryName(vjDBG_DISP_MGRstr,vjDBG_DISP_MGR);
159    addCategoryName(vjDBG_ENV_MGRstr, vjDBG_ENV_MGR);
160    addCategoryName(vjDBG_PERFORMANCEstr, vjDBG_PERFORMANCE);
161    addCategoryName(vjDBG_CONFIGstr, vjDBG_CONFIG);
162    //*/
163 }
164
165 void vjDebug::getAllowedCatsFromEnv()
166 {
167    ///* XXX: For insure
168    char* dbg_cats_env = getenv("VJ_DEBUG_CATEGORIES");
169
170    if(dbg_cats_env != NULL)
171    {
172       std::cout << "vjDEBUG::Found VJ_DEBUG_CATEGORIES: Listing allowed categories. (If blank, then none allowed.\n" << std::flush;
173       std::string dbg_cats(dbg_cats_env);
174
175       std::map< std::string, int >::iterator i;
176       for(i=mCategoryNames.begin();i != mCategoryNames.end();i++)
177       {
178          std::string cat_name = (*i).first;
179          if (dbg_cats.find(cat_name) != std::string::npos )    // Found one
180          {
181             std::cout << "vjDEBUG::getAllowedCatsFromEnv: Allowing: "
182                       << (*i).first.c_str() << " val:" << (*i).second
183                       << std::endl << std::flush;
184             addAllowedCategory((*i).second);                   // Add the category
185          }
186       }
187    }
188    else
189    {
190       std::cout << "vjDEBUG::VJ_DEBUG_CATEGORIES not found:\n"
191                 << " Setting to: vjDBG_ALL!" << std::endl << std::flush;
192       addAllowedCategory(vjDBG_ALL);
193    }
194    //*/
195    //addAllowedCategory(vjDBG_ALL);
196 }
197
198 void vjDebug::growAllowedCategoryVector(int newSize)
199 {
200    while((int)mAllowedCategories.size() < newSize)
201       mAllowedCategories.push_back(false);
202 }
203
Note: See TracBrowser for help on using the browser.