46 #define CONNECTION_DEBUG(fmt, ...) \
47 ROS_DEBUG_NAMED("ConnectionMonitor", fmt, ## __VA_ARGS__)
49 #define CONNECTION_WARN(fmt, ...) \
50 ROS_WARN_NAMED("ConnectionMonitor", fmt, ## __VA_ARGS__)
55 : feedback_sub_(feedback_sub), result_sub_(result_sub)
64 boost::recursive_mutex::scoped_lock lock(data_mutex_);
73 "goalConnectCallback: Trying to add [%s] to goalSubscribers, but it is already in the goalSubscribers list",
79 check_connection_condition_.notify_all();
84 boost::recursive_mutex::scoped_lock lock(data_mutex_);
86 std::map<std::string, size_t>::iterator it;
89 if (it == goalSubscribers_.end()) {
91 "goalDisconnectCallback: Trying to remove [%s] to goalSubscribers, but it is not in the goalSubscribers list",
94 CONNECTION_DEBUG(
"goalDisconnectCallback: Removing [%s] from goalSubscribers",
98 goalSubscribers_.erase(it);
106 boost::recursive_mutex::scoped_lock lock(data_mutex_);
107 std::ostringstream ss;
108 ss <<
"Goal Subscribers (" << goalSubscribers_.size() <<
" total)";
109 for (std::map<std::string, size_t>::iterator it = goalSubscribers_.begin();
110 it != goalSubscribers_.end(); it++)
112 ss <<
"\n - " << it->first;
121 boost::recursive_mutex::scoped_lock lock(data_mutex_);
124 if (cancelSubscribers_.find(pub.
getSubscriberName()) == cancelSubscribers_.end()) {
130 "cancelConnectCallback: Trying to add [%s] to cancelSubscribers, but it is already in the cancelSubscribers list",
136 check_connection_condition_.notify_all();
142 boost::recursive_mutex::scoped_lock lock(data_mutex_);
144 std::map<std::string, size_t>::iterator it;
147 if (it == cancelSubscribers_.end()) {
149 "cancelDisconnectCallback: Trying to remove [%s] to cancelSubscribers, but it is not in the cancelSubscribers list",
152 CONNECTION_DEBUG(
"cancelDisconnectCallback: Removing [%s] from cancelSubscribers",
156 cancelSubscribers_.erase(it);
164 boost::recursive_mutex::scoped_lock lock(data_mutex_);
166 std::ostringstream ss;
167 ss <<
"cancel Subscribers (" << cancelSubscribers_.size() <<
" total)";
168 for (std::map<std::string, size_t>::iterator it = cancelSubscribers_.begin();
169 it != cancelSubscribers_.end(); it++)
171 ss <<
"\n - " << it->first;
178 const actionlib_msgs::GoalStatusArrayConstPtr & status,
const std::string & cur_status_caller_id)
180 boost::recursive_mutex::scoped_lock lock(data_mutex_);
182 if (status_received_) {
183 if (status_caller_id_ != cur_status_caller_id) {
185 "processStatus: Previously received status from [%s], but we now received status from [%s]. Did the ActionServer change?",
186 status_caller_id_.c_str(), cur_status_caller_id.c_str());
187 status_caller_id_ = cur_status_caller_id;
189 latest_status_time_ = status->header.stamp;
192 "processStatus: Just got our first status message from the ActionServer at node [%s]",
193 cur_status_caller_id.c_str());
194 status_received_ =
true;
195 status_caller_id_ = cur_status_caller_id;
196 latest_status_time_ = status->header.stamp;
199 check_connection_condition_.notify_all();
205 boost::recursive_mutex::scoped_lock lock(data_mutex_);
207 if (!status_received_) {
208 CONNECTION_DEBUG(
"isServerConnected: Didn't receive status yet, so not connected yet");
212 if (goalSubscribers_.find(status_caller_id_) == goalSubscribers_.end()) {
214 "isServerConnected: Server [%s] has not yet subscribed to the goal topic, so not connected yet",
215 status_caller_id_.c_str());
220 if (cancelSubscribers_.find(status_caller_id_) == cancelSubscribers_.end()) {
222 "isServerConnected: Server [%s] has not yet subscribed to the cancel topic, so not connected yet",
223 status_caller_id_.c_str());
228 if (feedback_sub_.getNumPublishers() == 0) {
230 "isServerConnected: Client has not yet connected to feedback topic of server [%s]",
231 status_caller_id_.c_str());
235 if (result_sub_.getNumPublishers() == 0) {
237 "isServerConnected: Client has not yet connected to result topic of server [%s]",
238 status_caller_id_.c_str());
242 CONNECTION_DEBUG(
"isServerConnected: Server [%s] is fully connected", status_caller_id_.c_str());
250 ROS_ERROR_NAMED(
"actionlib",
"Timeouts can't be negative. Timeout is [%.2fs]", timeout.
toSec());
255 boost::recursive_mutex::scoped_lock lock(data_mutex_);
257 if (isServerConnected()) {
264 while (nh.
ok() && !isServerConnected()) {
275 time_left = loop_period;
278 check_connection_condition_.timed_wait(lock,
279 boost::posix_time::milliseconds(
static_cast<int64_t
>(time_left.
toSec() * 1000.0f)));
282 return isServerConnected();