VR-Forces 5.0.3 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 
19 
24 {
25 public:
26 
28  {
29  ChannelSettings( int nl = DtNlInfo, const DtString& p = "", bool enabled = false )
30  : notifyLevel( nl )
31  , prefix( p )
32  , enabled( enabled )
33  {
34  }
35 
38  bool enabled;
39 
40  };
41 
42  typedef DtChannelSpecificOutputStream* (*DtOutputChannelStreamCreatorFcn)(
43  DtOutputStreamBuffer*, int&, int, DtPrinter*, const std::string& );
44 
45  typedef DtOutputStreamBuffer* (*DtOutputStreamBufferCreatorFcn)();
46 
47 public:
48 
49  DtOutputChannelManager( int& globalNotifyReference );
50 
51  virtual ~DtOutputChannelManager();
52 
54  virtual void addPrinter( DtPrinter* printer );
55 
57  virtual void addAndManagePrinter( DtPrinter* printer );
58 
61  virtual void removePrinter( DtPrinter* printer );
62 
66  virtual DtOutputStream& printError( const DtString& channel = "" );
67  virtual DtOutputStream& printWarn( const DtString& channel = "" );
68  virtual DtOutputStream& printInfo( const DtString& channel = "" );
69  virtual DtOutputStream& printVerbose( const DtString& channel = "" );
70  virtual DtOutputStream& printDebug( const DtString& channel = "" );
71 
72  virtual void setChannelSettings( const DtRwChannelDescriptorList& settings );
73 
74  virtual int channelNotifyLevel( const DtString& channel );
75  virtual void setChannelNotifyLevel( const DtString& channel, int level );
76 
77  virtual DtString channelPrefix( const DtString& channel );
78  virtual void setChannelPrefix( const DtString& channel,
79  const DtString& prefix );
80 
81  virtual bool channelEnabled( const DtString& channel );
82  virtual void setChannelEnabled( const DtString& channel,
83  bool enabled );
84 
85  virtual void addDefaultStream( int notifyLevel, DtOutputStream& stream );
86 
87  virtual DtOutputStream& defaultStream( int notifyLevel );
88 
90  virtual void printStatus( const DtString& channel = "" );
91 
92  virtual DtString channelStatus( const DtString& channel );
93 
94  virtual void setStreamCreatorFcn( DtOutputChannelStreamCreatorFcn fcn );
95 
96  virtual void setStreamBufferCreatorFcn( DtOutputStreamBufferCreatorFcn fcn );
97 
98  virtual DtOutputStreamBuffer* createStreamBuffer();
99 
100  virtual void setManageDefaultStreams( bool manage );
101 
102  virtual std::vector<DtString> allChannels() const;
103 
104 protected:
105 
106  virtual DtOutputStream& streamForChannel( const DtString& channel, int notifyLevel );
107 
108  virtual DtChannelSpecificOutputStream* createStream( int& globalThresholdRef, int threshold = 1,
109  DtPrinter* default_printer = 0, const std::string& prefix = "" );
110 
111  virtual void attachToAllStreams( DtPrinter* printer );
112  virtual void detachFromAllStreams( DtPrinter* printer );
113 
114  virtual ChannelSettings* channelSettings( const DtString& channel );
115 
116  virtual void addAllPrinters( DtOutputStream* stream );
117 
118 protected:
119 
121  {
122  explicit DefaultStreamInfo( DtOutputStream* stream = 0, DtOutputStreamBuffer* buffer = 0 );
123 
124  DtOutputStream* stream;
125  DtOutputStreamBuffer* buffer;
126  };
127 
128 protected:
129 
130  std::vector<DtPrinter*> myPrinters;
131  std::vector<DtPrinter*> myManagedPrinters;
132 
133  typedef std::map<DtString,ChannelSettings*> ChannelSettingsMap;
135 
137 
138  typedef std::vector<DtChannelSpecificOutputStream*> StreamVector;
139  typedef std::map<DtString,StreamVector> ChannelMap;
141 
142  std::vector<DefaultStreamInfo> myDefaultStreams;
143 
144  DtOutputStreamBuffer myNullStreamBuffer;
145  std::auto_ptr<DtOutputStream> myNullStream;
146 
147  DtOutputChannelStreamCreatorFcn myStreamCreatorFcn;
148  DtOutputStreamBufferCreatorFcn myStreamBufferCreatorFcn;
149 
151 
152  //locked when accessing/modifying internal maps to allow streams to be
153  //accessed from different threads concurrently.
154  mutable tbb::spin_mutex myMutex;
155 
156 };
157 
158 
159 class DtChannelSpecificOutputStream : public DtOutputStream
160 #ifdef DtObjectDebugger_Enable
161  , public DtObjectDebugger<DtChannelSpecificOutputStream>
162 #endif
163 {
164 public:
165 
166  DtChannelSpecificOutputStream( DtOutputStreamBuffer* b, int& globalThresholdRef, int threshold = 1,
167  DtPrinter* default_printer = 0, const std::string& prefix = "" )
168  : DtOutputStream( b, globalThresholdRef, threshold, default_printer )
169  , myPrefix( prefix )
170  , myBuffer( b )
171  {
172  }
173 
175  {
176  }
177 
178  virtual void write( const std::string &str )
179  {
180  if ( myPrefix != "" && str != "" )
181  {
182  DtOutputStream::write( std::string("[") + myPrefix + "]: " + str );
183  }
184  else //if (str != "")
185  {
186  DtOutputStream::write( str );
187  }
188  }
189 
190  virtual void setPrefix( const DtString& str )
191  {
192  myPrefix = str.c_str();
193  }
194 
195  DtOutputStreamBuffer* getBuffer()
196  {
197  return myBuffer;
198  }
199 
200  static DtChannelSpecificOutputStream* creator( DtOutputStreamBuffer* b, int& globalThresholdRef, int threshold = 1,
201  DtPrinter* default_printer = 0, const std::string& prefix = "" )
202  {
203  return new DtChannelSpecificOutputStream( b, globalThresholdRef, threshold, default_printer, prefix );
204  }
205 
206 protected:
207 
208  std::string myPrefix;
209  DtOutputStreamBuffer* myBuffer;
210 
211 };
212 
213 
bool enabled
Definition: outputChannelManager.h:38
DtOutputStreamBuffer * getBuffer()
Definition: outputChannelManager.h:195
ChannelSettings(int nl=DtNlInfo, const DtString &p="", bool enabled=false)
Definition: outputChannelManager.h:29
virtual ~DtChannelSpecificOutputStream()
Definition: outputChannelManager.h:174
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:144
std::vector< DefaultStreamInfo > myDefaultStreams
Definition: outputChannelManager.h:142
int notifyLevel
Definition: outputChannelManager.h:36
ChannelSettingsMap myChannelSettingsMap
Definition: outputChannelManager.h:134
#define DT_DEFINE_OBJECT_DEBUGGER_NAME(type)
Definition: objectCounter.h:265
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
Default on in debug, off in release.
Definition: objectCounter.h:31
std::map< DtString, ChannelSettings * > ChannelSettingsMap
Definition: outputChannelManager.h:133
std::vector< DtPrinter * > myPrinters
Definition: outputChannelManager.h:130
Definition: outputChannelManager.h:159
tbb::spin_mutex myMutex
Definition: outputChannelManager.h:154
virtual void setPrefix(const DtString &str)
Definition: outputChannelManager.h:190
The DtOutputChannelManager class manages default streams and channel-specific streams by notify level...
Definition: outputChannelManager.h:23
std::string myPrefix
Definition: outputChannelManager.h:208
std::vector< DtChannelSpecificOutputStream * > StreamVector
Definition: outputChannelManager.h:138
Definition: outputChannelManager.h:120
DtOutputStreamBufferCreatorFcn myStreamBufferCreatorFcn
Definition: outputChannelManager.h:148
virtual void write(const std::string &str)
Definition: outputChannelManager.h:178
DtString prefix
Definition: outputChannelManager.h:37
bool myManageDefaultStreams
Definition: outputChannelManager.h:150
DtOutputChannelStreamCreatorFcn myStreamCreatorFcn
Definition: outputChannelManager.h:147
int & myGlobalNotifyReference
Definition: outputChannelManager.h:136
std::auto_ptr< DtOutputStream > myNullStream
Definition: outputChannelManager.h:145
voidpf stream
Definition: ioapi.h:39
DtOutputStreamBuffer * myBuffer
Definition: outputChannelManager.h:209
Definition: outputChannelManager.h:27
A version of DtRwList that contains a homogeneous list of a templated RW type. The templated type spe...
Definition: rwTemplatedList.h:26
#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:125
std::map< DtString, StreamVector > ChannelMap
Definition: outputChannelManager.h:139
DtOutputStream * stream
Definition: outputChannelManager.h:124
std::vector< DtPrinter * > myManagedPrinters
Definition: outputChannelManager.h:131
ChannelMap myChannelMap
Definition: outputChannelManager.h:140
DtChannelSpecificOutputStream(DtOutputStreamBuffer *b, int &globalThresholdRef, int threshold=1, DtPrinter *default_printer=0, const std::string &prefix="")
Definition: outputChannelManager.h:166
static DtChannelSpecificOutputStream * creator(DtOutputStreamBuffer *b, int &globalThresholdRef, int threshold=1, DtPrinter *default_printer=0, const std::string &prefix="")
Definition: outputChannelManager.h:200

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)