Commit bcb3ca77 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by olivier stasse

Enhance interface of RealTimeLogger and RTLoggerStream

parent 133c8819
......@@ -7,12 +7,10 @@
#include <sstream>
#include <vector>
#include <boost/circular_buffer.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <dynamic-graph/config.hh>
#include <dynamic-graph/debug.h>
namespace dynamicgraph {
/// \ingroup debug
......@@ -50,22 +48,30 @@ class RealTimeLogger;
/// This class is only used by RealTimeLogger.
class RTLoggerStream {
public:
RTLoggerStream(RealTimeLogger *logger, std::ostream &os)
: logger_(logger), os_(os) {}
inline RTLoggerStream(RealTimeLogger *logger, std::ostream &os)
: ok_(logger!=NULL), logger_(logger), os_(os) {}
template <typename T> inline RTLoggerStream &operator<<(T t) {
if (logger_ != NULL)
os_ << t;
if (ok_) os_ << t;
return *this;
}
inline RTLoggerStream &operator<<(std::ostream &(*pf)(std::ostream &)) {
if (logger_ != NULL)
os_ << pf;
if (ok_) os_ << pf;
return *this;
}
~RTLoggerStream();
inline ~RTLoggerStream() {
if (ok_) {
os_ << std::ends;
logger_->frontReady();
}
}
inline bool isNull() {
return !ok_;
}
private:
const bool ok_;
RealTimeLogger *logger_;
std::ostream &os_;
};
......@@ -119,6 +125,11 @@ public:
/// The message is considered finished when the object is destroyed.
RTLoggerStream front();
/// Return an empty stream object.
RTLoggerStream emptyStream() {
return RTLoggerStream(NULL, oss_);
}
inline void frontReady() {
backIdx_ = (backIdx_ + 1) % buffer_.size();
wmutex.unlock();
......
......@@ -59,12 +59,6 @@ RTLoggerStream RealTimeLogger::front() {
return RTLoggerStream(this, oss_);
}
RTLoggerStream::~RTLoggerStream() {
os_ << std::ends;
if (logger_ != NULL)
logger_->frontReady();
}
struct RealTimeLogger::thread {
bool requestShutdown_;
int threadPolicy_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment