Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 import json, sys, re
00016 import rospy, rostopic
00017 from ros_glass_tools.srv import Topics
00018
00019
00020
00021
00022 class ListTopics:
00023 '''Node to return a list of all running topics when service is called'''
00024 def __init__(self):
00025 rospy.init_node("list_topics_server")
00026 self.serv = rospy.Service("list_topics", Topics, self.list)
00027
00028
00029
00030
00031 def list(self, request):
00032 '''request for service handler return the list'''
00033 topics = self.get_ros_topics()
00034 return topics
00035
00036 def get_ros_topics(self):
00037 '''return list of published topics'''
00038 try:
00039 topics = rospy.get_published_topics()
00040 return ' ,'.join((topic[0] for topic in topics))
00041 except:
00042 rospy.logerr("no core active")
00043 return False
00044
00045
00046
00047
00048 if __name__ == '__main__':
00049 lt = ListTopics()
00050 rospy.spin()