dynamic_service.py
Go to the documentation of this file.
1 #! /usr/bin/python
2 #
3 # This code is based on dynamic_action.py of the actionlib package, written by
4 # Eitan Marder-Eppstein.
5 # Adapted to work for services by Felix Widmaier at Synapticon GmbH.
6 #
7 # **********************************************************
8 # Software License Agreement (BSD License)
9 #
10 # Copyright (c) 2009, Willow Garage, Inc.
11 # Copyright (c) 2018, Synapticon GmbH
12 # All rights reserved.
13 #
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions
16 # are met:
17 #
18 # * Redistributions of source code must retain the above copyright
19 # notice, this list of conditions and the following disclaimer.
20 # * Redistributions in binary form must reproduce the above
21 # copyright notice, this list of conditions and the following
22 # disclaimer in the documentation and/or other materials provided
23 # with the distribution.
24 # * Neither the name of Willow Garage, Inc. nor the names of its
25 # contributors may be used to endorse or promote products derived
26 # from this software without specific prior written permission.
27 #
28 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 # POSSIBILITY OF SUCH DAMAGE.
40 # **********************************************************
41 """Helper class to load service message types."""
42 import roslib
43 import rospy
44 import sys
45 
46 
47 class DynamicService(object):
48  """Provides types of the given service message."""
49 
50  def __init__(self, name):
51  """Initialize.
52 
53  Args:
54  name (str): Name of the service type (e.g. "std_srvs/SetBool").
55 
56  """
57  self.name = name
58  self.base = self.load_submsg('')
59  self.request = self.load_submsg('Request')
60  self.response = self.load_submsg('Response')
61 
62  def load_submsg(self, subname):
63  """Load submessage.
64 
65  Args:
66  subname (str): Suffix that is added to the type.
67 
68  Returns:
69  The sub-message type.
70 
71  """
72  msgclass = roslib.message.get_service_class(self.name + subname)
73  if msgclass is None:
74  rospy.logfatal('Could not load message for: %s' % (self.name +
75  subname))
76  sys.exit(1)
77  return msgclass
rx_service_tools.dynamic_service.DynamicService.response
response
Definition: dynamic_service.py:60
rx_service_tools.dynamic_service.DynamicService.base
base
Definition: dynamic_service.py:58
rx_service_tools.dynamic_service.DynamicService
Definition: dynamic_service.py:47
rx_service_tools.dynamic_service.DynamicService.__init__
def __init__(self, name)
Definition: dynamic_service.py:50
rx_service_tools.dynamic_service.DynamicService.load_submsg
def load_submsg(self, subname)
Definition: dynamic_service.py:62
rx_service_tools.dynamic_service.DynamicService.name
name
Definition: dynamic_service.py:57
rx_service_tools.dynamic_service.DynamicService.request
request
Definition: dynamic_service.py:59


rx_service_tools
Author(s): Alireza Hosseini , Felix Widmaier
autogenerated on Thu Mar 17 2022 02:57:10