Index: mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl b/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl |
deleted file mode 100644 |
index 1b5cafa01e4501e67a3e9694bdb55d818a98513e..0000000000000000000000000000000000000000 |
--- a/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl |
+++ /dev/null |
@@ -1,188 +0,0 @@ |
-{%- for method in interface.methods %} |
- var k{{interface.name}}_{{method.name}}_Name = {{method.ordinal}}; |
-{%- endfor %} |
- |
- function {{interface.name}}Proxy(receiver) { |
- bindings.ProxyBase.call(this, receiver); |
- } |
- {{interface.name}}Proxy.prototype = Object.create(bindings.ProxyBase.prototype); |
- |
-{%- for method in interface.methods %} |
- {{interface.name}}Proxy.prototype.{{method.name|stylize_method}} = function( |
-{%- for parameter in method.parameters -%} |
-{{parameter.name}}{% if not loop.last %}, {% endif %} |
-{%- endfor -%} |
-) { |
- var params = new {{interface.name}}_{{method.name}}_Params(); |
-{%- for parameter in method.parameters %} |
- params.{{parameter.name}} = {{parameter|js_proxy_method_parameter_value}}; |
-{%- endfor %} |
- |
-{%- if method.response_parameters == None %} |
- var builder = new codec.MessageBuilder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_Params.encodedSize)); |
- builder.encodeStruct({{interface.name}}_{{method.name}}_Params, params); |
- var message = builder.finish(); |
- this.receiver_.accept(message); |
-{%- else %} |
- return new Promise(function(resolve, reject) { |
- var builder = new codec.MessageWithRequestIDBuilder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_Params.encodedSize), |
- codec.kMessageExpectsResponse, 0); |
- builder.encodeStruct({{interface.name}}_{{method.name}}_Params, params); |
- var message = builder.finish(); |
- this.receiver_.acceptAndExpectResponse(message).then(function(message) { |
- var reader = new codec.MessageReader(message); |
- var responseParams = |
- reader.decodeStruct({{interface.name}}_{{method.name}}_ResponseParams); |
- resolve(responseParams); |
- }).catch(function(result) { |
- reject(Error("Connection error: " + result)); |
- }); |
- }.bind(this)); |
-{%- endif %} |
- }; |
-{%- endfor %} |
- |
- function {{interface.name}}Stub(delegate) { |
- bindings.StubBase.call(this, delegate); |
- } |
- {{interface.name}}Stub.prototype = Object.create(bindings.StubBase.prototype); |
- |
-{%- for method in interface.methods %} |
-{%- set js_method_name = method.name|stylize_method %} |
-{%- set delegate_expr = "bindings.StubBindings(this).delegate" %} |
- {{interface.name}}Stub.prototype.{{js_method_name}} = function({{method.parameters|map(attribute='name')|join(', ')}}) { |
- return {{delegate_expr}} && {{delegate_expr}}.{{js_method_name}} && {{delegate_expr}}.{{js_method_name}}({{method.parameters|map('js_stub_method_parameter_value')|join(', ')}}); |
- } |
-{%- endfor %} |
- |
- {{interface.name}}Stub.prototype.accept = function(message) { |
- var reader = new codec.MessageReader(message); |
- switch (reader.messageName) { |
-{%- for method in interface.methods %} |
-{%- if method.response_parameters == None %} |
- case k{{interface.name}}_{{method.name}}_Name: |
- var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params); |
- this.{{method.name|stylize_method}}( |
-{%- for parameter in method.parameters -%} |
- params.{{parameter.name}}{% if not loop.last %}, {% endif %} |
-{%- endfor %}); |
- return true; |
-{%- endif %} |
-{%- endfor %} |
- default: |
- return false; |
- } |
- }; |
- |
- {{interface.name}}Stub.prototype.acceptWithResponder = |
- function(message, responder) { |
- var reader = new codec.MessageReader(message); |
- switch (reader.messageName) { |
-{%- for method in interface.methods %} |
-{%- if method.response_parameters != None %} |
- case k{{interface.name}}_{{method.name}}_Name: |
- var params = reader.decodeStruct({{interface.name}}_{{method.name}}_Params); |
- return this.{{method.name|stylize_method}}( |
-{%- for parameter in method.parameters -%} |
-params.{{parameter.name}}{% if not loop.last %}, {% endif -%} |
-{%- endfor %}).then(function(response) { |
- var responseParams = |
- new {{interface.name}}_{{method.name}}_ResponseParams(); |
-{%- for parameter in method.response_parameters %} |
- responseParams.{{parameter.name}} = response.{{parameter.name}}; |
-{%- endfor %} |
- var builder = new codec.MessageWithRequestIDBuilder( |
- k{{interface.name}}_{{method.name}}_Name, |
- codec.align({{interface.name}}_{{method.name}}_ResponseParams.encodedSize), |
- codec.kMessageIsResponse, reader.requestID); |
- builder.encodeStruct({{interface.name}}_{{method.name}}_ResponseParams, |
- responseParams); |
- var message = builder.finish(); |
- responder.accept(message); |
- }); |
-{%- endif %} |
-{%- endfor %} |
- default: |
- return Promise.reject(Error("Unhandled message: " + reader.messageName)); |
- } |
- }; |
- |
-{#--- Validation #} |
- |
- function validate{{interface.name}}Request(messageValidator) { |
-{%- if not(interface.methods) %} |
- return validator.validationError.NONE; |
-{%- else %} |
- var message = messageValidator.message; |
- var paramsClass = null; |
- switch (message.getName()) { |
-{%- for method in interface.methods %} |
- case k{{interface.name}}_{{method.name}}_Name: |
-{%- if method.response_parameters == None %} |
- if (!message.expectsResponse() && !message.isResponse()) |
- paramsClass = {{interface.name}}_{{method.name}}_Params; |
-{%- else %} |
- if (message.expectsResponse()) |
- paramsClass = {{interface.name}}_{{method.name}}_Params; |
-{%- endif %} |
- break; |
-{%- endfor %} |
- } |
- if (paramsClass === null) |
- return validator.validationError.NONE; |
- return paramsClass.validate(messageValidator, messageValidator.message.getHeaderNumBytes()); |
-{%- endif %} |
- } |
- |
- function validate{{interface.name}}Response(messageValidator) { |
-{%- if not(interface|has_callbacks) %} |
- return validator.validationError.NONE; |
-{%- else %} |
- var message = messageValidator.message; |
- var paramsClass = null; |
- switch (message.getName()) { |
-{%- for method in interface.methods %} |
-{%- if method.response_parameters != None %} |
- case k{{interface.name}}_{{method.name}}_Name: |
- if (message.isResponse()) |
- paramsClass = {{interface.name}}_{{method.name}}_ResponseParams; |
- break; |
-{%- endif %} |
-{%- endfor %} |
- } |
- if (paramsClass === null) |
- return validator.validationError.NONE; |
- return paramsClass.validate(messageValidator, messageValidator.message.getHeaderNumBytes()); |
-{%- endif %} |
- } |
- |
- var {{interface.name}} = { |
- name: '{{namespace|replace(".","::")}}::{{interface.name}}', |
- proxyClass: {{interface.name}}Proxy, |
- stubClass: {{interface.name}}Stub, |
- validateRequest: validate{{interface.name}}Request, |
-{%- if interface|has_callbacks %} |
- validateResponse: validate{{interface.name}}Response, |
-{%- else %} |
- validateResponse: null, |
-{%- endif %} |
- }; |
-{#--- Interface Constants #} |
-{%- for constant in interface.constants %} |
- {{interface.name}}.{{constant.name}} = {{constant.value|expression_to_text}}, |
-{%- endfor %} |
-{#--- Interface Enums #} |
-{%- from "enum_definition.tmpl" import enum_def -%} |
-{%- for enum in interface.enums %} |
- {{ enum_def("%s.%s"|format(interface.name, enum.name), enum) }} |
-{%- endfor %} |
- {{interface.name}}Stub.prototype.validator = validate{{interface.name}}Request; |
-{%- if interface|has_callbacks %} |
- {{interface.name}}Proxy.prototype.validator = validate{{interface.name}}Response; |
-{%- else %} |
- {{interface.name}}Proxy.prototype.validator = null; |
-{%- endif %} |