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

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)