def create_transport(self, resolved_name, pub_uri, protocol_params): """ Connect to topic resolved_name on Publisher pub_uri using TCPROS. @param resolved_name str: resolved topic name @type resolved_name: str @param pub_uri: XML-RPC URI of publisher @type pub_uri: str @param protocol_params: protocol parameters to use for connecting @type protocol_params: [XmlRpcLegal] @return: code, message, debug @rtype: (int, str, int) """ #Validate protocol params = [TCPROS, address, port] if type(protocol_params) != list or len(protocol_params) != 3: return 0, "ERROR: invalid TCPROS parameters", 0 if protocol_params[0] != TCPROS: return 0, "INTERNAL ERROR: protocol id is not TCPROS: %s" % protocol_params[ 0], 0 id, dest_addr, dest_port = protocol_params sub = rospy.impl.registration.get_topic_manager().get_subscriber_impl( resolved_name) #Create connection protocol = TCPROSSub(resolved_name, sub.data_class, \ queue_size=sub.queue_size, buff_size=sub.buff_size, tcp_nodelay=sub.tcp_nodelay) conn = TCPROSTransport(protocol, resolved_name) conn.set_endpoint_id(pub_uri) t = threading.Thread(name=resolved_name, target=robust_connect_subscriber, args=(conn, dest_addr, dest_port, pub_uri, sub.receive_callback, resolved_name)) # don't enable this just yet, need to work on this logic #rospy.core._add_shutdown_thread(t) # Attach connection to _SubscriberImpl if sub.add_connection(conn): #pass tcp connection to handler # since the thread might cause the connection to close # it should only be started after the connection has been added to the subscriber # https://github.com/ros/ros_comm/issues/544 t.start() return 1, "Connected topic[%s]. Transport impl[%s]" % ( resolved_name, conn.__class__.__name__), dest_port else: # _SubscriberImpl already closed or duplicate subscriber created conn.close() return 0, "ERROR: Race condition failure creating topic subscriber [%s]" % ( resolved_name), 0
def create_transport(self, resolved_name, pub_uri, protocol_params): """ Connect to topic resolved_name on Publisher pub_uri using TCPROS. @param resolved_name str: resolved topic name @type resolved_name: str @param pub_uri: XML-RPC URI of publisher @type pub_uri: str @param protocol_params: protocol parameters to use for connecting @type protocol_params: [XmlRpcLegal] @return: code, message, debug @rtype: (int, str, int) """ #Validate protocol params = [TCPROS, address, port] if type(protocol_params) != list or len(protocol_params) != 3: return 0, "ERROR: invalid TCPROS parameters", 0 if protocol_params[0] != TCPROS: return 0, "INTERNAL ERROR: protocol id is not TCPROS: %s"%id, 0 id, dest_addr, dest_port = protocol_params sub = rospy.impl.registration.get_topic_manager().get_subscriber_impl(resolved_name) #Create connection protocol = TCPROSSub(resolved_name, sub.data_class, \ queue_size=sub.queue_size, buff_size=sub.buff_size, tcp_nodelay=sub.tcp_nodelay) conn = TCPROSTransport(protocol, resolved_name) conn.set_endpoint_id(pub_uri); t = threading.Thread(name=resolved_name, target=robust_connect_subscriber, args=(conn, dest_addr, dest_port, pub_uri, sub.receive_callback,resolved_name)) # don't enable this just yet, need to work on this logic #rospy.core._add_shutdown_thread(t) # Attach connection to _SubscriberImpl if sub.add_connection(conn): #pass tcp connection to handler # since the thread might cause the connection to close # it should only be started after the connection has been added to the subscriber # https://github.com/ros/ros_comm/issues/544 t.start() return 1, "Connected topic[%s]. Transport impl[%s]"%(resolved_name, conn.__class__.__name__), dest_port else: # _SubscriberImpl already closed or duplicate subscriber created conn.close() return 0, "ERROR: Race condition failure creating topic subscriber [%s]"%(resolved_name), 0