topic_dict.py
Go to the documentation of this file.
1 # Copyright (c) 2011, Dorian Scholz, TU Darmstadt
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following
12 # disclaimer in the documentation and/or other materials provided
13 # with the distribution.
14 # * Neither the name of the TU Darmstadt nor the names of its
15 # contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 
31 import roslib
32 import rospy
33 
34 
35 class TopicDict(object):
36 
37  def __init__(self):
38  self.update_topics()
39 
40  def get_topics(self):
41  return self.topic_dict
42 
43  def update_topics(self):
44  self.topic_dict = {}
45  topic_list = rospy.get_published_topics()
46  for topic_name, topic_type in topic_list:
47  message = roslib.message.get_message_class(topic_type)()
48  self.topic_dict.update(self._recursive_create_field_dict(topic_name, message))
49 
50  def _recursive_create_field_dict(self, topic_name, field):
51  field_dict = {}
52  field_dict[topic_name] = {
53  'type': type(field),
54  'children': {},
55  }
56 
57  if hasattr(field, '__slots__'):
58  for slot_name in field.__slots__:
59  field_dict[topic_name]['children'].update(
60  self._recursive_create_field_dict(slot_name, getattr(field, slot_name)))
61 
62  return field_dict
63 
64 
65 if __name__ == '__main__':
66  import pprint
67  pprint.pprint(TopicDict().get_topics())
def _recursive_create_field_dict(self, topic_name, field)
Definition: topic_dict.py:50


rqt_py_common
Author(s): Dorian Scholz, Isaac Saito, Dirk Thomas
autogenerated on Mon Mar 22 2021 02:13:26