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 #ifndef ACTIONLIB_CLIENT_GOAL_STATUS_H_ 00036 #define ACTIONLIB_CLIENT_GOAL_STATUS_H_ 00037 00038 #include <string> 00039 00040 #include "actionlib/GoalStatus.h" 00041 00042 namespace actionlib 00043 { 00044 00050 class ClientGoalStatus 00051 { 00052 public: 00054 enum StateEnum 00055 { 00056 PENDING, 00057 ACTIVE, 00058 PREEMPTED, 00059 SUCCEEDED, 00060 ABORTED, 00061 REJECTED, 00062 LOST 00063 } ; 00064 00065 ClientGoalStatus(StateEnum state) 00066 { 00067 state_ = state; 00068 } 00069 00076 ClientGoalStatus(const GoalStatus& goal_status) 00077 { 00078 fromGoalStatus(goal_status); 00079 } 00080 00085 inline bool isDone() const 00086 { 00087 if (state_ == PENDING || state_ == ACTIVE) 00088 return false; 00089 return true; 00090 } 00091 00095 inline const StateEnum& operator=(const StateEnum& state) 00096 { 00097 state_ = state; 00098 return state; 00099 } 00100 00104 inline bool operator==(const ClientGoalStatus& rhs) 00105 { 00106 return state_ == rhs.state_; 00107 } 00108 00112 inline bool operator!=(const ClientGoalStatus& rhs) 00113 { 00114 return !(state_ == rhs.state_); 00115 } 00116 00123 void fromGoalStatus(const GoalStatus& goal_status) 00124 { 00125 switch(goal_status.status) 00126 { 00127 case GoalStatus::PREEMPTED: 00128 state_ = ClientGoalStatus::PREEMPTED; break; 00129 case GoalStatus::SUCCEEDED: 00130 state_ = ClientGoalStatus::SUCCEEDED; break; 00131 case GoalStatus::ABORTED: 00132 state_ = ClientGoalStatus::ABORTED; break; 00133 case GoalStatus::REJECTED: 00134 state_ = ClientGoalStatus::REJECTED; break; 00135 default: 00136 state_ = ClientGoalStatus::LOST; 00137 ROS_ERROR_NAMED("actionlib", "Cannot convert GoalStatus %u to ClientGoalState", goal_status.status); break; 00138 } 00139 } 00140 00145 std::string toString() const 00146 { 00147 switch(state_) 00148 { 00149 case PENDING: 00150 return "PENDING"; 00151 case ACTIVE: 00152 return "ACTIVE"; 00153 case PREEMPTED: 00154 return "PREEMPTED"; 00155 case SUCCEEDED: 00156 return "SUCCEEDED"; 00157 case ABORTED: 00158 return "ABORTED"; 00159 case REJECTED: 00160 return "REJECTED"; 00161 case LOST: 00162 return "LOST"; 00163 default: 00164 ROS_ERROR_NAMED("actionlib", "BUG: Unhandled ClientGoalStatus"); 00165 break; 00166 } 00167 return "BUG-UNKNOWN"; 00168 } 00169 00170 private: 00171 StateEnum state_; 00172 ClientGoalStatus(); 00173 }; 00174 00175 } 00176 00177 #endif // ACTION_TOOLS_CLIENT_GOAL_STATE_H_