VR-Forces 4.8 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  , public DtObjectDebugger<DtChannelSpecificOutputStream>
150 {
151 public:
153  DtOutputStreamBuffer *b,
154  int &globalThresholdRef,
155  int threshold = 1,
156  DtPrinter *dflt_printer = 0,
157  const std::string& prefix = "")
158  : DtOutputStream(b, globalThresholdRef, threshold, dflt_printer)
159  , myPrefix(prefix)
160  , myBuffer(b)
161  {
162  }
163 
165  {
166  };
167 
168  virtual void write( const std::string &str )
169  {
170  if (myPrefix != "" && str != "")
171  {
172  DtOutputStream::write(std::string("[") + myPrefix + "]: " + str);
173  }
174  else //if (str != "")
175  {
176  DtOutputStream::write(str);
177  }
178  }
179 
180  virtual void setPrefix(const DtString& str)
181  {
182  myPrefix = str.c_str();
183  }
184 
185  DtOutputStreamBuffer* getBuffer()
186  {
187  return myBuffer;
188  }
189 
191  DtOutputStreamBuffer *b,
192  int &globalThresholdRef,
193  int threshold = 1,
194  DtPrinter *dflt_printer = 0,
195  const std::string& prefix = "")
196  {
197  return new DtChannelSpecificOutputStream(b, globalThresholdRef,
198  threshold, dflt_printer, prefix);
199  }
200 
201 protected:
202  std::string myPrefix;
203  DtOutputStreamBuffer* myBuffer;
204 };
205 
bool enabled
Definition: outputChannelManager.h:40
DtOutputStreamBuffer * getBuffer()
Definition: outputChannelManager.h:185
ChannelSettings(int nl=DtNlInfo, const DtString &p="", bool enabled=false)
Definition: outputChannelManager.h:29
virtual ~DtChannelSpecificOutputStream()
Definition: outputChannelManager.h:164
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:180
The DtOutputChannelManager class manages default streams and channel-specific streams by notify level...
Definition: outputChannelManager.h:21
std::string myPrefix
Definition: outputChannelManager.h:202
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:168
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:203
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:190
#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:152

Document ID: Generated on Thu Aug 27 10:56:05 EDT 2020 from SVN revision 217100
Copyright © 2005-2020 MAK Technologies. All Rights Reserved (www.mak.com)