VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
outputChannelManager.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 2022 MAK Technologies, Inc.
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include "vrfutil/vrfutilDefines.h"
14 #include <vrfutil/objectCounter.h>
15 
16 #include "tbb/spin_mutex.h"
17 
18 #include <stdarg.h>
19 
21 
26 {
27 public:
28 
30  {
31  ChannelSettings( int nl = DtNlInfo, const DtString& p = "", bool enabled = false )
32  : notifyLevel( nl )
33  , prefix( p )
34  , enabled( enabled )
35  {
36  }
37 
40  bool enabled;
41 
42  };
43 
44  typedef DtChannelSpecificOutputStream* (*DtOutputChannelStreamCreatorFcn)(
45  DtOutputStreamBuffer*, int&, int, DtPrinter*, const std::string& );
46 
47  typedef DtOutputStreamBuffer* (*DtOutputStreamBufferCreatorFcn)();
48 
49 public:
50 
51  DtOutputChannelManager( int& globalNotifyReference );
52 
53  virtual ~DtOutputChannelManager();
54 
56  virtual void addPrinter( DtPrinter* printer );
57 
59  virtual void addAndManagePrinter( DtPrinter* printer );
60 
63  virtual void removePrinter( DtPrinter* printer );
64 
68  virtual DtOutputStream& printError( const DtString& channel = "" );
69  virtual DtOutputStream& printWarn( const DtString& channel = "" );
70  virtual DtOutputStream& printInfo( const DtString& channel = "" );
71  virtual DtOutputStream& printVerbose( const DtString& channel = "" );
72  virtual DtOutputStream& printDebug( const DtString& channel = "" );
73 
74  virtual void setChannelSettings( const DtRwChannelDescriptorList& settings );
75 
76  virtual int channelNotifyLevel( const DtString& channel );
77  virtual void setChannelNotifyLevel( const DtString& channel, int level );
78 
79  virtual DtString channelPrefix( const DtString& channel );
80  virtual void setChannelPrefix( const DtString& channel,
81  const DtString& prefix );
82 
83  virtual bool channelEnabled( const DtString& channel );
84  virtual void setChannelEnabled( const DtString& channel,
85  bool enabled );
86 
87  virtual void addDefaultStream( int notifyLevel, DtOutputStream& stream );
88 
89  virtual DtOutputStream& defaultStream( int notifyLevel );
90 
92  virtual void printStatus( const DtString& channel = "" );
93 
94  virtual DtString channelStatus( const DtString& channel );
95 
96  virtual void setStreamCreatorFcn( DtOutputChannelStreamCreatorFcn fcn );
97 
98  virtual void setStreamBufferCreatorFcn( DtOutputStreamBufferCreatorFcn fcn );
99 
100  virtual DtOutputStreamBuffer* createStreamBuffer();
101 
102  virtual void setManageDefaultStreams( bool manage );
103 
104  virtual std::vector<DtString> allChannels() const;
105 
106 protected:
107 
108  virtual DtOutputStream& streamForChannel( const DtString& channel, int notifyLevel );
109 
110  virtual DtChannelSpecificOutputStream* createStream( int& globalThresholdRef, int threshold = 1,
111  DtPrinter* default_printer = 0, const std::string& prefix = "" );
112 
113  virtual void attachToAllStreams( DtPrinter* printer );
114  virtual void detachFromAllStreams( DtPrinter* printer );
115 
116  virtual ChannelSettings* channelSettings( const DtString& channel );
117 
118  virtual void addAllPrinters( DtOutputStream* stream );
119 
120 protected:
121 
123  {
124  explicit DefaultStreamInfo( DtOutputStream* stream = 0, DtOutputStreamBuffer* buffer = 0 );
125 
126  DtOutputStream* stream;
127  DtOutputStreamBuffer* buffer;
128  };
129 
130 protected:
131 
132  std::vector<DtPrinter*> myPrinters;
133  std::vector<DtPrinter*> myManagedPrinters;
134 
135  typedef std::map<DtString,ChannelSettings*> ChannelSettingsMap;
137 
139 
140  typedef std::vector<DtChannelSpecificOutputStream*> StreamVector;
141  typedef std::map<DtString,StreamVector> ChannelMap;
143 
144  std::vector<DefaultStreamInfo> myDefaultStreams;
145 
146  DtOutputStreamBuffer myNullStreamBuffer;
147  std::unique_ptr<DtOutputStream> myNullStream;
148 
149  DtOutputChannelStreamCreatorFcn myStreamCreatorFcn;
150  DtOutputStreamBufferCreatorFcn myStreamBufferCreatorFcn;
151 
153 
154  //locked when accessing/modifying internal maps to allow streams to be
155  //accessed from different threads concurrently.
156  mutable tbb::spin_mutex myMutex;
157 
158 };
159 
160 
161 class DtChannelSpecificOutputStream : public DtOutputStream
162 #ifdef DtObjectDebugger_Enable
163  , public DtObjectDebugger<DtChannelSpecificOutputStream>
164 #endif
165 {
166 public:
167 
168  DtChannelSpecificOutputStream( DtOutputStreamBuffer* b, int& globalThresholdRef, int threshold = 1,
169  DtPrinter* default_printer = 0, const std::string& prefix = "" )
170  : DtOutputStream( b, globalThresholdRef, threshold, default_printer )
171  , myPrefix( prefix )
172  , myBuffer( b )
173  {
174  }
175 
176  virtual ~DtChannelSpecificOutputStream() override {
177  }
178 
179  virtual void write( const std::string &str )
180  {
181  if ( myPrefix != "" && str != "" )
182  {
183  DtOutputStream::write( std::string("[") + myPrefix + "]: " + str );
184  }
185  else //if (str != "")
186  {
187  DtOutputStream::write( str );
188  }
189  }
190 
192  virtual void operator() (const char* s, ...) override
193  {
196  if (okToPrint())
197  {
200  myStreamBufMutex.lock();
201  myStreamBuf->pubsync();
202  myStreamBufMutex.unlock();
203 
204  if (!s)
205  {
206  return;
207  }
208 
209  char str[2048];
210  va_list args;
211  va_start(args, s);
212  vsprintf(str, s, args);
213  va_end(args);
214  std::string temp(str);
215 
216  if (myPrefix != "" && temp != "")
217  {
218  DtOutputStream::write(std::string("[") + myPrefix + "]: " + temp);
219  }
220  else //if (str != "")
221  {
222  DtOutputStream::write(temp);
223  }
224  }
225  }
226 
227 
228  virtual void setPrefix( const DtString& str )
229  {
230  myPrefix = str.c_str();
231  }
232 
233  DtOutputStreamBuffer* getBuffer()
234  {
235  return myBuffer;
236  }
237 
238  static DtChannelSpecificOutputStream* creator( DtOutputStreamBuffer* b, int& globalThresholdRef, int threshold = 1,
239  DtPrinter* default_printer = 0, const std::string& prefix = "" )
240  {
241  return new DtChannelSpecificOutputStream( b, globalThresholdRef, threshold, default_printer, prefix );
242  }
243 
244 protected:
245 
246  std::string myPrefix;
247  DtOutputStreamBuffer* myBuffer;
248 
249 };
250 
251 
bool enabled
Definition: outputChannelManager.h:40
DtOutputStreamBuffer * getBuffer()
Definition: outputChannelManager.h:233
ChannelSettings(int nl=DtNlInfo, const DtString &p="", bool enabled=false)
Definition: outputChannelManager.h:31
DT_DLL_VRVCORE DtTaitBryan level(const DtCoordinateSystem &cs, const DtVector &localOrigin, double topoHeading)
Returns a level orientation with the topographic heading.
DtOutputStreamBuffer myNullStreamBuffer
Definition: outputChannelManager.h:146
virtual void operator()(const char *s,...) override
This is a copy of DtOutputStream::operator() until the write().
Definition: outputChannelManager.h:192
std::vector< DefaultStreamInfo > myDefaultStreams
Definition: outputChannelManager.h:144
int notifyLevel
Definition: outputChannelManager.h:38
ChannelSettingsMap myChannelSettingsMap
Definition: outputChannelManager.h:136
virtual ~DtChannelSpecificOutputStream() override
Definition: outputChannelManager.h:176
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:31
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
Default on in debug, off in release.
Definition: objectCounter.h:27
std::map< DtString, ChannelSettings * > ChannelSettingsMap
Definition: outputChannelManager.h:135
std::vector< DtPrinter * > myPrinters
Definition: outputChannelManager.h:132
Definition: outputChannelManager.h:161
tbb::spin_mutex myMutex
Definition: outputChannelManager.h:156
virtual void setPrefix(const DtString &str)
Definition: outputChannelManager.h:228
The DtOutputChannelManager class manages default streams and channel-specific streams by notify level...
Definition: outputChannelManager.h:25
std::string myPrefix
Definition: outputChannelManager.h:246
std::vector< DtChannelSpecificOutputStream * > StreamVector
Definition: outputChannelManager.h:140
Definition: outputChannelManager.h:122
DtOutputStreamBufferCreatorFcn myStreamBufferCreatorFcn
Definition: outputChannelManager.h:150
virtual void write(const std::string &str)
Definition: outputChannelManager.h:179
DtString prefix
Definition: outputChannelManager.h:39
bool myManageDefaultStreams
Definition: outputChannelManager.h:152
DtOutputChannelStreamCreatorFcn myStreamCreatorFcn
Definition: outputChannelManager.h:149
int & myGlobalNotifyReference
Definition: outputChannelManager.h:138
voidpf stream
Definition: ioapi.h:39
DtOutputStreamBuffer * myBuffer
Definition: outputChannelManager.h:247
Definition: outputChannelManager.h:29
Definition: rwTemplatedList.h:34
#define DT_DLL_vrfutil
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfutilDefines.h:34
DtOutputStreamBuffer * buffer
Definition: outputChannelManager.h:127
std::map< DtString, StreamVector > ChannelMap
Definition: outputChannelManager.h:141
DtOutputStream * stream
Definition: outputChannelManager.h:126
std::vector< DtPrinter * > myManagedPrinters
Definition: outputChannelManager.h:133
ChannelMap myChannelMap
Definition: outputChannelManager.h:142
DtChannelSpecificOutputStream(DtOutputStreamBuffer *b, int &globalThresholdRef, int threshold=1, DtPrinter *default_printer=0, const std::string &prefix="")
Definition: outputChannelManager.h:168
static DtChannelSpecificOutputStream * creator(DtOutputStreamBuffer *b, int &globalThresholdRef, int threshold=1, DtPrinter *default_printer=0, const std::string &prefix="")
Definition: outputChannelManager.h:238
std::unique_ptr< DtOutputStream > myNullStream
Definition: outputChannelManager.h:147

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)