// 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 -%}
{%- set header_guard = "%s_C_H_"|format(
variant_path|upper|replace("/","_")|replace(".","_")|
replace("-", "_")) %}
{%- import "module_macros.tmpl" as module_macros %}
#ifndef {{header_guard}}
#define {{header_guard}}
{#-- TODO(mef): Derive EXPORT_MACRO from module name --#}
{%- set export_macro = "CRONET_EXPORT" %}
#include "cronet_export.h"
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
typedef const char* Cronet_String;
typedef void* Cronet_RawDataPtr;
typedef void* Cronet_ClientContext;
// Forward declare interfaces.
{%- for interface in interfaces %}
{%- set interface_name = interface|get_name_for_kind %}
typedef struct {{interface_name}} {{interface_name}};
typedef struct {{interface_name}}* {{interface_name}}Ptr;
{%- endfor %}
// Forward declare structs.
{%- for struct in structs %}
{%- set struct_name = struct|get_name_for_kind %}
typedef struct {{struct_name}} {{struct_name}};
typedef struct {{struct_name}}* {{struct_name}}Ptr;
{%- endfor %}
// Declare enums
{%- for enum in all_enums %}
{%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=False) %}
typedef enum {{enum_name}} {
{%- for field in enum.fields %}
{%- if field.value %}
{{enum_name}}_{{field.name}} = {{field.value|expression_to_text}},
{%- else %}
{{enum_name}}_{{field.name}},
{%- endif %}
{%- endfor %}
} {{enum_name}};
{% endfor %}
// Declare constants
{%- for constant in module.constants %}
{{constant|format_constant_declaration}};
{%- endfor %}
{#--- Interface Stubs -#}
{% for interface in interfaces %}
{%- set interface_name = interface|get_name_for_kind %}
///////////////////////
{%- if interface|is_abstract %}
// Abstract interface {{interface_name}} is implemented by the app.
// There is no method to create a concrete implementation.
{% else %}
// Concrete interface {{interface_name}}.
// Create an instance of {{interface_name}}.
{{export_macro}} {{interface_name}}Ptr {{interface_name}}_Create(void);
{%- endif %}
// Destroy an instance of {{interface_name}}.
{{export_macro}} void {{interface_name}}_Destroy({{interface_name}}Ptr self);
// Set and get app-specific Cronet_ClientContext.
{{export_macro}} void {{interface_name}}_SetClientContext({{interface_name}}Ptr self, Cronet_ClientContext client_context);
{{export_macro}} Cronet_ClientContext {{interface_name}}_GetClientContext({{interface_name}}Ptr self);
{%- if interface|is_abstract %}
// Abstract interface {{interface_name}} is implemented by the app.
// The following concrete methods forward call to app implementation.
// The app doesn't normally call them.
{%- else %}
// Concrete methods of {{interface_name}} implemented by Cronet.
// The app calls them to manipulate {{interface_name}}.
{%- endif %}
{%- for method in interface.methods %}
{{export_macro}}
{%- 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 %});
{%- endfor %}
{%- if interface|is_abstract %}
// The app implements abstract interface {{interface_name}} by defining custom functions
// for each method.
{%- else %}
// Concrete interface {{interface_name}} is implemented by Cronet.
// The app can implement these for testing / mocking.
{%- endif %}
{%- for method in interface.methods %}
{%- if method.response_parameters and method.sync %}
{%- for param in method.response_parameters %}
typedef {{param.kind|c_wrapper_type}}
{%- endfor -%}
{%- else %}
typedef void
{%- endif %}
(*{{interface_name}}_{{method.name}}Func)({{interface_name}}Ptr self
{%- if method.parameters %}, {{module_macros.declare_c_params("", method.parameters)}}
{%- endif %});
{%- endfor %}
{%- if interface|is_abstract %}
// The app creates an instance of {{interface_name}} by providing custom functions
// for each method.
{%- else %}
// Concrete interface {{interface_name}} is implemented by Cronet.
// The app can use this for testing / mocking.
{%- endif %}
{{export_macro}} {{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 %}
);
{%- endfor %}
{% for struct in structs %}
{% set struct_name = struct|get_name_for_kind %}
///////////////////////
// Struct {{struct_name}}.
{{export_macro}} {{struct_name}}Ptr {{struct_name}}_Create(void);
{{export_macro}} void {{struct_name}}_Destroy({{struct_name}}Ptr self);
// {{struct_name}} setters.
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{{export_macro}}
{%- set kind = packed_field.field.kind %}
{%- if kind|is_array_kind %}
void {{struct_name}}_{{packed_field.field.name}}_add({{struct_name}}Ptr self, const {{kind.kind|c_wrapper_type}} element);
{%- else %}
void {{struct_name}}_{{packed_field.field.name}}_set({{struct_name}}Ptr self, const {{packed_field.field.kind|c_wrapper_type}} {{packed_field.field.name}});
{%- endif %}
{%- if kind|is_struct_kind %}
// Move data from |{{packed_field.field.name}}|. The caller retains ownership of |{{packed_field.field.name}}| and must destroy it.
void {{struct_name}}_{{packed_field.field.name}}_move({{struct_name}}Ptr self, {{packed_field.field.kind|c_wrapper_type}} {{packed_field.field.name}});
{%- endif %}
{%- endfor %}
// {{struct_name}} getters.
{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %}
{{export_macro}}
{%- set kind = packed_field.field.kind %}
{%- if kind|is_array_kind %}
uint32_t {{struct_name}}_{{packed_field.field.name}}_size(const {{struct_name}}Ptr self);
{{export_macro}}
{{kind.kind|c_wrapper_type}} {{struct_name}}_{{packed_field.field.name}}_at(const {{struct_name}}Ptr self, uint32_t index);
{{export_macro}}
void {{struct_name}}_{{packed_field.field.name}}_clear({{struct_name}}Ptr self);
{%- else %}
{{packed_field.field.kind|c_wrapper_type}} {{struct_name}}_{{packed_field.field.name}}_get(const {{struct_name}}Ptr self);
{%- endif %}
{%- endfor %}
{%- endfor %}
#ifdef __cplusplus
}
#endif
#endif // {{header_guard}}