1 #ifndef H_CAN_THREADING_BASE 2 #define H_CAN_THREADING_BASE 5 #include <boost/thread/thread.hpp> 6 #include <boost/bind.hpp> 13 boost::condition_variable
cond_;
17 boost::mutex::scoped_lock lock(mutex_);
23 template<
typename InterfaceType>
StateWaiter(InterfaceType *interface){
24 state_ = interface->getState();
28 boost::mutex::scoped_lock cond_lock(mutex_);
29 boost::system_time abs_time = boost::get_system_time() + duration;
32 if(!cond_.timed_wait(cond_lock,abs_time))
41 template<
typename WrappedInterface>
class ThreadedInterface :
public WrappedInterface{
44 WrappedInterface::run();
47 virtual bool init(
const std::string &device,
bool loopback) {
48 if(!thread_ && WrappedInterface::init(device, loopback)){
53 return WrappedInterface::getState().isReady();
56 WrappedInterface::shutdown();
71 template<
typename T1,
typename T2>
ThreadedInterface(
const T1 &t1,
const T2 &t2): WrappedInterface(t1, t2) {}
boost::shared_ptr< boost::thread > thread_
virtual bool init(const std::string &device, bool loopback)
bool wait(const can::State::DriverState &s, const DurationType &duration)
boost::condition_variable cond_
StateWaiter(InterfaceType *interface)
ThreadedInterface(const T1 &t1)
StateListener::ListenerConstSharedPtr StateListenerConstSharedPtr
enum can::State::DriverState driver_state
virtual ~ThreadedInterface()
ThreadedInterface(const T1 &t1, const T2 &t2)
can::StateInterface::StateListenerConstSharedPtr state_listener_
void updateState(const can::State &s)