Changeset 1743 for trunk/MagicSoft/Mars
- Timestamp:
- 02/06/03 11:35:56 (22 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MLog.cc
r1524 r1743 45 45 #include <stdlib.h> // mkstempe 46 46 #include <fstream.h> 47 #include <pthread.h> 47 48 #include <TGListBox.h> 48 49 … … 68 69 setp(&fBuffer, &fBuffer+1); 69 70 *this << '\0'; 71 72 // 73 // Creat drawing semaphore 74 // 75 fMuxGui = new pthread_mutex_t; 76 pthread_mutex_init((pthread_mutex_t*)fMuxGui, NULL); 70 77 } 71 78 … … 75 82 // which is used for the output (i) 76 83 // 77 MLog::MLog(int i) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(i), fIsNull(kFALSE), fGuiLineId(0), fout(NULL), fOutAllocated(kFALSE), fgui(NULL) 84 MLog::MLog(int i) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(i), fIsNull(kFALSE), fGuiLineId(0), fout(NULL), fOutAllocated(kFALSE), fgui(NULL), fNumLines(0) 78 85 { 79 86 Init(); … … 85 92 // ofstream as the default output device 86 93 // 87 MLog::MLog(ofstream &out) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fIsNull(kFALSE), fGuiLineId(0), fout(&out), fOutAllocated(kFALSE), fgui(NULL) 94 MLog::MLog(ofstream &out) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fIsNull(kFALSE), fGuiLineId(0), fout(&out), fOutAllocated(kFALSE), fgui(NULL), fNumLines(0) 88 95 { 89 96 Init(); … … 95 102 // TGListBox as the default output device 96 103 // 97 MLog::MLog(TGListBox &out) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eGui), fGuiLineId(0), fout(NULL), fOutAllocated(kFALSE), fgui(&out) 104 MLog::MLog(TGListBox &out) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eGui), fGuiLineId(0), fout(NULL), fOutAllocated(kFALSE), fgui(&out), fNumLines(0) 98 105 { 99 106 Init(); … … 106 113 // or not. 107 114 // 108 MLog::MLog(const char *fname, int flag) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fIsNull(kFALSE), fGuiLineId(0), fgui(NULL) 115 MLog::MLog(const char *fname, int flag) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fIsNull(kFALSE), fGuiLineId(0), fgui(NULL), fNumLines(0) 109 116 { 110 117 Init(); … … 112 119 AllocateFile(fname); 113 120 CheckFlag(eFile, flag); 121 } 122 123 // -------------------------------------------------------------------------- 124 // 125 // Destructor, destroying the gui mutex. 126 // 127 MLog::~MLog() 128 { 129 DeallocateFile(); 130 pthread_mutex_destroy((pthread_mutex_t*)fMuxGui); 114 131 } 115 132 … … 153 170 if (fDevice&eGui && fgui) 154 171 { 172 char **newstr = new char*[fNumLines+1]; 173 174 for (int i=0; i<fNumLines; i++) 175 newstr[i] = fGuiLines[i]; 176 177 if (fNumLines>0) 178 delete fGuiLines; 179 155 180 char *dummy = new char[len]; 156 181 memcpy(dummy, fBase, len-1); 157 *(dummy+len-1)='\0';158 fgui->AddEntry(dummy, fGuiLineId); 159 fgui->SetTopEntry(fGuiLineId++);160 fgui->SetBit(kHasChanged); 161 delete dummy;182 dummy[len-1]='\0'; 183 184 newstr[fNumLines++] = dummy; 185 186 fGuiLines = newstr; 162 187 } 163 188 } 164 189 190 void MLog::UpdateGui() 191 { 192 if (fNumLines==0) 193 return; 194 195 Lock(); 196 197 // cout << "/---------------------------------------" << endl; 198 199 for (int i=0; i<fNumLines; i++) 200 { 201 fgui->AddEntry(fGuiLines[i], fGuiLineId++); 202 // cout << fGuiLines[i] << endl; 203 delete fGuiLines[i]; 204 } 205 206 delete fGuiLines; 207 208 // cout << "\\---------------------------------------" << endl; 209 210 fNumLines=0; 211 212 fgui->SetTopEntry(fGuiLineId-1); 213 fgui->SetBit(kHasChanged); 214 215 UnLock(); 216 } 217 218 void MLog::Lock() 219 { 220 pthread_mutex_lock((pthread_mutex_t*)fMuxGui); 221 } 222 223 void MLog::UnLock() 224 { 225 pthread_mutex_unlock((pthread_mutex_t*)fMuxGui); 226 } 227 165 228 // -------------------------------------------------------------------------- 166 229 // … … 169 232 int MLog::sync() 170 233 { 234 Lock(); 171 235 WriteBuffer(); 236 UnLock(); 172 237 173 238 if (fDevice&eStdout) … … 197 262 // no output if 198 263 // 199 if (fOutputLevel > fDebugLevel) 200 return 0; 201 202 *fPPtr++ = (char)i; 203 204 if (fPPtr == fEPtr) 205 WriteBuffer(); 264 if (fOutputLevel <= fDebugLevel) 265 { 266 Lock(); 267 268 *fPPtr++ = (char)i; 269 270 if (fPPtr == fEPtr) 271 WriteBuffer(); 272 273 UnLock(); 274 } 206 275 207 276 return 0; … … 215 284 void MLog::AllocateFile(const char *fname) 216 285 { 217 fout = fname ? new ofstream(fname) : new ofstream(mkstemp("logXXXXXX")); 286 char *txt = (char*)"logXXXXXX"; 287 fout = fname ? new ofstream(fname) : new ofstream(mkstemp(txt)); 218 288 fOutAllocated = kTRUE; 219 289 } -
trunk/MagicSoft/Mars/mbase/MLog.h
r1666 r1743 40 40 TGListBox *fgui; //! Listbox output 41 41 42 Bool_t fIsDirectGui; //! Pipe text directly to the GUI (for single threaded environments) 43 char **fGuiLines; //! Lines to pipe to gui 44 Int_t fNumLines; 45 46 void *fMuxGui; //! Mutex locking access of TGListBox 47 42 48 void Init(); 43 49 … … 58 64 59 65 MLog(MLog &log); 66 ~MLog(); 60 67 61 ~MLog() 62 { 63 DeallocateFile(); 64 } 68 void Lock(); 69 void UnLock(); 70 71 void EnableDirectGui() { fIsDirectGui = kTRUE; } 72 void DisableDirectGui() { fIsDirectGui = kFALSE; } 73 void UpdateGui(); 65 74 66 75 void SetDebugLevel(int i) { fDebugLevel = i; } 67 int GetDebugLevel() const{ return fDebugLevel; }76 int GetDebugLevel() const { return fDebugLevel; } 68 77 void SetOutputLevel(int i) { fOutputLevel = i; } 69 78 void SetOutputDevice(int i) { fDevice = i; }
Note:
See TracChangeset
for help on using the changeset viewer.