1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
// 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}}
|