ref_server.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
36 
38 #include <actionlib/TestAction.h>
39 #include <ros/ros.h>
40 #include <cstdio>
41 #include <string>
42 
43 namespace actionlib
44 {
45 
46 class RefServer : public ActionServer<TestAction>
47 {
48 public:
50 
51  RefServer(ros::NodeHandle & n, const std::string & name);
52 
53 private:
54  void goalCallback(GoalHandle gh);
55  void cancelCallback(GoalHandle gh);
56 };
57 
58 } // namespace actionlib
59 
60 using namespace actionlib;
61 
62 RefServer::RefServer(ros::NodeHandle & n, const std::string & name)
63 : ActionServer<TestAction>(n, name,
64  boost::bind(&RefServer::goalCallback, this, boost::placeholders::_1),
65  boost::bind(&RefServer::cancelCallback, this, boost::placeholders::_1),
66  false)
67 {
68  start();
69  printf("Creating ActionServer [%s]\n", name.c_str());
70 }
71 
73 {
74  TestGoal goal = *gh.getGoal();
75 
76  switch (goal.goal) {
77  case 1:
79  gh.setSucceeded(TestResult(), "The ref server has succeeded");
80  break;
81  case 2:
82  gh.setAccepted();
83  gh.setAborted(TestResult(), "The ref server has aborted");
84  break;
85  case 3:
86  gh.setRejected(TestResult(), "The ref server has rejected");
87  break;
88  default:
89  break;
90  }
91 }
92 
94 {
95 }
96 
97 
98 int main(int argc, char ** argv)
99 {
100  ros::init(argc, argv, "ref_server");
101 
102  ros::NodeHandle nh;
103 
104  RefServer ref_server(nh, "reference_action");
105 
106  ros::spin();
107 }
actionlib::ServerGoalHandle::getGoal
boost::shared_ptr< const Goal > getGoal() const
Accessor for the goal associated with the ServerGoalHandle.
Definition: server_goal_handle_imp.h:327
actionlib::ServerGoalHandle
Encapsulates a state machine for a given goal that the user can trigger transitions on....
Definition: server_goal_handle.h:98
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
actionlib::ActionServer
The ActionServer is a helpful tool for managing goal requests to a node. It allows the user to specif...
Definition: action_server.h:107
ros.h
boost
actionlib::ServerGoalHandle::setRejected
void setRejected(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to rejected.
Definition: server_goal_handle_imp.h:178
main
int main(int argc, char **argv)
Definition: ref_server.cpp:98
mock_simple_server.ref_server
ref_server
Definition: mock_simple_server.py:94
actionlib::RefServer::goalCallback
void goalCallback(GoalHandle gh)
Definition: ref_server.cpp:72
actionlib::RefServer::GoalHandle
ServerGoalHandle< TestAction > GoalHandle
Definition: ref_server.cpp:113
actionlib::ServerGoalHandle::setAccepted
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...
Definition: server_goal_handle_imp.h:92
actionlib::ServerGoalHandle::setSucceeded
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to succeeded.
Definition: server_goal_handle_imp.h:254
action_server.h
actionlib::RefServer::cancelCallback
void cancelCallback(GoalHandle gh)
Definition: ref_server.cpp:93
actionlib::ActionServerBase< TestAction >::start
void start()
Explicitly start the action server, used it auto_start is set to false.
Definition: action_server_base.h:230
actionlib::RefServer
Definition: ref_server.cpp:78
actionlib::ServerGoalHandle::setAborted
void setAborted(const Result &result=Result(), const std::string &text=std::string(""))
Set the status of the goal associated with the ServerGoalHandle to aborted.
Definition: server_goal_handle_imp.h:216
actionlib
Definition: action_definition.h:40
ros::spin
ROSCPP_DECL void spin()
actionlib::RefServer::RefServer
RefServer(ros::NodeHandle &n, const std::string &name)
Definition: ref_server.cpp:62
ros::NodeHandle


actionlib
Author(s): Eitan Marder-Eppstein, Vijay Pradeep, Mikael Arguedas
autogenerated on Fri May 19 2023 02:36:55