Beispiel #1
0
    def lookupService(self, caller_id, service):
        """
        Lookup all provider of a particular service in following rules:
        1. Local/Auto/Unlabeled
            1. Use local services if possible.
            2. Otherwise, use remote services.
        2. Remote
            1. If average time cost belows the balance-curve, use remote services.
            2. Otherwise, use remote services if possible.
        @param caller_id str: ROS caller id
        @type  caller_id: str
        @param service: fully-qualified name of service to lookup.
        @type: service: str
        @return: (code, message, serviceUrl). service URL is provider's
        ROSRPC URI with address and port.  Fails if there is no provider.
        @rtype: (int, str, str)
        """
        uri = None
        cfg = swcfg.services.get_config(service)

        def skeleton(x, y):
            fallback_p = const(bool(cfg.fallback))
            # TODO: support fallback list
            return on_fallback(x, y, fallback_p, success_uri)

        # local?
        if swcfg.localtype == cfg.priority:
            fn = skeleton(self._lookup_local_service, self._lookup_remote_service)
        else:
            fn = skeleton(self._lookup_remote_service, self._lookup_local_service)
        uri = fn(service)
        if success_uri(uri):
            return ResponseFactory.uri_found(service, uri).pack()
        else:
            return ResponseFactory.unknown_service(service).pack()
 def lookupService(self, caller_id, service):
     """
     Forked from ROSMasterHandler
     Lookup all provider of a particular service.
     @param caller_id str: ROS caller id
     @type  caller_id: str
     @param service: fully-qualified name of service to lookup.
     @type: service: str
     @return: (code, message, serviceUrl). service URL is provider's
        ROSRPC URI with address and port.  Fails if there is no provider.
     @rtype: (int, str, str)
     """
     # try to find a clint-registered service
     code, msg, value = super(IlluminantHandler, self).lookupService(caller_id, service)
     if code == 1:  # if got a client-registered service, return it.
         return code, msg, value
     else:  # otherwise, use a cell if possible
         uri = self._lookup_cell(service)
         if uri is None:
             return ResponseFactory.unknown_service(service).pack()
         else:
             uri = uri[1]
             with self.trans_lock:
                 code, msg, parsed = self.trans.parse(uri)
             if not parsed:
                 return ResponseFactory.unknown_service(service).pack()
             else:
                 return ResponseFactory.uri_found(service, parsed).pack()
Beispiel #3
0
    def lookupService(self, caller_id, service):
        """
        Lookup all provider of a particular service in following rules:
        1. Local/Auto/Unlabeled
            1. Use local services if possible.
            2. Otherwise, use remote services.
        2. Remote
            1. If average time cost belows the balance-curve, use remote services.
            2. Otherwise, use remote services if possible.
        @param caller_id str: ROS caller id
        @type  caller_id: str
        @param service: fully-qualified name of service to lookup.
        @type: service: str
        @return: (code, message, serviceUrl). service URL is provider's
        ROSRPC URI with address and port.  Fails if there is no provider.
        @rtype: (int, str, str)
        """
        uri = None
        cfg = swcfg.services.get_config(service)

        def skeleton(x, y):
            fallback_p = const(bool(cfg.fallback))
            # TODO: support fallback list
            return on_fallback(x, y, fallback_p, success_uri)

        # local?
        if swcfg.localtype == cfg.priority:
            fn = skeleton(self._lookup_local_service,
                          self._lookup_remote_service)
        else:
            fn = skeleton(self._lookup_remote_service,
                          self._lookup_local_service)
        uri = fn(service)
        if success_uri(uri):
            return ResponseFactory.uri_found(service, uri).pack()
        else:
            return ResponseFactory.unknown_service(service).pack()