Exemplo n.º 1
0
    def __init__(self, name, service_class, handler, buff_size=DEFAULT_BUFF_SIZE):
        super(ServiceImpl, self).__init__(name, service_class)

        if not name or not isstring(name):
            raise ValueError("service name is not a non-empty string")
        # #2202
        if not rosgraph.names.is_legal_name(name):
            import warnings
            warnings.warn("'%s' is not a legal ROS graph resource name. This may cause problems with other ROS tools"%name, stacklevel=2)

        
        self.handler = handler
        self.registered = False
        self.seq = 0
        self.done = False
        self.buff_size=buff_size

        start_tcpros_server() #lazy-init the tcprosserver
        host, port = get_tcpros_server_address()
        self.uri = '%s%s:%s'%(rospy.core.ROSRPC, host, port)
        logdebug("... service URL is %s"%self.uri)

        self.protocol = TCPService(self.resolved_name, service_class, self.buff_size)

        logdebug("[%s]: new Service instance"%self.resolved_name)
Exemplo n.º 2
0
    def __init__(self,
                 name,
                 service_class,
                 handler,
                 buff_size=DEFAULT_BUFF_SIZE,
                 error_handler=None):
        super(ServiceImpl, self).__init__(name, service_class)

        if not name or not isstring(name):
            raise ValueError("service name is not a non-empty string")
        # #2202
        if not rosgraph.names.is_legal_name(name):
            import warnings
            warnings.warn(
                "'%s' is not a legal ROS graph resource name. This may cause problems with other ROS tools"
                % name,
                stacklevel=2)

        self.handler = handler
        if error_handler is not None:
            self.error_handler = error_handler
        self.registered = False
        self.seq = 0
        self.done = False
        self.buff_size = buff_size

        start_tcpros_server()  #lazy-init the tcprosserver
        host, port = get_tcpros_server_address()
        self.uri = '%s%s:%s' % (rospy.core.ROSRPC, host, port)
        logdebug("... service URL is %s" % self.uri)

        self.protocol = TCPService(self.resolved_name, service_class,
                                   self.buff_size)

        logdebug("[%s]: new Service instance" % self.resolved_name)
Exemplo n.º 3
0
 def init_publisher(self, resolved_name, protocol):
     """
     Initialize this node to receive an inbound TCP connection,
     i.e. startup a TCP server if one is not already running.
     
     @param resolved_name: topic name
     @type  resolved__name: str
     
     @param protocol: negotiated protocol
       parameters. protocol[0] must be the string 'TCPROS'
     @type  protocol: [str, value*]
     @return: (code, msg, [TCPROS, addr, port])
     @rtype: (int, str, list)
     """
     if protocol[0] != TCPROS:
         return 0, "Internal error: protocol does not match TCPROS: %s"%protocol, []
     start_tcpros_server()
     addr, port = get_tcpros_server_address()
     return 1, "ready on %s:%s" % (addr, port), [TCPROS, addr, port]
 def init_publisher(self, resolved_name, protocol):
     """
     Initialize this node to receive an inbound TCP connection,
     i.e. startup a TCP server if one is not already running.
     
     @param resolved_name: topic name
     @type  resolved__name: str
     
     @param protocol: negotiated protocol
       parameters. protocol[0] must be the string 'TCPROS'
     @type  protocol: [str, value*]
     @return: (code, msg, [TCPROS, addr, port])
     @rtype: (int, str, list)
     """
     if protocol[0] != TCPROS:
         return 0, "Internal error: protocol does not match TCPROS: %s"%protocol, []
     start_tcpros_server()
     addr, port = get_tcpros_server_address()
     return 1, "ready on %s:%s"%(addr, port), [TCPROS, addr, port]