提交 b6ad8850 编写于 作者: A Adam Barth

Roll mojo2 (#2722)

* Update to mojo 7d579155cc597aa3befcbfad66eef54bda06b57c

* Update to new API
上级 cc2cc42f
......@@ -19,7 +19,7 @@
vars = {
'chromium_git': 'https://chromium.googlesource.com',
'mojo_sdk_revision': '55352570f8c52ca1282dcfa26a4a32adc08495d6',
'mojo_sdk_revision': 'fbe912aa65e0346382bc1e2874eb88fa3aad3358',
'base_revision': '672b04e54b937ec899429a6bd5409c5a6300d151',
'skia_revision': '8cc209111876b7c78b5ec577c9221d8ed5e21024',
......
9a791294e429f9f2ca4f427796a284edb6f6768e
\ No newline at end of file
7d579155cc597aa3befcbfad66eef54bda06b57c
\ No newline at end of file
......@@ -11,13 +11,14 @@
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_impl_base.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace mojo {
// static
void ApplicationImpl::Terminate() {
void ApplicationImplBase::Terminate() {
if (base::MessageLoop::current()->is_running())
base::MessageLoop::current()->Quit();
}
......
......@@ -4,7 +4,7 @@
#include "mojo/application/content_handler_factory.h"
#include <set>
#include <map>
#include "base/bind.h"
#include "base/callback.h"
......@@ -14,7 +14,6 @@
#include "base/trace_event/trace_event.h"
#include "mojo/application/application_runner_chromium.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
......@@ -112,11 +111,13 @@ class ContentHandlerImpl : public ContentHandler {
} // namespace
ContentHandlerFactory::ContentHandlerFactory(Delegate* delegate)
: delegate_(delegate) {
}
ContentHandlerFactory::~ContentHandlerFactory() {
// static
ServiceProviderImpl::InterfaceRequestHandler<ContentHandler>
ContentHandlerFactory::GetInterfaceRequestHandler(Delegate* delegate) {
return [delegate](const ConnectionContext& connection_context,
InterfaceRequest<ContentHandler> content_handler_request) {
new ContentHandlerImpl(delegate, content_handler_request.Pass());
};
}
void ContentHandlerFactory::ManagedDelegate::RunApplication(
......@@ -129,9 +130,4 @@ void ContentHandlerFactory::ManagedDelegate::RunApplication(
loop.Run();
}
void ContentHandlerFactory::Create(ApplicationConnection* connection,
InterfaceRequest<ContentHandler> request) {
new ContentHandlerImpl(delegate_, request.Pass());
}
} // namespace mojo
......@@ -6,14 +6,18 @@
#define MOJO_APPLICATION_CONTENT_HANDLER_FACTORY_H_
#include "base/memory/scoped_ptr.h"
#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/public/cpp/application/service_provider_impl.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/services/content_handler/interfaces/content_handler.mojom.h"
#include "mojo/services/network/interfaces/url_loader.mojom.h"
namespace mojo {
class ContentHandlerFactory : public InterfaceFactory<ContentHandler> {
struct ConnectionContext;
// TODO(vtl): Nuke this class. Now it's only a "namespace" for stuff, most of
// which is overcomplicated.
class ContentHandlerFactory {
public:
class HandledApplicationHolder {
public:
......@@ -46,17 +50,9 @@ class ContentHandlerFactory : public InterfaceFactory<ContentHandler> {
URLResponsePtr response) override;
};
explicit ContentHandlerFactory(Delegate* delegate);
~ContentHandlerFactory() override;
private:
// From InterfaceFactory:
void Create(ApplicationConnection* connection,
InterfaceRequest<ContentHandler> request) override;
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(ContentHandlerFactory);
// For use with |ServiceProviderImpl::AddService<ContentHandler>()|.
static ServiceProviderImpl::InterfaceRequestHandler<ContentHandler>
GetInterfaceRequestHandler(Delegate* delegate);
};
template <class A>
......
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/mojo_application.gni")
import("//mojo/public/tools/bindings/mojom.gni")
import("//testing/test.gni")
......@@ -40,13 +41,13 @@ source_set("tests") {
]
}
test("mojo_common_unittests") {
mojo_native_application("mojo_common_apptests") {
testonly = true
deps = [
":tests",
"//mojo/data_pipe_utils:tests",
"//mojo/edk/test:run_all_unittests",
"//mojo/environment:chromium",
"//mojo/message_pump:tests",
"//mojo/application",
"//mojo/application:test_support",
]
}
......
......@@ -12,7 +12,6 @@
#include "base/time/time.h"
#include "base/trace_event/trace_config.h"
#include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_impl.h"
namespace mojo {
......
## 0.4.23
- 28 changes: https://github.com/domokit/mojo/compare/107bac0...ef5cd66
MOJO_SDK: ef5cd660ec6f1c50eaff62c81ea7662662d04e15
## 0.4.22
- 22 changes: https://github.com/domokit/mojo/compare/12d71ee...f56fd59
MOJO_SDK: f56fd59ec51e1ecdd52fb848ceff1b6b6fe7f7fa
## 0.4.21
- 35 changes: https://github.com/domokit/mojo/compare/e95b5db...c200560
MOJO_SDK: c200560ac45a79b61b8e8c0444af471789f5669f
## 0.4.20
- 125 changes: https://github.com/domokit/mojo/compare/2f662f4...705723c
......
......@@ -17,6 +17,7 @@ import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart'
part 'src/control_message.dart';
part 'src/codec.dart';
part 'src/enum.dart';
part 'src/interfaces.dart';
part 'src/message.dart';
part 'src/proxy.dart';
part 'src/struct.dart';
......
......@@ -5,15 +5,16 @@
library core;
import 'dart:async';
import 'dart:collection';
import 'dart:isolate';
import 'dart:mojo.internal';
import 'dart:typed_data';
import 'src/internal.dart';
part 'src/buffer.dart';
part 'src/data_pipe.dart';
part 'src/drain_data.dart';
part 'src/event_stream.dart';
part 'src/event_subscription.dart';
part 'src/event_handler.dart';
part 'src/fill_data.dart';
part 'src/handle.dart';
part 'src/message_pipe.dart';
......
......@@ -16,7 +16,7 @@ class _ApplicationInitializeParams extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(32, 0)
];
Object shell = null;
shell_mojom.ShellInterface shell = null;
List<String> args = null;
String url = null;
......@@ -131,8 +131,8 @@ class _ApplicationAcceptConnectionParams extends bindings.Struct {
const bindings.StructDataHeader(40, 0)
];
String requestorUrl = null;
Object services = null;
Object exposedServices = null;
service_provider_mojom.ServiceProviderInterfaceRequest services = null;
service_provider_mojom.ServiceProviderInterface exposedServices = null;
String resolvedUrl = null;
_ApplicationAcceptConnectionParams() : super(kVersions.last.size);
......@@ -310,29 +310,61 @@ class _ApplicationServiceDescription implements service_describer.ServiceDescrip
abstract class Application {
static const String serviceName = null;
void initialize(Object shell, List<String> args, String url);
void acceptConnection(String requestorUrl, Object services, Object exposedServices, String resolvedUrl);
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ApplicationServiceDescription();
}
return _cachedServiceDescription;
}
static ApplicationProxy connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ApplicationProxy p = new ApplicationProxy.unbound();
String name = serviceName ?? Application.serviceName;
if ((name == null) || name.isEmpty) {
throw new core.MojoApiError(
"If an interface has no ServiceName, then one must be provided.");
}
s.connectToService(url, p, name);
return p;
}
void initialize(shell_mojom.ShellInterface shell, List<String> args, String url);
void acceptConnection(String requestorUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices, String resolvedUrl);
void requestQuit();
}
abstract class ApplicationInterface
implements bindings.MojoInterface<Application>,
Application {
factory ApplicationInterface([Application impl]) =>
new ApplicationStub.unbound(impl);
factory ApplicationInterface.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint,
[Application impl]) =>
new ApplicationStub.fromEndpoint(endpoint, impl);
}
class _ApplicationProxyImpl extends bindings.Proxy {
_ApplicationProxyImpl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
abstract class ApplicationInterfaceRequest
implements bindings.MojoInterface<Application>,
Application {
factory ApplicationInterfaceRequest() =>
new ApplicationProxy.unbound();
}
_ApplicationProxyImpl.fromHandle(core.MojoHandle handle) :
super.fromHandle(handle);
class _ApplicationProxyControl
extends bindings.ProxyMessageHandler
implements bindings.ProxyControl<Application> {
_ApplicationProxyControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
_ApplicationProxyImpl.unbound() : super.unbound();
_ApplicationProxyControl.fromHandle(
core.MojoHandle handle) : super.fromHandle(handle);
static _ApplicationProxyImpl newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For _ApplicationProxyImpl"));
return new _ApplicationProxyImpl.fromEndpoint(endpoint);
}
_ApplicationProxyControl.unbound() : super.unbound();
service_describer.ServiceDescription get serviceDescription =>
new _ApplicationServiceDescription();
String get serviceName => Application.serviceName;
void handleResponse(bindings.ServiceMessage message) {
switch (message.header.type) {
......@@ -343,81 +375,32 @@ class _ApplicationProxyImpl extends bindings.Proxy {
}
}
Application get impl => null;
set impl(Application _) {
throw new core.MojoApiError("The impl of a Proxy cannot be set.");
}
@override
String toString() {
var superString = super.toString();
return "_ApplicationProxyImpl($superString)";
return "_ApplicationProxyControl($superString)";
}
}
class _ApplicationProxyCalls implements Application {
_ApplicationProxyImpl _proxyImpl;
_ApplicationProxyCalls(this._proxyImpl);
void initialize(Object shell, List<String> args, String url) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationInitializeParams();
params.shell = shell;
params.args = args;
params.url = url;
_proxyImpl.sendMessage(params, _applicationMethodInitializeName);
}
void acceptConnection(String requestorUrl, Object services, Object exposedServices, String resolvedUrl) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationAcceptConnectionParams();
params.requestorUrl = requestorUrl;
params.services = services;
params.exposedServices = exposedServices;
params.resolvedUrl = resolvedUrl;
_proxyImpl.sendMessage(params, _applicationMethodAcceptConnectionName);
}
void requestQuit() {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationRequestQuitParams();
_proxyImpl.sendMessage(params, _applicationMethodRequestQuitName);
}
}
class ApplicationProxy implements bindings.ProxyBase {
final bindings.Proxy impl;
Application ptr;
ApplicationProxy(_ApplicationProxyImpl proxyImpl) :
impl = proxyImpl,
ptr = new _ApplicationProxyCalls(proxyImpl);
class ApplicationProxy
extends bindings.Proxy<Application>
implements Application,
ApplicationInterface,
ApplicationInterfaceRequest {
ApplicationProxy.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) :
impl = new _ApplicationProxyImpl.fromEndpoint(endpoint) {
ptr = new _ApplicationProxyCalls(impl);
}
core.MojoMessagePipeEndpoint endpoint)
: super(new _ApplicationProxyControl.fromEndpoint(endpoint));
ApplicationProxy.fromHandle(core.MojoHandle handle) :
impl = new _ApplicationProxyImpl.fromHandle(handle) {
ptr = new _ApplicationProxyCalls(impl);
}
ApplicationProxy.fromHandle(core.MojoHandle handle)
: super(new _ApplicationProxyControl.fromHandle(handle));
ApplicationProxy.unbound() :
impl = new _ApplicationProxyImpl.unbound() {
ptr = new _ApplicationProxyCalls(impl);
}
factory ApplicationProxy.connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ApplicationProxy p = new ApplicationProxy.unbound();
s.connectToService(url, p, serviceName);
return p;
}
ApplicationProxy.unbound()
: super(new _ApplicationProxyControl.unbound());
static ApplicationProxy newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
......@@ -425,50 +408,63 @@ class ApplicationProxy implements bindings.ProxyBase {
return new ApplicationProxy.fromEndpoint(endpoint);
}
String get serviceName => Application.serviceName;
Future close({bool immediate: false}) => impl.close(immediate: immediate);
Future responseOrError(Future f) => impl.responseOrError(f);
Future get errorFuture => impl.errorFuture;
int get version => impl.version;
Future<int> queryVersion() => impl.queryVersion();
void requireVersion(int requiredVersion) {
impl.requireVersion(requiredVersion);
void initialize(shell_mojom.ShellInterface shell, List<String> args, String url) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationInitializeParams();
params.shell = shell;
params.args = args;
params.url = url;
ctrl.sendMessage(params,
_applicationMethodInitializeName);
}
String toString() {
return "ApplicationProxy($impl)";
void acceptConnection(String requestorUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices, String resolvedUrl) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationAcceptConnectionParams();
params.requestorUrl = requestorUrl;
params.services = services;
params.exposedServices = exposedServices;
params.resolvedUrl = resolvedUrl;
ctrl.sendMessage(params,
_applicationMethodAcceptConnectionName);
}
void requestQuit() {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationRequestQuitParams();
ctrl.sendMessage(params,
_applicationMethodRequestQuitName);
}
}
class ApplicationStub extends bindings.Stub {
class _ApplicationStubControl
extends bindings.StubMessageHandler
implements bindings.StubControl<Application> {
Application _impl;
ApplicationStub.fromEndpoint(
_ApplicationStubControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [Application impl])
: super.fromEndpoint(endpoint, autoBegin: impl != null) {
_impl = impl;
}
ApplicationStub.fromHandle(
_ApplicationStubControl.fromHandle(
core.MojoHandle handle, [Application impl])
: super.fromHandle(handle, autoBegin: impl != null) {
_impl = impl;
}
ApplicationStub.unbound() : super.unbound();
_ApplicationStubControl.unbound([this._impl]) : super.unbound();
static ApplicationStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ApplicationStub"));
return new ApplicationStub.fromEndpoint(endpoint);
}
String get serviceName => Application.serviceName;
......@@ -521,19 +517,46 @@ class ApplicationStub extends bindings.Stub {
}
}
@override
String toString() {
var superString = super.toString();
return "ApplicationStub($superString)";
return "_ApplicationStubControl($superString)";
}
int get version => 0;
}
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ApplicationServiceDescription();
}
return _cachedServiceDescription;
class ApplicationStub
extends bindings.Stub<Application>
implements Application,
ApplicationInterface,
ApplicationInterfaceRequest {
ApplicationStub.unbound([Application impl])
: super(new _ApplicationStubControl.unbound(impl));
ApplicationStub.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [Application impl])
: super(new _ApplicationStubControl.fromEndpoint(endpoint, impl));
ApplicationStub.fromHandle(
core.MojoHandle handle, [Application impl])
: super(new _ApplicationStubControl.fromHandle(handle, impl));
static ApplicationStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ApplicationStub"));
return new ApplicationStub.fromEndpoint(endpoint);
}
void initialize(shell_mojom.ShellInterface shell, List<String> args, String url) {
return impl.initialize(shell, args, url);
}
void acceptConnection(String requestorUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices, String resolvedUrl) {
return impl.acceptConnection(requestorUrl, services, exposedServices, resolvedUrl);
}
void requestQuit() {
return impl.requestQuit();
}
}
......
......@@ -16,8 +16,8 @@ class _ApplicationConnectorConnectToApplicationParams extends bindings.Struct {
const bindings.StructDataHeader(32, 0)
];
String applicationUrl = null;
Object services = null;
Object exposedServices = null;
service_provider_mojom.ServiceProviderInterfaceRequest services = null;
service_provider_mojom.ServiceProviderInterface exposedServices = null;
_ApplicationConnectorConnectToApplicationParams() : super(kVersions.last.size);
......@@ -112,7 +112,7 @@ class _ApplicationConnectorDuplicateParams extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(16, 0)
];
Object applicationConnectorRequest = null;
ApplicationConnectorInterfaceRequest applicationConnectorRequest = null;
_ApplicationConnectorDuplicateParams() : super(kVersions.last.size);
......@@ -194,28 +194,60 @@ class _ApplicationConnectorServiceDescription implements service_describer.Servi
abstract class ApplicationConnector {
static const String serviceName = null;
void connectToApplication(String applicationUrl, Object services, Object exposedServices);
void duplicate(Object applicationConnectorRequest);
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ApplicationConnectorServiceDescription();
}
return _cachedServiceDescription;
}
static ApplicationConnectorProxy connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ApplicationConnectorProxy p = new ApplicationConnectorProxy.unbound();
String name = serviceName ?? ApplicationConnector.serviceName;
if ((name == null) || name.isEmpty) {
throw new core.MojoApiError(
"If an interface has no ServiceName, then one must be provided.");
}
s.connectToService(url, p, name);
return p;
}
void connectToApplication(String applicationUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices);
void duplicate(ApplicationConnectorInterfaceRequest applicationConnectorRequest);
}
abstract class ApplicationConnectorInterface
implements bindings.MojoInterface<ApplicationConnector>,
ApplicationConnector {
factory ApplicationConnectorInterface([ApplicationConnector impl]) =>
new ApplicationConnectorStub.unbound(impl);
factory ApplicationConnectorInterface.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint,
[ApplicationConnector impl]) =>
new ApplicationConnectorStub.fromEndpoint(endpoint, impl);
}
class _ApplicationConnectorProxyImpl extends bindings.Proxy {
_ApplicationConnectorProxyImpl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
abstract class ApplicationConnectorInterfaceRequest
implements bindings.MojoInterface<ApplicationConnector>,
ApplicationConnector {
factory ApplicationConnectorInterfaceRequest() =>
new ApplicationConnectorProxy.unbound();
}
_ApplicationConnectorProxyImpl.fromHandle(core.MojoHandle handle) :
super.fromHandle(handle);
class _ApplicationConnectorProxyControl
extends bindings.ProxyMessageHandler
implements bindings.ProxyControl<ApplicationConnector> {
_ApplicationConnectorProxyControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
_ApplicationConnectorProxyImpl.unbound() : super.unbound();
_ApplicationConnectorProxyControl.fromHandle(
core.MojoHandle handle) : super.fromHandle(handle);
static _ApplicationConnectorProxyImpl newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For _ApplicationConnectorProxyImpl"));
return new _ApplicationConnectorProxyImpl.fromEndpoint(endpoint);
}
_ApplicationConnectorProxyControl.unbound() : super.unbound();
service_describer.ServiceDescription get serviceDescription =>
new _ApplicationConnectorServiceDescription();
String get serviceName => ApplicationConnector.serviceName;
void handleResponse(bindings.ServiceMessage message) {
switch (message.header.type) {
......@@ -226,70 +258,32 @@ class _ApplicationConnectorProxyImpl extends bindings.Proxy {
}
}
ApplicationConnector get impl => null;
set impl(ApplicationConnector _) {
throw new core.MojoApiError("The impl of a Proxy cannot be set.");
}
@override
String toString() {
var superString = super.toString();
return "_ApplicationConnectorProxyImpl($superString)";
return "_ApplicationConnectorProxyControl($superString)";
}
}
class _ApplicationConnectorProxyCalls implements ApplicationConnector {
_ApplicationConnectorProxyImpl _proxyImpl;
_ApplicationConnectorProxyCalls(this._proxyImpl);
void connectToApplication(String applicationUrl, Object services, Object exposedServices) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationConnectorConnectToApplicationParams();
params.applicationUrl = applicationUrl;
params.services = services;
params.exposedServices = exposedServices;
_proxyImpl.sendMessage(params, _applicationConnectorMethodConnectToApplicationName);
}
void duplicate(Object applicationConnectorRequest) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationConnectorDuplicateParams();
params.applicationConnectorRequest = applicationConnectorRequest;
_proxyImpl.sendMessage(params, _applicationConnectorMethodDuplicateName);
}
}
class ApplicationConnectorProxy implements bindings.ProxyBase {
final bindings.Proxy impl;
ApplicationConnector ptr;
ApplicationConnectorProxy(_ApplicationConnectorProxyImpl proxyImpl) :
impl = proxyImpl,
ptr = new _ApplicationConnectorProxyCalls(proxyImpl);
class ApplicationConnectorProxy
extends bindings.Proxy<ApplicationConnector>
implements ApplicationConnector,
ApplicationConnectorInterface,
ApplicationConnectorInterfaceRequest {
ApplicationConnectorProxy.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) :
impl = new _ApplicationConnectorProxyImpl.fromEndpoint(endpoint) {
ptr = new _ApplicationConnectorProxyCalls(impl);
}
ApplicationConnectorProxy.fromHandle(core.MojoHandle handle) :
impl = new _ApplicationConnectorProxyImpl.fromHandle(handle) {
ptr = new _ApplicationConnectorProxyCalls(impl);
}
core.MojoMessagePipeEndpoint endpoint)
: super(new _ApplicationConnectorProxyControl.fromEndpoint(endpoint));
ApplicationConnectorProxy.unbound() :
impl = new _ApplicationConnectorProxyImpl.unbound() {
ptr = new _ApplicationConnectorProxyCalls(impl);
}
ApplicationConnectorProxy.fromHandle(core.MojoHandle handle)
: super(new _ApplicationConnectorProxyControl.fromHandle(handle));
factory ApplicationConnectorProxy.connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ApplicationConnectorProxy p = new ApplicationConnectorProxy.unbound();
s.connectToService(url, p, serviceName);
return p;
}
ApplicationConnectorProxy.unbound()
: super(new _ApplicationConnectorProxyControl.unbound());
static ApplicationConnectorProxy newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
......@@ -297,50 +291,51 @@ class ApplicationConnectorProxy implements bindings.ProxyBase {
return new ApplicationConnectorProxy.fromEndpoint(endpoint);
}
String get serviceName => ApplicationConnector.serviceName;
Future close({bool immediate: false}) => impl.close(immediate: immediate);
Future responseOrError(Future f) => impl.responseOrError(f);
Future get errorFuture => impl.errorFuture;
int get version => impl.version;
Future<int> queryVersion() => impl.queryVersion();
void requireVersion(int requiredVersion) {
impl.requireVersion(requiredVersion);
void connectToApplication(String applicationUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationConnectorConnectToApplicationParams();
params.applicationUrl = applicationUrl;
params.services = services;
params.exposedServices = exposedServices;
ctrl.sendMessage(params,
_applicationConnectorMethodConnectToApplicationName);
}
String toString() {
return "ApplicationConnectorProxy($impl)";
void duplicate(ApplicationConnectorInterfaceRequest applicationConnectorRequest) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ApplicationConnectorDuplicateParams();
params.applicationConnectorRequest = applicationConnectorRequest;
ctrl.sendMessage(params,
_applicationConnectorMethodDuplicateName);
}
}
class ApplicationConnectorStub extends bindings.Stub {
class _ApplicationConnectorStubControl
extends bindings.StubMessageHandler
implements bindings.StubControl<ApplicationConnector> {
ApplicationConnector _impl;
ApplicationConnectorStub.fromEndpoint(
_ApplicationConnectorStubControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [ApplicationConnector impl])
: super.fromEndpoint(endpoint, autoBegin: impl != null) {
_impl = impl;
}
ApplicationConnectorStub.fromHandle(
_ApplicationConnectorStubControl.fromHandle(
core.MojoHandle handle, [ApplicationConnector impl])
: super.fromHandle(handle, autoBegin: impl != null) {
_impl = impl;
}
ApplicationConnectorStub.unbound() : super.unbound();
_ApplicationConnectorStubControl.unbound([this._impl]) : super.unbound();
static ApplicationConnectorStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ApplicationConnectorStub"));
return new ApplicationConnectorStub.fromEndpoint(endpoint);
}
String get serviceName => ApplicationConnector.serviceName;
......@@ -390,19 +385,43 @@ class ApplicationConnectorStub extends bindings.Stub {
}
}
@override
String toString() {
var superString = super.toString();
return "ApplicationConnectorStub($superString)";
return "_ApplicationConnectorStubControl($superString)";
}
int get version => 0;
}
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ApplicationConnectorServiceDescription();
}
return _cachedServiceDescription;
class ApplicationConnectorStub
extends bindings.Stub<ApplicationConnector>
implements ApplicationConnector,
ApplicationConnectorInterface,
ApplicationConnectorInterfaceRequest {
ApplicationConnectorStub.unbound([ApplicationConnector impl])
: super(new _ApplicationConnectorStubControl.unbound(impl));
ApplicationConnectorStub.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [ApplicationConnector impl])
: super(new _ApplicationConnectorStubControl.fromEndpoint(endpoint, impl));
ApplicationConnectorStub.fromHandle(
core.MojoHandle handle, [ApplicationConnector impl])
: super(new _ApplicationConnectorStubControl.fromHandle(handle, impl));
static ApplicationConnectorStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ApplicationConnectorStub"));
return new ApplicationConnectorStub.fromEndpoint(endpoint);
}
void connectToApplication(String applicationUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices) {
return impl.connectToApplication(applicationUrl, services, exposedServices);
}
void duplicate(ApplicationConnectorInterfaceRequest applicationConnectorRequest) {
return impl.duplicate(applicationConnectorRequest);
}
}
......
......@@ -207,7 +207,7 @@ class MojomFileGraph extends bindings.Struct {
];
Map<String, MojomFile> files = null;
Map<String, mojom_types_mojom.UserDefinedType> resolvedTypes = null;
Map<String, mojom_types_mojom.UserDefinedValue> resolvedValues = null;
Map<String, mojom_types_mojom.DeclaredConstant> resolvedConstants = null;
MojomFileGraph() : super(kVersions.last.size);
......@@ -325,7 +325,7 @@ class MojomFileGraph extends bindings.Struct {
{
decoder1.decodeDataHeaderForMap();
List<String> keys0;
List<mojom_types_mojom.UserDefinedValue> values0;
List<mojom_types_mojom.DeclaredConstant> values0;
{
var decoder2 = decoder1.decodePointer(bindings.ArrayDataHeader.kHeaderSize, false);
......@@ -342,19 +342,16 @@ class MojomFileGraph extends bindings.Struct {
var decoder2 = decoder1.decodePointer(bindings.ArrayDataHeader.kHeaderSize + bindings.kPointerSize, false);
{
var si2 = decoder2.decodeDataHeaderForUnionArray(keys0.length);
values0 = new List<mojom_types_mojom.UserDefinedValue>(si2.numElements);
var si2 = decoder2.decodeDataHeaderForPointerArray(keys0.length);
values0 = new List<mojom_types_mojom.DeclaredConstant>(si2.numElements);
for (int i2 = 0; i2 < si2.numElements; ++i2) {
values0[i2] = mojom_types_mojom.UserDefinedValue.decode(decoder2, bindings.ArrayDataHeader.kHeaderSize + bindings.kUnionSize * i2);
if (values0[i2] == null) {
throw new bindings.MojoCodecError(
'Trying to decode null union for non-nullable mojom_types_mojom.UserDefinedValue.');
}
var decoder3 = decoder2.decodePointer(bindings.ArrayDataHeader.kHeaderSize + bindings.kPointerSize * i2, false);
values0[i2] = mojom_types_mojom.DeclaredConstant.decode(decoder3);
}
}
}
result.resolvedValues = new Map<String, mojom_types_mojom.UserDefinedValue>.fromIterables(
result.resolvedConstants = new Map<String, mojom_types_mojom.DeclaredConstant>.fromIterables(
keys0, values0);
}
}
......@@ -418,12 +415,12 @@ class MojomFileGraph extends bindings.Struct {
rethrow;
}
try {
if (resolvedValues == null) {
if (resolvedConstants == null) {
encoder0.encodeNullPointer(24, false);
} else {
var encoder1 = encoder0.encoderForMap(24);
var keys0 = resolvedValues.keys.toList();
var values0 = resolvedValues.values.toList();
var keys0 = resolvedConstants.keys.toList();
var values0 = resolvedConstants.values.toList();
{
var encoder2 = encoder1.encodePointerArray(keys0.length, bindings.ArrayDataHeader.kHeaderSize, bindings.kUnspecifiedArrayLength);
......@@ -433,15 +430,15 @@ class MojomFileGraph extends bindings.Struct {
}
{
var encoder2 = encoder1.encodeUnionArray(values0.length, bindings.ArrayDataHeader.kHeaderSize + bindings.kPointerSize, bindings.kUnspecifiedArrayLength);
var encoder2 = encoder1.encodePointerArray(values0.length, bindings.ArrayDataHeader.kHeaderSize + bindings.kPointerSize, bindings.kUnspecifiedArrayLength);
for (int i1 = 0; i1 < values0.length; ++i1) {
encoder2.encodeUnion(values0[i1], bindings.ArrayDataHeader.kHeaderSize + bindings.kUnionSize * i1, false);
encoder2.encodeStruct(values0[i1], bindings.ArrayDataHeader.kHeaderSize + bindings.kPointerSize * i1, false);
}
}
}
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"resolvedValues of struct MojomFileGraph: $e";
"resolvedConstants of struct MojomFileGraph: $e";
rethrow;
}
}
......@@ -450,14 +447,14 @@ class MojomFileGraph extends bindings.Struct {
return "MojomFileGraph("
"files: $files" ", "
"resolvedTypes: $resolvedTypes" ", "
"resolvedValues: $resolvedValues" ")";
"resolvedConstants: $resolvedConstants" ")";
}
Map toJson() {
Map map = new Map();
map["files"] = files;
map["resolvedTypes"] = resolvedTypes;
map["resolvedValues"] = resolvedValues;
map["resolvedConstants"] = resolvedConstants;
return map;
}
}
......
......@@ -1414,10 +1414,9 @@ class MojomUnion extends bindings.Struct {
class EnumValue extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(48, 0)
const bindings.StructDataHeader(40, 0)
];
DeclarationData declData = null;
String enumTypeKey = null;
Value initializerValue = null;
int intValue = 0;
......@@ -1463,15 +1462,11 @@ class EnumValue extends bindings.Struct {
}
if (mainDataHeader.version >= 0) {
result.enumTypeKey = decoder0.decodeString(16, false);
}
if (mainDataHeader.version >= 0) {
result.initializerValue = Value.decode(decoder0, 24);
result.initializerValue = Value.decode(decoder0, 16);
}
if (mainDataHeader.version >= 0) {
result.intValue = decoder0.decodeInt32(40);
result.intValue = decoder0.decodeInt32(32);
}
return result;
}
......@@ -1486,21 +1481,14 @@ class EnumValue extends bindings.Struct {
rethrow;
}
try {
encoder0.encodeString(enumTypeKey, 16, false);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"enumTypeKey of struct EnumValue: $e";
rethrow;
}
try {
encoder0.encodeUnion(initializerValue, 24, true);
encoder0.encodeUnion(initializerValue, 16, true);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"initializerValue of struct EnumValue: $e";
rethrow;
}
try {
encoder0.encodeInt32(intValue, 40);
encoder0.encodeInt32(intValue, 32);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"intValue of struct EnumValue: $e";
......@@ -1511,7 +1499,6 @@ class EnumValue extends bindings.Struct {
String toString() {
return "EnumValue("
"declData: $declData" ", "
"enumTypeKey: $enumTypeKey" ", "
"initializerValue: $initializerValue" ", "
"intValue: $intValue" ")";
}
......@@ -1519,7 +1506,6 @@ class EnumValue extends bindings.Struct {
Map toJson() {
Map map = new Map();
map["declData"] = declData;
map["enumTypeKey"] = enumTypeKey;
map["initializerValue"] = initializerValue;
map["intValue"] = intValue;
return map;
......@@ -1914,16 +1900,16 @@ class MojomInterface extends bindings.Struct {
}
class UserValueReference extends bindings.Struct {
class ConstantReference extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(24, 0)
];
String identifier = null;
String valueKey = null;
String constantKey = null;
UserValueReference() : super(kVersions.last.size);
ConstantReference() : super(kVersions.last.size);
static UserValueReference deserialize(bindings.Message message) {
static ConstantReference deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
if (decoder.excessHandles != null) {
......@@ -1932,11 +1918,11 @@ class UserValueReference extends bindings.Struct {
return result;
}
static UserValueReference decode(bindings.Decoder decoder0) {
static ConstantReference decode(bindings.Decoder decoder0) {
if (decoder0 == null) {
return null;
}
UserValueReference result = new UserValueReference();
ConstantReference result = new ConstantReference();
var mainDataHeader = decoder0.decodeStructDataHeader();
if (mainDataHeader.version <= kVersions.last.version) {
......@@ -1962,7 +1948,7 @@ class UserValueReference extends bindings.Struct {
}
if (mainDataHeader.version >= 0) {
result.valueKey = decoder0.decodeString(16, true);
result.constantKey = decoder0.decodeString(16, false);
}
return result;
}
......@@ -1973,28 +1959,128 @@ class UserValueReference extends bindings.Struct {
encoder0.encodeString(identifier, 8, false);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"identifier of struct UserValueReference: $e";
"identifier of struct ConstantReference: $e";
rethrow;
}
try {
encoder0.encodeString(valueKey, 16, true);
encoder0.encodeString(constantKey, 16, false);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"valueKey of struct UserValueReference: $e";
"constantKey of struct ConstantReference: $e";
rethrow;
}
}
String toString() {
return "UserValueReference("
return "ConstantReference("
"identifier: $identifier" ", "
"valueKey: $valueKey" ")";
"constantKey: $constantKey" ")";
}
Map toJson() {
Map map = new Map();
map["identifier"] = identifier;
map["valueKey"] = valueKey;
map["constantKey"] = constantKey;
return map;
}
}
class EnumValueReference extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(32, 0)
];
String identifier = null;
String enumTypeKey = null;
int enumValueIndex = 0;
EnumValueReference() : super(kVersions.last.size);
static EnumValueReference deserialize(bindings.Message message) {
var decoder = new bindings.Decoder(message);
var result = decode(decoder);
if (decoder.excessHandles != null) {
decoder.excessHandles.forEach((h) => h.close());
}
return result;
}
static EnumValueReference decode(bindings.Decoder decoder0) {
if (decoder0 == null) {
return null;
}
EnumValueReference result = new EnumValueReference();
var mainDataHeader = decoder0.decodeStructDataHeader();
if (mainDataHeader.version <= kVersions.last.version) {
// Scan in reverse order to optimize for more recent versions.
for (int i = kVersions.length - 1; i >= 0; --i) {
if (mainDataHeader.version >= kVersions[i].version) {
if (mainDataHeader.size == kVersions[i].size) {
// Found a match.
break;
}
throw new bindings.MojoCodecError(
'Header size doesn\'t correspond to known version size.');
}
}
} else if (mainDataHeader.size < kVersions.last.size) {
throw new bindings.MojoCodecError(
'Message newer than the last known version cannot be shorter than '
'required by the last known version.');
}
if (mainDataHeader.version >= 0) {
result.identifier = decoder0.decodeString(8, false);
}
if (mainDataHeader.version >= 0) {
result.enumTypeKey = decoder0.decodeString(16, false);
}
if (mainDataHeader.version >= 0) {
result.enumValueIndex = decoder0.decodeUint32(24);
}
return result;
}
void encode(bindings.Encoder encoder) {
var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last);
try {
encoder0.encodeString(identifier, 8, false);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"identifier of struct EnumValueReference: $e";
rethrow;
}
try {
encoder0.encodeString(enumTypeKey, 16, false);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"enumTypeKey of struct EnumValueReference: $e";
rethrow;
}
try {
encoder0.encodeUint32(enumValueIndex, 24);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"enumValueIndex of struct EnumValueReference: $e";
rethrow;
}
}
String toString() {
return "EnumValueReference("
"identifier: $identifier" ", "
"enumTypeKey: $enumTypeKey" ", "
"enumValueIndex: $enumValueIndex" ")";
}
Map toJson() {
Map map = new Map();
map["identifier"] = identifier;
map["enumTypeKey"] = enumTypeKey;
map["enumValueIndex"] = enumValueIndex;
return map;
}
}
......@@ -3285,7 +3371,8 @@ class DefaultFieldValue extends bindings.Union {
enum ValueTag {
literalValue,
userValueReference,
constantReference,
enumValueReference,
builtinValue,
unknown
}
......@@ -3293,14 +3380,16 @@ enum ValueTag {
class Value extends bindings.Union {
static final _tagToInt = const {
ValueTag.literalValue: 0,
ValueTag.userValueReference: 1,
ValueTag.builtinValue: 2,
ValueTag.constantReference: 1,
ValueTag.enumValueReference: 2,
ValueTag.builtinValue: 3,
};
static final _intToTag = const {
0: ValueTag.literalValue,
1: ValueTag.userValueReference,
2: ValueTag.builtinValue,
1: ValueTag.constantReference,
2: ValueTag.enumValueReference,
3: ValueTag.builtinValue,
};
var _data;
......@@ -3318,15 +3407,26 @@ class Value extends bindings.Union {
_tag = ValueTag.literalValue;
_data = value;
}
UserValueReference get userValueReference {
if (_tag != ValueTag.userValueReference) {
throw new bindings.UnsetUnionTagError(_tag, ValueTag.userValueReference);
ConstantReference get constantReference {
if (_tag != ValueTag.constantReference) {
throw new bindings.UnsetUnionTagError(_tag, ValueTag.constantReference);
}
return _data;
}
set userValueReference(UserValueReference value) {
_tag = ValueTag.userValueReference;
set constantReference(ConstantReference value) {
_tag = ValueTag.constantReference;
_data = value;
}
EnumValueReference get enumValueReference {
if (_tag != ValueTag.enumValueReference) {
throw new bindings.UnsetUnionTagError(_tag, ValueTag.enumValueReference);
}
return _data;
}
set enumValueReference(EnumValueReference value) {
_tag = ValueTag.enumValueReference;
_data = value;
}
BuiltinConstantValue get builtinValue {
......@@ -3355,10 +3455,15 @@ class Value extends bindings.Union {
var decoder1 = decoder0.decodePointer(offset + 8, false);
result.literalValue = LiteralValue.decode(decoder1, 0);
break;
case ValueTag.userValueReference:
case ValueTag.constantReference:
var decoder1 = decoder0.decodePointer(offset + 8, false);
result.userValueReference = UserValueReference.decode(decoder1);
result.constantReference = ConstantReference.decode(decoder1);
break;
case ValueTag.enumValueReference:
var decoder1 = decoder0.decodePointer(offset + 8, false);
result.enumValueReference = EnumValueReference.decode(decoder1);
break;
case ValueTag.builtinValue:
......@@ -3383,8 +3488,11 @@ class Value extends bindings.Union {
case ValueTag.literalValue:
encoder0.encodeNestedUnion(literalValue, offset + 8, false);
break;
case ValueTag.userValueReference:
encoder0.encodeStruct(userValueReference, offset + 8, false);
case ValueTag.constantReference:
encoder0.encodeStruct(constantReference, offset + 8, false);
break;
case ValueTag.enumValueReference:
encoder0.encodeStruct(enumValueReference, offset + 8, false);
break;
case ValueTag.builtinValue:
encoder0.encodeEnum(builtinValue, offset + 8);
......@@ -3400,8 +3508,11 @@ class Value extends bindings.Union {
case ValueTag.literalValue:
result += "literalValue";
break;
case ValueTag.userValueReference:
result += "userValueReference";
case ValueTag.constantReference:
result += "constantReference";
break;
case ValueTag.enumValueReference:
result += "enumValueReference";
break;
case ValueTag.builtinValue:
result += "builtinValue";
......@@ -3758,108 +3869,3 @@ class LiteralValue extends bindings.Union {
}
enum UserDefinedValueTag {
enumValue,
declaredConstant,
unknown
}
class UserDefinedValue extends bindings.Union {
static final _tagToInt = const {
UserDefinedValueTag.enumValue: 0,
UserDefinedValueTag.declaredConstant: 1,
};
static final _intToTag = const {
0: UserDefinedValueTag.enumValue,
1: UserDefinedValueTag.declaredConstant,
};
var _data;
UserDefinedValueTag _tag = UserDefinedValueTag.unknown;
UserDefinedValueTag get tag => _tag;
EnumValue get enumValue {
if (_tag != UserDefinedValueTag.enumValue) {
throw new bindings.UnsetUnionTagError(_tag, UserDefinedValueTag.enumValue);
}
return _data;
}
set enumValue(EnumValue value) {
_tag = UserDefinedValueTag.enumValue;
_data = value;
}
DeclaredConstant get declaredConstant {
if (_tag != UserDefinedValueTag.declaredConstant) {
throw new bindings.UnsetUnionTagError(_tag, UserDefinedValueTag.declaredConstant);
}
return _data;
}
set declaredConstant(DeclaredConstant value) {
_tag = UserDefinedValueTag.declaredConstant;
_data = value;
}
static UserDefinedValue decode(bindings.Decoder decoder0, int offset) {
int size = decoder0.decodeUint32(offset);
if (size == 0) {
return null;
}
UserDefinedValue result = new UserDefinedValue();
UserDefinedValueTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case UserDefinedValueTag.enumValue:
var decoder1 = decoder0.decodePointer(offset + 8, false);
result.enumValue = EnumValue.decode(decoder1);
break;
case UserDefinedValueTag.declaredConstant:
var decoder1 = decoder0.decodePointer(offset + 8, false);
result.declaredConstant = DeclaredConstant.decode(decoder1);
break;
default:
throw new bindings.MojoCodecError("Bad union tag: $tag");
}
return result;
}
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case UserDefinedValueTag.enumValue:
encoder0.encodeStruct(enumValue, offset + 8, false);
break;
case UserDefinedValueTag.declaredConstant:
encoder0.encodeStruct(declaredConstant, offset + 8, false);
break;
default:
throw new bindings.MojoCodecError("Bad union tag: $_tag");
}
}
String toString() {
String result = "UserDefinedValue(";
switch (_tag) {
case UserDefinedValueTag.enumValue:
result += "enumValue";
break;
case UserDefinedValueTag.declaredConstant:
result += "declaredConstant";
break;
default:
result += "unknown";
}
result += ": $_data)";
return result;
}
}
......@@ -108,27 +108,59 @@ class _ServiceProviderServiceDescription implements service_describer.ServiceDes
abstract class ServiceProvider {
static const String serviceName = null;
void connectToService(String interfaceName, core.MojoMessagePipeEndpoint pipe);
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ServiceProviderServiceDescription();
}
return _cachedServiceDescription;
}
static ServiceProviderProxy connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ServiceProviderProxy p = new ServiceProviderProxy.unbound();
String name = serviceName ?? ServiceProvider.serviceName;
if ((name == null) || name.isEmpty) {
throw new core.MojoApiError(
"If an interface has no ServiceName, then one must be provided.");
}
s.connectToService(url, p, name);
return p;
}
void connectToService_(String interfaceName, core.MojoMessagePipeEndpoint pipe);
}
abstract class ServiceProviderInterface
implements bindings.MojoInterface<ServiceProvider>,
ServiceProvider {
factory ServiceProviderInterface([ServiceProvider impl]) =>
new ServiceProviderStub.unbound(impl);
factory ServiceProviderInterface.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint,
[ServiceProvider impl]) =>
new ServiceProviderStub.fromEndpoint(endpoint, impl);
}
class _ServiceProviderProxyImpl extends bindings.Proxy {
_ServiceProviderProxyImpl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
abstract class ServiceProviderInterfaceRequest
implements bindings.MojoInterface<ServiceProvider>,
ServiceProvider {
factory ServiceProviderInterfaceRequest() =>
new ServiceProviderProxy.unbound();
}
_ServiceProviderProxyImpl.fromHandle(core.MojoHandle handle) :
super.fromHandle(handle);
class _ServiceProviderProxyControl
extends bindings.ProxyMessageHandler
implements bindings.ProxyControl<ServiceProvider> {
_ServiceProviderProxyControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
_ServiceProviderProxyImpl.unbound() : super.unbound();
_ServiceProviderProxyControl.fromHandle(
core.MojoHandle handle) : super.fromHandle(handle);
static _ServiceProviderProxyImpl newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For _ServiceProviderProxyImpl"));
return new _ServiceProviderProxyImpl.fromEndpoint(endpoint);
}
_ServiceProviderProxyControl.unbound() : super.unbound();
service_describer.ServiceDescription get serviceDescription =>
new _ServiceProviderServiceDescription();
String get serviceName => ServiceProvider.serviceName;
void handleResponse(bindings.ServiceMessage message) {
switch (message.header.type) {
......@@ -139,60 +171,32 @@ class _ServiceProviderProxyImpl extends bindings.Proxy {
}
}
ServiceProvider get impl => null;
set impl(ServiceProvider _) {
throw new core.MojoApiError("The impl of a Proxy cannot be set.");
}
@override
String toString() {
var superString = super.toString();
return "_ServiceProviderProxyImpl($superString)";
return "_ServiceProviderProxyControl($superString)";
}
}
class _ServiceProviderProxyCalls implements ServiceProvider {
_ServiceProviderProxyImpl _proxyImpl;
_ServiceProviderProxyCalls(this._proxyImpl);
void connectToService(String interfaceName, core.MojoMessagePipeEndpoint pipe) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ServiceProviderConnectToServiceParams();
params.interfaceName = interfaceName;
params.pipe = pipe;
_proxyImpl.sendMessage(params, _serviceProviderMethodConnectToServiceName);
}
}
class ServiceProviderProxy implements bindings.ProxyBase {
final bindings.Proxy impl;
ServiceProvider ptr;
ServiceProviderProxy(_ServiceProviderProxyImpl proxyImpl) :
impl = proxyImpl,
ptr = new _ServiceProviderProxyCalls(proxyImpl);
class ServiceProviderProxy
extends bindings.Proxy<ServiceProvider>
implements ServiceProvider,
ServiceProviderInterface,
ServiceProviderInterfaceRequest {
ServiceProviderProxy.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) :
impl = new _ServiceProviderProxyImpl.fromEndpoint(endpoint) {
ptr = new _ServiceProviderProxyCalls(impl);
}
ServiceProviderProxy.fromHandle(core.MojoHandle handle) :
impl = new _ServiceProviderProxyImpl.fromHandle(handle) {
ptr = new _ServiceProviderProxyCalls(impl);
}
core.MojoMessagePipeEndpoint endpoint)
: super(new _ServiceProviderProxyControl.fromEndpoint(endpoint));
ServiceProviderProxy.unbound() :
impl = new _ServiceProviderProxyImpl.unbound() {
ptr = new _ServiceProviderProxyCalls(impl);
}
ServiceProviderProxy.fromHandle(core.MojoHandle handle)
: super(new _ServiceProviderProxyControl.fromHandle(handle));
factory ServiceProviderProxy.connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ServiceProviderProxy p = new ServiceProviderProxy.unbound();
s.connectToService(url, p, serviceName);
return p;
}
ServiceProviderProxy.unbound()
: super(new _ServiceProviderProxyControl.unbound());
static ServiceProviderProxy newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
......@@ -200,50 +204,40 @@ class ServiceProviderProxy implements bindings.ProxyBase {
return new ServiceProviderProxy.fromEndpoint(endpoint);
}
String get serviceName => ServiceProvider.serviceName;
Future close({bool immediate: false}) => impl.close(immediate: immediate);
Future responseOrError(Future f) => impl.responseOrError(f);
Future get errorFuture => impl.errorFuture;
int get version => impl.version;
Future<int> queryVersion() => impl.queryVersion();
void requireVersion(int requiredVersion) {
impl.requireVersion(requiredVersion);
}
String toString() {
return "ServiceProviderProxy($impl)";
void connectToService_(String interfaceName, core.MojoMessagePipeEndpoint pipe) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ServiceProviderConnectToServiceParams();
params.interfaceName = interfaceName;
params.pipe = pipe;
ctrl.sendMessage(params,
_serviceProviderMethodConnectToServiceName);
}
}
class ServiceProviderStub extends bindings.Stub {
class _ServiceProviderStubControl
extends bindings.StubMessageHandler
implements bindings.StubControl<ServiceProvider> {
ServiceProvider _impl;
ServiceProviderStub.fromEndpoint(
_ServiceProviderStubControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [ServiceProvider impl])
: super.fromEndpoint(endpoint, autoBegin: impl != null) {
_impl = impl;
}
ServiceProviderStub.fromHandle(
_ServiceProviderStubControl.fromHandle(
core.MojoHandle handle, [ServiceProvider impl])
: super.fromHandle(handle, autoBegin: impl != null) {
_impl = impl;
}
ServiceProviderStub.unbound() : super.unbound();
_ServiceProviderStubControl.unbound([this._impl]) : super.unbound();
static ServiceProviderStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ServiceProviderStub"));
return new ServiceProviderStub.fromEndpoint(endpoint);
}
String get serviceName => ServiceProvider.serviceName;
......@@ -260,7 +254,7 @@ class ServiceProviderStub extends bindings.Stub {
case _serviceProviderMethodConnectToServiceName:
var params = _ServiceProviderConnectToServiceParams.deserialize(
message.payload);
_impl.connectToService(params.interfaceName, params.pipe);
_impl.connectToService_(params.interfaceName, params.pipe);
break;
default:
throw new bindings.MojoCodecError("Unexpected message name");
......@@ -288,19 +282,40 @@ class ServiceProviderStub extends bindings.Stub {
}
}
@override
String toString() {
var superString = super.toString();
return "ServiceProviderStub($superString)";
return "_ServiceProviderStubControl($superString)";
}
int get version => 0;
}
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ServiceProviderServiceDescription();
}
return _cachedServiceDescription;
class ServiceProviderStub
extends bindings.Stub<ServiceProvider>
implements ServiceProvider,
ServiceProviderInterface,
ServiceProviderInterfaceRequest {
ServiceProviderStub.unbound([ServiceProvider impl])
: super(new _ServiceProviderStubControl.unbound(impl));
ServiceProviderStub.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [ServiceProvider impl])
: super(new _ServiceProviderStubControl.fromEndpoint(endpoint, impl));
ServiceProviderStub.fromHandle(
core.MojoHandle handle, [ServiceProvider impl])
: super(new _ServiceProviderStubControl.fromHandle(handle, impl));
static ServiceProviderStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ServiceProviderStub"));
return new ServiceProviderStub.fromEndpoint(endpoint);
}
void connectToService_(String interfaceName, core.MojoMessagePipeEndpoint pipe) {
return impl.connectToService_(interfaceName, pipe);
}
}
......
......@@ -17,8 +17,8 @@ class _ShellConnectToApplicationParams extends bindings.Struct {
const bindings.StructDataHeader(32, 0)
];
String applicationUrl = null;
Object services = null;
Object exposedServices = null;
service_provider_mojom.ServiceProviderInterfaceRequest services = null;
service_provider_mojom.ServiceProviderInterface exposedServices = null;
_ShellConnectToApplicationParams() : super(kVersions.last.size);
......@@ -113,7 +113,7 @@ class _ShellCreateApplicationConnectorParams extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(16, 0)
];
Object applicationConnectorRequest = null;
application_connector_mojom.ApplicationConnectorInterfaceRequest applicationConnectorRequest = null;
_ShellCreateApplicationConnectorParams() : super(kVersions.last.size);
......@@ -195,28 +195,60 @@ class _ShellServiceDescription implements service_describer.ServiceDescription {
abstract class Shell {
static const String serviceName = null;
void connectToApplication(String applicationUrl, Object services, Object exposedServices);
void createApplicationConnector(Object applicationConnectorRequest);
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ShellServiceDescription();
}
return _cachedServiceDescription;
}
static ShellProxy connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ShellProxy p = new ShellProxy.unbound();
String name = serviceName ?? Shell.serviceName;
if ((name == null) || name.isEmpty) {
throw new core.MojoApiError(
"If an interface has no ServiceName, then one must be provided.");
}
s.connectToService(url, p, name);
return p;
}
void connectToApplication(String applicationUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices);
void createApplicationConnector(application_connector_mojom.ApplicationConnectorInterfaceRequest applicationConnectorRequest);
}
abstract class ShellInterface
implements bindings.MojoInterface<Shell>,
Shell {
factory ShellInterface([Shell impl]) =>
new ShellStub.unbound(impl);
factory ShellInterface.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint,
[Shell impl]) =>
new ShellStub.fromEndpoint(endpoint, impl);
}
class _ShellProxyImpl extends bindings.Proxy {
_ShellProxyImpl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
abstract class ShellInterfaceRequest
implements bindings.MojoInterface<Shell>,
Shell {
factory ShellInterfaceRequest() =>
new ShellProxy.unbound();
}
_ShellProxyImpl.fromHandle(core.MojoHandle handle) :
super.fromHandle(handle);
class _ShellProxyControl
extends bindings.ProxyMessageHandler
implements bindings.ProxyControl<Shell> {
_ShellProxyControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) : super.fromEndpoint(endpoint);
_ShellProxyImpl.unbound() : super.unbound();
_ShellProxyControl.fromHandle(
core.MojoHandle handle) : super.fromHandle(handle);
static _ShellProxyImpl newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For _ShellProxyImpl"));
return new _ShellProxyImpl.fromEndpoint(endpoint);
}
_ShellProxyControl.unbound() : super.unbound();
service_describer.ServiceDescription get serviceDescription =>
new _ShellServiceDescription();
String get serviceName => Shell.serviceName;
void handleResponse(bindings.ServiceMessage message) {
switch (message.header.type) {
......@@ -227,70 +259,32 @@ class _ShellProxyImpl extends bindings.Proxy {
}
}
Shell get impl => null;
set impl(Shell _) {
throw new core.MojoApiError("The impl of a Proxy cannot be set.");
}
@override
String toString() {
var superString = super.toString();
return "_ShellProxyImpl($superString)";
return "_ShellProxyControl($superString)";
}
}
class _ShellProxyCalls implements Shell {
_ShellProxyImpl _proxyImpl;
_ShellProxyCalls(this._proxyImpl);
void connectToApplication(String applicationUrl, Object services, Object exposedServices) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ShellConnectToApplicationParams();
params.applicationUrl = applicationUrl;
params.services = services;
params.exposedServices = exposedServices;
_proxyImpl.sendMessage(params, _shellMethodConnectToApplicationName);
}
void createApplicationConnector(Object applicationConnectorRequest) {
if (!_proxyImpl.isBound) {
_proxyImpl.proxyError("The Proxy is closed.");
return;
}
var params = new _ShellCreateApplicationConnectorParams();
params.applicationConnectorRequest = applicationConnectorRequest;
_proxyImpl.sendMessage(params, _shellMethodCreateApplicationConnectorName);
}
}
class ShellProxy implements bindings.ProxyBase {
final bindings.Proxy impl;
Shell ptr;
ShellProxy(_ShellProxyImpl proxyImpl) :
impl = proxyImpl,
ptr = new _ShellProxyCalls(proxyImpl);
class ShellProxy
extends bindings.Proxy<Shell>
implements Shell,
ShellInterface,
ShellInterfaceRequest {
ShellProxy.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint) :
impl = new _ShellProxyImpl.fromEndpoint(endpoint) {
ptr = new _ShellProxyCalls(impl);
}
ShellProxy.fromHandle(core.MojoHandle handle) :
impl = new _ShellProxyImpl.fromHandle(handle) {
ptr = new _ShellProxyCalls(impl);
}
core.MojoMessagePipeEndpoint endpoint)
: super(new _ShellProxyControl.fromEndpoint(endpoint));
ShellProxy.unbound() :
impl = new _ShellProxyImpl.unbound() {
ptr = new _ShellProxyCalls(impl);
}
ShellProxy.fromHandle(core.MojoHandle handle)
: super(new _ShellProxyControl.fromHandle(handle));
factory ShellProxy.connectToService(
bindings.ServiceConnector s, String url, [String serviceName]) {
ShellProxy p = new ShellProxy.unbound();
s.connectToService(url, p, serviceName);
return p;
}
ShellProxy.unbound()
: super(new _ShellProxyControl.unbound());
static ShellProxy newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
......@@ -298,50 +292,51 @@ class ShellProxy implements bindings.ProxyBase {
return new ShellProxy.fromEndpoint(endpoint);
}
String get serviceName => Shell.serviceName;
Future close({bool immediate: false}) => impl.close(immediate: immediate);
Future responseOrError(Future f) => impl.responseOrError(f);
Future get errorFuture => impl.errorFuture;
int get version => impl.version;
Future<int> queryVersion() => impl.queryVersion();
void requireVersion(int requiredVersion) {
impl.requireVersion(requiredVersion);
void connectToApplication(String applicationUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ShellConnectToApplicationParams();
params.applicationUrl = applicationUrl;
params.services = services;
params.exposedServices = exposedServices;
ctrl.sendMessage(params,
_shellMethodConnectToApplicationName);
}
String toString() {
return "ShellProxy($impl)";
void createApplicationConnector(application_connector_mojom.ApplicationConnectorInterfaceRequest applicationConnectorRequest) {
if (!ctrl.isBound) {
ctrl.proxyError("The Proxy is closed.");
return;
}
var params = new _ShellCreateApplicationConnectorParams();
params.applicationConnectorRequest = applicationConnectorRequest;
ctrl.sendMessage(params,
_shellMethodCreateApplicationConnectorName);
}
}
class ShellStub extends bindings.Stub {
class _ShellStubControl
extends bindings.StubMessageHandler
implements bindings.StubControl<Shell> {
Shell _impl;
ShellStub.fromEndpoint(
_ShellStubControl.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [Shell impl])
: super.fromEndpoint(endpoint, autoBegin: impl != null) {
_impl = impl;
}
ShellStub.fromHandle(
_ShellStubControl.fromHandle(
core.MojoHandle handle, [Shell impl])
: super.fromHandle(handle, autoBegin: impl != null) {
_impl = impl;
}
ShellStub.unbound() : super.unbound();
_ShellStubControl.unbound([this._impl]) : super.unbound();
static ShellStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ShellStub"));
return new ShellStub.fromEndpoint(endpoint);
}
String get serviceName => Shell.serviceName;
......@@ -391,19 +386,43 @@ class ShellStub extends bindings.Stub {
}
}
@override
String toString() {
var superString = super.toString();
return "ShellStub($superString)";
return "_ShellStubControl($superString)";
}
int get version => 0;
}
static service_describer.ServiceDescription _cachedServiceDescription;
static service_describer.ServiceDescription get serviceDescription {
if (_cachedServiceDescription == null) {
_cachedServiceDescription = new _ShellServiceDescription();
}
return _cachedServiceDescription;
class ShellStub
extends bindings.Stub<Shell>
implements Shell,
ShellInterface,
ShellInterfaceRequest {
ShellStub.unbound([Shell impl])
: super(new _ShellStubControl.unbound(impl));
ShellStub.fromEndpoint(
core.MojoMessagePipeEndpoint endpoint, [Shell impl])
: super(new _ShellStubControl.fromEndpoint(endpoint, impl));
ShellStub.fromHandle(
core.MojoHandle handle, [Shell impl])
: super(new _ShellStubControl.fromHandle(handle, impl));
static ShellStub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) {
assert(endpoint.setDescription("For ShellStub"));
return new ShellStub.fromEndpoint(endpoint);
}
void connectToApplication(String applicationUrl, service_provider_mojom.ServiceProviderInterfaceRequest services, service_provider_mojom.ServiceProviderInterface exposedServices) {
return impl.connectToApplication(applicationUrl, services, exposedServices);
}
void createApplicationConnector(application_connector_mojom.ApplicationConnectorInterfaceRequest applicationConnectorRequest) {
return impl.createApplicationConnector(applicationConnectorRequest);
}
}
......
......@@ -6,20 +6,20 @@ part of application;
class _ApplicationImpl implements application_mojom.Application {
application_mojom.ApplicationStub _stub;
shell_mojom.ShellProxy shell;
shell_mojom.ShellInterface shell;
Application _application;
_ApplicationImpl(
Application application, core.MojoMessagePipeEndpoint endpoint) {
_application = application;
_stub = new application_mojom.ApplicationStub.fromEndpoint(endpoint, this);
_stub.onError = ((_) => close());
_stub.ctrl.onError = ((_) => close());
}
_ApplicationImpl.fromHandle(Application application, core.MojoHandle handle) {
_application = application;
_stub = new application_mojom.ApplicationStub.fromHandle(handle, this);
_stub.onError = ((_) => close());
_stub.ctrl.onError = ((_) => close());
}
_ApplicationImpl.fromStub(Application application,
......@@ -27,23 +27,26 @@ class _ApplicationImpl implements application_mojom.Application {
_application = application;
_stub = applicationStub;
_stub.impl = this;
_stub.onError = ((_) => close());
_stub.ctrl.onError = ((_) => close());
}
set onError(core.ErrorHandler f) {
_stub.onError = f;
_stub.ctrl.onError = f;
}
void initialize(
bindings.ProxyBase shellProxy, List<String> args, String url) {
void initialize(shell_mojom.ShellInterface shellInterface,
List<String> args,
String url) {
assert(shell == null);
shell = shellProxy;
shell = shellInterface;
_application.initialize(args, url);
}
@override
void acceptConnection(String requestorUrl, ServiceProviderStub services,
bindings.ProxyBase exposedServices, String resolvedUrl) =>
void acceptConnection(String requestorUrl,
ServiceProviderInterfaceRequest services,
ServiceProviderInterface exposedServices,
String resolvedUrl) =>
_application._acceptConnection(
requestorUrl, services, exposedServices, resolvedUrl);
......@@ -97,16 +100,15 @@ abstract class Application implements bindings.ServiceConnector {
// Returns a connection to the app at |url|.
ApplicationConnection connectToApplication(String url) {
var proxy = new ServiceProviderProxy.unbound();
var stub = new ServiceProviderStub.unbound();
_applicationImpl.shell.ptr.connectToApplication(url, proxy, stub);
var connection = new ApplicationConnection(stub, proxy);
_applicationImpl.shell.connectToApplication(url, proxy, null);
var connection = new ApplicationConnection(null, proxy);
_applicationConnections.add(connection);
return connection;
}
void connectToService(String url, bindings.ProxyBase proxy,
void connectToService(String url, bindings.MojoInterface iface,
[String serviceName]) {
connectToApplication(url).requestService(proxy, serviceName);
connectToApplication(url).requestService(iface, serviceName);
}
void requestQuit() {}
......
......@@ -14,18 +14,18 @@ class LocalServiceProvider implements ServiceProvider {
LocalServiceProvider(this.connection, this._stub) {
_stub.impl = this;
if (!_stub.isOpen) {
if (!_stub.ctrl.isOpen) {
throw new core.MojoApiError("The service provider stub must be open");
}
}
set onError(Function f) {
_stub.onError = f;
_stub.ctrl.onError = f;
}
Future close({bool immediate: false}) => _stub.close(immediate: immediate);
void connectToService(
void connectToService_(
String interfaceName, core.MojoMessagePipeEndpoint pipe) {
if (connection._nameToServiceFactory.containsKey(interfaceName)) {
connection._nameToServiceFactory[interfaceName](pipe);
......@@ -49,8 +49,8 @@ class LocalServiceProvider implements ServiceProvider {
/// [Application.acceptConnection].
///
/// To request a service (e.g. `Foo`) from the remote application:
/// var fooProxy =
/// applicationConnection.requestService(new FooProxy.unbound());
/// var foo = new FooInterfaceRequest();
/// applicationConnection.requestService(foo);
///
/// To provide a service to the remote application, specify a function that
/// instantiantes a service. For example:
......@@ -62,6 +62,9 @@ class LocalServiceProvider implements ServiceProvider {
/// To handle requests for services beyond those set up with [provideService],
/// set [fallbackServiceFactory] to a function that instantiates a service as in
/// the [provideService] case, or closes the pipe.
// TODO(vtl): Once "exposed_services" is removed from Shell's
// ConnectToApplication() (and Application's AcceptConnection(), etc.), this
// class will be a bit of overkill. https://github.com/domokit/mojo/issues/762
class ApplicationConnection {
ServiceProviderProxy remoteServiceProvider;
LocalServiceProvider _localServiceProvider;
......@@ -87,25 +90,24 @@ class ApplicationConnection {
_fallbackServiceFactory = f;
}
bindings.ProxyBase requestService(bindings.ProxyBase proxy,
[String serviceName]) {
if (proxy.impl.isBound ||
void requestService(bindings.MojoInterface iface, [String serviceName]) {
if (iface.ctrl.isBound ||
(remoteServiceProvider == null) ||
!remoteServiceProvider.impl.isBound) {
!remoteServiceProvider.ctrl.isBound) {
throw new core.MojoApiError(
"The proxy is bound, or there is no remove service provider proxy");
"The interface is already bound, "
"or there is no remote service provider");
}
var name = serviceName ?? proxy.serviceName;
var name = serviceName ?? iface.ctrl.serviceName;
if ((name == null) || name.isEmpty) {
throw new core.MojoApiError(
"If an interface has no ServiceName, then one must be provided.");
}
var pipe = new core.MojoMessagePipe();
proxy.impl.bind(pipe.endpoints[0]);
remoteServiceProvider.ptr.connectToService(name, pipe.endpoints[1]);
return proxy;
iface.ctrl.bind(pipe.endpoints[0]);
remoteServiceProvider.connectToService_(name, pipe.endpoints[1]);
}
/// Prepares this connection to provide the specified service when a call for
......
......@@ -60,8 +60,7 @@ class MojoSharedBuffer {
return null;
}
List result =
MojoSharedBufferNatives.GetInformation(handle.h);
List result = MojoSharedBufferNatives.GetInformation(handle.h);
if (result[0] != MojoResult.kOk) {
_status = result[0];
......
......@@ -210,68 +210,51 @@ class Encoder {
encodeHandle(value != null ? value.handle : null, offset, nullable);
void encodeInterface(
core.MojoEventHandler interface, int offset, bool nullable) {
if (interface == null) {
MojoInterface mojoInterface, int offset, bool nullable) {
if (mojoInterface == null) {
encodeInvalideHandle(offset, nullable);
// Set the version field to 0.
encodeUint32(0, offset + kSerializedHandleSize);
return;
}
if (interface is Stub) {
if (interface.isBound) {
throw new MojoCodecError(
'Cannot encode a bound stub for an interface');
}
if (!mojoInterface.ctrl.isBound) {
var pipe = new core.MojoMessagePipe();
interface.bind(pipe.endpoints[0]);
mojoInterface.ctrl.bind(pipe.endpoints[0]);
encodeMessagePipeHandle(pipe.endpoints[1], offset, nullable);
// Set the version to the version in the stub.
encodeUint32(interface.version, offset + kSerializedHandleSize);
} else if (interface is Proxy) {
if (!interface.isBound) {
throw new MojoCodecError(
'Cannot encode an unbound proxy for an interface');
}
if (!interface.isOpen) {
encodeUint32(mojoInterface.ctrl.version, offset + kSerializedHandleSize);
} else {
if (!mojoInterface.ctrl.isOpen) {
// Make sure that we are listening so that state for the proxy is
// cleaned up when the message is sent and the handle is closed.
interface.beginHandlingEvents();
mojoInterface.ctrl.beginHandlingEvents();
}
encodeMessagePipeHandle(interface.endpoint, offset, nullable);
encodeMessagePipeHandle(mojoInterface.ctrl.endpoint, offset, nullable);
// Set the version to the current version of the proxy.
encodeUint32(interface.version, offset + kSerializedHandleSize);
} else {
throw new MojoCodecError('Cannot encode an unknown MojoEventHandler');
encodeUint32(mojoInterface.ctrl.version, offset + kSerializedHandleSize);
}
}
void encodeInterfaceRequest(Object request, int offset, bool nullable) {
if (request == null) {
void encodeInterfaceRequest(
MojoInterface mojoInterface, int offset, bool nullable) {
if (mojoInterface == null) {
encodeInvalideHandle(offset, nullable);
return;
}
if (request is ProxyBase) {
if (request.impl.isBound) {
throw new MojoCodecError(
'Cannot encode a bound proxy for an interface request');
}
if (!mojoInterface.ctrl.isBound) {
var pipe = new core.MojoMessagePipe();
request.impl.bind(pipe.endpoints[0]);
request.impl.beginHandlingEvents();
mojoInterface.ctrl.bind(pipe.endpoints[0]);
mojoInterface.ctrl.beginHandlingEvents();
encodeMessagePipeHandle(pipe.endpoints[1], offset, nullable);
} else if (request is Stub) {
if (!request.isBound) {
throw new MojoCodecError(
'Cannot encode an unbound stub for an interface request');
}
if (!request.isOpen) {
} else {
if (!mojoInterface.ctrl.isOpen) {
// Make sure that we are listening so that state for the stub is
// cleaned up when the message is sent and the handle is closed.
request.beginHandlingEvents();
mojoInterface.ctrl.beginHandlingEvents();
}
encodeMessagePipeHandle(request.endpoint, offset, nullable);
encodeMessagePipeHandle(mojoInterface.ctrl.endpoint, offset, nullable);
// Set the version to the current version of the stub.
encodeUint32(request.version, offset + kSerializedHandleSize);
encodeUint32(mojoInterface.ctrl.version, offset + kSerializedHandleSize);
}
}
......@@ -746,19 +729,19 @@ class Decoder {
core.MojoSharedBuffer decodeSharedBufferHandle(int offset, bool nullable) =>
new core.MojoSharedBuffer(decodeHandle(offset, nullable));
ProxyBase decodeServiceInterface(
MojoInterface decodeServiceInterface(
int offset, bool nullable, Function clientFactory) {
var endpoint = decodeMessagePipeHandle(offset, nullable);
var version = decodeUint32(offset + kSerializedHandleSize);
if (!endpoint.handle.isValid) {
return null;
}
ProxyBase client = clientFactory(endpoint);
client.impl._version = version;
Proxy client = clientFactory(endpoint);
client.ctrl._version = version;
return client;
}
Stub decodeInterfaceRequest(
MojoInterface decodeInterfaceRequest(
int offset, bool nullable, Function interfaceFactory) {
var endpoint = decodeMessagePipeHandle(offset, nullable);
return endpoint.handle.isValid ? interfaceFactory(endpoint) : null;
......
......@@ -15,19 +15,19 @@ class ControlMessageHandler {
static bool _isRunOrClose(ServiceMessage message) =>
(message.header.type == icm.kRunOrClosePipeMessageId);
static Future<Message> handleMessage(Stub stub,
static Future<Message> handleMessage(StubControl stubControl,
int interface_version,
ServiceMessage message) {
assert(isControlMessage(message));
if (_isRun(message)) {
return _handleRun(stub, interface_version, message);
return _handleRun(stubControl, interface_version, message);
} else {
assert(_isRunOrClose(message));
return _handleRunOrClose(stub, interface_version, message);
return _handleRunOrClose(stubControl, interface_version, message);
}
}
static Future<Message> _handleRun(Stub stub,
static Future<Message> _handleRun(StubControl stubControl,
int interface_version,
ServiceMessage message) {
// Construct RunMessage response.
......@@ -38,13 +38,13 @@ class ControlMessageHandler {
response.queryVersionResult.version = interface_version;
// Return response.
return new Future.value(
stub.buildResponseWithId(response,
icm.kRunMessageId,
message.header.requestId,
MessageHeader.kMessageIsResponse));
stubControl.buildResponseWithId(response,
icm.kRunMessageId,
message.header.requestId,
MessageHeader.kMessageIsResponse));
}
static Future _handleRunOrClose(Stub stub,
static Future _handleRunOrClose(StubControl stubControl,
int interface_version,
ServiceMessage message) {
// Deserialize message.
......@@ -53,7 +53,7 @@ class ControlMessageHandler {
var requiredVersion = params.requireVersion.version;
if (interface_version < requiredVersion) {
// Stub does not implement required version. Close the pipe immediately.
stub.close(immediate: true);
stubControl.close(immediate: true);
}
return null;
}
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of core;
class MojoEventSubscription {
// The underlying Mojo handle.
MojoHandle _handle;
// The send port that we give to the handle watcher to notify us of handle
// events.
SendPort _sendPort;
// The receive port on which we listen and receive events from the handle
// watcher.
RawReceivePort _receivePort;
// The signals on this handle that we're interested in.
int _signals;
// Whether subscribe() has been called.
bool _isSubscribed;
MojoEventSubscription(MojoHandle handle,
[int signals = MojoHandleSignals.kPeerClosedReadable])
: _handle = handle,
_signals = signals,
_isSubscribed = false {
if (!MojoHandle.registerFinalizer(this)) {
throw new MojoInternalError("Failed to register the MojoHandle.");
}
}
Future close({bool immediate: false}) => _close(immediate: immediate);
void subscribe(void handler(int event)) {
if (_isSubscribed) {
throw new MojoApiError("Already subscribed: $this.");
}
_receivePort = new RawReceivePort(handler);
_sendPort = _receivePort.sendPort;
if (_signals != MojoHandleSignals.kNone) {
int res = MojoHandleWatcher.add(_handle.h, _sendPort, _signals);
if (res != MojoResult.kOk) {
throw new MojoInternalError("MojoHandleWatcher add failed: $res");
}
}
_isSubscribed = true;
}
bool enableSignals([int signals]) {
if (signals != null) {
_signals = signals;
}
if (_isSubscribed) {
return MojoHandleWatcher.add(_handle.h, _sendPort, _signals) ==
MojoResult.kOk;
}
return false;
}
bool enableReadEvents() =>
enableSignals(MojoHandleSignals.kPeerClosedReadable);
bool enableWriteEvents() => enableSignals(MojoHandleSignals.kWritable);
bool enableAllEvents() => enableSignals(MojoHandleSignals.kReadWrite);
/// End the subscription by removing the handle from the handle watcher and
/// closing the Dart port, but do not close the underlying handle. The handle
/// can then be reused, or closed at a later time.
void unsubscribe({bool immediate: false}) {
if ((_handle == null) || !_isSubscribed || (_receivePort == null)) {
throw new MojoApiError("Cannont unsubscribe from a MojoEventSubscription "
"that has not been subscribed to");
}
MojoHandleWatcher.remove(_handle.h);
_receivePort.close();
_receivePort = null;
_sendPort = null;
_isSubscribed = false;
}
Future _close({bool immediate: false, bool local: false}) {
if (_handle != null) {
if (_isSubscribed && !local) {
return _handleWatcherClose(immediate: immediate).then((result) {
// If the handle watcher is gone, then close the handle ourselves.
if (result != MojoResult.kOk) {
_localClose();
}
});
} else {
_localClose();
}
}
return new Future.value(null);
}
Future _handleWatcherClose({bool immediate: false}) {
assert(_handle != null);
MojoHandleNatives.removeOpenHandle(_handle.h);
return MojoHandleWatcher.close(_handle.h, wait: !immediate).then((r) {
if (_receivePort != null) {
_receivePort.close();
_receivePort = null;
}
return r;
});
}
void _localClose() {
if (_handle != null) {
_handle.close();
_handle = null;
}
if (_receivePort != null) {
_receivePort.close();
_receivePort = null;
}
}
bool get readyRead => _handle.readyRead;
bool get readyWrite => _handle.readyWrite;
int get signals => _signals;
String toString() => "$_handle";
}
/// Object returned to pipe's error handlers containing both the thrown error
/// and the associated stack trace.
class MojoHandlerError {
/// The object passed to the handler's error handling function containing both
/// the thrown error and the associated stack trace.
class MojoEventHandlerError {
final Object error;
final StackTrace stacktrace;
MojoHandlerError(this.error, this.stacktrace);
MojoEventHandlerError(this.error, this.stacktrace);
@override
String toString() => error.toString();
}
typedef void ErrorHandler(MojoHandlerError e);
typedef void ErrorHandler(MojoEventHandlerError e);
class MojoEventHandler {
ErrorHandler onError;
MojoMessagePipeEndpoint _endpoint;
MojoEventSubscription _eventSubscription;
bool _isOpen = false;
......@@ -168,6 +44,29 @@ class MojoEventHandler {
MojoEventHandler.unbound();
/// The event handler calls the [handleRead] method when the underlying Mojo
/// message pipe endpoint has a message available to be read. Implementers
/// should read, decode, and handle the message. If [handleRead] throws
/// an exception derived from [Error], the exception will be thrown into the
/// root zone, and the application will end. Otherwise, the exception object
/// will be passed to [onError] if it has been set, and the exception will
/// not be propagated to the root zone.
void handleRead() {}
/// Like [handleRead] but indicating that the underlying message pipe endpoint
/// is ready for writing.
void handleWrite() {}
/// Called when [handleRead] or [handleWrite] throw an exception generated by
/// Mojo library code. Other exceptions will be re-thrown.
ErrorHandler onError;
MojoMessagePipeEndpoint get endpoint => _endpoint;
bool get isOpen => _isOpen;
bool get isInHandler => _isInHandler;
bool get isBound => _endpoint != null;
bool get isPeerClosed => _isPeerClosed;
void bind(MojoMessagePipeEndpoint endpoint) {
if (isBound) {
throw new MojoApiError("MojoEventHandler is already bound.");
......@@ -252,6 +151,10 @@ class MojoEventHandler {
return result != null ? result : new Future.value(null);
}
@override
String toString() => "MojoEventHandler("
"isOpen: $_isOpen, isBound: $isBound, endpoint: $_endpoint)";
void _tryHandleEvent(int event) {
// This callback is running in the handler for a RawReceivePort. All
// exceptions rethrown or not caught here will be unhandled exceptions in
......@@ -271,7 +174,7 @@ class MojoEventHandler {
} catch (e, s) {
close(immediate: true).then((_) {
if (onError != null) {
onError(new MojoHandlerError(e, s));
onError(new MojoEventHandlerError(e, s));
}
});
}
......@@ -302,26 +205,4 @@ class MojoEventHandler {
});
}
}
/// The event handler calls the [handleRead] method when the underlying Mojo
/// message pipe endpoint has a message available to be read. Implementers
/// should read, decode, and handle the message. If [handleRead] throws
/// an exception derived from [Error], the exception will be thrown into the
/// root zone, and the application will end. Otherwise, the exception object
/// will be passed to [onError] if it has been set, and the exception will
/// not be propagated to the root zone.
void handleRead() {}
/// Like [handleRead] but indicating that the underlying message pipe endpoint
/// is ready for writing.
void handleWrite() {}
MojoMessagePipeEndpoint get endpoint => _endpoint;
bool get isOpen => _isOpen;
bool get isInHandler => _isInHandler;
bool get isBound => _endpoint != null;
bool get isPeerClosed => _isPeerClosed;
String toString() => "MojoEventHandler("
"isOpen: $_isOpen, isBound: $isBound, endpoint: $_endpoint)";
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of core;
class MojoEventSubscription {
// The underlying Mojo handle.
MojoHandle _handle;
// The send port that we give to the handle watcher to notify us of handle
// events.
SendPort _sendPort;
// The receive port on which we listen and receive events from the handle
// watcher.
RawReceivePort _receivePort;
// The signals on this handle that we're interested in.
int _signals;
// Whether subscribe() has been called.
bool _isSubscribed;
MojoEventSubscription(MojoHandle handle,
[int signals = MojoHandleSignals.kPeerClosedReadable])
: _handle = handle,
_signals = signals,
_isSubscribed = false {
if (!MojoHandle.registerFinalizer(this)) {
throw new MojoInternalError("Failed to register the MojoHandle.");
}
}
bool get readyRead => _handle.readyRead;
bool get readyWrite => _handle.readyWrite;
int get signals => _signals;
Future close({bool immediate: false}) => _close(immediate: immediate);
void subscribe(void handler(int event)) {
if (_isSubscribed) {
throw new MojoApiError("Already subscribed: $this.");
}
_receivePort = new RawReceivePort(handler);
_sendPort = _receivePort.sendPort;
if (_signals != MojoHandleSignals.kNone) {
int res = MojoHandleWatcher.add(_handle.h, _sendPort, _signals);
if (res != MojoResult.kOk) {
throw new MojoInternalError("MojoHandleWatcher add failed: $res");
}
}
_isSubscribed = true;
}
bool enableSignals([int signals]) {
if (signals != null) {
_signals = signals;
}
if (_isSubscribed) {
return MojoHandleWatcher.add(_handle.h, _sendPort, _signals) ==
MojoResult.kOk;
}
return false;
}
bool enableReadEvents() =>
enableSignals(MojoHandleSignals.kPeerClosedReadable);
bool enableWriteEvents() => enableSignals(MojoHandleSignals.kWritable);
bool enableAllEvents() => enableSignals(MojoHandleSignals.kReadWrite);
/// End the subscription by removing the handle from the handle watcher and
/// closing the Dart port, but do not close the underlying handle. The handle
/// can then be reused, or closed at a later time.
void unsubscribe({bool immediate: false}) {
if ((_handle == null) || !_isSubscribed || (_receivePort == null)) {
throw new MojoApiError("Cannont unsubscribe from a MojoEventSubscription "
"that has not been subscribed to");
}
MojoHandleWatcher.remove(_handle.h);
_receivePort.close();
_receivePort = null;
_sendPort = null;
_isSubscribed = false;
}
@override
String toString() => "$_handle";
Future _close({bool immediate: false, bool local: false}) {
if (_handle != null) {
if (_isSubscribed && !local) {
return _handleWatcherClose(immediate: immediate).then((result) {
// If the handle watcher is gone, then close the handle ourselves.
if (result != MojoResult.kOk) {
_localClose();
}
});
} else {
_localClose();
}
}
return new Future.value(null);
}
Future _handleWatcherClose({bool immediate: false}) {
assert(_handle != null);
MojoHandleNatives.removeOpenHandle(_handle.h);
return MojoHandleWatcher.close(_handle.h, wait: !immediate).then((r) {
if (_receivePort != null) {
_receivePort.close();
_receivePort = null;
}
return r;
});
}
void _localClose() {
if (_handle != null) {
_handle.close();
_handle = null;
}
if (_receivePort != null) {
_receivePort.close();
_receivePort = null;
}
}
}
......@@ -5,11 +5,15 @@
part of core;
class MojoHandle {
// TODO(floitsch): get the INVALID value from the backing internal
// implementation.
static const int INVALID = 0;
static const int DEADLINE_INDEFINITE = -1;
int _h;
int get h => _h;
// The type of this field is determined by the backing internal
// implementation.
Object _h;
Object get h => _h;
MojoHandle(this._h, {String description}) {
MojoHandleNatives.addOpenHandle(_h, description: description);
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of bindings;
/// [MojoInterface] is the interface implemented by the generated
/// Interface and InterfaceRequest classes. The [MojoInterfaceControl] field
/// [ctrl] gives access to the underlying implementation of the interface, which
/// is either a [ProxyControl] or [StubControl] depending on the situation.
abstract class MojoInterface<T> {
MojoInterfaceControl get ctrl;
T impl;
Future close({bool immediate: false});
}
/// This interface is implemented by [ProxyMessageHandler] and
/// [StubMessageHandler]. Most of the interface is inherited from, and
/// ultimately implemented by [core.MojoEventHandler].
abstract class MojoInterfaceControl implements core.MojoEventHandler {
String get serviceName;
int get version;
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
library mojo_internal;
// Import 'internal_contract.dart' by default, but use 'dart:mojo.internal' if
// the embedder supports it.
export 'internal_contract.dart'
if (dart.library.mojo.internal) 'dart:mojo.internal';
此差异已折叠。
......@@ -84,9 +84,9 @@ class MojoMessagePipeEndpoint {
}
// handles may be null, otherwise convert to ints.
List<int> mojoHandles;
List mojoHandles;
if (handles != null) {
mojoHandles = new List<int>(handles.length);
mojoHandles = new List(handles.length);
for (int i = 0; i < handles.length; i++) {
mojoHandles[i] = handles[i].h;
}
......
......@@ -4,13 +4,71 @@
part of bindings;
/// The object that [ProxyMessageHandler.errorFuture] completes with when there
/// is an error.
class ProxyError {
final String message;
ProxyError(this.message);
String toString() => "ProxyError: $message";
}
abstract class Proxy extends core.MojoEventHandler {
/// Generated ProxyControl classes implement this interface.
/// ProxyControl objects are accessible through the [ctrl] field on Proxies.
abstract class ProxyControl<T> implements ProxyMessageHandler {
// TODO(zra): This is only used by ApplicationConnection.requestService(), so
// try to remove when/after ApplicationConnection is removed/refactored.
String get serviceName;
// Currently we don't have impl hooked up to anything for Proxies, but we have
// the field here so that there is a consistent interface with Stubs. By
// having the field here we can also retain the option of hooking a proxy
// up to something other than the remote implementation in the future.
T impl;
}
/// Generated Proxy classes extend this base class.
class Proxy<T> implements MojoInterface<T> {
// In general it's probalby better to avoid adding fields and methods to this
// class. Names added to this class have to be mangled by Mojo bindings
// generation to avoid name conflicts.
/// Proxies control the ProxyMessageHandler by way of this [ProxyControl]
/// object.
final ProxyControl<T> ctrl;
Proxy(this.ctrl);
/// This is a convenience method that simply forwards to ctrl.close().
/// If a Mojo interface has a method 'close', its name will be mangled to be
/// 'close_'.
Future close({bool immediate: false}) => ctrl.close(immediate: immediate);
/// This is a convenience method that simply forwards to
/// ctrl.responseOrError(). If a Mojo interface has a method
/// 'responseOrError', its name will be mangled to be 'responseOrError_'.
Future responseOrError(Future f) => ctrl.responseOrError(f);
/// This getter and setter pair is for convenience and simply forwards to
/// ctrl.impl. If a Mojo interface has a method 'close', its name will be
/// mangled to be 'impl_'.
T get impl => ctrl.impl;
set impl(T impl) {
ctrl.impl = impl;
}
}
/// Generated Proxy classes have a factory Proxy.connectToService which takes
/// a ServiceConnector, a url, and optionally a service name and returns a
/// bound Proxy. For example, every class extending the Application base class
/// in package:mojo/application.dart inherits an implementation of the
/// ServiceConnector interface.
abstract class ServiceConnector {
/// Connects [proxy] to the service called [serviceName] that lives at [url].
void connectToService(String url, Proxy proxy, [String serviceName]);
}
abstract class ProxyMessageHandler extends core.MojoEventHandler
implements MojoInterfaceControl {
HashMap<int, Completer> _completerMap = new HashMap<int, Completer>();
Completer _errorCompleter = new Completer();
Set<Completer> _errorCompleters;
......@@ -18,14 +76,18 @@ abstract class Proxy extends core.MojoEventHandler {
int _version = 0;
int _pendingCount = 0;
Proxy.fromEndpoint(core.MojoMessagePipeEndpoint endpoint)
ProxyMessageHandler.fromEndpoint(core.MojoMessagePipeEndpoint endpoint)
: super.fromEndpoint(endpoint);
Proxy.fromHandle(core.MojoHandle handle) : super.fromHandle(handle);
ProxyMessageHandler.fromHandle(core.MojoHandle handle)
: super.fromHandle(handle);
Proxy.unbound() : super.unbound();
ProxyMessageHandler.unbound() : super.unbound();
void handleResponse(ServiceMessage reader);
/// The function that handles responses to sent proxy message. It should be
/// implemented by the generated ProxyControl classes that extend
/// [ProxyMessageHandler].
void handleResponse(ServiceMessage msg);
/// If there is an error in using this proxy, this future completes with
/// a ProxyError.
......@@ -40,6 +102,7 @@ abstract class Proxy extends core.MojoEventHandler {
/// Note: The description is null or incomplete if type info is unavailable.
service_describer.ServiceDescription get description => null;
@override
void handleRead() {
var result = endpoint.queryAndRead();
if ((result.data == null) || (result.dataLength == 0)) {
......@@ -61,6 +124,7 @@ abstract class Proxy extends core.MojoEventHandler {
}
}
@override
void handleWrite() {
proxyError("Unexpected writable signal");
}
......@@ -71,9 +135,9 @@ abstract class Proxy extends core.MojoEventHandler {
// complete.
_completerMap.clear();
// Signal to any pending calls that the Proxy is closed.
// Signal to any pending calls that the ProxyMessageHandler is closed.
if (_pendingCount > 0) {
proxyError("The Proxy is closed.");
proxyError("The ProxyMessageHandler is closed.");
}
return super.close(immediate: immediate);
......@@ -81,7 +145,7 @@ abstract class Proxy extends core.MojoEventHandler {
void sendMessage(Struct message, int name) {
if (!isBound) {
proxyError("The Proxy is closed.");
proxyError("The ProxyMessageHandler is closed.");
return;
}
if (!isOpen) {
......@@ -99,7 +163,7 @@ abstract class Proxy extends core.MojoEventHandler {
Future sendMessageWithRequestId(Struct message, int name, int id, int flags) {
var completer = new Completer();
if (!isBound) {
proxyError("The Proxy is closed.");
proxyError("The ProxyMessageHandler is closed.");
return completer.future;
}
if (!isOpen) {
......@@ -126,9 +190,10 @@ abstract class Proxy extends core.MojoEventHandler {
// Need a getter for this for access in subclasses.
HashMap<int, Completer> get completerMap => _completerMap;
@override
String toString() {
var superString = super.toString();
return "Proxy(${superString})";
return "ProxyMessageHandler(${superString})";
}
/// Queries the max version that the remote side supports.
......@@ -186,7 +251,7 @@ abstract class Proxy extends core.MojoEventHandler {
/// Example usage:
///
/// try {
/// result = await MyProxy.responseOrError(MyProxy.ptr.call(a,b,c));
/// result = await myProxy.responseOrError(myProxy.call(a,b,c));
/// } catch (e) {
/// ...
/// }
......@@ -241,20 +306,3 @@ abstract class Proxy extends core.MojoEventHandler {
c.complete(response);
}
}
/// Generated Proxy classes implement this interface.
abstract class ProxyBase {
final Proxy impl = null;
final String serviceName = null;
Object get ptr;
}
/// Generated Proxy classes have a factory Proxy.connectToService which takes
/// a ServiceConnector, a url, and optionally a service name and returns a
/// bound Proxy. For example, every class extending the Application base class
/// in package:mojo/application.dart inherits and implementation of the
/// ServiceConnector interface.
abstract class ServiceConnector {
/// Connects [proxy] to the service called [serviceName] that lives at [url].
void connectToService(String url, ProxyBase proxy, [String serviceName]);
}
......@@ -4,22 +4,67 @@
part of bindings;
abstract class Stub extends core.MojoEventHandler {
/// Generated StubControl classes implement this interface.
/// StubControl objects are accessible through the [ctrl] field on Stubs.
abstract class StubControl<T> implements StubMessageHandler {
// TODO(zra): This is only used by ApplicationConnection.requestService(), so
// try to remove when/after ApplicationConnection is removed/refactored.
String get serviceName;
/// [impl] refers to the implementation of the methods of the interface T.
T impl;
}
/// Generated Stub classes extend this base class.
class Stub<T> implements MojoInterface<T> {
// In general it's probalby better to avoid adding fields and methods to this
// class. Names added to this class have to be mangled by Mojo bindings
// generation to avoid name conflicts.
/// Proxies control the StubMessageHandler by way of this [StubControl]
/// object.
final StubControl<T> ctrl;
Stub(this.ctrl);
/// This is a convenience method that simply forwards to ctrl.close().
/// If a Mojo interface has a method 'close', its name will be mangled to be
/// 'close_'.
Future close({bool immediate: false}) => ctrl.close(immediate: immediate);
/// This getter and setter pair is for convenience and simply forwards to
/// ctrl.impl. If a Mojo interface has a method 'impl', its name will be
/// mangled to be 'impl_'.
T get impl => ctrl.impl;
set impl(T impl) {
ctrl.impl = impl;
}
}
abstract class StubMessageHandler extends core.MojoEventHandler
implements MojoInterfaceControl {
int _outstandingResponseFutures = 0;
bool _isClosing = false;
Completer _closeCompleter;
Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint,
{bool autoBegin: true})
StubMessageHandler.fromEndpoint(core.MojoMessagePipeEndpoint endpoint,
{bool autoBegin: true})
: super.fromEndpoint(endpoint, autoBegin: autoBegin);
Stub.fromHandle(core.MojoHandle handle, {bool autoBegin: true})
StubMessageHandler.fromHandle(core.MojoHandle handle, {bool autoBegin: true})
: super.fromHandle(handle, autoBegin: autoBegin);
Stub.unbound() : super.unbound();
StubMessageHandler.unbound() : super.unbound();
/// Generated StubControl classes implement this method to route messages to
/// the correct implementation method.
dynamic handleMessage(ServiceMessage message);
/// Generated StubControl classes implement this getter to return the version
/// of the mojom interface for which the bindings are generated.
int get version;
@override
void handleRead() {
var result = endpoint.queryAndRead();
if ((result.data == null) || (result.dataLength == 0)) {
......@@ -64,29 +109,7 @@ abstract class Stub extends core.MojoEventHandler {
}
}
void _sendResponse(Message response) {
if (isOpen) {
endpoint.write(
response.buffer, response.buffer.lengthInBytes, response.handles);
// FailedPrecondition is only used to indicate that the other end of
// the pipe has been closed. We can ignore the close here and wait for
// the PeerClosed signal on the event stream.
assert((endpoint.status == core.MojoResult.kOk) ||
(endpoint.status == core.MojoResult.kFailedPrecondition));
if (_isClosing && (_outstandingResponseFutures == 0)) {
// This was the final response future for which we needed to send
// a response. It is safe to close.
super.close().then((_) {
if (_isClosing) {
_isClosing = false;
_closeCompleter.complete(null);
_closeCompleter = null;
}
});
}
}
}
@override
void handleWrite() {
throw 'Unexpected write signal in client.';
}
......@@ -128,15 +151,37 @@ abstract class Stub extends core.MojoEventHandler {
return response.serializeWithHeader(header);
}
@override
String toString() {
var superString = super.toString();
return "Stub(${superString})";
return "StubMessageHandler(${superString})";
}
int get version;
/// Returns a service description, which exposes the mojom type information
/// of the service being stubbed.
/// Note: The description is null or incomplete if type info is unavailable.
service_describer.ServiceDescription get description => null;
void _sendResponse(Message response) {
if (isOpen) {
endpoint.write(
response.buffer, response.buffer.lengthInBytes, response.handles);
// FailedPrecondition is only used to indicate that the other end of
// the pipe has been closed. We can ignore the close here and wait for
// the PeerClosed signal on the event stream.
assert((endpoint.status == core.MojoResult.kOk) ||
(endpoint.status == core.MojoResult.kFailedPrecondition));
if (_isClosing && (_outstandingResponseFutures == 0)) {
// This was the final response future for which we needed to send
// a response. It is safe to close.
super.close().then((_) {
if (_isClosing) {
_isClosing = false;
_closeCompleter.complete(null);
_closeCompleter = null;
}
});
}
}
}
}
......@@ -2,4 +2,4 @@ author: Chromium Authors <mojo-dev@googlegroups.com>
description: Dart files to support executing inside Mojo.
homepage: https://github.com/domokit/mojo
name: mojo
version: 0.4.20
version: 0.4.23
......@@ -4,8 +4,6 @@
part of internal;
/// This class contains static methods to send a stream of events to application
/// isolates that register Mojo handles with it.
class MojoHandleWatcher {
// Control commands.
static const int _ADD = 0;
......@@ -32,19 +30,6 @@ class MojoHandleWatcher {
return result;
}
/// Stops watching and closes the given [handleToken].
///
/// Returns an integer, encoding the result as specified in the [MojoResult]
/// class. In particular, a successful operation returns [MojoResult.kOk].
///
/// Notifies the HandleWatcherIsolate that a handle it is
/// watching should be removed from its set and closed.
///
/// The [handleToken] is a token that identifies the Mojo handle.
///
/// If [wait] is true, returns a future that resolves only after the handle
// has actually been closed by the handle watcher. Otherwise, returns a
// future that resolves immediately.
static Future<int> close(int handleToken, {bool wait: false}) {
if (!wait) {
return new Future.value(_sendControlData(_CLOSE, handleToken, null, 0));
......@@ -61,55 +46,14 @@ class MojoHandleWatcher {
});
}
/// Starts watching for events on the given [handleToken].
///
/// Returns an integer, encoding the result as specified in the [MojoResult]
/// class. In particular, a successful operation returns [MojoResult.kOk].
///
/// Instructs the MojoHandleWatcher isolate to add [handleToken] to the set of
/// handles it watches, and to notify the calling isolate only for the events
/// specified by [signals] using the send port [port].
// TODO(floitsch): what does "MojoHandleWatcher isolate" mean?
// TODO(floitsch): what is the calling isolate?
///
/// The [handleToken] is a token that identifies the Mojo handle.
///
/// The filtering [signals] are encoded as specified in the
/// [MojoHandleSignals] class. For example, setting [signals] to
/// [MojoHandleSignals.kPeerClosedReadable] instructs the handle watcher to
/// notify the caller, when the handle becomes readable (that is, has data
/// available for reading), or when it is closed.
static int add(int handleToken, SendPort port, int signals) {
return _sendControlData(_ADD, handleToken, port, signals);
}
/// Stops watching the given [handleToken].
///
/// Returns an integer, encoding the result as specified in the [MojoResult]
/// class. In particular, a successful operation returns [MojoResult.kOk].
///
/// Instructs the MojoHandleWatcher isolate to remove [handleToken] from the
/// set of handles it watches. This allows the application isolate
/// to, for example, pause the stream of events.
///
/// The [handleToken] is a token that identifies the Mojo handle.
static int remove(int handleToken) {
return _sendControlData(_REMOVE, handleToken, null, 0);
}
/// Requests a notification on the given [port] at [deadline].
///
/// Returns an integer, encoding the result as specified in the [MojoResult]
/// class. In particular, a successful operation returns [MojoResult.kOk].
///
/// The [deadline] is in milliseconds, with
/// [MojoCoreNatives.timerMillisecondClock] as reference.
///
/// If the given [port] was already registered for a timer (in any isolate),
/// then the old value is discarded.
///
/// A negative [deadline] is used to remove a port. That is, a negative value
/// is ignored after any existing value for the port has been discarded.
static int timer(Object ignored, SendPort port, int deadline) {
// The deadline will be unwrapped before sending to the handle watcher.
return _sendControlData(_TIMER, deadline, port, 0);
......
......@@ -34,9 +34,13 @@ package_mojo_sources = [
"lib/src/data_pipe.dart",
"lib/src/drain_data.dart",
"lib/src/enum.dart",
"lib/src/event_stream.dart",
"lib/src/event_handler.dart",
"lib/src/event_subscription.dart",
"lib/src/fill_data.dart",
"lib/src/handle.dart",
"lib/src/interfaces.dart",
"lib/src/internal_contract.dart",
"lib/src/internal.dart",
"lib/src/message.dart",
"lib/src/message_pipe.dart",
"lib/src/proxy.dart",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Test that an import of 'package:mojo' doesn't fail on the VM.
import 'package:mojo/core.dart';
shouldThrowUnsupported(description, f) {
try {
f();
throw "$description did not throw as expected.";
} catch (e) {
if (e is! UnsupportedError) {
throw "$description error is not an UnsupportedError $e.";
}
}
}
main() {
var invalid = new MojoHandle.invalid();
shouldThrowUnsupported("getTimeTicksNow()", () => getTimeTicksNow());
shouldThrowUnsupported(
"MojoMessagePipe allocation", () => new MojoMessagePipe());
shouldThrowUnsupported("MojoDataPipe allocation", () => new MojoDataPipe());
shouldThrowUnsupported(
"MojoSharedBuffer allocation", () => new MojoSharedBuffer.create(1024));
}
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/mojo_application.gni")
source_set("data_pipe_utils") {
sources = [
"data_pipe_drainer.cc",
......@@ -27,7 +29,7 @@ source_set("data_pipe_utils") {
]
}
source_set("tests") {
mojo_native_application("mojo_data_pipe_utils_apptests") {
testonly = true
sources = [
......@@ -37,6 +39,8 @@ source_set("tests") {
deps = [
":data_pipe_utils",
"//base",
"//mojo/application",
"//mojo/application:test_support",
"//testing/gtest",
]
}
......@@ -73,17 +73,20 @@ MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
DCHECK(platform_handle);
DCHECK(internal::g_core);
RefPtr<system::Dispatcher> dispatcher;
MojoResult result = internal::g_core->GetDispatcher(
platform_handle_wrapper_handle, &dispatcher);
system::Handle h;
MojoResult result =
internal::g_core->GetHandle(platform_handle_wrapper_handle, &h);
if (result != MOJO_RESULT_OK)
return result;
if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE)
if (h.dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE)
return MOJO_RESULT_INVALID_ARGUMENT;
if (!h.has_all_rights(MOJO_HANDLE_RIGHT_READ | MOJO_HANDLE_RIGHT_WRITE))
return MOJO_RESULT_PERMISSION_DENIED;
*platform_handle =
static_cast<system::PlatformHandleDispatcher*>(dispatcher.get())
static_cast<system::PlatformHandleDispatcher*>(h.dispatcher.get())
->PassPlatformHandle();
return MOJO_RESULT_OK;
}
......
......@@ -27,6 +27,23 @@ MojoResult MojoClose(MojoHandle handle) {
return g_core->Close(handle);
}
MojoResult MojoGetRights(MojoHandle handle, MojoHandleRights* rights) {
return g_core->GetRights(handle, MakeUserPointer(rights));
}
MojoResult MojoDuplicateHandleWithReducedRights(
MojoHandle handle,
MojoHandleRights rights_to_remove,
MojoHandle* new_handle) {
return g_core->DuplicateHandleWithReducedRights(handle, rights_to_remove,
MakeUserPointer(new_handle));
}
MojoResult MojoDuplicateHandle(MojoHandle handle, MojoHandle* new_handle) {
return g_core->DuplicateHandleWithReducedRights(
handle, MOJO_HANDLE_RIGHT_NONE, MakeUserPointer(new_handle));
}
MojoResult MojoWait(MojoHandle handle,
MojoHandleSignals signals,
MojoDeadline deadline,
......
......@@ -20,6 +20,7 @@
using mojo::embedder::internal::g_core;
using mojo::system::Core;
using mojo::system::Dispatcher;
using mojo::system::Handle;
using mojo::system::MakeUserPointer;
using mojo::util::RefPtr;
......@@ -55,23 +56,23 @@ MojoResult MojoSystemImplTransferHandle(MojoSystemImpl from_system,
if (result_handle == nullptr)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> d;
MojoResult result = from_core->GetAndRemoveDispatcher(handle, &d);
Handle h;
MojoResult result = from_core->GetAndRemoveHandle(handle, &h);
if (result != MOJO_RESULT_OK)
return result;
// TODO(vtl): The rights should come from the original handle (to be dealt
// with when I fix/replace |Core::GetAndRemoveDispatcher()|.
MojoHandle created_handle = to_core->AddHandle(mojo::system::Handle(
d.Clone(), MOJO_HANDLE_RIGHT_TRANSFER | MOJO_HANDLE_RIGHT_READ |
MOJO_HANDLE_RIGHT_WRITE));
MojoHandle created_handle =
to_core->AddHandle(Handle(h.dispatcher.Clone(), h.rights));
if (created_handle == MOJO_HANDLE_INVALID) {
// The handle has been lost, unfortunately. There's no guarentee we can put
// it back where it came from, or get the original ID back. Holding locks
// for multiple cores risks deadlock, so that isn't a solution. This case
// should not happen for reasonable uses of this API, however.
// TODO(vtl): This behaviour is pretty crappy. This can be fixed by marking
// the original handle as busy and only removing it on success, though
// that'd require some work.
LOG(ERROR) << "Could not transfer handle";
d->Close();
h.dispatcher->Close();
return MOJO_RESULT_RESOURCE_EXHAUSTED;
}
......@@ -91,6 +92,34 @@ MojoResult MojoSystemImplClose(MojoSystemImpl system, MojoHandle handle) {
return core->Close(handle);
}
MojoResult MojoSystemImplGetRights(MojoSystemImpl system,
MojoHandle handle,
MojoHandleRights* rights) {
mojo::system::Core* core = static_cast<mojo::system::Core*>(system);
DCHECK(core);
return core->GetRights(handle, MakeUserPointer(rights));
}
MojoResult MojoSystemImplDuplicateHandleWithReducedRights(
MojoSystemImpl system,
MojoHandle handle,
MojoHandleRights rights_to_remove,
MojoHandle* new_handle) {
mojo::system::Core* core = static_cast<mojo::system::Core*>(system);
DCHECK(core);
return core->DuplicateHandleWithReducedRights(handle, rights_to_remove,
MakeUserPointer(new_handle));
}
MojoResult MojoSystemImplDuplicateHandle(MojoSystemImpl system,
MojoHandle handle,
MojoHandle* new_handle) {
mojo::system::Core* core = static_cast<mojo::system::Core*>(system);
DCHECK(core);
return core->DuplicateHandleWithReducedRights(handle, MOJO_HANDLE_RIGHT_NONE,
MakeUserPointer(new_handle));
}
MojoResult MojoSystemImplWait(MojoSystemImpl system,
MojoHandle handle,
MojoHandleSignals signals,
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -180,6 +180,7 @@ TEST(MessagePipeDispatcherTest, SupportsEntrypointClass) {
EXPECT_EQ(MOJO_RESULT_OK, d_peer->Close());
}
EXPECT_TRUE(d->SupportsEntrypointClass(EntrypointClass::NONE));
EXPECT_TRUE(d->SupportsEntrypointClass(EntrypointClass::MESSAGE_PIPE));
EXPECT_FALSE(d->SupportsEntrypointClass(EntrypointClass::DATA_PIPE_PRODUCER));
EXPECT_FALSE(d->SupportsEntrypointClass(EntrypointClass::DATA_PIPE_CONSUMER));
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册