6513e2700d479b28938e9e6c702d6a876e6848c2
[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 {% include 'licence-header.j2' %}
37
38
39 #include <stdint.h>
40
41 #ifdef __cplusplus
42 extern "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
53 {% for ev_type in def_stream_type.event_types | sort %}
54 #define {{ prefix }}trace_{{ ev_type.name }} {{ c_common.trace_func_name(def_stream_type, ev_type) }}
55 {% endfor %}
56 {% endif %}
57
58 struct {{ prefix }}ctx;
59
60 uint32_t {{ prefix }}packet_size(void *ctx);
61 int {{ prefix }}packet_is_full(void *ctx);
62 int {{ prefix }}packet_is_empty(void *ctx);
63 uint32_t {{ prefix }}packet_events_discarded(void *ctx);
64 uint8_t *{{ prefix }}packet_buf(void *ctx);
65 void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
66 uint32_t {{ prefix }}packet_buf_size(void *ctx);
67 int {{ prefix }}packet_is_open(void *ctx);
68 int {{ prefix }}is_in_tracing_section(void *ctx);
69 volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *ctx);
70 int {{ prefix }}is_tracing_enabled(void *ctx);
71 void {{ prefix }}enable_tracing(void *ctx, int enable);
72
73 /* barectf platform callbacks */
74 struct {{ prefix }}platform_callbacks {
75 {% set clk_types = trace_type.clock_types %}
76 {% if clk_types %}
77 /* clock callbacks */
78 {% for clk_type in clk_types | sort %}
79 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
80 {% endfor %}
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 */
94 struct {{ 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 }}` */
134 struct {{ prefix }}{{ stream_type.name }}_ctx {
135 /* parent */
136 struct {{ prefix }}ctx parent;
137
138 /* config-specific members follow */
139 {% if trace_type._pkt_header_ft %}
140 {% for member_name in trace_type._pkt_header_ft.members %}
141 uint32_t off_tph_{{ member_name }};
142 {% endfor %}
143 {% endif %}
144 {% for member_name in stream_type._pkt_ctx_ft.members %}
145 uint32_t off_spc_{{ member_name }};
146 {% endfor %}
147 {% if stream_type.default_clock_type %}
148 {{ cg_opts.clock_type_c_types[stream_type.default_clock_type] }} cur_last_event_ts;
149 {% endif %}
150 };
151
152 {% endfor %}
153 {% include 'c/ctx-init-func-proto.j2' %};
154
155 {% for stream_type in trace_type.stream_types | sort %}
156 {% include 'c/open-func-proto.j2' %};
157
158 {% include 'c/close-func-proto.j2' %};
159 {% for ev_type in stream_type.event_types | sort %}
160
161 {% include 'c/trace-func-proto.j2' %};
162 {% endfor %}
163 {% endfor %}
164
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif /* _{{ ucprefix }}H */
This page took 0.033156 seconds and 3 git commands to generate.