コード例 #1
0
def test_XmlRpcNode():
    from rosgraph.xmlrpc import XmlRpcNode, XmlRpcHandler
    # not a very comprehensive test (yet)
    #port, handler
    tests = [
        (None, None, None),
        (8080, None, 8080),
        ('8080', None, 8080),
        (u'8080', None, 8080),
    ]

    for port, handler, true_port in tests:
        n = XmlRpcNode(port, handler)
        assert true_port == n.port
        assert handler == n.handler
        assert None == n.uri
        assert None == n.server
        n.set_uri('http://fake:1234')
        assert 'http://fake:1234' == n.uri

        n.start()
        start = time.time()
        while not n.uri and time.time() - start < 5.:
            time.sleep(0.00001)  #poll for XMLRPC init

        assert n.uri
        n.shutdown('test case')

    # get coverage on run init
    n = XmlRpcNode(0, XmlRpcHandler())
    n._run_init()
    n.shutdown('test case')

    # mock in server in order to play with _run()
    n.server = mock.Mock()
    n.is_shutdown = False
    n._run_init = mock.Mock()
    n.server.serve_forever.side_effect = IOError(1, 'boom')
    n._run()
コード例 #2
0
    def configure_external(self):

        # Start another TCPROSServer to handle requests on the external port
        #  - TODO: allow handlers these to be passed into TCPROSServer constructor
        self.external_tcpros = external_tcpros = TCPROSServer()
        tcpros_handler = rosproxy.tcpros.ProxyTCPROSHandler(
            self.topic_manager, external_tcpros)

        self._configure_proxy_services(external_tcpros)
        self._configure_proxy_topics(external_tcpros, tcpros_handler)

        tcpros_port = rospy.get_param('~tcpros_port', 11312)
        xmlrpc_port = rospy.get_param('~xmlrpc_port', 11313)

        rospy.loginfo("reading port configuration: TCPROS[%s] XMLRPC[%s]" %
                      (tcpros_port, xmlrpc_port))

        external_tcpros.start_server(port=tcpros_port)

        # TODO: this may report the address of the wrong interface
        rospy.loginfo("ROSRPC URI is rosrpc://%s:%s" %
                      (rosgraph.network.get_local_address(), tcpros_port))

        # Startup XMLRPC interface so we can do pub/sub
        master_uri = rosgraph.get_master_uri()
        name = 'proxy-proxy'

        protocol_handlers = [tcpros_handler]
        rpc_handler = rosproxy.handler.ProxyHandler(name, master_uri,
                                                    self.topic_manager,
                                                    protocol_handlers)
        self.external_node = external_node = XmlRpcNode(
            xmlrpc_port, rpc_handler)

        # - start the node and wait for init
        external_node.start()
        import time
        timeout_t = time.time() + 10.
        while time.time() < timeout_t and external_node.uri is None:
            time.sleep(0.01)

        rospy.loginfo("XMLRPC interface is up %s" % self.external_node.uri)
コード例 #3
0
    def __init__(self, master_uri, new_topics_callback):
        self.master_uri          = master_uri
        self.new_topics_callback = new_topics_callback

        name = rosgraph.names.ns_join(rosgraph.names.get_ros_namespace(), rosgraph.names.anonymous_name('master_sync'))
        self.master = rosgraph.Master(name, master_uri=self.master_uri)

        self._lock = threading.RLock()

        self._type_cache = {}

        self._subs = {}
        self._pubs = {}
        self._srvs = {}

        self._external_node = XmlRpcNode(rpc_handler=_TopicPubListenerHandler(self._new_topics))
        self._external_node.start()

        timeout_t = time.time() + 5.0
        while time.time() < timeout_t and self._external_node.uri is None:
            time.sleep(0.01)
コード例 #4
0
    def __init__(self, master_uri, cb):
        self.master_uri = master_uri

        ns = rosgraph.names.get_ros_namespace()
        anon_name = rosgraph.names.anonymous_name('master_sync')

        self.master = rosgraph.Master(rosgraph.names.ns_join(ns, anon_name), master_uri=self.master_uri)

        self.cb = cb

        self.type_cache = {}

        self.subs = {}
        self.pubs = {}
        self.srvs = {}

        rpc_handler = TopicPubListenerHandler(self.new_topics)
        self.external_node = XmlRpcNode(rpc_handler=rpc_handler)
        self.external_node.start()

        timeout_t = time.time() + 5.
        while time.time() < timeout_t and self.external_node.uri is None:
            time.sleep(0.01)