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 
CallbackQueueInterface * callback_queue
Queue to add callbacks to. If NULL, the global callback queue will be used.
std::string md5sum
MD5 of the service.
#define ROS_FATAL(...)
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...
VoidConstPtr tracked_object
An object whose destruction will prevent the callback associated with this service from being called...
Abstract interface for a queue used to handle all callbacks within roscpp.
std::string res_datatype
Response message datatype.
Encapsulates all options available for creating a ServiceServer.
const char * datatype()
ServiceCallbackHelperPtr helper
Helper object used for creating messages and calling callbacks.
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...
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.
const char * md5sum()
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...
#define ROS_BREAK()
std::string datatype
Datatype of the service.
std::string req_datatype
Request message datatype.


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Sun Feb 3 2019 03:29:54