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

Revision 8789, 5.9 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 #include <vjConfig.h>
35
36 #include <Kernel/vjDebug.h>
37
38 #include <Sync/vjMutex.h>
39 #include <Kernel/vjStreamLock.h>
40
41 /*
42 vjDebug* vjDebug::_instance = NULL;
43 vjMutex  vjDebug::_inst_lock;
44 */
45
46 vjSingletonImp(vjDebug);
47
48 #include <vjConfig.h>
49 #include <stdlib.h>
50
51 #include <Sync/vjMutex.h>
52 #include <Threads/vjThread.h>
53 #include <Kernel/vjStreamLock.h>
54
55
56
57 vjDebug::vjDebug()
58 {
59    indentLevel = 0;     // Initialy don't indent
60    debugLevel = 1;      // Should actually try to read env variable
61
62    char* debug_lev = getenv("VJ_DEBUG_NFY_LEVEL");
63    if(debug_lev != NULL)
64    {
65       debugLevel = atoi(debug_lev);
66       std::cout << "VJ_DEBUG_NFY_LEVEL: Set to " << debugLevel << std::endl
67                 << std::flush;
68    } else {
69       std::cout << "VJ_DEBUG_NFY_LEVEL: Not found. " << std::endl << std::flush;
70       std::cout << "VJ_DEBUG_NFY_LEVEL: Defaults to " << debugLevel
71                 << std::endl << std::flush;
72    }
73
74    setDefaultCategoryNames();
75    getAllowedCatsFromEnv();
76 }
77
78 std::ostream& vjDebug::getStream(int cat, int level, bool show_thread_info,
79                                  bool use_indent, int indentChange, bool lockStream)
80 {
81    if(indentChange < 0)                // If decreasing indent
82       indentLevel += indentChange;
83
84    //cout << "VJ " << level << ": ";
85
86    // Lock the stream
87 #ifdef LOCK_DEBUG_STREAM
88    if(lockStream)
89    {
90       debugLock().acquire();     // Get the lock
91    }
92 #endif
93
94    // --- Create stream header --- //
95    /*
96    if(show_thread_info)
97       std::cout << vjDEBUG_STREAM_LOCK << vjThread::self() << " VJ:";
98    else
99       std::cout << vjDEBUG_STREAM_LOCK << "              ";
100    */
101
102    // Ouput thread info
103    // If not, then output space if we are also using indent (assume this means new line used)
104    if(show_thread_info)
105       std::cout << "[" << vjThread::self() << "] VJ: ";
106    else if(use_indent)
107       std::cout << "                  ";
108
109
110       // Insert the correct number of tabs into the stream for indenting
111    if(use_indent)
112    {
113       for(int i=0;i<indentLevel;i++)
114          std::cout << "\t";
115    }
116
117    if(indentChange > 0)             // If increasing indent
118       indentLevel += indentChange;
119
120    return std::cout;
121 }
122
123 void vjDebug::addCategoryName(std::string name, int cat)
124 {
125    mCategoryNames[name] = cat;
126 }
127
128 void vjDebug::addAllowedCategory(int cat)
129 {
130    if((int)mAllowedCategories.size() < (cat+1))
131       growAllowedCategoryVector(cat+1);
132
133    mAllowedCategories[cat] = true;
134 }
135
136 // Are we allowed to print this category??
137 bool vjDebug::isCategoryAllowed(int cat)
138 {
139    // If no entry for cat, grow the vector
140    if((int)mAllowedCategories.size() < (cat+1))
141       growAllowedCategoryVector(cat+1);
142
143    // If I specified to listen to all OR
144    // If it has category of ALL
145    if((mAllowedCategories[vjDBG_ALL]) || (cat == vjDBG_ALL))
146       return true;
147    else
148       return mAllowedCategories[cat];
149 }
150
151 void vjDebug::setDefaultCategoryNames()
152 {
153    ///* XXX: Removed for insure checking
154    addCategoryName(vjDBG_ALLstr,vjDBG_ALL);
155    addCategoryName(vjDBG_ERRORstr,vjDBG_ERROR);
156    addCategoryName(vjDBG_KERNELstr,vjDBG_KERNEL);
157    addCategoryName(vjDBG_INPUT_MGRstr,vjDBG_INPUT_MGR);
158    addCategoryName(vjDBG_DRAW_MGRstr,vjDBG_DRAW_MGR);
159    addCategoryName(vjDBG_DISP_MGRstr,vjDBG_DISP_MGR);
160    addCategoryName(vjDBG_ENV_MGRstr, vjDBG_ENV_MGR);
161    addCategoryName(vjDBG_PERFORMANCEstr, vjDBG_PERFORMANCE);
162    addCategoryName(vjDBG_CONFIGstr, vjDBG_CONFIG);
163    //*/
164 }
165
166 void vjDebug::getAllowedCatsFromEnv()
167 {
168    ///* XXX: For insure
169    char* dbg_cats_env = getenv("VJ_DEBUG_CATEGORIES");
170
171    if(dbg_cats_env != NULL)
172    {
173       std::cout << "vjDEBUG::Found VJ_DEBUG_CATEGORIES: Listing allowed categories. (If blank, then none allowed.\n" << std::flush;
174       std::string dbg_cats(dbg_cats_env);
175
176       std::map< std::string, int >::iterator i;
177       for(i=mCategoryNames.begin();i != mCategoryNames.end();i++)
178       {
179          std::string cat_name = (*i).first;
180          if (dbg_cats.find(cat_name) != std::string::npos )    // Found one
181          {
182             std::cout << "vjDEBUG::getAllowedCatsFromEnv: Allowing: "
183                       << (*i).first.c_str() << " val:" << (*i).second
184                       << std::endl << std::flush;
185             addAllowedCategory((*i).second);                   // Add the category
186          }
187       }
188    }
189    else
190    {
191       std::cout << "vjDEBUG::VJ_DEBUG_CATEGORIES not found:\n"
192                 << " Setting to: vjDBG_ALL!" << std::endl << std::flush;
193       addAllowedCategory(vjDBG_ALL);
194    }
195    //*/
196    //addAllowedCategory(vjDBG_ALL);
197 }
198
199 void vjDebug::growAllowedCategoryVector(int newSize)
200 {
201    while((int)mAllowedCategories.size() < newSize)
202       mAllowedCategories.push_back(false);
203 }
204
Note: See TracBrowser for help on using the browser.