Libbarrett  1.2.4
include/barrett/log/real_time_writer.h
Go to the documentation of this file.
00001 
00033 #ifndef BARRETT_LOG_REAL_TIME_WRITER_H_
00034 #define BARRETT_LOG_REAL_TIME_WRITER_H_
00035 
00036 
00037 #include <boost/thread.hpp>
00038 
00039 #include <barrett/detail/ca_macro.h>
00040 #include <barrett/log/traits.h>
00041 #include <barrett/log/writer.h>
00042 
00043 
00044 namespace barrett {
00045 namespace log {
00046 
00047 
00048 // A log writer that is real-time safe. The data is double-buffered and is written to disk in a separate thread.
00049 template<typename T, typename Traits = Traits<T> >
00050 class RealTimeWriter : public Writer<T, Traits> {
00051 public:
00052         typedef typename Writer<T, Traits>::parameter_type parameter_type;
00053         static const int DEFAULT_PRIORITY = 20;
00054 
00055         RealTimeWriter(const char* fileName, double recordPeriod_s, int priority_ = DEFAULT_PRIORITY);
00056         RealTimeWriter(const char* fileName, double approxPeriod_s, size_t recordsInSingleBuffer, int priority_ = DEFAULT_PRIORITY);
00057         ~RealTimeWriter();
00058 
00059         void putRecord(parameter_type data);
00060         void close();
00061 
00062 protected:
00063         void init(size_t recordsInSingleBuffer);
00064         void writeToDiskEntryPoint();
00065 
00066         double period;
00067         size_t singleBufferSize;
00068         char* inBuff;
00069         char* outBuff;
00070         char* endInBuff;
00071         char* endOutBuff;
00072         char* currentPos;
00073         bool writeToDisk;
00074 
00075         boost::thread thread;
00076         int priority;
00077 
00078 private:
00079         DISALLOW_COPY_AND_ASSIGN(RealTimeWriter);
00080 };
00081 
00082 
00083 }
00084 }
00085 
00086 
00087 // include template definitions
00088 #include <barrett/log/detail/real_time_writer-inl.h>
00089 
00090 
00091 #endif /* BARRETT_LOG_REAL_TIME_WRITER_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines