1// Copyright 2017 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/* DO NOT EDIT. Generated from {{module.path}} */ 6 7{%- if variant -%} 8{%- set variant_path = "%s-%s"|format(module.path, variant) -%} 9{%- else -%} 10{%- set variant_path = module.path -%} 11{%- endif -%} 12 13{%- set header_guard = "%s_C_H_"|format( 14 variant_path|upper|replace("/","_")|replace(".","_")| 15 replace("-", "_")) %} 16 17{%- import "module_macros.tmpl" as module_macros %} 18 19#ifndef {{header_guard}} 20#define {{header_guard}} 21 22{#-- TODO(mef): Derive EXPORT_MACRO from module name --#} 23{%- set export_macro = "CRONET_EXPORT" %} 24#include "cronet_export.h" 25 26#ifdef __cplusplus 27extern "C" { 28#endif 29 30#include <stdint.h> 31 32typedef const char* Cronet_String; 33typedef void* Cronet_RawDataPtr; 34typedef void* Cronet_ClientContext; 35 36// Forward declare interfaces. 37{%- for interface in interfaces %} 38{%- set interface_name = interface|get_name_for_kind %} 39typedef struct {{interface_name}} {{interface_name}}; 40typedef struct {{interface_name}}* {{interface_name}}Ptr; 41{%- endfor %} 42 43// Forward declare structs. 44{%- for struct in structs %} 45{%- set struct_name = struct|get_name_for_kind %} 46typedef struct {{struct_name}} {{struct_name}}; 47typedef struct {{struct_name}}* {{struct_name}}Ptr; 48{%- endfor %} 49 50// Declare enums 51{%- for enum in all_enums %} 52{%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=False) %} 53typedef enum {{enum_name}} { 54{%- for field in enum.fields %} 55{%- if field.value %} 56 {{enum_name}}_{{field.name}} = {{field.value|expression_to_text}}, 57{%- else %} 58 {{enum_name}}_{{field.name}}, 59{%- endif %} 60{%- endfor %} 61} {{enum_name}}; 62 63{% endfor %} 64 65// Declare constants 66{%- for constant in module.constants %} 67{{constant|format_constant_declaration}}; 68{%- endfor %} 69 70{#--- Interface Stubs -#} 71{% for interface in interfaces %} 72{%- set interface_name = interface|get_name_for_kind %} 73 74/////////////////////// 75{%- if interface|is_abstract %} 76// Abstract interface {{interface_name}} is implemented by the app. 77 78// There is no method to create a concrete implementation. 79 80{% else %} 81// Concrete interface {{interface_name}}. 82 83// Create an instance of {{interface_name}}. 84{{export_macro}} {{interface_name}}Ptr {{interface_name}}_Create(void); 85{%- endif %} 86// Destroy an instance of {{interface_name}}. 87{{export_macro}} void {{interface_name}}_Destroy({{interface_name}}Ptr self); 88// Set and get app-specific Cronet_ClientContext. 89{{export_macro}} void {{interface_name}}_SetClientContext({{interface_name}}Ptr self, Cronet_ClientContext client_context); 90{{export_macro}} Cronet_ClientContext {{interface_name}}_GetClientContext({{interface_name}}Ptr self); 91{%- if interface|is_abstract %} 92// Abstract interface {{interface_name}} is implemented by the app. 93// The following concrete methods forward call to app implementation. 94// The app doesn't normally call them. 95{%- else %} 96// Concrete methods of {{interface_name}} implemented by Cronet. 97// The app calls them to manipulate {{interface_name}}. 98{%- endif %} 99{%- for method in interface.methods %} 100{{export_macro}} 101{%- if method.response_parameters and method.sync %} 102{%- for param in method.response_parameters %} 103{{param.kind|c_wrapper_type}} 104{%- endfor -%} 105{%- else %} 106void 107{%- endif %} 108 {{interface_name}}_{{method.name}}({{interface_name}}Ptr self 109{%- if method.parameters %}, {{module_macros.declare_c_params("", method.parameters)}} 110{%- endif %}); 111{%- endfor %} 112 113{%- if interface|is_abstract %} 114// The app implements abstract interface {{interface_name}} by defining custom functions 115// for each method. 116{%- else %} 117// Concrete interface {{interface_name}} is implemented by Cronet. 118// The app can implement these for testing / mocking. 119{%- endif %} 120{%- for method in interface.methods %} 121{%- if method.response_parameters and method.sync %} 122{%- for param in method.response_parameters %} 123typedef {{param.kind|c_wrapper_type}} 124{%- endfor -%} 125{%- else %} 126typedef void 127{%- endif %} 128 (*{{interface_name}}_{{method.name}}Func)({{interface_name}}Ptr self 129{%- if method.parameters %}, {{module_macros.declare_c_params("", method.parameters)}} 130{%- endif %}); 131{%- endfor %} 132 133{%- if interface|is_abstract %} 134// The app creates an instance of {{interface_name}} by providing custom functions 135// for each method. 136{%- else %} 137// Concrete interface {{interface_name}} is implemented by Cronet. 138// The app can use this for testing / mocking. 139{%- endif %} 140{{export_macro}} {{interface_name}}Ptr {{interface_name}}_CreateWith( 141{%- for method in interface.methods -%} 142 {{interface_name}}_{{method.name}}Func {{method.name}}Func 143{%- if not loop.last %}, {% endif %} 144{%- endfor %} 145 ); 146{%- endfor %} 147 148{% for struct in structs %} 149{% set struct_name = struct|get_name_for_kind %} 150/////////////////////// 151// Struct {{struct_name}}. 152{{export_macro}} {{struct_name}}Ptr {{struct_name}}_Create(void); 153{{export_macro}} void {{struct_name}}_Destroy({{struct_name}}Ptr self); 154// {{struct_name}} setters. 155{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %} 156{{export_macro}} 157{%- set kind = packed_field.field.kind %} 158{%- if kind|is_array_kind %} 159void {{struct_name}}_{{packed_field.field.name}}_add({{struct_name}}Ptr self, const {{kind.kind|c_wrapper_type}} element); 160{%- else %} 161void {{struct_name}}_{{packed_field.field.name}}_set({{struct_name}}Ptr self, const {{packed_field.field.kind|c_wrapper_type}} {{packed_field.field.name}}); 162{%- endif %} 163{%- if kind|is_struct_kind %} 164// Move data from |{{packed_field.field.name}}|. The caller retains ownership of |{{packed_field.field.name}}| and must destroy it. 165void {{struct_name}}_{{packed_field.field.name}}_move({{struct_name}}Ptr self, {{packed_field.field.kind|c_wrapper_type}} {{packed_field.field.name}}); 166{%- endif %} 167{%- endfor %} 168// {{struct_name}} getters. 169{%- for packed_field in struct.packed.packed_fields_in_ordinal_order %} 170{{export_macro}} 171{%- set kind = packed_field.field.kind %} 172{%- if kind|is_array_kind %} 173uint32_t {{struct_name}}_{{packed_field.field.name}}_size(const {{struct_name}}Ptr self); 174{{export_macro}} 175{{kind.kind|c_wrapper_type}} {{struct_name}}_{{packed_field.field.name}}_at(const {{struct_name}}Ptr self, uint32_t index); 176{{export_macro}} 177void {{struct_name}}_{{packed_field.field.name}}_clear({{struct_name}}Ptr self); 178{%- else %} 179{{packed_field.field.kind|c_wrapper_type}} {{struct_name}}_{{packed_field.field.name}}_get(const {{struct_name}}Ptr self); 180{%- endif %} 181{%- endfor %} 182{%- endfor %} 183 184#ifdef __cplusplus 185} 186#endif 187 188#endif // {{header_guard}} 189 190