message_info_service.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #####################################################################
4 # Software License Agreement (BSD License)
5 #
6 # Copyright (c) 2013, Clearpath Robotics
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 #
13 # * Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # * Redistributions in binary form must reproduce the above
16 # copyright notice, this list of conditions and the following
17 # disclaimer in the documentation and/or other materials provided
18 # with the distribution.
19 # * Neither the name of Willow Garage, Inc. nor the names of its
20 # contributors may be used to endorse or promote products derived
21 # from this software without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 # POSSIBILITY OF SUCH DAMAGE.
35 
36 """ The node provided by this file exposes a helper service used by
37 the C++ rosserial_server. The service allows the C++ driver to look
38 up message definitions and hash strings which would not have been
39 known to it at compile time, allowing it to fully advertise topics
40 originating from microcontrollers.
41 
42 This allows rosserial_server to be distributed in binary form. """
43 
44 import rospy
45 from rosserial_msgs.srv import RequestMessageInfo
46 from rosserial_msgs.srv import RequestServiceInfo
47 from rosserial_python import load_message
48 from rosserial_python import load_service
49 
50 
51 class MessageInfoService(object):
52  """ """
53  def __init__(self):
54  rospy.init_node("message_info_service")
55  rospy.loginfo("rosserial message_info_service node")
56  self.message_cache = {}
57  self.service_cache = {}
58  self.service = rospy.Service("message_info", RequestMessageInfo, self._message_info_cb)
59  self.serviceInfoService = rospy.Service("service_info", RequestServiceInfo, self._service_info_cb)
60 
61  def _message_info_cb(self, req):
62  package_message = tuple(req.type.split("/"))
63  if not self.message_cache.has_key(package_message):
64  rospy.loginfo("Loading module to return info on %s/%s." % package_message)
65  msg = load_message(*package_message)
66  self.message_cache[package_message] = (msg._md5sum, msg._full_text)
67  else:
68  rospy.loginfo("Returning info from cache on %s/%s." % package_message)
69  return self.message_cache[package_message]
70 
71  def _service_info_cb(self, req):
72  rospy.logdebug("req.service is %s" % req.service)
73  package_service = tuple(req.service.split("/"))
74  if not self.service_cache.has_key(package_service):
75  rospy.loginfo("Loading module to return info on service %s/%s." % package_service)
76  srv,mreq,mres = load_service(*package_service)
77  self.service_cache[package_service] = (srv._md5sum,mreq._md5sum,mres._md5sum)
78  else:
79  rospy.loginfo("Returning info from cache on %s/%s." % package_service)
80  return self.service_cache[package_service]
81 
82  def spin(self):
83  rospy.spin()
84 
85 if __name__=="__main__":
def load_message(package, message)
Definition: SerialClient.py:79
def load_service(package, service)
Definition: SerialClient.py:84


rosserial_python
Author(s): Michael Ferguson
autogenerated on Mon Jun 10 2019 14:53:29