docs: whats-new.adoc: use headings for main topics
[barectf.git] / docs / modules / platform / pages / api.adoc
CommitLineData
016a4d97
PP
1= Platform API
2:us: _
3
4include::ROOT:partial$def-prefix-note.adoc[]
5
6The public header (usually named `barectf.h`) which barectf
7xref:cli:index.adoc[generates] offers an API to write a
8barectf platform.
9
10[[ctx]]
11== Context structure
12
13For a given xref:yaml:dst-obj.adoc[data stream type] named `__NAME__`:
14
15[source,c]
16----
17struct barectf_NAME_ctx {
18 /* ... */
19};
20----
21
22A barectf platform is responsible for allocating and deallocating such
23a structure for each data stream type.
24
25What this structure actually contains is not important; a barectf
26platform only needs to store it.
27
28[[cbs]]
29== Platform callback functions structure
30
31[source,c]
32----
33struct barectf_platform_callbacks {
34 /* Clock source callback functions here */
35
36 /*
37 * Returns whether or not the back end is full.
38 */
39 int (*is_backend_full)(void *user_data);
40
41 /*
42 * Opens the current packet.
43 */
44 void (*open_packet)(void *user_data);
45
46 /*
47 * Closes the current packet.
48 */
49 void (*close_packet)(void *user_data);
50};
51----
52
53Each callback function receives as its `user_data` parameter what you
54passed to the <<init,barectf context initialization function>> as the
55`user_data` parameter.
56
57[[cb-clk-src]]
58=== Clock source
59
60For each xref:yaml:clk-type-obj.adoc[clock type object] `__NAME__`
61within the trace type's
62xref:yaml:trace-type-obj.adoc#clk-types-prop[`clock-types` property],
63the platform callback functions structure contains one clock source
64callback function:
65
66[source,c]
67----
68CTYPE (*NAME_clock_get_value)(void *user_data);
69----
70
71`__CTYPE__` is the clock type object's
72xref:yaml:clk-type-obj.adoc#c-type-prop[`$c-type` property] (`uint32_t`
73by default).
74
75A clock source function returns the clock's current value. The clock
76value must be monotonic.
77
78[[cb-open]]
79=== Packet opening
80
81[source,c]
82----
83void (*open_packet)(void *user_data);
84----
85
86This function must call the <<open,packet opening function>>.
87
88[[cb-close]]
89=== Packet closing
90
91[source,c]
92----
93void (*close_packet)(void *user_data);
94----
95
96This function must:
97
98. Call the <<close,packet closing function>>.
99
100. Copy or move the current packet to the back end.
101
102After step{nbsp}2, this function _can_ set a new packet buffer with
103<<barectf-packet-set-buf-func,`+barectf_packet_set_buf()+`>>. If it
104doesn't, the next calls to the <<open,packet opening function>> and
105xref:tracing-funcs:index.adoc[tracing functions] will write to the
106current packet buffer.
107
108[[cb-is-back-end-full]]
109=== Is the back end full?
110
111[source,c]
112----
113int (*is_backend_full)(void *user_data);
114----
115
116This function returns whether or not the back end is full.
117
118In other words, if a new packet is <<cb-open,opened>> now, does this
119packet have its reserved space in the back end?
120
121[[accessors]]
122== Context property accessors
123
c24e3f21 124* [[barectf-pkt-buf-addr-func]]{empty}
016a4d97
PP
125+
126[source,c]
127----
128uint8_t *barectf_packet_buf_addr(const void *vctx);
129----
130+
131Returns the packet buffer address of the barectf context `vctx`.
132
133* {empty}
134+
135[source,c]
136----
137uint32_t barectf_packet_buf_size(const void *vctx);
138----
139+
140Returns the packet buffer size (bytes) of the barectf context `vctx`.
141
142* {empty}
143+
144[source,c]
145----
146int barectf_packet_is_full(const void *vctx);
147----
148+
149Returns whether or not the packet of the barectf context `vctx` is full.
150
151* {empty}
152+
153[source,c]
154----
155int barectf_packet_is_empty(const void *vctx);
156----
157+
158Returns whether or not the packet of the barectf context `vctx` is empty.
159
160* {empty}
161+
162[source,c]
163----
164int barectf_packet_is_open(const void *vctx);
165----
166+
167Returns whether or not the packet of the barectf context `vctx` is
168open.
169
170* [[barectf-packet-set-buf-func]]{empty}
171+
172[source,c]
173----
174void barectf_packet_set_buf(void *vctx, uint8_t *addr, uint32_t size);
175----
176+
177Sets the packet buffer of the barectf context `vctx` to the address `addr`
178and the size `size` bytes.
179+
180You can only call this function from the <<cb-close,packet closing
181callback function>>.
182
c24e3f21 183* [[barectf-disc-er-count-func]]{empty}
016a4d97
PP
184+
185[source,c]
186----
187uint32_t barectf_discarded_event_records_count(const void *vctx);
188----
189+
190Returns the number of
191xref:how-barectf-works:ctf-primer.adoc#disc-er-counter[discarded event
192records] in the barectf context `vctx`.
193
194* {empty}
195+
196[source,c]
197----
198int barectf_is_in_tracing_section(const void *vctx);
199----
200+
201Returns whether or not there's a current
202xref:tracing-funcs:index.adoc[tracing function] call for the barectf
203context `vctx`.
204
205* {empty}
206+
207[source,c]
208----
209volatile const int *barectf_is_in_tracing_section_ptr(const void *vctx);
210----
211+
212Returns a pointer to an `int` variable which indicates whether or not
213there's a current xref:tracing-funcs:index.adoc[tracing function] call
214for the barectf context `vctx`.
215
216[[init]]
217== Context initialization
218
219Initializes the <<ctx,barectf context>> `vctx` with the initial packet
220buffer located at the address `buf_addr` and having `buf_size` bytes,
221the <<cbs,platform callback functions>> `cbs`, and the
222user data `data`.
223
224[source,c]
225----
226void barectf_init(void *vctx, uint8_t *buf_addr, uint32_t buf_size,
227 struct barectf_platform_callbacks cbs, void *user_data);
228----
229
230`user_data` is what the platform callback functions receive as
231their first parameter.
232
233[[open]]
234== Packet opening
235
236For a given xref:yaml:dst-obj.adoc[data stream type] named `__NAME__`, a
237packet opening function opens the current
238xref:how-barectf-works:ctf-primer.adoc#pkt[packet] of a
239<<ctx,barectf context>> `sctx`:
240
241[source,c]
242----
243void barectf_NAME_open_packet(struct barectf_NAME_ctx *sctx);
244----
245
246[[open-params]]
247=== Parameters
248
249For each member `__MNAME__` of the data stream type object's
250xref:yaml:dst-obj.adoc#pkt-ctx-ft-extra-members-prop[`packet-context-field-type-extra-members`
251property], this function has an additional parameter named
252`pc{us}__MNAME__`.
253
254See xref:yaml:ft-obj.adoc#gen-c-types[Generated C{nbsp}types] to
255determine the exact C{nbsp}type of each parameter.
256
257Note that a member with a xref:yaml:dyn-array-ft-obj.adoc[dynamic array
258field type] actually makes barectf generate _two_ adjacent parameters:
259
260. One for the dynamic array's length.
261+
262Example: `uint32_t pc___my_array_len`
263
264. One for the dynamic array's data.
265+
266Example: `const uint8_t *pc_my_array`
267
268=== Role
269
270A packet opening function:
271
272. Writes initial
273 xref:how-barectf-works:ctf-primer.adoc#pkt[packet header and context]
274 fields.
275+
276The source of some of those fields can be <<open-params,parameters>>.
277
278. Saves the offsets of some packet context field to write them at
279 <<close,packet closing>> time.
280
281. Marks the current packet as being open.
282
283In general, a <<cb-open,packet opening platform callback function>> and
284a platform initialization function (for the first packet) call this
285function.
286
287[[close]]
288== Packet closing
289
290For a given xref:yaml:dst-obj.adoc[data stream type] named `__NAME__`, a
291packet closing function closes the current
292xref:how-barectf-works:ctf-primer.adoc#pkt[packet] of a
293<<ctx,barectf context>> `sctx`:
294
295[source,c]
296----
297void barectf_NAME_close_packet(struct barectf_NAME_ctx *sctx);
298----
299
300=== Role
301
302A packet closing function:
303
304. Writes some
305 xref:how-barectf-works:ctf-primer.adoc#pkt[packet context]
306 fields.
307
308. Marks the current packet as being closed.
309
310In general, a <<cb-close,packet closing platform callback function>> and
311a platform finalization function (for the last packet) call this
312function.
This page took 0.034063 seconds and 4 git commands to generate.