templates: commonize the licence header
[deliverable/barectf.git] / barectf / templates / c / barectf.h.j2
CommitLineData
fdbf8740
PP
1{#
2 # The MIT License (MIT)
3 #
4 # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #}
1b49c7b8 25{% import 'common.j2' as common %}
d6483c83 26{% import 'c/common.j2' as c_common %}
1b49c7b8
PP
27{% set prefix = common.prefix %}
28{% set ucprefix = common.ucprefix %}
29{% set trace_type = cfg.trace.type %}
30{% set cg_opts = cfg.options.code_generation_options %}
31{% set def_stream_type = cg_opts.default_stream_type %}
32{% set header_opts = cg_opts.header_options %}
33#ifndef _{{ ucprefix }}H
34#define _{{ ucprefix }}H
35
e72875eb
PP
36{% include 'licence-header.j2' %}
37
1b49c7b8
PP
38
39#include <stdint.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45{% if header_opts.identifier_prefix_definition %}
46#define _BARECTF_PREFIX {{ prefix }}
47{% endif %}
48{% if def_stream_type and header_opts.default_stream_type_name_definition %}
49#define _BARECTF_DEFAULT_STREAM {{ def_stream_type.name }}
50{% endif %}
51{% if def_stream_type %}
52
d6483c83 53 {% for ev_type in def_stream_type.event_types | sort %}
1b49c7b8 54#define {{ prefix }}trace_{{ ev_type.name }} {{ c_common.trace_func_name(def_stream_type, ev_type) }}
d6483c83 55 {% endfor %}
1b49c7b8
PP
56{% endif %}
57
58struct {{ prefix }}ctx;
59
60uint32_t {{ prefix }}packet_size(void *ctx);
61int {{ prefix }}packet_is_full(void *ctx);
62int {{ prefix }}packet_is_empty(void *ctx);
63uint32_t {{ prefix }}packet_events_discarded(void *ctx);
64uint8_t *{{ prefix }}packet_buf(void *ctx);
65void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
66uint32_t {{ prefix }}packet_buf_size(void *ctx);
67int {{ prefix }}packet_is_open(void *ctx);
68int {{ prefix }}is_in_tracing_section(void *ctx);
69volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *ctx);
70int {{ prefix }}is_tracing_enabled(void *ctx);
71void {{ prefix }}enable_tracing(void *ctx, int enable);
72
73/* barectf platform callbacks */
74struct {{ prefix }}platform_callbacks {
75{% set clk_types = trace_type.clock_types %}
76{% if clk_types %}
77 /* clock callbacks */
d6483c83 78 {% for clk_type in clk_types | sort %}
1b49c7b8 79 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
d6483c83 80 {% endfor %}
1b49c7b8
PP
81
82{% endif %}
83 /* is back-end full? */
84 int (*is_backend_full)(void *);
85
86 /* open packet */
87 void (*open_packet)(void *);
88
89 /* close packet */
90 void (*close_packet)(void *);
91};
92
93/* common barectf context */
94struct {{ prefix }}ctx {
95 /* platform callbacks */
96 struct {{ prefix }}platform_callbacks cbs;
97
98 /* platform data (passed to callbacks) */
99 void *data;
100
101 /* output buffer (will contain a CTF binary packet) */
102 uint8_t *buf;
103
104 /* packet's total size (bits) */
105 uint32_t packet_size;
106
107 /* packet's content size (bits) */
108 uint32_t content_size;
109
110 /* current position from beginning of packet (bits) */
111 uint32_t at;
112
113 /* size of packet header + context fields (content offset) */
114 uint32_t off_content;
115
116 /* discarded event counter */
117 uint32_t events_discarded;
118
119 /* current packet is open? */
120 int packet_is_open;
121
122 /* in tracing code? */
123 volatile int in_tracing_section;
124
125 /* tracing is enabled? */
126 volatile int is_tracing_enabled;
127
128 /* use current/last event time when opening/closing packets */
129 int use_cur_last_event_ts;
130};
131
132{% for stream_type in trace_type.stream_types | sort %}
133/* context for stream type `{{ stream_type.name }}` */
134struct {{ prefix }}{{ stream_type.name }}_ctx {
135 /* parent */
136 struct {{ prefix }}ctx parent;
137
138 /* config-specific members follow */
d6483c83
PP
139 {% if trace_type._pkt_header_ft %}
140 {% for member_name in trace_type._pkt_header_ft.members %}
1b49c7b8 141 uint32_t off_tph_{{ member_name }};
d6483c83
PP
142 {% endfor %}
143 {% endif %}
144 {% for member_name in stream_type._pkt_ctx_ft.members %}
1b49c7b8 145 uint32_t off_spc_{{ member_name }};
d6483c83
PP
146 {% endfor %}
147 {% if stream_type.default_clock_type %}
1b49c7b8 148 {{ cg_opts.clock_type_c_types[stream_type.default_clock_type] }} cur_last_event_ts;
d6483c83 149 {% endif %}
1b49c7b8
PP
150};
151
152{% endfor %}
d6483c83 153{% include 'c/ctx-init-func-proto.j2' %};
1b49c7b8
PP
154
155{% for stream_type in trace_type.stream_types | sort %}
d6483c83 156 {% include 'c/open-func-proto.j2' %};
1b49c7b8 157
d6483c83
PP
158 {% include 'c/close-func-proto.j2' %};
159 {% for ev_type in stream_type.event_types | sort %}
1b49c7b8 160
d6483c83
PP
161 {% include 'c/trace-func-proto.j2' %};
162 {% endfor %}
1b49c7b8
PP
163{% endfor %}
164
165#ifdef __cplusplus
166}
167#endif
168
169#endif /* _{{ ucprefix }}H */
This page took 0.029236 seconds and 4 git commands to generate.