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()
def registerService(self, caller_id, service, service_api, caller_api): """ Forked from ROSMasterHandler. Register the caller as a provider of the specified service. 0. If service is `remote-only`, register with ROS Master 1. If Service is `local-only`, register with current shadow instance. 2. Otherwise, register with both sides. @param caller_id str: ROS caller id @type caller_id: str @param service: Fully-qualified name of service @type service: str @param service_api: Service URI @type service_api: str @param caller_api: XML-RPC URI of caller node @type caller_api: str @return: (code, message, ignore) @rtype: (int, str, int) """ cfg = swcfg.services.get_config(service) if not cfg.is_local_only(): self._reg_remote_service(caller_id, service, service_api, caller_api) if not cfg.is_remote_only(): self._reg_local_service(caller_id, service, service_api, caller_api) return ResponseFactory.service_reg(caller_id, service).pack()
def unregisterService(self, caller_id, service, service_api): """ Forked from ROSMasterHandler. Unregister the caller as a provider of the specified service. @param caller_id str: ROS caller id @type caller_id: str @param service: Fully-qualified name of service @type service: str @param service_api: API URI of service to unregister. Unregistration will only occur if current registration matches. @type service_api: str @return: (code, message, numUnregistered). Number of unregistrations (either 0 or 1). If this is zero it means that the caller was not registered as a service provider. The call still succeeds as the intended final state is reached. @rtype: (int, str, int) """ cfg = swcfg.services.get_config(service) if not cfg.is_local_only(): self._unreg_remote_service(caller_id, service, service_api) if not cfg.is_remote_only(): self._unreg_local_service(caller_id, service, service_api) return ResponseFactory.service_unreg(caller_id, service).pack()
def unregCell(self, service, service_uri, daemon_uri): with self.record_lock: self.records[service].remove(service_uri, daemon_uri) return ResponseFactory.service_unreg(daemon_uri, service).pack()