Go to the documentation of this file.
33 #include <boost/thread/thread_time.hpp>
34 #include <boost/date_time/posix_time/posix_time_types.hpp>
39 #include <uuid/uuid.h>
54 UuidToStringA(&uuid, &str);
55 std::string return_string(
reinterpret_cast<char *
>(str));
60 uuid_generate_random(uuid);
62 uuid_unparse(uuid, uuid_str);
63 return std::string(uuid_str);
67 Bond::Bond(
const std::string &topic,
const std::string &
id,
68 boost::function<
void(
void)> on_broken,
69 boost::function<
void(
void)> on_formed)
77 on_broken_(on_broken),
78 on_formed_(on_formed),
79 sisterDiedFirst_(false),
82 connect_timer_(
ros::WallDuration(),
boost::bind(&
Bond::onConnectTimeout, this)),
83 heartbeat_timer_(
ros::WallDuration(),
boost::bind(&
Bond::onHeartbeatTimeout, this)),
84 disconnect_timer_(
ros::WallDuration(),
boost::bind(&
Bond::onDisconnectTimeout, this))
115 boost::mutex::scoped_lock lock(
mutex_);
123 ROS_ERROR(
"Cannot set timeouts after calling start()");
134 ROS_ERROR(
"Cannot set timeouts after calling start()");
145 ROS_ERROR(
"Cannot set timeouts after calling start()");
156 ROS_ERROR(
"Cannot set timeouts after calling start()");
166 ROS_ERROR(
"Cannot set callback queue after calling start()");
176 boost::mutex::scoped_lock lock(
mutex_);
188 boost::mutex::scoped_lock lock(
mutex_);
194 boost::mutex::scoped_lock lock(
mutex_);
204 boost::mutex::scoped_lock lock(
mutex_);
222 static_cast<int64_t
>(wait_time.
toSec() * 1000.0f)));
233 boost::mutex::scoped_lock lock(
mutex_);
251 static_cast<int64_t
>(wait_time.
toSec() * 1000.0f)));
258 boost::mutex::scoped_lock lock(
mutex_);
265 boost::mutex::scoped_lock lock(
mutex_);
278 boost::mutex::scoped_lock lock(
mutex_);
286 bool disable_heartbeat_timeout;
287 nh_.
param(bond::Constants::DISABLE_HEARTBEAT_TIMEOUT_PARAM, disable_heartbeat_timeout,
false);
288 if (disable_heartbeat_timeout) {
289 ROS_WARN(
"Heartbeat timeout is disabled. Not breaking bond (topic: %s, id: %s)",
295 boost::mutex::scoped_lock lock(
mutex_);
303 boost::mutex::scoped_lock lock(
mutex_);
314 boost::mutex::scoped_lock lock(
mutex_);
321 "More than two locations are trying to use a single bond (topic: %s, id: %s). "
322 "You should only instantiate at most two bond instances for each (topic, id) pair.",
344 boost::mutex::scoped_lock lock(
mutex_);
357 bond::Status::Ptr msg(
new bond::Status);
361 msg->active = active;
370 std::vector<boost::function<void(
void)> > callbacks;
372 boost::mutex::scoped_lock lock(
mutex_);
377 for (
size_t i = 0; i < callbacks.size(); ++i) {
void doPublishing(const ros::SteadyTimerEvent &e)
void setDuration(const ros::Duration &d)
void setPeriod(const WallDuration &period, bool reset=true)
void setHeartbeatTimeout(double dur)
void start()
Starts the bond and connects to the sister process.
std::vector< boost::function< void(void)> > pending_callbacks_
void breakBond()
Breaks the bond, notifying the other process.
void setCallbackQueue(ros::CallbackQueueInterface *queue)
void publishStatus(bool active)
double disconnect_timeout_
static SM_AwaitSisterDeath AwaitSisterDeath
void publish(const boost::shared_ptr< M > &message) const
Publisher advertise(AdvertiseOptions &ops)
boost::function< void(void)> on_broken_
void setHeartbeatPeriod(double dur)
static std::string makeUUID()
~Bond()
Destructs the object, breaking the bond if it is still formed.
void onHeartbeatTimeout()
double heartbeat_timeout_
static SM_WaitingForSister WaitingForSister
void setBrokenCallback(boost::function< void(void)> on_broken)
Sets the broken callback.
Forms a bond to monitor another process.
void setDisconnectTimeout(double dur)
boost::function< void(void)> on_formed_
void bondStatusCB(const bond::Status::ConstPtr &msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
void onDisconnectTimeout()
void flushPendingCallbacks()
bool isBroken()
Indicates if the bond is broken.
void setCallbackQueue(CallbackQueueInterface *queue)
void setFormedCallback(boost::function< void(void)> on_formed)
Sets the formed callback.
Bond(const std::string &topic, const std::string &id, boost::function< void(void)> on_broken=boost::function< void(void)>(), boost::function< void(void)> on_formed=boost::function< void(void)>())
Constructs a bond, but does not connect.
SteadyTimer createSteadyTimer(SteadyTimerOptions &ops) const
bool waitUntilFormed(ros::Duration timeout=ros::Duration(-1))
Blocks until the bond is formed for at most 'duration'.
T param(const std::string ¶m_name, const T &default_val) const
Timeout disconnect_timer_
std::string sister_instance_id_
bool waitUntilBroken(ros::Duration timeout=ros::Duration(-1))
Blocks until the bond is broken for at most 'duration'.
BondSMState & getState() const
boost::condition condition_
ros::SteadyTimer publishingTimer_
void setConnectTimeout(double dur)
bondcpp
Author(s): Stuart Glaser
autogenerated on Tue Mar 1 2022 23:53:37