OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 part of application; | 5 part of application; |
6 | 6 |
7 typedef void ServiceFactory(core.MojoMessagePipeEndpoint endpoint); | 7 typedef void ServiceFactory(core.MojoMessagePipeEndpoint endpoint); |
8 typedef void FallbackServiceFactory( | 8 typedef void FallbackServiceFactory( |
9 String interfaceName, core.MojoMessagePipeEndpoint endpoint); | 9 String interfaceName, core.MojoMessagePipeEndpoint endpoint); |
10 | 10 |
11 class LocalServiceProvider implements ServiceProvider { | 11 class LocalServiceProvider implements ServiceProvider { |
12 final ApplicationConnection connection; | 12 final ApplicationConnection connection; |
13 ServiceProviderStub _stub; | 13 ServiceProviderStub _stub; |
14 | 14 |
15 LocalServiceProvider(this.connection, this._stub) { | 15 LocalServiceProvider(this.connection, this._stub) { |
16 _stub.impl = this; | 16 _stub.impl = this; |
17 if (!_stub.isOpen) { | 17 if (!_stub.isOpen) { |
18 throw new core.MojoApiError("The service provider stub must be open"); | 18 throw new core.MojoApiError("The service provider stub must be open"); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 set onError(Function f) { | 22 set onError(Function f) { |
23 _stub.onError = f; | 23 _stub.onError = f; |
24 } | 24 } |
25 | 25 |
26 Future close({bool immediate: false}) => _stub.close(immediate: immediate); | 26 Future close({bool immediate: false}) => _stub.close(immediate: immediate); |
27 | 27 |
28 void connectToService( | 28 void connectToService_( |
29 String interfaceName, core.MojoMessagePipeEndpoint pipe) { | 29 String interfaceName, core.MojoMessagePipeEndpoint pipe) { |
30 if (connection._nameToServiceFactory.containsKey(interfaceName)) { | 30 if (connection._nameToServiceFactory.containsKey(interfaceName)) { |
31 connection._nameToServiceFactory[interfaceName](pipe); | 31 connection._nameToServiceFactory[interfaceName](pipe); |
32 return; | 32 return; |
33 } | 33 } |
34 if (connection.fallbackServiceFactory != null) { | 34 if (connection.fallbackServiceFactory != null) { |
35 connection.fallbackServiceFactory(interfaceName, pipe); | 35 connection.fallbackServiceFactory(interfaceName, pipe); |
36 return; | 36 return; |
37 } | 37 } |
38 // The specified interface isn't provided. Close the pipe so the | 38 // The specified interface isn't provided. Close the pipe so the |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 FallbackServiceFactory get fallbackServiceFactory => _fallbackServiceFactory; | 84 FallbackServiceFactory get fallbackServiceFactory => _fallbackServiceFactory; |
85 set fallbackServiceFactory(FallbackServiceFactory f) { | 85 set fallbackServiceFactory(FallbackServiceFactory f) { |
86 if (_localServiceProvider == null) { | 86 if (_localServiceProvider == null) { |
87 throw new core.MojoApiError( | 87 throw new core.MojoApiError( |
88 "There must be a local service provider to set a service factory"); | 88 "There must be a local service provider to set a service factory"); |
89 } | 89 } |
90 _fallbackServiceFactory = f; | 90 _fallbackServiceFactory = f; |
91 } | 91 } |
92 | 92 |
93 bindings.ProxyBase requestService(bindings.ProxyBase proxy, | 93 bindings.Proxy requestService(bindings.Proxy proxy, |
94 [String serviceName]) { | 94 [String serviceName]) { |
95 if (proxy.impl.isBound || | 95 if (proxy.ctrl.isBound || |
96 (remoteServiceProvider == null) || | 96 (remoteServiceProvider == null) || |
97 !remoteServiceProvider.impl.isBound) { | 97 !remoteServiceProvider.ctrl.isBound) { |
98 throw new core.MojoApiError( | 98 throw new core.MojoApiError( |
99 "The proxy is bound, or there is no remove service provider proxy"); | 99 "The proxy is bound, or there is no remove service provider proxy"); |
100 } | 100 } |
101 | 101 |
102 var name = serviceName ?? proxy.serviceName; | 102 var name = serviceName ?? proxy.ctrl.serviceName; |
103 if ((name == null) || name.isEmpty) { | 103 if ((name == null) || name.isEmpty) { |
104 throw new core.MojoApiError( | 104 throw new core.MojoApiError( |
105 "If an interface has no ServiceName, then one must be provided."); | 105 "If an interface has no ServiceName, then one must be provided."); |
106 } | 106 } |
107 | 107 |
108 var pipe = new core.MojoMessagePipe(); | 108 var pipe = new core.MojoMessagePipe(); |
109 proxy.impl.bind(pipe.endpoints[0]); | 109 proxy.ctrl.bind(pipe.endpoints[0]); |
110 remoteServiceProvider.ptr.connectToService(name, pipe.endpoints[1]); | 110 remoteServiceProvider.connectToService_(name, pipe.endpoints[1]); |
111 return proxy; | 111 return proxy; |
112 } | 112 } |
113 | 113 |
114 /// Prepares this connection to provide the specified service when a call for | 114 /// Prepares this connection to provide the specified service when a call for |
115 /// the given [interfaceName] is received. The provided service can also | 115 /// the given [interfaceName] is received. The provided service can also |
116 /// choose to expose a service description. | 116 /// choose to expose a service description. |
117 void provideService(String interfaceName, ServiceFactory factory, | 117 void provideService(String interfaceName, ServiceFactory factory, |
118 {service_describer.ServiceDescription description}) { | 118 {service_describer.ServiceDescription description}) { |
119 if (_localServiceProvider == null) { | 119 if (_localServiceProvider == null) { |
120 throw new core.MojoApiError( | 120 throw new core.MojoApiError( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 if (_localServiceProvider != null) { | 161 if (_localServiceProvider != null) { |
162 lspCloseFuture = _localServiceProvider.close(immediate: immediate); | 162 lspCloseFuture = _localServiceProvider.close(immediate: immediate); |
163 _localServiceProvider = null; | 163 _localServiceProvider = null; |
164 } else { | 164 } else { |
165 lspCloseFuture = new Future.value(null); | 165 lspCloseFuture = new Future.value(null); |
166 } | 166 } |
167 return rspCloseFuture.then((_) => lspCloseFuture); | 167 return rspCloseFuture.then((_) => lspCloseFuture); |
168 } | 168 } |
169 } | 169 } |
OLD | NEW |