[dart-sdk] remove ServicesConnector class
In favor of StartupContext.incmoing
Test:
1. fx run-test fuchsia_services_package_integration_tests
2. run echo client async example
3. run mind reader example
4. launch ermine
Change-Id: Ie83b605ac4c692884b31184b8d197d0e696270a9
diff --git a/examples/fidl/echo_client_async_dart/lib/main.dart b/examples/fidl/echo_client_async_dart/lib/main.dart
index 2065a17..f08255e 100644
--- a/examples/fidl/echo_client_async_dart/lib/main.dart
+++ b/examples/fidl/echo_client_async_dart/lib/main.dart
@@ -5,10 +5,11 @@
import 'dart:async';
import 'package:fidl_fidl_examples_echo/fidl_async.dart' as fidl_echo;
import 'package:fuchsia_services/services.dart';
+import 'package:fidl_fuchsia_io/fidl_async.dart';
import 'package:fidl_fuchsia_sys/fidl_async.dart';
import 'package:fuchsia/fuchsia.dart' show exit;
-Future<Null> main(List<String> args) async {
+Future<void> main(List<String> args) async {
String serverUrl =
'fuchsia-pkg://fuchsia.com/echo_server_async_dart#meta/echo_server_async_dart.cmx';
if (args.length >= 2 && args[0] == '--server') {
@@ -16,14 +17,24 @@
}
final context = StartupContext.fromStartupInfo();
- final servicesConnector = ServicesConnector();
+
+ /// A [DirectoryProxy] who's channels will facilitate the connection between
+ /// this client component and the launched server component we're about to
+ /// launch. This client component is looking for service under /in/svc/
+ /// directory to connect to while the server exposes services others can
+ /// connect to under /out/public directory.
+ final dirProxy = DirectoryProxy();
// Connect. The destination server is specified, and we request for it to be
// started if it wasn't already.
- final launchInfo =
- LaunchInfo(url: serverUrl, directoryRequest: servicesConnector.request());
- // Creates a new instance of the component described by launchInfo.
+ final launchInfo = LaunchInfo(
+ url: serverUrl,
+ // The directoryRequest is the handle to the /out directory of the launched
+ // component.
+ directoryRequest: dirProxy.ctrl.request().passChannel(),
+ );
+ // Creates a new instance of the component described by launchInfo.
final componentController = ComponentControllerProxy();
await context.launcher
@@ -32,7 +43,7 @@
// Bind. We bind EchoProxy, a generated proxy class, to the remote Echo
// service.
final _echo = fidl_echo.EchoProxy();
- await servicesConnector.connectToService(_echo.ctrl);
+ Incoming(dirProxy).connectToService(_echo);
// Invoke echoString with a value and print it's response.
final response = await _echo.echoString('hello');
diff --git a/public/dart/fuchsia_services/BUILD.gn b/public/dart/fuchsia_services/BUILD.gn
index bd196e4..5c7fd77 100644
--- a/public/dart/fuchsia_services/BUILD.gn
+++ b/public/dart/fuchsia_services/BUILD.gn
@@ -20,7 +20,6 @@
"src/internal/_startup_context_impl.dart",
"src/outgoing.dart",
"src/service_provider_impl.dart",
- "src/services_connector.dart",
"src/startup_context.dart",
]
diff --git a/public/dart/fuchsia_services/examples/mind_reader/bin/client/lib/main.dart b/public/dart/fuchsia_services/examples/mind_reader/bin/client/lib/main.dart
index 4012ae3..d90f6e9 100644
--- a/public/dart/fuchsia_services/examples/mind_reader/bin/client/lib/main.dart
+++ b/public/dart/fuchsia_services/examples/mind_reader/bin/client/lib/main.dart
@@ -4,6 +4,7 @@
import 'dart:async';
+import 'package:fidl_fuchsia_io/fidl_async.dart';
import 'package:fidl_fuchsia_services_examples/fidl_async.dart';
import 'package:fidl_fuchsia_sys/fidl_async.dart';
import 'package:fuchsia/fuchsia.dart' show exit;
@@ -12,7 +13,7 @@
import 'src/_thought_leaker_impl.dart';
-/// The URL which will be used to launch the mind reader server componet.
+/// The URL which will be used to launch the mind reader server component.
const _mindReaderServerUrl =
'fuchsia-pkg://fuchsia.com/mind_reader_dart#meta/mind_reader_server.cmx';
@@ -45,9 +46,13 @@
log.info('Exposing ThoughtLeakerImpl with the thought "$thoughtToExpose"');
}
- /// A [ServicesConnector] object is used to connect to a service which is
- /// exposed in the launched components out/public directory.
- final connector = ServicesConnector();
+
+ /// A [DirectoryProxy] who's channels will facilitate the connection between
+ /// this client component and the launched server component we're about to
+ /// launch. This client component is looking for service under /in/svc/
+ /// directory to connect to while the server exposes services others can
+ /// connect to under /out/public directory.
+ final dirProxy = DirectoryProxy();
/// The [LaunchInfo] struct is used to construct the component we want to
/// launch.
@@ -55,7 +60,7 @@
url: _mindReaderServerUrl,
// The directoryRequest is the handle to the /out directory of the launched
// component.
- directoryRequest: connector.request(),
+ directoryRequest: dirProxy.ctrl.request().passChannel(),
// The service list is a list of services which are exposed to the child.
// If a service is not included in this list the child will fail to connect.
@@ -73,7 +78,7 @@
// Now that the component has launched we attempt to connect to the mind
// reader service which is exposed to us by the child.
final mindReader = MindReaderProxy();
- await connector.connectToService(mindReader.ctrl);
+ Incoming(dirProxy).connectToService(mindReader);
// We ask the service to read our mind and wait for the response.
final response = await mindReader.readMind();
diff --git a/public/dart/fuchsia_services/lib/services.dart b/public/dart/fuchsia_services/lib/services.dart
index 0009351..9fdac2c 100644
--- a/public/dart/fuchsia_services/lib/services.dart
+++ b/public/dart/fuchsia_services/lib/services.dart
@@ -4,7 +4,7 @@
/// The base-level functionality required by any component on Fuchsia.
export 'src/environment_service_connection.dart';
+export 'src/incoming.dart';
export 'src/outgoing.dart';
export 'src/service_provider_impl.dart';
-export 'src/services_connector.dart';
export 'src/startup_context.dart';
diff --git a/public/dart/fuchsia_services/lib/src/services_connector.dart b/public/dart/fuchsia_services/lib/src/services_connector.dart
deleted file mode 100644
index 114b9b5..0000000
--- a/public/dart/fuchsia_services/lib/src/services_connector.dart
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright 2019 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import 'dart:async';
-
-import 'package:fidl/fidl.dart';
-import 'package:fidl_fuchsia_io/fidl_async.dart';
-import 'package:zircon/zircon.dart';
-
-import 'incoming.dart';
-
-/// Deprecated - Facilitate the ability to connect to services outside of the
-/// Modular Framework, for example via a command-line tool.
-///
-/// The user is responsible to launch a component and wire up a connection
-/// between the new launched component and the request returned from this
-/// [ServicesConnection.request()]. This is typically done using
-/// [StartupContext#launcher].
-///
-/// For Module Framework APIs see `package:fuchsia_modular`
-///
-/// Deprecated, instead use
-/// `StartupContext.fromStartupInfo().incoming.connectToService`
-// TODO(MS-2335) remove this class
-class ServicesConnector {
- Incoming _incoming;
-
- /// Creates a interface request, binds one of the channels to this object, and
- /// returns the other channel.
- ///
- /// Note: previously returned [Channel] will no longer be associate with this
- /// object.
- Channel request() {
- final _dirProxy = DirectoryProxy();
- _incoming = Incoming(_dirProxy);
- return _dirProxy.ctrl.request().passChannel();
- }
-
- /// Connects the most recently returned [Channel] from [request()] with the
- /// provided services represented by its [controller].
- // TODO(MS-2335) remove this class
- Future<void> connectToService<T>(AsyncProxyController<T> controller) async {
- final String serviceName = controller.$serviceName;
- if (serviceName == null) {
- throw Exception(
- "${controller.$interfaceName}'s controller.\$serviceName must "
- 'not be null. Check the FIDL file for a missing [Discoverable]');
- }
- _incoming.connectToServiceByNameWithChannel(
- controller.$serviceName, controller.request().passChannel());
- }
-
- /// Terminates connection and return Zircon status.
- Future<int> close() async {
- return _incoming.close();
- }
-}
diff --git a/shell/ermine/lib/src/models/app_model.dart b/shell/ermine/lib/src/models/app_model.dart
index 78c659f..474afc6 100644
--- a/shell/ermine/lib/src/models/app_model.dart
+++ b/shell/ermine/lib/src/models/app_model.dart
@@ -3,8 +3,8 @@
// found in the LICENSE file.
import 'dart:async';
-import 'package:flutter/material.dart';
+import 'package:fidl_fuchsia_io/fidl_async.dart';
import 'package:fidl_fuchsia_modular/fidl_async.dart'
show
SessionShellContextProxy,
@@ -29,10 +29,10 @@
import 'package:fidl_fuchsia_ui_gfx/fidl_async.dart'
show ExportToken, ImportToken;
import 'package:fidl_fuchsia_ui_policy/fidl_async.dart' show PresentationProxy;
-import 'package:fuchsia_services/services.dart'
- show connectToEnvironmentService, ServicesConnector, StartupContext;
+import 'package:flutter/material.dart';
import 'package:fuchsia_scenic_flutter/child_view_connection.dart'
show ChildViewConnection;
+import 'package:fuchsia_services/services.dart';
import 'package:lib.widgets/model.dart' show Model;
import 'package:lib.widgets/utils.dart' show PointerEventsListener;
import 'package:zircon/zircon.dart';
@@ -119,7 +119,6 @@
// Load the ask bar.
_loadAskBar();
}
-
/// Called after runApp which initializes flutter's gesture system.
void onStarted() {
_pointerEventsListener.listen(_presentation);
@@ -128,12 +127,12 @@
}
void _loadAskBar() {
- final serviceConnector = ServicesConnector();
+ final dirProxy = DirectoryProxy();
startupContext.launcher.createComponent(
LaunchInfo(
url: _kErmineAskModuleUrl,
- directoryRequest: serviceConnector.request(),
+ directoryRequest: dirProxy.ctrl.request().passChannel(),
additionalServices: ServiceList(
names: <String>[
PuppetMaster.$serviceName,
@@ -153,9 +152,9 @@
);
final viewProvider = ViewProviderProxy();
- serviceConnector
- ..connectToService(viewProvider.ctrl)
- ..connectToService(_ask.ctrl)
+ Incoming(dirProxy)
+ ..connectToService(viewProvider)
+ ..connectToService(_ask)
..close();
// Create a token pair for the newly-created View.