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

Unified Diff: mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl

Issue 968243003: Dart: Adds optional named arguments for creating bindings. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Binding -> Stub, delegate -> impl Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
diff --git a/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
index cbd39ef51c051574d0a550745bd6babeff920c7a..16004f106cfeb22601d73f08cf78d2bd752fe6aa 100644
--- a/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
+++ b/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl
@@ -38,10 +38,13 @@ abstract class {{interface|name}} {
class {{interface|name}}ProxyImpl extends bindings.Proxy {
{{interface|name}}ProxyImpl.fromEndpoint(
- core.MojoMessagePipeEndpoint endpoint) : super(endpoint);
+ core.MojoMessagePipeEndpoint endpoint,
+ {bool doListen: true, Function onClosed}) :
+ super.fromEndpoint(endpoint, doListen: doListen, onClosed: onClosed);
- {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle) :
- super.fromHandle(handle);
+ {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle,
+ {bool doListen: true, Function onClosed}) :
+ super.fromHandle(handle, doListen: doListen, onClosed: onClosed);
{{interface|name}}ProxyImpl.unbound() : super.unbound();
@@ -89,6 +92,7 @@ class _{{interface|name}}ProxyCalls implements {{interface|name}} {
{%- endfor -%}
{%- set request_struct = method|struct_from_method -%}
) {
+ assert(_proxyImpl.isBound);
var params = new {{request_struct|name}}();
{%- for parameter in method.parameters %}
params.{{parameter|name}} = {{parameter|name}};
@@ -103,6 +107,7 @@ class _{{interface|name}}ProxyCalls implements {{interface|name}} {
{{parameter.kind|dart_type}} {{parameter|name}},
{%- endfor -%}
[Function responseFactory = null]) {
+ assert(_proxyImpl.isBound);
var params = new {{request_struct|name}}();
{%- for parameter in method.parameters %}
params.{{parameter|name}} = {{parameter|name}};
@@ -128,13 +133,17 @@ class {{interface|name}}Proxy implements bindings.ProxyBase {
ptr = new _{{interface|name}}ProxyCalls(proxyImpl);
{{interface|name}}Proxy.fromEndpoint(
- core.MojoMessagePipeEndpoint endpoint) :
- impl = new {{interface|name}}ProxyImpl.fromEndpoint(endpoint) {
+ core.MojoMessagePipeEndpoint endpoint,
+ {bool doListen: true, Function onClosed}) :
+ impl = new {{interface|name}}ProxyImpl.fromEndpoint(
+ endpoint, doListen: doListen, onClosed: onClosed) {
ptr = new _{{interface|name}}ProxyCalls(impl);
}
- {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) :
- impl = new {{interface|name}}ProxyImpl.fromHandle(handle) {
+ {{interface|name}}Proxy.fromHandle(core.MojoHandle handle,
+ {bool doListen: true, Function onClosed}) :
+ impl = new {{interface|name}}ProxyImpl.fromHandle(
+ handle, doListen: doListen, onClosed: onClosed) {
ptr = new _{{interface|name}}ProxyCalls(impl);
}
@@ -152,19 +161,37 @@ class {{interface|name}}Proxy implements bindings.ProxyBase {
class {{interface|name}}Stub extends bindings.Stub {
- {{interface|name}} _delegate = null;
-
- {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) :
- super(endpoint);
+ {{interface|name}} _impl = null;
+
+ {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint,
+ { {{interface|name}} impl, bool doListen: true, Function onClosed}) :
+ super.fromEndpoint(endpoint, doListen: false) {
+ assert(!doListen || (impl != null));
+ if (impl != null) {
+ this._impl = impl;
+ }
+ if (doListen) {
+ listen(onClosed: onClosed);
+ }
+ }
- {{interface|name}}Stub.fromHandle(core.MojoHandle handle) :
- super.fromHandle(handle);
+ {{interface|name}}Stub.fromHandle(core.MojoHandle handle,
+ { {{interface|name}} impl, bool doListen: true, Function onClosed}) :
+ super.fromHandle(handle, doListen: false) {
+ assert(!doListen || (impl != null));
+ if (impl != null) {
+ this._impl = impl;
+ }
+ if (doListen) {
+ listen(onClosed: onClosed);
+ }
+ }
{{interface|name}}Stub.unbound() : super.unbound();
static {{interface|name}}Stub newFromEndpoint(
core.MojoMessagePipeEndpoint endpoint) =>
- new {{interface|name}}Stub.fromEndpoint(endpoint);
+ new {{interface|name}}Stub.fromEndpoint(endpoint, doListen: false);
static const String name = {{interface|name}}Name;
@@ -186,7 +213,7 @@ class {{interface|name}}Stub extends bindings.Stub {
{%- endfor %}
Future<bindings.Message> handleMessage(bindings.ServiceMessage message) {
- assert(_delegate != null);
+ assert(_impl != null);
switch (message.header.type) {
{%- for method in interface.methods %}
{%- set request_struct = method|struct_from_method %}
@@ -194,14 +221,14 @@ class {{interface|name}}Stub extends bindings.Stub {
var params = {{request_struct|name}}.deserialize(
message.payload);
{%- if method.response_parameters == None %}
- _delegate.{{method|name}}(
+ _impl.{{method|name}}(
{%- for parameter in method.parameters -%}
params.{{parameter|name}}{% if not loop.last %}, {% endif %}
{%- endfor -%}
);
{%- else %}
{%- set response_struct = method|response_struct_from_method %}
- return _delegate.{{method|name}}(
+ return _impl.{{method|name}}(
{%- for parameter in method.parameters -%}
params.{{parameter|name}},
{%- endfor -%}
@@ -224,9 +251,9 @@ class {{interface|name}}Stub extends bindings.Stub {
return null;
}
- {{interface|name}} get delegate => _delegate;
- set delegate({{interface|name}} d) {
- assert(_delegate == null);
- _delegate = d;
+ {{interface|name}} get impl => _impl;
+ set impl({{interface|name}} d) {
+ assert(_impl == null);
+ _impl = d;
}
}

Powered by Google App Engine
This is Rietveld 408576698