VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlPrint.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2015 VT MAK
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vlutil/vlMachineTypes.h>
13 #include <vlutil/vlMutex.h>
14 #include <iostream>
15 #include <fstream>
16 #include <vector>
17 #include <ios>
18 
19 #ifdef _WIN32
20 #include <winsock2.h>
21 #endif
22 
23 
24 #ifdef DtUSE_UTILITIES_NAMESPACE
25 namespace DtUSE_UTILITIES_NAMESPACE
26 {
27 #endif
28 
29 
35 extern DT_DLL_VLUTIL int DtNotifyLevel;
36 
37 
40 {
41  DtNlFatal = 0,
42  DtNlWarn = 1,
43  DtNlInfo = 2,
46 };
47 
48 
56 {
57 public:
58 
60  inline DtPrinter();
61 
63  inline DtPrinter( const DtPrinter& );
64 
66  virtual inline ~DtPrinter();
67 
71  virtual void write( const std::string& str, int notify_level, bool newLine ) = 0;
72 
73 };
74 
75 
81 {
82 public:
83 
86  DtFilePrinter();
87 
90  DtFilePrinter( const char* filename );
91 
94  virtual ~DtFilePrinter();
95 
97  virtual void setPrintTimestamps( bool doit );
98 
102  virtual void setLogRollingInterval( unsigned int intervalInSeconds );
103 
106  virtual void resetFile( const char* filename );
107 
109  virtual bool isOpen();
110 
113  virtual void write( const std::string& st, int notify_level, bool newLine );
114 
115 protected:
116 
118  virtual void cacheFilename( const std::string& filename );
119 
120 private:
121 
123  DtFilePrinter( const DtFilePrinter& orig );
124 
126  DtFilePrinter& operator = ( const DtFilePrinter& orig );
127 
128 protected:
129 
131 
133 
135  unsigned int myLogRollingIndex;
136  unsigned int myLogRollingInterval;
137 
138  std::string myFilename;
139  std::string myFileBase;
140  std::string myFileExt;
141 
142 #ifndef __sgi__
143  std::ofstream myFile;
144 #else
145  std::fstream myFile;
146 #endif
147 
148 };
149 
150 
155 {
156 public:
157 
159  inline DtStdoutPrinter();
160 
162  virtual inline ~DtStdoutPrinter();
163 
165  virtual void write( const std::string& st, int notify_level, bool newLine );
166 
167 protected:
168 
170 
171 };
172 
173 
178 {
179 public:
180 
182  inline DtStderrPrinter();
183 
185  virtual inline ~DtStderrPrinter();
186 
188  virtual void write( const std::string& st, int notify_level, bool newLine );
189 
190 protected:
191 
193 
194 };
195 
196 
197 #ifdef _WIN32
198 
202 class DT_DLL_VLUTIL DtWindowsConsolePrinter : public DtPrinter
203 {
204 public:
205 
207  DtWindowsConsolePrinter( bool disableClose = false );
208 
210  virtual ~DtWindowsConsolePrinter();
211 
213  virtual void write( const std::string& st, int notify_level, bool newLine );
214 
215 protected:
216 
217  HANDLE myConsoleHandle;
218  DtMutex myLock;
219 
220 };
221 
222 #endif
223 
224 
226 class DtOutputStream;
227 
231 class DT_DLL_VLUTIL DtOutputStreamBuffer : public std::basic_streambuf<char>
232 {
233 public:
234 
237 
239  virtual ~DtOutputStreamBuffer();
240 
241  virtual void setOutputStream( DtOutputStream* stream );
242 
243 protected:
244 
245  virtual int sync();
246  virtual int_type overflow( int_type c );
247 
248 private:
249 
252 
254  DtOutputStreamBuffer& operator = ( const DtOutputStreamBuffer& );
255 
256 protected:
257 
258  std::string myBuffer;
261 
262 };
263 
264 
282 class DT_DLL_VLUTIL DtOutputStream : public std::basic_ostream<char>
283 {
284 public:
285 
290  DtOutputStream( DtOutputStreamBuffer* buffer, int& globalThresholdRef,
291  int threshold = 1, DtPrinter* dflt_printer = 0 );
292 
294  virtual ~DtOutputStream();
295 
297  virtual void attachPrinter( DtPrinter* sink );
298 
301  virtual bool detachPrinter( DtPrinter* sink );
302 
305  virtual void detachAllPrinters();
306 
310  virtual void write( const std::string& str, bool newLine = false );
311 
314  virtual void setThreshold( int level );
315 
318  virtual int threshold() const;
319 
323  virtual bool okToPrint() const;
324 
326  virtual void operator () ( const char* s, ... );
327 
328 
329 private:
330 
332  DtOutputStream( const DtOutputStream& );
333 
335  DtOutputStream& operator = ( const DtOutputStream& );
336 
337 protected:
338 
339  typedef std::vector<DtPrinter*> PrinterPtrVec;
340 
346 
349 
350 };
351 
352 
363 
374 
375 
382 
393 
394 
403 
404 extern DT_DLL_VLUTIL void DtFatalError( const char* str, ... );
405 extern DT_DLL_VLUTIL void DtFatalPerror( const char* str, ... );
406 extern DT_DLL_VLUTIL void DtWarnPerror( const char* str, ... );
407 extern DT_DLL_VLUTIL void DtFatalNetPerror( const char* str, ... );
408 extern DT_DLL_VLUTIL void DtWarnNetPerror( const char* str, ... );
410 
411 
417 DT_DLL_VLUTIL void DtSetVrLinkPrinter( DtPrinter* newPrinter );
418 
419 
423 
424 #ifdef _WIN32
425 
433 
434 DT_DLL_VLUTIL void setFileOutput( const char* filename, int con = 0, int son = 0 );
435 DT_DLL_VLUTIL void closeConsole();
437 
438 #endif
439 
440 
445 DT_DLL_VLUTIL void DtAbort();
446 
448 typedef void (*DtAbortFunc)();
449 
452 
455 
456 #if DT_NO_VSNPRINTF
457 DT_DLL_VLUTIL int vsnprintf( char*, size_t, const char*, va_list );
459 #endif
460 
461 //-------------------------------------------
462 //Inline Function Definitions
463 //-----------------------------------------
464 inline void DtOutputStream::setThreshold( int level )
465 {
466  myThreshold = level;
467 }
468 
469 inline int DtOutputStream::threshold() const
470 {
471  return myThreshold;
472 }
473 
475 {
476 }
477 
479 {
480 }
481 
483 {
484 }
485 
487 {
488 }
489 
491 {
492 }
493 
495 {
496 }
497 
499 {
500 }
501 
502 
503 #ifdef DtUSE_UTILITIES_NAMESPACE
504 }
505 #endif
class DtStderrPrinter is a subclass of DtPrinter which copies all input received from DtOutputStream ...
Definition: vlPrint.h:177
void DtSetVrLinkPrinter(DtPrinter *newPrinter)
DtSetVrLinkPrinter is provided for backwards compatibility.
This file contains the declaration of DtMutex.
DtOutputStream DtFatal
These DtOutputStream instances are used for all print messaging in VR-Link.
DtPrinter()
Default CTOR.
Definition: vlPrint.h:474
DtStdoutPrinter()
Default CTOR.
Definition: vlPrint.h:486
unsigned int myLogRollingInterval
Definition: vlPrint.h:136
void DtSetAbortFunc(DtAbortFunc func)
bool myTimestampFlag
Definition: vlPrint.h:132
DtPrinter is an abstract base class which provides an interface for output.
Definition: vlPrint.h:55
DtFilePrinter is a subclass of DtPrinter which opens a file and dumps all information received from D...
Definition: vlPrint.h:80
DtMutex myFileLock
Definition: vlPrint.h:130
Definition: vlPrint.h:44
std::string myFilename
Definition: vlPrint.h:138
DtStderrPrinter DtStandardErrorConsole
This class is a basic DtPrinter instance which can be used with DtOutputStream instances.
virtual ~DtPrinter()
Virtual DTOR.
Definition: vlPrint.h:482
void DtWarnPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
DtMutex myPrintersMutex
Definition: vlPrint.h:344
DtStdoutPrinter is a subclass of DtPrinter which copies all input received from DtOutputStream to the...
Definition: vlPrint.h:154
virtual ~DtStdoutPrinter()
Virtual DTOR.
Definition: vlPrint.h:490
DtOutputStreamBuffer is the internal buffer for DtOutputStream.
Definition: vlPrint.h:231
DtOutputStream * myOutputStream
Definition: vlPrint.h:260
std::string myFileBase
Definition: vlPrint.h:139
virtual ~DtStderrPrinter()
Virtual DTOR.
Definition: vlPrint.h:498
DtOutputStreamBuffer * myStreamBuf
Definition: vlPrint.h:341
void(* DtAbortFunc)()
Definition: vlPrint.h:448
DtStdoutPrinter DtStandardOutConsole
This class is a basic DtPrinter instance which can be used with DtOutputStream instances.
Definition: vlPrint.h:41
int & myGlobalThresholdReference
This is the global value we compare myThreshold to.
Definition: vlPrint.h:348
int DtNotifyLevel
DtNotifyLevel is used to control the level of diagnostics output by VR-Link.
int myThreshold
Definition: vlPrint.h:345
DtMutex myLock
Definition: vlPrint.h:169
PrinterPtrVec myPrinters
Definition: vlPrint.h:343
instances of DtMutex are used to provide a platform independent mutual exclusion mechanism ...
Definition: vlMutex.h:31
DtOutputStream DtVerbose
These DtOutputStream instances are used for all print messaging in VR-Link.
DtOutputStream is used for all toolkit output.
Definition: vlPrint.h:282
void DtFatalNetPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
DtOutputStream DtWarn
These DtOutputStream instances are used for all print messaging in VR-Link.
void DtFatalPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
void DtAbort()
DtAbort() exits the program.
std::vector< DtPrinter * > PrinterPtrVec
Definition: vlPrint.h:339
void DtPrintEnvironmentVariables(DtOutputStream &os=DtInfo)
Print the environment variables If notifyLevel isn&#39;t specified, function will use DtNlInfo as appropr...
DtOutputStream DtInfo
DtInfo is an global instance of a DtOutputStream.
Definition: vlPrint.h:45
Definition: vlPrint.h:42
virtual void setThreshold(int level)
Sets the threshold required for sending string output to all attached printer.
Definition: vlPrint.h:464
DtAbortFunc DtGetAbortFunc()
std::string myFileExt
Definition: vlPrint.h:140
DtStderrPrinter()
Default CTOR.
Definition: vlPrint.h:494
time_t myLogFileOpenTime
Definition: vlPrint.h:134
DtNotifyLevelType
Default is DtNlInfo.
Definition: vlPrint.h:39
std::string myBuffer
Definition: vlPrint.h:258
void DtFatalError(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
DtMutex myStreamBufMutex
Definition: vlPrint.h:342
unsigned int myLogRollingIndex
Definition: vlPrint.h:135
virtual int threshold() const
Returns the current threshold required to send string output to all attached printers.
Definition: vlPrint.h:469
DtMutex myBufferMutex
Definition: vlPrint.h:259
void DtWarnNetPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
Definition: vlPrint.h:43
DtMutex myLock
Definition: vlPrint.h:192
This file contains typedefs for machine dependant types.
std::ofstream myFile
Definition: vlPrint.h:143
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109
DtOutputStream DtDebug
These DtOutputStream instances are used for all print messaging in VR-Link.

Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)