| |
| |
| |
| # deprecatedConnectToAgentService<T> function |
| |
| |
| |
| |
| |
| |
| *[<Null safety>](https://dart.dev/null-safety)* |
| |
| |
| |
| |
| void deprecatedConnectToAgentService |
| <T>(String? agentUrl, [AsyncProxy](../package-fidl_fidl/AsyncProxy-class.md)<T>? serviceProxy, {dynamic componentContextProxy}) |
| |
| |
| |
| <p>Connect to the service specified by <code>serviceProxy</code> and implemented by the |
| agent with <code>agentUrl</code>. Optionally, provide a <code>componentContextProxy</code> which |
| will be used to connect to the agent. If <code>agentUrl</code> is null then the framework |
| will attempt to automatically resolve an appropriate agent for the service.</p> |
| <p>The agent will be launched if it's not already running.</p> |
| |
| |
| |
| ## Implementation |
| |
| ```dart |
| 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); |
| }); |
| } |
| ``` |
| |
| |
| |
| |
| |
| |
| |