advertise_service_options.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Stanford University or Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef ROSCPP_ADVERTISE_SERVICE_OPTIONS_H
29 #define ROSCPP_ADVERTISE_SERVICE_OPTIONS_H
30 
31 #include "ros/forwards.h"
33 #include "ros/service_traits.h"
34 #include "ros/message_traits.h"
35 #include "common.h"
36 
37 namespace ros
38 {
39 
43 struct ROSCPP_DECL AdvertiseServiceOptions
44 {
46  : callback_queue(0)
47  {
48  }
49 
55  template<class MReq, class MRes>
56  void init(const std::string& _service, const boost::function<bool(MReq&, MRes&)>& _callback)
57  {
58  namespace st = service_traits;
59  namespace mt = message_traits;
60  if (st::md5sum<MReq>() != st::md5sum<MRes>())
61  {
62  ROS_FATAL("the request and response parameters to the server "
63  "callback function must be autogenerated from the same "
64  "server definition file (.srv). your advertise_servce "
65  "call for %s appeared to use request/response types "
66  "from different .srv files.", service.c_str());
67  ROS_BREAK();
68  }
69 
70  service = _service;
71  md5sum = st::md5sum<MReq>();
72  datatype = st::datatype<MReq>();
73  req_datatype = mt::datatype<MReq>();
74  res_datatype = mt::datatype<MRes>();
75  helper = boost::make_shared<ServiceCallbackHelperT<ServiceSpec<MReq, MRes> > >(_callback);
76  }
77 
83  template<class Service>
84  void init(const std::string& _service, const boost::function<bool(typename Service::Request&, typename Service::Response&)>& _callback)
85  {
86  namespace st = service_traits;
87  namespace mt = message_traits;
88  typedef typename Service::Request Request;
89  typedef typename Service::Response Response;
90  service = _service;
91  md5sum = st::md5sum<Service>();
92  datatype = st::datatype<Service>();
93  req_datatype = mt::datatype<Request>();
94  res_datatype = mt::datatype<Response>();
95  helper = boost::make_shared<ServiceCallbackHelperT<ServiceSpec<Request, Response> > >(_callback);
96  }
97 
103  template<class Spec>
104  void initBySpecType(const std::string& _service, const typename Spec::CallbackType& _callback)
105  {
106  namespace st = service_traits;
107  namespace mt = message_traits;
108  typedef typename Spec::RequestType Request;
109  typedef typename Spec::ResponseType Response;
110  service = _service;
111  md5sum = st::md5sum<Request>();
112  datatype = st::datatype<Request>();
113  req_datatype = mt::datatype<Request>();
114  res_datatype = mt::datatype<Response>();
115  helper = boost::make_shared<ServiceCallbackHelperT<Spec> >(_callback);
116  }
117 
118  std::string service;
119  std::string md5sum;
120  std::string datatype;
121  std::string req_datatype;
122  std::string res_datatype;
123 
125 
127 
139 
147  template<class Service>
148  static AdvertiseServiceOptions create(const std::string& service,
149  const boost::function<bool(typename Service::Request&, typename Service::Response&)>& callback,
150  const VoidConstPtr& tracked_object,
151  CallbackQueueInterface* queue)
152  {
154  ops.init<typename Service::Request, typename Service::Response>(service, callback);
155  ops.tracked_object = tracked_object;
156  ops.callback_queue = queue;
157  return ops;
158  }
159 };
160 
161 
162 
163 }
164 
165 #endif
166 
ROS_BREAK
#define ROS_BREAK()
md5sum
const char * md5sum()
ros::AdvertiseServiceOptions::init
void init(const std::string &_service, const boost::function< bool(MReq &, MRes &)> &_callback)
Templated convenience method for filling out md5sum/etc. based on the service request/response types.
Definition: advertise_service_options.h:56
ros::AdvertiseServiceOptions::create
static AdvertiseServiceOptions create(const std::string &service, const boost::function< bool(typename Service::Request &, typename Service::Response &)> &callback, const VoidConstPtr &tracked_object, CallbackQueueInterface *queue)
Templated helper function for creating an AdvertiseServiceOptions with all of its options.
Definition: advertise_service_options.h:148
boost::shared_ptr< ServiceCallbackHelper >
forwards.h
ros
ros::AdvertiseServiceOptions::AdvertiseServiceOptions
AdvertiseServiceOptions()
Definition: advertise_service_options.h:45
ros::AdvertiseServiceOptions::tracked_object
VoidConstPtr tracked_object
An object whose destruction will prevent the callback associated with this service from being called.
Definition: advertise_service_options.h:138
ros::AdvertiseServiceOptions::init
void init(const std::string &_service, const boost::function< bool(typename Service::Request &, typename Service::Response &)> &_callback)
Templated convenience method for filling out md5sum/etc. based on the service type.
Definition: advertise_service_options.h:84
ros::AdvertiseServiceOptions::md5sum
std::string md5sum
MD5 of the service.
Definition: advertise_service_options.h:119
ros::AdvertiseServiceOptions::helper
ServiceCallbackHelperPtr helper
Helper object used for creating messages and calling callbacks.
Definition: advertise_service_options.h:124
ros::AdvertiseServiceOptions::datatype
std::string datatype
Datatype of the service.
Definition: advertise_service_options.h:120
ros::AdvertiseServiceOptions::callback_queue
CallbackQueueInterface * callback_queue
Queue to add callbacks to. If NULL, the global callback queue will be used.
Definition: advertise_service_options.h:126
message_traits.h
ros::AdvertiseServiceOptions::req_datatype
std::string req_datatype
Request message datatype.
Definition: advertise_service_options.h:121
ros::AdvertiseServiceOptions
Encapsulates all options available for creating a ServiceServer.
Definition: advertise_service_options.h:43
ROS_FATAL
#define ROS_FATAL(...)
ros::AdvertiseServiceOptions::service
std::string service
Service name.
Definition: advertise_service_options.h:118
datatype
const char * datatype()
service_callback_helper.h
ros::AdvertiseServiceOptions::res_datatype
std::string res_datatype
Response message datatype.
Definition: advertise_service_options.h:122
ros::CallbackQueueInterface
Abstract interface for a queue used to handle all callbacks within roscpp.
Definition: callback_queue_interface.h:82
service_traits.h
ros::AdvertiseServiceOptions::initBySpecType
void initBySpecType(const std::string &_service, const typename Spec::CallbackType &_callback)
Templated convenience method for filling out md5sum/etc. based on the service spec type.
Definition: advertise_service_options.h:104


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:35