// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/* DO NOT EDIT. Generated from {{module.path}} */
{%- if variant -%}
{%- set variant_path = "%s-%s"|format(module.path, variant) -%}
{%- else -%}
{%- set variant_path = module.path -%}
{%- endif %}
{%- import "module_macros.tmpl" as module_macros %}
#include "{{variant_path}}_impl_interface.h"
#include "base/check.h"
{#--- Interface Stubs -#}
{% for interface in interfaces %}
{%- set interface_name = interface|get_name_for_kind %}
// C functions of {{interface_name}} that forward calls to C++ implementation.
void {{interface_name}}_Destroy({{interface_name}}Ptr self) {
DCHECK(self);
return delete self;
}
void {{interface_name}}_SetClientContext({{interface_name}}Ptr self, Cronet_ClientContext client_context) {
DCHECK(self);
self->set_client_context(client_context);
}
Cronet_ClientContext {{interface_name}}_GetClientContext({{interface_name}}Ptr self) {
DCHECK(self);
return self->client_context();
}
{% for method in interface.methods %}
{%- if method.response_parameters and method.sync %}
{%- for param in method.response_parameters %}
{{param.kind|c_wrapper_type}}
{%- endfor -%}
{%- else %}
void
{%- endif %}
{{interface_name}}_{{method.name}}({{interface_name}}Ptr self
{%- if method.parameters %}, {{module_macros.declare_c_params("", method.parameters)}}
{%- endif %}) {
DCHECK(self);
{%- if method.response_parameters and method.sync %}
return
{%- endif %}
self->{{method.name}}({{module_macros.forward_c_params("", method.parameters)}});
}
{% endfor %}
// Implementation of {{interface_name}} that forwards calls to C functions implemented by the app.
class {{interface_name}}Stub : public {{interface_name}} {
public:
{%- if interface.methods|count == 1 -%}
explicit
{%- endif %}
{{interface_name}}Stub(
{%- for method in interface.methods -%}
{{interface_name}}_{{method.name}}Func {{method.name}}Func
{%- if not loop.last %}, {% endif %}
{%- endfor %}) :
{%- for method in interface.methods -%}
{{method.name}}Func_({{method.name}}Func)
{%- if not loop.last %}, {% endif %}
{%- endfor %} {}
{{interface_name}}Stub(const {{interface_name}}Stub&) = delete;
{{interface_name}}Stub& operator=(const {{interface_name}}Stub&) = delete;
~{{interface_name}}Stub() override {}
protected:
{% for method in interface.methods %}
{{module_macros.declare_c_return(method)}}
{{method.name}}({{module_macros.declare_c_params("", method.parameters)}}) override {
{%- if method.response_parameters and method.sync %}
return
{%- endif %}
{{method.name}}Func_(this
{%- if method.parameters %}, {{module_macros.forward_c_params("", method.parameters)}}
{%- endif %});
}
{%- endfor %}
private:
{%- for method in interface.methods -%}
const {{interface_name}}_{{method.name}}Func {{method.name}}Func_;
{%- endfor %}
};
{{interface_name}}Ptr {{interface_name}}_CreateWith(
{%- for method in interface.methods -%}
{{interface_name}}_{{method.name}}Func {{method.name}}Func
{%- if not loop.last %}, {% endif %}
{%- endfor %}
) {
return new {{interface_name}}Stub(
{%- for method in interface.methods -%}
{{method.name}}Func
{%- if not loop.last %}, {% endif %}
{%- endfor %}
);
}
{% endfor %}