VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
13 #include "tbb/spin_mutex.h"
14 
16 
21 {
22 public:
23  DtOutputChannelManager(int& globalNotifyReference);
24  virtual ~DtOutputChannelManager();
25 
27  {
28  ChannelSettings(int nl = DtNlInfo, const DtString& p = "",
29  bool enabled = false)
30  : notifyLevel(nl)
31  , prefix(p)
32  , enabled(enabled)
33  {
34 
35  }
36 
39  bool enabled;
40  };
41 
43  virtual void addPrinter(DtPrinter* printer);
44 
46  virtual void addAndManagePrinter(DtPrinter* printer);
47 
50  virtual void removePrinter(DtPrinter* printer);
51 
55  virtual DtOutputStream& printError(const DtString& channel = "");
56  virtual DtOutputStream& printWarn(const DtString& channel = "");
57  virtual DtOutputStream& printInfo(const DtString& channel = "");
58  virtual DtOutputStream& printVerbose(const DtString& channel = "");
59  virtual DtOutputStream& printDebug(const DtString& channel = "");
60 
61  virtual void setChannelSettings(const DtRwChannelDescriptorList& settings);
62 
63  virtual int channelNotifyLevel(const DtString& channel);
64  virtual void setChannelNotifyLevel(const DtString& channel,
65  int level);
66 
67  virtual DtString channelPrefix(const DtString& channel);
68  virtual void setChannelPrefix(const DtString& channel,
69  const DtString& prefix);
70 
71  virtual bool channelEnabled(const DtString& channel);
72  virtual void setChannelEnabled(const DtString& channel,
73  bool enabled);
74 
75  virtual void addDefaultStream(int notifyLevel, DtOutputStream& stream);
76 
77  virtual DtOutputStream& defaultStream(int notifyLevel);
78 
80  virtual void printStatus(const DtString& channel = "");
81 
82  virtual DtString channelStatus(const DtString& channel);
83 
84  typedef DtChannelSpecificOutputStream* (*DtOutputChannelStreamCreatorFcn)(
85  DtOutputStreamBuffer*, int&, int, DtPrinter*, const std::string&);
86  virtual void setStreamCreatorFcn(DtOutputChannelStreamCreatorFcn fcn);
87 
88  typedef DtOutputStreamBuffer* (*DtOutputStreamBufferCreatorFcn)();
89  virtual void setStreamBufferCreatorFcn(DtOutputStreamBufferCreatorFcn fcn);
90 
91  virtual DtOutputStreamBuffer* createStreamBuffer();
92 
93  virtual void setManageDefaultStreams(bool manage);
94 
95  virtual std::vector<DtString> allChannels();
96 
97 protected:
98  virtual DtOutputStream& streamForChannel(const DtString& channel, int notifyLevel);
99 
100  virtual DtChannelSpecificOutputStream* createStream(DtOutputStreamBuffer *b,
101  int &globalThresholdRef, int threshold = 1, DtPrinter *dflt_printer = 0,
102  const std::string& prefix = "");
103 
104  virtual void attachToAllStreams(DtPrinter* printer);
105  virtual void detachFromAllStreams(DtPrinter* printer);
106 
107  virtual ChannelSettings* channelSettings(const DtString& channel);
108 
109  virtual void addAllPrinters(DtOutputStream* stream);
110 
111 protected:
112  std::vector<DtPrinter*> myPrinters;
113  std::vector<DtPrinter*> myManagedPrinters;
114 
115  typedef std::map<DtString, ChannelSettings*> ChannelSettingsMap;
117 
119 
120  typedef std::vector<DtChannelSpecificOutputStream*> StreamVector;
121  typedef std::map<DtString, StreamVector> ChannelMap;
123 
124  typedef std::map<DtOutputStream*, DtOutputStreamBuffer*> BufferMap;
126 
127  std::vector<DtOutputStream*> myDefaultStreams;
128  std::vector<DtOutputStreamBuffer*> myDefaultStreamBuffers;
129 
130  DtOutputStreamBuffer myNullStreamBuffer;
131  std::auto_ptr<DtOutputStream> myNullStream;
132 
133  DtOutputChannelStreamCreatorFcn myStreamCreatorFcn;
134  DtOutputStreamBufferCreatorFcn myStreamBufferCreatorFcn;
135 
137 
138  //locked when accessing/modifying internal maps to allow streams to be
139  //accessed from different threads concurrently.
140  tbb::spin_mutex myMutex;
141 };
142 
143 class DtChannelSpecificOutputStream : public DtOutputStream
144 {
145 public:
146  DtChannelSpecificOutputStream(DtOutputStreamBuffer *b,
147  int &globalThresholdRef,
148  int threshold = 1,
149  DtPrinter *dflt_printer = 0,
150  const std::string& prefix = "")
151  : DtOutputStream(b, globalThresholdRef, threshold, dflt_printer)
152  , myPrefix(prefix)
153  {
154 
155  }
156 
158 
159  virtual void write( const std::string &str )
160  {
161  if (myPrefix != "" && str != "")
162  {
163  DtOutputStream::write(std::string("[") + myPrefix + "]: " + str);
164  }
165  else //if (str != "")
166  {
168  }
169  }
170 
171  virtual void setPrefix(const DtString& str)
172  {
173  myPrefix = str.c_str();
174  }
175 
176  static DtChannelSpecificOutputStream* creator(DtOutputStreamBuffer *b,
177  int &globalThresholdRef,
178  int threshold = 1,
179  DtPrinter *dflt_printer = 0,
180  const std::string& prefix = "")
181  {
182  return new DtChannelSpecificOutputStream(b, globalThresholdRef,
183  threshold, dflt_printer, prefix);
184  }
185 
186 protected:
187  std::string myPrefix;
188 };

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)