36 #ifndef __DRIVER_BASE__DRIVER_H__ 37 #define __DRIVER_BASE__DRIVER_H__ 40 #include <boost/function.hpp> 41 #include <boost/thread/recursive_mutex.hpp> 42 #include <boost/thread/mutex.hpp> 96 virtual std::string
getID() = 0;
106 boost::recursive_mutex::scoped_lock lock(mutex_);
119 boost::recursive_mutex::scoped_lock lock(mutex_);
142 boost::recursive_mutex::scoped_lock lock(mutex_);
231 static const std::string names[4] = {
232 std::string(
"CLOSED"),
233 std::string(
"OPENED"),
234 std::string(
"RUNNING"),
235 std::string(
"Unknown")
238 if (s >= 0 && s <= 2)
239 return names[(int) s];
244 Driver() : state_(CLOSED), status_ok_(false), status_recovery_complete_(false) {}
259 status_recovery_complete_ =
false;
264 boost::mutex::scoped_lock lock_(status_message_mutex_);
271 void setStatusMessage(
const std::string &msg,
bool ok =
false,
bool recovery_complete =
false)
273 boost::mutex::scoped_lock lock_(status_message_mutex_);
275 status_message_ = msg;
277 status_recovery_complete_ |= recovery_complete;
284 va_start(va, format);
285 if (vsnprintf(buff,
sizeof(buff), format, va) >= (
int)
sizeof(buff))
286 ROS_DEBUG(
"Really long string in Driver::setStatusMessagef, it was trunccated.");
294 static const std::string
open = std::string(
"open");
295 static const std::string
close = std::string(
"close");
296 static const std::string
start = std::string(
"start");
297 static const std::string
stop = std::string(
"stop");
298 static const std::string unknown = std::string(
"Unknown");
314 boost::recursive_mutex::scoped_lock lock_(mutex_);
319 (this->*transition)();
327 bool out = state_ == target;
bool getRecoveryComplete()
void clearRecoveryComplete()
static const state_t CLOSED
static const state_t RUNNING
static const std::string & getStateName(state_t s)
bool status_recovery_complete_
std::string status_message_
hookFunction postOpenHook
void setPostOpenHook(hookFunction f)
const std::string getStatusMessage()
bool raiseState(state_t target)
void setStatusMessagef(const char *format,...)
bool lowerState(state_t target)
bool tryTransition(state_t target, void(Driver::*transition)())
const std::string getStateName()
const std::string & getTransitionName(void(Driver::*transition)())
boost::function< void() > hookFunction
bool goState(state_t target)
boost::recursive_mutex mutex_
void setStatusMessage(const std::string &msg, bool ok=false, bool recovery_complete=false)
boost::mutex status_message_mutex_
static const state_t OPENED
virtual std::string getID()=0