LRAUV  revA
LogWriter.h
Go to the documentation of this file.
1 
10 #ifndef LOGWRITER_H_
11 #define LOGWRITER_H_
12 
13 #include "LogEntry.h"
14 #include "utils/AuvMath.h"
15 #include "utils/FlexArray.h"
16 #include "utils/Mutex.h"
17 
18 class OutStream;
19 class Unit;
20 
25 class LogWriter
26 {
27 public:
28 
30  {
31  NO_SERVICE = -1,
39  };
40 
41  static ServiceType Str2ServiceType( const char* const serviceTypeStr, int len = -1 );
42 
43  static const char* ServiceType2Str( LogWriter::ServiceType serviceType );
44 
45  static size_t ServiceType2Strlen( LogWriter::ServiceType serviceType );
46 
47  static const char* const SERVICE_TYPE_STRS[SERVICE_COUNT];
48 
49  static size_t const SERVICE_TYPE_STRLEN[SERVICE_COUNT];
50 
52  virtual ~LogWriter();
53 
55  virtual unsigned int writeHeader()
56  {
57  return 0;
58  }
59 
61  virtual void setOutStream( OutStream& outStream );
62 
64  virtual bool isValid();
65 
67  virtual unsigned int write( const LogEntry* entry, const Unit* unit = NULL ) = 0;
68 
70  virtual void endCycle() {}
71 
73  virtual unsigned int writeFooter()
74  {
75  return 0;
76  }
77 
79  virtual void config( Logger& logger ) {}
80 
82  virtual void resetInputs() {}
83 
84  void addParent()
85  {
86  ++parentCount_;
87  }
88 
89  void removeParent()
90  {
91  --parentCount_;
92  }
93 
95  {
96  return parentCount_;
97  }
98 
99  virtual void activate()
100  {
101  active_ = true;
102  }
103 
104  virtual void deactivate()
105  {
106  active_ = false;
107  }
108 
109  virtual bool isActive()
110  {
111  return active_;
112  }
113 
114  virtual void lockWrites()
115  {
116  writeMutex_.lock();
117  }
118 
119  virtual void unlockWrites()
120  {
122  }
123 
124 protected:
125 
127  LogWriter();
128 
130  LogWriter( OutStream& outStream );
131 
134 
136 
138 
140 
142 
143  bool active_;
144 
145 private:
146  // Note that the copy constructor below is private and not given a body.
147  // Any attempt to call it will return a compiler error.
148  LogWriter( const LogWriter& old ); // disallow copy constructor
149 
150 };
151 
152 #endif /*LOGWRITER_H_*/
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
Definition: LogWriter.h:34
void removeParent()
Definition: LogWriter.h:89
Base class for a generalized set of "log data destinations," including to files (text or binary)...
Definition: LogWriter.h:25
static const char * ServiceType2Str(LogWriter::ServiceType serviceType)
Definition: LogWriter.cpp:68
virtual void resetInputs()
Reset cached input settings.
Definition: LogWriter.h:82
void addParent()
Definition: LogWriter.h:84
int getParentCount()
Definition: LogWriter.h:94
OutStream * logStream_
Stores an OutStream.
Definition: LogWriter.h:133
virtual void endCycle()
Do what needs to be done at the end of the cycle.
Definition: LogWriter.h:70
int unlock()
Unlock the mutex.
Definition: Mutex.cpp:51
A simple pthread Mutex abstraction.
Definition: Mutex.h:20
virtual void config(Logger &logger)
Configure from a config file.
Definition: LogWriter.h:79
bool wroteHeader_
Definition: LogWriter.h:135
virtual unsigned int write(const LogEntry *entry, const Unit *unit=NULL)=0
Write the given LogEntry - should lock the writeMutex_.
virtual void deactivate()
Definition: LogWriter.h:104
Definition: LogWriter.h:37
One "entry" in a LogQueue.
Definition: LogEntry.h:33
Definition: LogWriter.h:33
Contains the FlexArrayBase and FlexArray class declarations.
Definition: LogWriter.h:38
Contains the AuvMath class declaration.
ServiceType
Definition: LogWriter.h:29
Definition: LogWriter.h:36
virtual bool isValid()
Return true if logStream_ is available.
Definition: LogWriter.cpp:115
Contains the LogEntry class definition.
Definition: LogWriter.h:32
Definition: LogWriter.h:31
virtual bool isActive()
Definition: LogWriter.h:109
Mutex writeMutex_
Definition: LogWriter.h:139
virtual void lockWrites()
Definition: LogWriter.h:114
static size_t ServiceType2Strlen(LogWriter::ServiceType serviceType)
Definition: LogWriter.cpp:77
LogWriter()
Protected constructor for pure virtual class.
Definition: LogWriter.cpp:88
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
static const char *const SERVICE_TYPE_STRS[SERVICE_COUNT]
Definition: LogWriter.h:47
virtual unsigned int writeHeader()
Write the log header, if any.
Definition: LogWriter.h:55
static size_t const SERVICE_TYPE_STRLEN[SERVICE_COUNT]
Definition: LogWriter.h:49
static ServiceType Str2ServiceType(const char *const serviceTypeStr, int len=-1)
Definition: LogWriter.cpp:32
int parentCount_
Definition: LogWriter.h:141
virtual void unlockWrites()
Definition: LogWriter.h:119
bool wroteFooter_
Definition: LogWriter.h:137
This is a very abstract class that can be implemented by classes that want to send stream output...
Definition: OutStream.h:41
virtual ~LogWriter()
Destructor.
Definition: LogWriter.cpp:106
bool active_
Definition: LogWriter.h:143
virtual void setOutStream(OutStream &outStream)
Sets the OutStream.
Definition: LogWriter.cpp:121
virtual void activate()
Definition: LogWriter.h:99
int lock()
Lock the mutex.
Definition: Mutex.cpp:34
Code that represents an engineering unit.
Definition: Unit.h:24
Definition: LogWriter.h:35
virtual unsigned int writeFooter()
Write the log footer, if any.
Definition: LogWriter.h:73