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


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:07