37 #ifndef ACTIONLIB__SERVER__SERVER_GOAL_HANDLE_IMP_H_
38 #define ACTIONLIB__SERVER__SERVER_GOAL_HANDLE_IMP_H_
47 template<
class ActionSpec>
51 template<
class ActionSpec>
52 ServerGoalHandle<ActionSpec>::ServerGoalHandle(
const ServerGoalHandle & gh)
53 : status_it_(gh.status_it_), goal_(gh.goal_), as_(gh.as_), handle_tracker_(gh.handle_tracker_),
56 template<
class ActionSpec>
57 void ServerGoalHandle<ActionSpec>::setAccepted(
const std::string & text)
61 "You are attempting to call methods on an uninitialized goal handle");
66 DestructionGuard::ScopedProtector protector(*guard_);
67 if (!protector.isProtected()) {
69 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
74 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
76 boost::recursive_mutex::scoped_lock lock(as_->lock_);
77 unsigned int status = (*status_it_).status_.status;
80 if (status == actionlib_msgs::GoalStatus::PENDING) {
81 (*status_it_).status_.status = actionlib_msgs::GoalStatus::ACTIVE;
82 (*status_it_).status_.text = text;
84 }
else if (status == actionlib_msgs::GoalStatus::RECALLING) {
86 (*status_it_).status_.status = actionlib_msgs::GoalStatus::PREEMPTING;
87 (*status_it_).status_.text = text;
91 "To transition to an active state, the goal must be in a pending or recalling state, it is currently in state: %d",
92 (*status_it_).status_.status);
95 ROS_ERROR_NAMED(
"actionlib",
"Attempt to set status on an uninitialized ServerGoalHandle");
99 template<
class ActionSpec>
100 void ServerGoalHandle<ActionSpec>::setCanceled(
const Result & result,
const std::string & text)
102 if (as_ ==
nullptr) {
104 "You are attempting to call methods on an uninitialized goal handle");
109 DestructionGuard::ScopedProtector protector(*guard_);
110 if (!protector.isProtected()) {
112 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
116 ROS_DEBUG_NAMED(
"actionlib",
"Setting status to canceled on goal, id: %s, stamp: %.2f",
117 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
119 boost::recursive_mutex::scoped_lock lock(as_->lock_);
120 unsigned int status = (*status_it_).status_.status;
121 if (status == actionlib_msgs::GoalStatus::PENDING ||
122 status == actionlib_msgs::GoalStatus::RECALLING)
124 (*status_it_).status_.status = actionlib_msgs::GoalStatus::RECALLED;
125 (*status_it_).status_.text = text;
126 as_->publishResult((*status_it_).status_, result);
127 }
else if (status == actionlib_msgs::GoalStatus::ACTIVE ||
128 status == actionlib_msgs::GoalStatus::PREEMPTING) {
129 (*status_it_).status_.status = actionlib_msgs::GoalStatus::PREEMPTED;
130 (*status_it_).status_.text = text;
131 as_->publishResult((*status_it_).status_, result);
134 "To transition to a cancelled state, the goal must be in a pending, recalling, active, or preempting state, it is currently in state: %d",
135 (*status_it_).status_.status);
138 ROS_ERROR_NAMED(
"actionlib",
"Attempt to set status on an uninitialized ServerGoalHandle");
142 template<
class ActionSpec>
143 void ServerGoalHandle<ActionSpec>::setRejected(
const Result & result,
const std::string & text)
145 if (as_ ==
nullptr) {
147 "You are attempting to call methods on an uninitialized goal handle");
152 DestructionGuard::ScopedProtector protector(*guard_);
153 if (!protector.isProtected()) {
155 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
159 ROS_DEBUG_NAMED(
"actionlib",
"Setting status to rejected on goal, id: %s, stamp: %.2f",
160 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
162 boost::recursive_mutex::scoped_lock lock(as_->lock_);
163 unsigned int status = (*status_it_).status_.status;
164 if (status == actionlib_msgs::GoalStatus::PENDING ||
165 status == actionlib_msgs::GoalStatus::RECALLING)
167 (*status_it_).status_.status = actionlib_msgs::GoalStatus::REJECTED;
168 (*status_it_).status_.text = text;
169 as_->publishResult((*status_it_).status_, result);
172 "To transition to a rejected state, the goal must be in a pending or recalling state, it is currently in state: %d",
173 (*status_it_).status_.status);
176 ROS_ERROR_NAMED(
"actionlib",
"Attempt to set status on an uninitialized ServerGoalHandle");
180 template<
class ActionSpec>
183 if (as_ ==
nullptr) {
185 "You are attempting to call methods on an uninitialized goal handle");
190 DestructionGuard::ScopedProtector protector(*guard_);
191 if (!protector.isProtected()) {
193 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
197 ROS_DEBUG_NAMED(
"actionlib",
"Setting status to aborted on goal, id: %s, stamp: %.2f",
198 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
200 boost::recursive_mutex::scoped_lock lock(as_->lock_);
201 unsigned int status = (*status_it_).status_.status;
202 if (status == actionlib_msgs::GoalStatus::PREEMPTING ||
203 status == actionlib_msgs::GoalStatus::ACTIVE)
205 (*status_it_).status_.status = actionlib_msgs::GoalStatus::ABORTED;
206 (*status_it_).status_.text = text;
207 as_->publishResult((*status_it_).status_, result);
210 "To transition to an aborted state, the goal must be in a preempting or active state, it is currently in state: %d",
214 ROS_ERROR_NAMED(
"actionlib",
"Attempt to set status on an uninitialized ServerGoalHandle");
218 template<
class ActionSpec>
221 if (as_ ==
nullptr) {
223 "You are attempting to call methods on an uninitialized goal handle");
228 DestructionGuard::ScopedProtector protector(*guard_);
229 if (!protector.isProtected()) {
231 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
235 ROS_DEBUG_NAMED(
"actionlib",
"Setting status to succeeded on goal, id: %s, stamp: %.2f",
236 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
238 boost::recursive_mutex::scoped_lock lock(as_->lock_);
239 unsigned int status = (*status_it_).status_.status;
240 if (status == actionlib_msgs::GoalStatus::PREEMPTING ||
241 status == actionlib_msgs::GoalStatus::ACTIVE)
243 (*status_it_).status_.status = actionlib_msgs::GoalStatus::SUCCEEDED;
244 (*status_it_).status_.text = text;
245 as_->publishResult((*status_it_).status_, result);
248 "To transition to a succeeded state, the goal must be in a preempting or active state, it is currently in state: %d",
252 ROS_ERROR_NAMED(
"actionlib",
"Attempt to set status on an uninitialized ServerGoalHandle");
256 template<
class ActionSpec>
259 if (as_ ==
nullptr) {
261 "You are attempting to call methods on an uninitialized goal handle");
266 DestructionGuard::ScopedProtector protector(*guard_);
267 if (!protector.isProtected()) {
269 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
273 ROS_DEBUG_NAMED(
"actionlib",
"Publishing feedback for goal, id: %s, stamp: %.2f",
274 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
276 boost::recursive_mutex::scoped_lock lock(as_->lock_);
277 as_->publishFeedback((*status_it_).status_, feedback);
280 "Attempt to publish feedback on an uninitialized ServerGoalHandle");
284 template<
class ActionSpec>
285 bool ServerGoalHandle<ActionSpec>::isValid()
const
287 return goal_ && as_ !=
nullptr;
290 template<
class ActionSpec>
303 template<
class ActionSpec>
306 if (goal_ && as_ !=
nullptr) {
308 if (protector.isProtected()) {
309 boost::recursive_mutex::scoped_lock lock(as_->lock_);
310 return (*status_it_).status_.goal_id;
312 return actionlib_msgs::GoalID();
316 "Attempt to get a goal id on an uninitialized ServerGoalHandle or one that has no ActionServer associated with it.");
317 return actionlib_msgs::GoalID();
321 template<
class ActionSpec>
324 if (goal_ && as_ !=
nullptr) {
327 boost::recursive_mutex::scoped_lock lock(as_->lock_);
328 return (*status_it_).status_;
330 return actionlib_msgs::GoalStatus();
334 "Attempt to get goal status on an uninitialized ServerGoalHandle or one that has no ActionServer associated with it.");
335 return actionlib_msgs::GoalStatus();
339 template<
class ActionSpec>
350 template<
class ActionSpec>
353 if (!goal_ && !other.
goal_) {
361 actionlib_msgs::GoalID my_id = getGoalID();
362 actionlib_msgs::GoalID their_id = other.
getGoalID();
363 return my_id.id == their_id.id;
366 template<
class ActionSpec>
367 bool ServerGoalHandle<ActionSpec>::operator!=(
const ServerGoalHandle & other)
const
369 return !(*
this == other);
372 template<
class ActionSpec>
373 ServerGoalHandle<ActionSpec>::ServerGoalHandle(
374 typename std::list<StatusTracker<ActionSpec> >::iterator status_it,
377 : status_it_(status_it), goal_((*status_it).goal_),
378 as_(as), handle_tracker_(handle_tracker), guard_(guard) {}
380 template<
class ActionSpec>
383 if (as_ ==
nullptr) {
385 "You are attempting to call methods on an uninitialized goal handle");
391 if (!protector.isProtected()) {
393 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
398 "Transitioning to a cancel requested state on goal id: %s, stamp: %.2f",
399 getGoalID().
id.c_str(), getGoalID().stamp.toSec());
401 boost::recursive_mutex::scoped_lock lock(as_->lock_);
402 unsigned int status = (*status_it_).status_.status;
403 if (status == actionlib_msgs::GoalStatus::PENDING) {
404 (*status_it_).status_.status = actionlib_msgs::GoalStatus::RECALLING;
405 as_->publishStatus();
409 if (status == actionlib_msgs::GoalStatus::ACTIVE) {
410 (*status_it_).status_.status = actionlib_msgs::GoalStatus::PREEMPTING;
411 as_->publishStatus();
418 #endif // ACTIONLIB__SERVER__SERVER_GOAL_HANDLE_IMP_H_