deprecatedConnectToAgentService<T> function

*[<Null safety>](https://dart.dev/null-safety)*

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

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() as fidl_modular.ComponentContextProxy?;

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