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