Chromium Code Reviews| 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 c10da54d13fb66cbe26c545d5f0c49374106d3ee..cbd39ef51c051574d0a550745bd6babeff920c7a 100644 |
| --- a/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl |
| +++ b/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl |
| @@ -2,31 +2,10 @@ |
| const int k{{interface|name}}_{{method|name}}_name = {{method.ordinal}}; |
| {%- endfor %} |
| -abstract class {{interface|name}} implements core.Listener { |
| - static const String name = '{{namespace|replace(".","::")}}::{{interface|name}}'; |
| - {{interface|name}}Stub stub; |
| - |
| - {{interface|name}}(core.MojoMessagePipeEndpoint endpoint) : |
| - stub = new {{interface|name}}Stub(endpoint); |
| - |
| - {{interface|name}}.fromHandle(core.MojoHandle handle) : |
| - stub = new {{interface|name}}Stub.fromHandle(handle); |
| - |
| - {{interface|name}}.fromStub(this.stub); |
| - |
| - {{interface|name}}.unbound() : |
| - stub = new {{interface|name}}Stub.unbound(); |
| - |
| - void close({bool nodefer : false}) => stub.close(nodefer: nodefer); |
| - |
| - StreamSubscription<int> listen({Function onClosed}) => |
| - stub.listen(onClosed: onClosed); |
|
sky
2015/02/27 18:50:31
Sorry, one last question. How do you observe a clo
zra
2015/02/27 19:04:47
The generated Stub class inherits listen from bind
|
| - |
| - {{interface|name}} get delegate => stub.delegate; |
| - set delegate({{interface|name}} d) { |
| - stub.delegate = d; |
| - } |
| +const String {{interface|name}}Name = |
| + '{{namespace|replace(".","::")}}::{{interface|name}}'; |
| +abstract class {{interface|name}} { |
| {%- for method in interface.methods %} |
| {%- if method.response_parameters == None %} |
| void {{method|name}}( |
| @@ -44,13 +23,11 @@ abstract class {{interface|name}} implements core.Listener { |
| {%- endif %} |
| {%- endfor %} |
| - |
| {#--- Interface Constants #} |
| {% for constant in interface.constants %} |
| static final {{constant|name}} = {{constant.value|expression_to_text}}; |
| {%- endfor %} |
| - |
| {#--- Interface Enums #} |
| {%- from "enum_definition.tmpl" import enum_def -%} |
| {%- for enum in interface.enums %} |
| @@ -58,19 +35,21 @@ abstract class {{interface|name}} implements core.Listener { |
| {%- endfor %} |
| } |
| -class {{interface|name}}Proxy extends bindings.Proxy implements {{interface|name}} { |
| - {{interface|name}}Proxy(core.MojoMessagePipeEndpoint endpoint) : super(endpoint); |
| - {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) : |
| - super.fromHandle(handle); |
| +class {{interface|name}}ProxyImpl extends bindings.Proxy { |
| + {{interface|name}}ProxyImpl.fromEndpoint( |
| + core.MojoMessagePipeEndpoint endpoint) : super(endpoint); |
| - {{interface|name}}Proxy.unbound() : super.unbound(); |
| + {{interface|name}}ProxyImpl.fromHandle(core.MojoHandle handle) : |
| + super.fromHandle(handle); |
| - String get name => {{interface|name}}.name; |
| + {{interface|name}}ProxyImpl.unbound() : super.unbound(); |
| - static {{interface|name}}Proxy newFromEndpoint( |
| + static {{interface|name}}ProxyImpl newFromEndpoint( |
| core.MojoMessagePipeEndpoint endpoint) => |
| - new {{interface|name}}Proxy(endpoint); |
| + new {{interface|name}}ProxyImpl.fromEndpoint(endpoint); |
| + |
| + String get name => {{interface|name}}Name; |
| void handleResponse(bindings.ServiceMessage message) { |
| switch (message.header.type) { |
| @@ -94,47 +73,89 @@ class {{interface|name}}Proxy extends bindings.Proxy implements {{interface|name |
| break; |
| } |
| } |
| +} |
| -{%- for method in interface.methods %} |
| -{%- if method.response_parameters == None %} |
| - void {{method|name}}( |
| -{%- for parameter in method.parameters -%} |
| - {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %} |
| -{%- endfor -%} |
| -{%- set request_struct = method|struct_from_method -%} |
| - ) { |
| - var params = new {{request_struct|name}}(); |
| -{%- for parameter in method.parameters %} |
| - params.{{parameter|name}} = {{parameter|name}}; |
| -{%- endfor %} |
| - sendMessage(params, k{{interface|name}}_{{method|name}}_name); |
| + |
| +class _{{interface|name}}ProxyCalls implements {{interface|name}} { |
| + {{interface|name}}ProxyImpl _proxyImpl; |
| + |
| + _{{interface|name}}ProxyCalls(this._proxyImpl); |
| + |
| + {%- for method in interface.methods %} |
| + {%- if method.response_parameters == None %} |
| + void {{method|name}}( |
| + {%- for parameter in method.parameters -%} |
| + {{parameter.kind|dart_type}} {{parameter|name}}{% if not loop.last %}, {% endif %} |
| + {%- endfor -%} |
| + {%- set request_struct = method|struct_from_method -%} |
| + ) { |
| + var params = new {{request_struct|name}}(); |
| + {%- for parameter in method.parameters %} |
| + params.{{parameter|name}} = {{parameter|name}}; |
| + {%- endfor %} |
| + _proxyImpl.sendMessage(params, k{{interface|name}}_{{method|name}}_name); |
| + } |
| + {% else %} |
| + {%- set response_struct = method|response_struct_from_method %} |
| + {%- set request_struct = method|struct_from_method %} |
| + Future<{{response_struct|name}}> {{method|name}}( |
| + {%- for parameter in method.parameters -%} |
| + {{parameter.kind|dart_type}} {{parameter|name}}, |
| + {%- endfor -%} |
| + [Function responseFactory = null]) { |
| + var params = new {{request_struct|name}}(); |
| + {%- for parameter in method.parameters %} |
| + params.{{parameter|name}} = {{parameter|name}}; |
| + {%- endfor %} |
| + return _proxyImpl.sendMessageWithRequestId( |
| + params, |
| + k{{interface|name}}_{{method|name}}_name, |
| + -1, |
| + bindings.MessageHeader.kMessageExpectsResponse); |
| + } |
| + {%- endif %} |
| + {%- endfor %} |
| +} |
| + |
| + |
| +class {{interface|name}}Proxy implements bindings.ProxyBase { |
| + final bindings.Proxy impl; |
| + {{interface|name}} ptr; |
| + final String name = {{interface|name}}Name; |
| + |
| + {{interface|name}}Proxy({{interface|name}}ProxyImpl proxyImpl) : |
| + impl = proxyImpl, |
| + ptr = new _{{interface|name}}ProxyCalls(proxyImpl); |
| + |
| + {{interface|name}}Proxy.fromEndpoint( |
| + core.MojoMessagePipeEndpoint endpoint) : |
| + impl = new {{interface|name}}ProxyImpl.fromEndpoint(endpoint) { |
| + ptr = new _{{interface|name}}ProxyCalls(impl); |
| } |
| -{% else %} |
| -{%- set response_struct = method|response_struct_from_method %} |
| -{%- set request_struct = method|struct_from_method %} |
| - Future<{{response_struct|name}}> {{method|name}}( |
| -{%- for parameter in method.parameters -%} |
| - {{parameter.kind|dart_type}} {{parameter|name}}, |
| -{%- endfor -%} |
| - [Function responseFactory = null]) { |
| - var params = new {{request_struct|name}}(); |
| -{%- for parameter in method.parameters %} |
| - params.{{parameter|name}} = {{parameter|name}}; |
| -{%- endfor %} |
| - return sendMessageWithRequestId( |
| - params, |
| - k{{interface|name}}_{{method|name}}_name, |
| - -1, |
| - bindings.MessageHeader.kMessageExpectsResponse); |
| + |
| + {{interface|name}}Proxy.fromHandle(core.MojoHandle handle) : |
| + impl = new {{interface|name}}ProxyImpl.fromHandle(handle) { |
| + ptr = new _{{interface|name}}ProxyCalls(impl); |
| } |
| -{%- endif %} |
| -{%- endfor %} |
| + |
| + {{interface|name}}Proxy.unbound() : |
| + impl = new {{interface|name}}ProxyImpl.unbound() { |
| + ptr = new _{{interface|name}}ProxyCalls(impl); |
| + } |
| + |
| + static {{interface|name}}Proxy newFromEndpoint( |
| + core.MojoMessagePipeEndpoint endpoint) => |
| + new {{interface|name}}Proxy.fromEndpoint(endpoint); |
| + |
| + void close() => impl.close(); |
| } |
| + |
| class {{interface|name}}Stub extends bindings.Stub { |
| {{interface|name}} _delegate = null; |
| - {{interface|name}}Stub(core.MojoMessagePipeEndpoint endpoint) : super(endpoint); |
| + {{interface|name}}Stub.fromEndpoint(core.MojoMessagePipeEndpoint endpoint) : |
| + super(endpoint); |
| {{interface|name}}Stub.fromHandle(core.MojoHandle handle) : |
| super.fromHandle(handle); |
| @@ -143,9 +164,9 @@ class {{interface|name}}Stub extends bindings.Stub { |
| static {{interface|name}}Stub newFromEndpoint( |
| core.MojoMessagePipeEndpoint endpoint) => |
| - new {{interface|name}}Stub(endpoint); |
| + new {{interface|name}}Stub.fromEndpoint(endpoint); |
| - static const String name = {{interface|name}}.name; |
| + static const String name = {{interface|name}}Name; |
| {% for method in interface.methods %} |
| {%- if method.response_parameters != None %} |
| @@ -209,6 +230,3 @@ class {{interface|name}}Stub extends bindings.Stub { |
| _delegate = d; |
| } |
| } |
| - |
| - |
| -{#--- TODO(zra): Validation #} |