1 #ifndef H_CAN_BUFFERED_READER 2 #define H_CAN_BUFFERED_READER 7 #include <boost/thread/mutex.hpp> 8 #include <boost/thread/condition_variable.hpp> 9 #include <boost/chrono.hpp> 16 boost::condition_variable
cond_;
24 LOG(
"buffer overflow, discarded oldest message " );
30 boost::mutex::scoped_lock lock(mutex_);
32 buffer_.push_back(msg);
36 LOG(
"discarded message " );
52 boost::mutex::scoped_lock lock(mutex_);
56 boost::mutex::scoped_lock lock(mutex_);
61 boost::mutex::scoped_lock lock(mutex_);
65 boost::mutex::scoped_lock lock(mutex_);
71 boost::mutex::scoped_lock lock(mutex_);
76 boost::mutex::scoped_lock lock(mutex_);
81 boost::mutex::scoped_lock lock(mutex_);
86 boost::mutex::scoped_lock lock(mutex_);
91 template<
typename DurationType>
bool read(
can::Frame * msg,
const DurationType &duration){
92 return readUntil(msg, boost::chrono::high_resolution_clock::now() + duration);
95 boost::mutex::scoped_lock lock(mutex_);
97 while(buffer_.empty() && cond_.wait_until(lock,abs_time) != boost::cv_status::timeout)
105 *msg = buffer_.front();
void listen(CommInterfaceSharedPtr interface, const Frame::Header &h)
void listen(CommInterfaceSharedPtr interface)
bool readUntil(can::Frame *msg, boost::chrono::high_resolution_clock::time_point abs_time)
ScopedEnabler(BufferedReader &reader)
void setMaxLen(size_t max_len)
boost::shared_ptr< CommInterface > CommInterfaceSharedPtr
void handleFrame(const can::Frame &msg)
CommInterface::FrameListenerConstSharedPtr listener_
bool read(can::Frame *msg, const DurationType &duration)
bool setEnabled(bool enabled)
BufferedReader(bool enable, size_t max_len=0)
std::deque< can::Frame > buffer_
FrameListener::ListenerConstSharedPtr FrameListenerConstSharedPtr
boost::condition_variable cond_