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>
56 template<
class ActionSpec>
61 "You are attempting to call methods on an uninitialized goal handle");
69 "The ActionServer associated with this GoalHandle is invalid. Did you delete the ActionServer before the GoalHandle?");
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>
104 "You are attempting to call methods on an uninitialized goal handle");
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",
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>
147 "You are attempting to call methods on an uninitialized goal handle");
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",
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>
185 "You are attempting to call methods on an uninitialized goal handle");
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",
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>
223 "You are attempting to call methods on an uninitialized goal handle");
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",
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>
261 "You are attempting to call methods on an uninitialized goal handle");
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",
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>
290 template<
class ActionSpec>
303 template<
class ActionSpec>
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>
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>
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>
369 return !(*
this == other);
372 template<
class ActionSpec>
380 template<
class ActionSpec>
385 "You are attempting to call methods on an uninitialized goal handle");
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",
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_
bool operator==(const ServerGoalHandle &other) const
Equals operator for ServerGoalHandles.
void publishFeedback(const Feedback &feedback)
Send feedback to any clients of the goal associated with this ServerGoalHandle.
ActionServerBase< ActionSpec > * as_
actionlib_msgs::GoalID getGoalID() const
Accessor for the goal id associated with the ServerGoalHandle.
boost::shared_ptr< void > handle_tracker_
void setRejected(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to rejected.
boost::shared_ptr< const Goal > getGoal() const
Accessor for the goal associated with the ServerGoalHandle.
bool operator!=(const ServerGoalHandle &other) const
!= operator for ServerGoalHandles
bool isProtected()
Checks if the ScopedProtector successfully protected the DestructionGuard.
boost::shared_ptr< const ActionGoal > goal_
void setCanceled(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to RECALLED or PREEMPTED depending on...
void setAccepted(const std::string &text=std::string(""))
Accept the goal referenced by the goal handle. This will transition to the ACTIVE state or the PREEMP...
#define ROS_DEBUG_NAMED(name,...)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to succeeded.
A class for storing the status of each goal the action server is currently working on...
boost::shared_ptr< DestructionGuard > guard_
bool isValid() const
Determine if the goal handle is valid (tracking a valid goal, and associated with a valid action serv...
ServerGoalHandle()
Default constructor for a ServerGoalHandle.
std::list< StatusTracker< ActionSpec > >::iterator status_it_
The ActionServerBase implements the logic for an ActionServer.
Encapsulates a state machine for a given goal that the user can trigger transitions on...
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to aborted.
#define ROS_ERROR_NAMED(name,...)
Protects a DestructionGuard until this object goes out of scope.
ServerGoalHandle & operator=(const ServerGoalHandle &gh)
Equals operator for a ServerGoalHandle.
actionlib_msgs::GoalStatus getGoalStatus() const
Accessor for the status associated with the ServerGoalHandle.
bool setCancelRequested()
A private method to set status to PENDING or RECALLING.