| Index: mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
|
| diff --git a/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
|
| index 329fa2ff90802c9f9b0b750066c7ec4c4a719808..b48a6187fb2cf2e0dcd03a95581a04cd2f815b73 100644
|
| --- a/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
|
| +++ b/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl
|
| @@ -1,9 +1,10 @@
|
| {% from "constant_definition.tmpl" import constant_def %}
|
| {% from "enum_definition.tmpl" import enum_def %}
|
| +{% from "struct_definition.tmpl" import struct_def %}
|
|
|
| -{%- macro declare_params(parameters) %}
|
| +{%- macro declare_params(parameters, boxed=false) %}
|
| {%- for param in parameters -%}
|
| -{{param.kind|java_type(False)}} {{param|name}}
|
| +{{param.kind|java_type(boxed)}} {{param|name}}
|
| {%- if not loop.last %}, {% endif %}
|
| {%- endfor %}
|
| {%- endmacro %}
|
| @@ -17,6 +18,7 @@
|
| {% endmacro %}
|
|
|
| {%- macro declare_callback(method) -%}
|
| +
|
| interface {{method|interface_response_name}} extends org.chromium.mojo.bindings.Callbacks.Callback{{method.response_parameters|length}}<
|
| {%- for param in method.response_parameters -%}
|
| {{param.kind|java_type(True)}}
|
| @@ -25,6 +27,15 @@ interface {{method|interface_response_name}} extends org.chromium.mojo.bindings.
|
| > { }
|
| {%- endmacro -%}
|
|
|
| +{%- macro run_callback(variable, parameters) -%}
|
| +{%- if parameters -%}
|
| +{%- for param in parameters -%}
|
| +{{variable}}.{{param|name}}
|
| +{%- if not loop.last %}, {% endif %}
|
| +{%- endfor -%}
|
| +{%- endif -%}
|
| +{%- endmacro -%}
|
| +
|
| {%- macro super_class(client) -%}
|
| {%- if client -%}
|
| org.chromium.mojo.bindings.InterfaceWithClient<{{client|java_type}}>
|
| @@ -33,6 +44,16 @@ org.chromium.mojo.bindings.Interface
|
| {%- endif -%}
|
| {%- endmacro -%}
|
|
|
| +{%- macro flags(method, is_parameter) -%}
|
| +{%- if not method.response_parameters -%}
|
| +0
|
| +{%- elif is_parameter: -%}
|
| +org.chromium.mojo.bindings.MessageHeader.MESSAGE_EXPECTS_RESPONSE_FLAG
|
| +{%- else -%}
|
| +org.chromium.mojo.bindings.MessageHeader.MESSAGE_IS_RESPONSE_FLAG
|
| +{%- endif -%}
|
| +{%- endmacro -%}
|
| +
|
| {% macro interface_def(interface, client) %}
|
| public interface {{interface|name}} extends {{super_class(client)}} {
|
| {% for constant in interface.constants %}
|
| @@ -43,6 +64,22 @@ public interface {{interface|name}} extends {{super_class(client)}} {
|
|
|
| {{enum_def(enum, false)|indent(4)}}
|
| {% endfor %}
|
| +
|
| + public static final Builder<{% if client %}{{client|java_type}}, {% endif %}{{interface|name}}, Proxy> BUILDER = new Builder<{% if client %}{{client|java_type}}, {% endif %}{{interface|name}}, Proxy>({% if client %}{% if client == interface %}null{% else %}{{client|java_type}}.BUILDER{% endif %}{% endif %}) {
|
| +
|
| + public Proxy buildProxy(org.chromium.mojo.system.Core core, org.chromium.mojo.bindings.MessageReceiverWithResponder messageReceiver) {
|
| + return new Proxy(core, messageReceiver);
|
| + }
|
| +
|
| + public Stub buildStub(org.chromium.mojo.system.Core core, {{interface|name}} impl) {
|
| + return new Stub(core, impl);
|
| + }
|
| +
|
| + public {{interface|name}}[] newArray(int size) {
|
| + return new {{interface|name}}[size];
|
| + }
|
| +
|
| + };
|
| {% for method in interface.methods %}
|
|
|
| void {{method|name}}({{declare_request_params(method)}});
|
| @@ -51,5 +88,153 @@ public interface {{interface|name}} extends {{super_class(client)}} {
|
| {% endif %}
|
| {% endfor %}
|
|
|
| + public final class Proxy extends {% if client %}org.chromium.mojo.bindings.InterfaceWithClient.Proxy<{{client|java_type}}>{% else %}org.chromium.mojo.bindings.Interface.Proxy{% endif %} implements {{interface|name}} {
|
| +
|
| + public Proxy(org.chromium.mojo.system.Core core, org.chromium.mojo.bindings.MessageReceiverWithResponder messageReceiver) {
|
| + super(core, messageReceiver);
|
| + }
|
| +{% for method in interface.methods %}
|
| +
|
| + @Override
|
| + public void {{method|name}}({{declare_request_params(method)}}) {
|
| +{% set request_struct = method|struct_from_method %}
|
| + {{interface|name}}Internal.{{request_struct|name}} message = new {{interface|name}}Internal.{{request_struct|name}}();
|
| +{% for param in method.parameters %}
|
| + message.{{param|name}} = {{param|name}};
|
| +{% endfor %}
|
| +{% if method.response_parameters %}
|
| + getMessageReceiver().acceptWithResponder(
|
| + message.serializeWithHeader(getCore(),
|
| + new org.chromium.mojo.bindings.MessageHeader({{method.ordinal}}, {{flags(method, True)}}, 0)),
|
| + new {{interface|name}}Internal.{{method|response_struct_from_method|name }}ForwardToCallback(callback));
|
| +{% else %}
|
| + getMessageReceiver().accept(message.serializeWithHeader(getCore(),
|
| + new org.chromium.mojo.bindings.MessageHeader({{method.ordinal}}, {{flags(method, True)}})));
|
| +{% endif %}
|
| + }
|
| +{% endfor %}
|
| +
|
| + }
|
| +
|
| + public final class Stub extends org.chromium.mojo.bindings.Interface.Stub<{{interface|name}}> {
|
| +
|
| + public Stub(org.chromium.mojo.system.Core core, {{interface|name}} impl) {
|
| + super(core, impl);
|
| + }
|
| +
|
| + @Override
|
| + public boolean accept(org.chromium.mojo.bindings.Message message) {
|
| + try {
|
| + org.chromium.mojo.bindings.MessageHeader header = message.getHeader();
|
| + org.chromium.mojo.bindings.Message payload = message.getPayload();
|
| + switch(header.getType()) {
|
| +{% for method in interface.methods %}
|
| +{% if not method.response_parameters %}
|
| +{% set request_struct = method|struct_from_method %}
|
| + case {{method.ordinal}}: {
|
| + if (!header.validateHeader({{flags(method, True)}})) {
|
| + return false;
|
| + }
|
| + {{interface|name}}Internal.{{request_struct|name}} data = {{interface|name}}Internal.{{request_struct|name}}.deserialize(payload);
|
| + getImpl().{{method|name}}({{run_callback('data', method.parameters)}});
|
| + return true;
|
| + }
|
| +{% endif %}
|
| +{% endfor %}
|
| + }
|
| + } catch (org.chromium.mojo.bindings.DeserializationException e) {
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + @Override
|
| + public boolean acceptWithResponder(org.chromium.mojo.bindings.Message message, org.chromium.mojo.bindings.MessageReceiver receiver) {
|
| + try {
|
| + org.chromium.mojo.bindings.MessageHeader header = message.getHeader();
|
| + org.chromium.mojo.bindings.Message payload = message.getPayload();
|
| + switch(header.getType()) {
|
| +{% for method in interface.methods %}
|
| +{% if method.response_parameters %}
|
| +{% set request_struct = method|struct_from_method %}
|
| +{% set response_struct = method|response_struct_from_method %}
|
| + case {{method.ordinal}}: {
|
| + if (!header.validateHeader({{flags(method, True)}})) {
|
| + return false;
|
| + }
|
| + {{interface|name}}Internal.{{request_struct|name}} data = {{interface|name}}Internal.{{request_struct|name}}.deserialize(payload);
|
| + getImpl().{{method|name}}({{run_callback('data', method.parameters)}}{% if method.parameters %}, {% endif %}new {{interface|name}}Internal.{{response_struct|name}}ProxyToResponder(getCore(), receiver, header.getRequestId()));
|
| + return true;
|
| + }
|
| +{% endif %}
|
| +{% endfor %}
|
| + }
|
| + } catch (org.chromium.mojo.bindings.DeserializationException e) {
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + }
|
| +}
|
| +{% endmacro %}
|
| +
|
| +{% macro interface_internal_def(interface) %}
|
| +class {{interface|name}}Internal {
|
| +{% for method in interface.methods %}
|
| +
|
| + {{ struct_def(method|struct_from_method, True)|indent(4) }}
|
| +{% if method.response_parameters %}
|
| +{% set response_struct = method|response_struct_from_method %}
|
| +
|
| + {{ struct_def(response_struct, True)|indent(4) }}
|
| +
|
| + static class {{response_struct|name}}ForwardToCallback implements org.chromium.mojo.bindings.MessageReceiver {
|
| + private final {{interface|name}}.{{method|interface_response_name}} mCallback;
|
| +
|
| + {{response_struct|name}}ForwardToCallback({{interface|name}}.{{method|interface_response_name}} callback) {
|
| + this.mCallback = callback;
|
| + }
|
| +
|
| + @Override
|
| + public boolean accept(org.chromium.mojo.bindings.Message message) {
|
| + try {
|
| + org.chromium.mojo.bindings.MessageHeader header = message.getHeader();
|
| + if (!header.validateHeader({{method.ordinal}}, {{flags(method, False)}})) {
|
| + return false;
|
| + }
|
| + org.chromium.mojo.bindings.Message payload = message.getPayload();
|
| + {{response_struct|name}} response = {{response_struct|name}}.deserialize(payload);
|
| + mCallback.call({{run_callback('response', method.response_parameters)}});
|
| + return true;
|
| + } catch (org.chromium.mojo.bindings.DeserializationException e) {
|
| + return false;
|
| + }
|
| + }
|
| + }
|
| +
|
| + static class {{response_struct|name}}ProxyToResponder implements {{interface|name}}.{{method|interface_response_name}} {
|
| +
|
| + private final org.chromium.mojo.system.Core mCore;
|
| + private final org.chromium.mojo.bindings.MessageReceiver mMessageReceiver;
|
| + private final long mRequestId;
|
| +
|
| + {{response_struct|name}}ProxyToResponder(org.chromium.mojo.system.Core core, org.chromium.mojo.bindings.MessageReceiver messageReceiver, long requestId) {
|
| + mCore = core;
|
| + mMessageReceiver = messageReceiver;
|
| + mRequestId = requestId;
|
| + }
|
| +
|
| + @Override
|
| + public void call({{declare_params(method.response_parameters, true)}}) {
|
| + {{response_struct|name}} response = new {{response_struct|name}}();
|
| +{% for param in method.response_parameters %}
|
| + response.{{param|name}} = {{param|name}};
|
| +{% endfor %}
|
| + org.chromium.mojo.bindings.Message message = response.serializeWithHeader(mCore, new org.chromium.mojo.bindings.MessageHeader({{method.ordinal}}, {{flags(method, False)}}, mRequestId));
|
| + mMessageReceiver.accept(message);
|
| + }
|
| + }
|
| +{% endif %}
|
| +{% endfor %}
|
| +
|
| }
|
| {% endmacro %}
|
|
|