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