rosmaster: adding getTopicTypes in order to support subscribers declaring types

This commit is contained in:
Ken Conley 2010-03-18 20:17:47 +00:00
parent 26d0d3c165
commit 6b947cca65
4 changed files with 49 additions and 0 deletions

View File

@ -430,6 +430,16 @@ class Master(object):
"""
return self._succeed(self.handle.getPublishedTopics(self.caller_id, subgraph))
def getTopicTypes(self):
"""
Retrieve list topic names and their types.
@param caller_id: ROS caller id
@type caller_id: str
@rtype: (int, str, [[str,str]] )
@return: (code, statusMessage, topicTypes). topicTypes is a list of [topicName, topicType] pairs.
"""
return self._succeed(self.handle.getTopicTypes(self.caller_id))
def getSystemState(self):
"""
Retrieve list representation of system state (i.e. publishers, subscribers, and services).

View File

@ -681,6 +681,12 @@ class ROSMasterHandler(object):
try:
self.ps_lock.acquire()
self.reg_manager.register_subscriber(topic, caller_id, caller_api)
# ROS 1.1: subscriber can now set type if it is not already set
# - don't let '*' type squash valid typing
if not topic in self.topics_types and topic_type != roslib.names.ANYTYPE:
self.topics_types[topic] = topic_type
mloginfo("+SUB [%s] %s %s",topic, caller_id, caller_api)
pub_uris = self.publishers.get_apis(topic)
finally:
@ -824,6 +830,22 @@ class ROSMasterHandler(object):
self.ps_lock.release()
return 1, "current topics", retval
@apivalidate([])
def getTopicTypes(self, caller_id):
"""
Retrieve list topic names and their types.
@param caller_id: ROS caller id
@type caller_id: str
@rtype: (int, str, [[str,str]] )
@return: (code, statusMessage, topicTypes). topicTypes is a list of [topicName, topicType] pairs.
"""
try:
self.ps_lock.acquire()
retval = self.topics_types.items()
finally:
self.ps_lock.release()
return 1, "current system state", retval
@apivalidate([[],[], []])
def getSystemState(self, caller_id):
"""

View File

@ -97,6 +97,10 @@ class MasterMock(object):
def getPublishedTopics(self, caller_id, subgraph):
self.call = ('getPublishedTopics', caller_id, subgraph)
return self.return_val
def getTopicTypes(self, caller_id):
self.call = ('getTopicTypes', caller_id)
return self.return_val
def getSystemState(self, caller_id):
self.call = ('getSystemState', caller_id)
@ -279,6 +283,16 @@ class MasterApiOfflineTest(unittest.TestCase):
self.throw_failure('getPublishedTopics', args, (0, '', r))
self.throw_error('getPublishedTopics', args, (-1, '', r))
def test_getTopicTypes(self):
h = self.m.handle
r = [ ['/foo', 'std_msgs/String'], ['/baz', 'std_msgs/Int32'] ]
h.return_val = (1, '', r)
self.assertEquals(r, self.m.getTopicTypes())
self.assertEquals(('getTopicTypes',_ID), h.call)
self.throw_failure('getTopicTypes', (), (0, '', r))
self.throw_error('getTopicTypes', (), (-1, '', r))
def test_getSystemState(self):
h = self.m.handle
r = [ [], [], [] ]

View File

@ -104,6 +104,9 @@ class MasterApiOnlineTest(unittest.TestCase):
def test_getPublishedTopics(self):
topics = self.m.getPublishedTopics('/')
def test_getTopicTypes(self):
topic_types = self.m.getTopicTypes()
def test_getSystemState(self):
pub, sub, srvs = self.m.getSystemState()