barectf.h.j2: rename "clock callbacks" -> "clock source callbacks"
[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_dst = cg_opts.default_data_stream_type %}
32 {% set header_opts = cg_opts.header_options %}
33 {% set const_params = false %}
34 #ifndef _{{ ucprefix }}H
35 #define _{{ ucprefix }}H
36
37 {% include 'license-header.j2' %}
38
39
40 #include <stdint.h>
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 {% if header_opts.identifier_prefix_definition %}
47 /* Backward compatibility */
48 #define _BARECTF_PREFIX {{ prefix }}
49
50 #define _BARECTF_IDENTIFIER_PREFIX {{ prefix }}
51 {% endif %}
52 {% if def_dst and header_opts.default_data_stream_type_name_definition %}
53 /* Backward compatibility */
54 #define _BARECTF_DEFAULT_STREAM {{ def_dst.name }}
55
56 #define _BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME {{ def_dst.name }}
57 {% endif %}
58 {% if def_dst %}
59
60 {% for ert in def_dst.event_record_types | sort %}
61 #define {{ prefix }}trace_{{ ert.name }} {{ c_common.trace_func_name(def_dst, ert) }}
62 {% endfor %}
63 {% endif %}
64
65 struct {{ prefix }}ctx;
66
67 uint32_t {{ prefix }}packet_size(const void *ctx);
68 int {{ prefix }}packet_is_full(const void *ctx);
69 int {{ prefix }}packet_is_empty(const void *ctx);
70 uint32_t {{ prefix }}packet_events_discarded(const void *ctx);
71 uint8_t *{{ prefix }}packet_buf(const void *ctx);
72 void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
73 uint32_t {{ prefix }}packet_buf_size(const void *ctx);
74 int {{ prefix }}packet_is_open(const void *ctx);
75 int {{ prefix }}is_in_tracing_section(const void *ctx);
76 volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void *ctx);
77 int {{ prefix }}is_tracing_enabled(const void *ctx);
78 void {{ prefix }}enable_tracing(void *ctx, int enable);
79
80 /* barectf platform callbacks */
81 struct {{ prefix }}platform_callbacks {
82 {% set clk_types = trace_type.clock_types %}
83 {% if clk_types %}
84 /* Clock source callbacks */
85 {% for clk_type in clk_types | sort %}
86 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
87 {% endfor %}
88
89 {% endif %}
90 /* Is the back end full? */
91 int (*is_backend_full)(void *);
92
93 /* Open packet */
94 void (*open_packet)(void *);
95
96 /* Close packet */
97 void (*close_packet)(void *);
98 };
99
100 /* Common barectf context */
101 struct {{ prefix }}ctx {
102 /* Platform callbacks */
103 struct {{ prefix }}platform_callbacks cbs;
104
105 /* Platform data (passed to callbacks) */
106 void *data;
107
108 /* Output buffer (will contain a CTF binary packet) */
109 uint8_t *buf;
110
111 /* Packet's total size (bits) */
112 uint32_t packet_size;
113
114 /* Packet's content size (bits) */
115 uint32_t content_size;
116
117 /* Current position from beginning of packet (bits) */
118 uint32_t at;
119
120 /* Size of packet header + context fields (content offset) */
121 uint32_t off_content;
122
123 /* Discarded event records counter snapshot */
124 uint32_t events_discarded;
125
126 /* Current packet is open? */
127 int packet_is_open;
128
129 /* In tracing code? */
130 volatile int in_tracing_section;
131
132 /* Tracing is enabled? */
133 volatile int is_tracing_enabled;
134
135 /* Use current/last event record timestamp when opening/closing packets */
136 int use_cur_last_event_ts;
137 };
138
139 {% for dst in trace_type.data_stream_types | sort %}
140 /* Context for data stream type `{{ dst.name }}` */
141 struct {{ prefix }}{{ dst.name }}_ctx {
142 /* Parent */
143 struct {{ prefix }}ctx parent;
144
145 /* Config-specific members follow */
146 {% if trace_type._pkt_header_ft %}
147 {% for member_name in trace_type._pkt_header_ft.members %}
148 uint32_t off_ph_{{ member_name }};
149 {% endfor %}
150 {% endif %}
151 {% for member_name in dst._pkt_ctx_ft.members %}
152 uint32_t off_pc_{{ member_name }};
153 {% endfor %}
154 {% if dst.default_clock_type %}
155 {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} cur_last_event_ts;
156 {% endif %}
157 };
158
159 {% endfor %}
160 {% include 'c/ctx-init-func-proto.j2' %};
161
162 {% for dst in trace_type.data_stream_types | sort %}
163 {% include 'c/open-func-proto.j2' %};
164
165 {% include 'c/close-func-proto.j2' %};
166 {% for ert in dst.event_record_types | sort %}
167
168 {% include 'c/trace-func-proto.j2' %};
169 {% endfor %}
170 {% endfor %}
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif /* _{{ ucprefix }}H */
This page took 0.061291 seconds and 4 git commands to generate.