Google is committed to advancing racial equity for Black communities. See how.

deprecatedConnectToAgentService<T> function

void deprecatedConnectToAgentService <T>(String agentUrl, AsyncProxy<T> serviceProxy, {dynamic componentContextProxy})

Connect to the service specified by serviceProxy and implemented by the agent with agentUrl. Optionally, provide a componentContextProxy which will be used to connect to the agent. If agentUrl is null then the framework will attempt to automatically resolve an appropriate agent for the service.

The agent will be launched if it's not already running.

Implementation

void deprecatedConnectToAgentService<T>(String agentUrl, AsyncProxy<T> serviceProxy,
    {fidl_modular.ComponentContextProxy componentContextProxy}) {
  if (serviceProxy == null) {
    throw Exception(
        'serviceProxy must not be null in call to connectToAgentService');
  }

  final serviceName = serviceProxy.ctrl.$serviceName;
  if (serviceName == null) {
    throw Exception("${serviceProxy.ctrl.$interfaceName}'s "
        'proxyServiceController.\$serviceName must not be null. Check the FIDL '
        'file for a missing [Discoverable]');
  }

  final agentControllerProxy = fidl_modular.AgentControllerProxy();

  // Creates an interface request and binds one of the channels. Binding this
  // channel prior to connecting to the agent allows the developer to make
  // proxy calls without awaiting for the connection to actually establish.
  final serviceProxyRequest = serviceProxy.ctrl.request();

  final agentServiceRequest = fidl_modular.AgentServiceRequest(
    serviceName: serviceName,
    channel: serviceProxyRequest.passChannel(),
    handler: agentUrl,
    agentController: agentControllerProxy.ctrl.request(),
  );

  serviceProxy.ctrl.whenClosed.then((_) {
    agentControllerProxy.ctrl.close();
  });

  componentContextProxy ??= getComponentContext();

  componentContextProxy
      .deprecatedConnectToAgentService(agentServiceRequest)
      .catchError((e) {
    log.shout('Failed to connect to agent service [$serviceName]', e);
  });
}