Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef ACTIONLIB__SERVER__SERVICE_SERVER_IMP_H_
00038 #define ACTIONLIB__SERVER__SERVICE_SERVER_IMP_H_
00039
00040 #include <string>
00041
00042 namespace actionlib
00043 {
00044
00045 template<class ActionSpec>
00046 ServiceServer advertiseService(ros::NodeHandle n, std::string name,
00047 boost::function<bool(const typename ActionSpec::_action_goal_type::_goal_type &,
00048 typename ActionSpec::_action_result_type::_result_type & result)> service_cb)
00049 {
00050 boost::shared_ptr<ServiceServerImp> server_ptr(new ServiceServerImpT<ActionSpec>(n, name,
00051 service_cb));
00052 return ServiceServer(server_ptr);
00053 }
00054
00055 template<class ActionSpec>
00056 ServiceServerImpT<ActionSpec>::ServiceServerImpT(ros::NodeHandle n, std::string name,
00057 boost::function<bool(const Goal &, Result & result)> service_cb)
00058 : service_cb_(service_cb)
00059 {
00060 as_ = boost::shared_ptr<ActionServer<ActionSpec> >(new ActionServer<ActionSpec>(n, name,
00061 boost::bind(&ServiceServerImpT::goalCB, this, _1), false));
00062 as_->start();
00063 }
00064
00065 template<class ActionSpec>
00066 void ServiceServerImpT<ActionSpec>::goalCB(GoalHandle goal)
00067 {
00068 goal.setAccepted("This goal has been accepted by the service server");
00069
00070
00071 Result r;
00072 if (service_cb_(*(goal.getGoal()), r)) {
00073 goal.setSucceeded(r, "The service server successfully processed the request");
00074 } else {
00075 goal.setAborted(r, "The service server failed to process the request");
00076 }
00077 }
00078
00079 }
00080 #endif // ACTIONLIB__SERVER__SERVICE_SERVER_IMP_H_