goal_manager_imp.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 /* This file has the template implementation for GoalHandle. It should be included with the
00036  * class definition.
00037  */
00038 
00039 #ifndef ACTIONLIB__CLIENT__GOAL_MANAGER_IMP_H_
00040 #define ACTIONLIB__CLIENT__GOAL_MANAGER_IMP_H_
00041 
00042 #include "ros/ros.h"
00043 
00044 namespace actionlib
00045 {
00046 
00047 template<class ActionSpec>
00048 void GoalManager<ActionSpec>::registerSendGoalFunc(SendGoalFunc send_goal_func)
00049 {
00050   send_goal_func_ = send_goal_func;
00051 }
00052 
00053 template<class ActionSpec>
00054 void GoalManager<ActionSpec>::registerCancelFunc(CancelFunc cancel_func)
00055 {
00056   cancel_func_ = cancel_func;
00057 }
00058 
00059 
00060 template<class ActionSpec>
00061 ClientGoalHandle<ActionSpec> GoalManager<ActionSpec>::initGoal(const Goal & goal,
00062   TransitionCallback transition_cb,
00063   FeedbackCallback feedback_cb)
00064 {
00065   ActionGoalPtr action_goal(new ActionGoal);
00066   action_goal->header.stamp = ros::Time::now();
00067   action_goal->goal_id = id_generator_.generateID();
00068   action_goal->goal = goal;
00069 
00070   typedef CommStateMachine<ActionSpec> CommStateMachineT;
00071   boost::shared_ptr<CommStateMachineT> comm_state_machine(new CommStateMachineT(action_goal,
00072     transition_cb,
00073     feedback_cb));
00074 
00075   boost::recursive_mutex::scoped_lock lock(list_mutex_);
00076   typename ManagedListT::Handle list_handle =
00077     list_.add(comm_state_machine, boost::bind(&GoalManagerT::listElemDeleter, this, _1), guard_);
00078 
00079   if (send_goal_func_) {
00080     send_goal_func_(action_goal);
00081   } else {
00082     ROS_WARN_NAMED("actionlib",
00083       "Possible coding error: send_goal_func_ set to NULL. Not going to send goal");
00084   }
00085 
00086   return GoalHandleT(this, list_handle, guard_);
00087 }
00088 
00089 template<class ActionSpec>
00090 void GoalManager<ActionSpec>::listElemDeleter(typename ManagedListT::iterator it)
00091 {
00092   assert(guard_);
00093   if (!guard_)
00094   {
00095     ROS_ERROR_NAMED("actionlib", "Goal manager deleter should not see invalid guards");
00096     return;
00097   }
00098   DestructionGuard::ScopedProtector protector(*guard_);
00099   if (!protector.isProtected()) {
00100     ROS_ERROR_NAMED("actionlib",
00101       "This action client associated with the goal handle has already been destructed. Not going to try delete the CommStateMachine associated with this goal");
00102     return;
00103   }
00104 
00105   ROS_DEBUG_NAMED("actionlib", "About to erase CommStateMachine");
00106   boost::recursive_mutex::scoped_lock lock(list_mutex_);
00107   list_.erase(it);
00108   ROS_DEBUG_NAMED("actionlib", "Done erasing CommStateMachine");
00109 }
00110 
00111 template<class ActionSpec>
00112 void GoalManager<ActionSpec>::updateStatuses(
00113   const actionlib_msgs::GoalStatusArrayConstPtr & status_array)
00114 {
00115   boost::recursive_mutex::scoped_lock lock(list_mutex_);
00116   typename ManagedListT::iterator it = list_.begin();
00117 
00118   while (it != list_.end()) {
00119     GoalHandleT gh(this, it.createHandle(), guard_);
00120     (*it)->updateStatus(gh, status_array);
00121     ++it;
00122   }
00123 }
00124 
00125 template<class ActionSpec>
00126 void GoalManager<ActionSpec>::updateFeedbacks(const ActionFeedbackConstPtr & action_feedback)
00127 {
00128   boost::recursive_mutex::scoped_lock lock(list_mutex_);
00129   typename ManagedListT::iterator it = list_.begin();
00130 
00131   while (it != list_.end()) {
00132     GoalHandleT gh(this, it.createHandle(), guard_);
00133     (*it)->updateFeedback(gh, action_feedback);
00134     ++it;
00135   }
00136 }
00137 
00138 template<class ActionSpec>
00139 void GoalManager<ActionSpec>::updateResults(const ActionResultConstPtr & action_result)
00140 {
00141   boost::recursive_mutex::scoped_lock lock(list_mutex_);
00142   typename ManagedListT::iterator it = list_.begin();
00143 
00144   while (it != list_.end()) {
00145     GoalHandleT gh(this, it.createHandle(), guard_);
00146     (*it)->updateResult(gh, action_result);
00147     ++it;
00148   }
00149 }
00150 
00151 
00152 }  // namespace actionlib
00153 
00154 #endif  // ACTIONLIB__CLIENT__GOAL_MANAGER_IMP_H_


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Sat Feb 16 2019 03:21:28