Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: mojo/public/dart/src/application_connection.dart

Issue 934253003: Dart Bindings: ApplicationConnection (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 part of application;
6
7 typedef core.Listener ServiceFactory(core.MojoMessagePipeEndpoint endpoint);
8 typedef void FallbackServiceFactory(
9 String interfaceName, core.MojoMessagePipeEndpoint endpoint);
10
11
12 class LocalServiceProvider extends ServiceProvider {
13 final ApplicationConnection connection;
14
15 LocalServiceProvider(ApplicationConnection this.connection,
16 ServiceProviderStub stub) : super.fromStub(stub) {
17 delegate = this;
18 }
19
20 void connectToService(String interfaceName, core.MojoMessagePipeEndpoint pipe) {
zra 2015/02/18 21:45:33 Long line
hansmuller1 2015/02/18 22:07:24 Fixed
21 if (connection._nameToServiceFactory.containsKey(interfaceName)) {
22 var listener = connection._nameToServiceFactory[interfaceName](pipe);
23 if (listener != null) {
24 listener.listen();
25 return;
26 }
27 }
28 if (connection.fallbackServiceFactory != null) {
29 connection.fallbackServiceFactory(interfaceName, pipe);
30 return;
31 }
32 // The specified interface isn't provided. Close the pipe so the
33 // remote endpoint sees that we don't support this interface.
34 pipe.handle.close();
35 }
36 }
37
38 // Encapsulates a pair of ServiceProviders that enable services (interface
39 // implementations) to be provided to a remote application as well as exposing
40 // services provided by a remote application. ApplicationConnection
41 // objects are returned by the Application ConnectToApplication() method
42 // and they're passed to the Application AcceptConnection() method.
43 //
44 // To request a service from the remote application:
45 // var proxy = applicationConnection.requestService(ViewManagerClient.name);
46 //
47 // To provide a service to the remote application, specify a function that
48 // returns a service. For example:
49 // applicationConnection.provideService(ViewManagerClient.name, (pipe) =>
50 // new ViewManagerClientImpl(pipe));
51 //
52 // To handle requests for any interface, set fallbackServiceFactory to a
53 // function that takes ownership of the incoming message pipe endpoint. If the
54 // fallbackServiceFactory function doesn't bind the pipe, it should close it.
55 //
56 // The fallbackServiceFactory is only used if a service wasn't specified
57 // with provideService().
58
59 class ApplicationConnection {
60 ServiceProviderProxy _remoteServiceProvider;
61 LocalServiceProvider _localServiceProvider;
62 final _nameToServiceFactory = new Map<String, ServiceFactory>();
63 FallbackServiceFactory fallbackServiceFactory;
64
65 ApplicationConnection(ServiceProviderStub stub, ServiceProviderProxy proxy)
66 : _remoteServiceProvider = proxy {
67 if (stub != null)
68 _localServiceProvider = new LocalServiceProvider(this, stub);
69 }
70
71 bindings.Proxy requestService(bindings.Proxy proxy) {
72 assert(!proxy.isBound && (_remoteServiceProvider != null) && _remoteServiceP rovider.isBound);
zra 2015/02/18 21:45:33 Long line.
hansmuller1 2015/02/18 22:07:24 Sorry about that, I fixed it while you where revie
73 var applicationPipe = new core.MojoMessagePipe();
74 var proxyEndpoint = applicationPipe.endpoints[0];
75 var applicationEndpoint = applicationPipe.endpoints[1];
76 proxy.bind(proxyEndpoint);
77 _remoteServiceProvider.connectToService(proxy.name, applicationEndpoint);
78 return proxy;
79 }
80
81 void provideService(String interfaceName, ServiceFactory factory) {
82 assert(_localServiceProvider != null);
83 _nameToServiceFactory[interfaceName] = factory;
84 }
85
86 void listen() {
87 if (_localServiceProvider != null)
88 _localServiceProvider.listen();
89 }
90
91 void close({bool nodefer : false}) {
92 if (_remoteServiceProvider != null) {
93 _remoteServiceProvider.close();
94 _remoteServiceProvider = null;
95 }
96 if (_localServiceProvider != null) {
97 _localServiceProvider.close(nodefer: nodefer);
98 _localServiceProvider = null;
99 }
100
101 }
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698