Document event.h (API)
[babeltrace.git] / include / babeltrace / ctf-ir / packet.h
CommitLineData
f79cf0f0
PP
1#ifndef BABELTRACE_CTF_IR_PACKET_H
2#define BABELTRACE_CTF_IR_PACKET_H
3
4/*
5 * BabelTrace - CTF IR: Stream packet
6 *
7 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * The Common Trace Format (CTF) Specification is available at
28 * http://www.efficios.com/ctf
29 */
30
31#include <stdint.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
f5efa812
PP
37/**
38@defgroup ctfirpacket CTF IR packet
39@ingroup ctfir
40@brief CTF IR packet.
41
42A CTF IR <strong><em>packet</em></strong> is a container of packet
43fields, that is, of the <strong>trace packet header</strong> and
44<strong>stream packet context</strong> fields.
45
46As a reminder, here's the structure of a CTF packet:
47
48@imgpacketstructure
49
50You can create a CTF IR packet \em from a
51\link ctfirstream CTF IR stream\endlink with bt_ctf_packet_create(). The
52stream you use to create a packet object becomes its parent.
53
54When you set the trace packet header and stream packet context fields of
55a packet with resp. bt_ctf_packet_set_header() and
56bt_ctf_packet_set_context(), their field type \em must be equivalent to
57the field types returned by resp. bt_ctf_trace_get_packet_header_type()
58and bt_ctf_stream_class_get_packet_context_type() for its parent trace
59class and stream class.
60
61You can attach a packet object to a \link ctfirevent CTF IR
62event\endlink object with bt_ctf_event_set_packet().
63
64As with any Babeltrace object, CTF IR packet objects have
65<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
66counts</a>. See \ref refs to learn more about the reference counting
67management of Babeltrace objects.
68
69bt_notification_event_create() \em freezes its event parameter on
70success, which in turns freezes the event's associated packet object.
71This is the only way that a CTF IR packet object can be frozen.
72You cannot modify a frozen packet: it is considered immutable,
73except for \link refs reference counting\endlink.
74
75@sa ctfirstream
76@sa ctfirstreamclass
77@sa ctfirtraceclass
78
79@file
80@brief CTF IR packet type and functions.
81@sa ctfirpacket
82
83@addtogroup ctfirpacket
84@{
85*/
86
87/**
88@struct bt_ctf_packet
89@brief A CTF IR packet.
90@sa ctfirpacket
91*/
f79cf0f0 92struct bt_ctf_packet;
f5efa812
PP
93struct bt_ctf_stream;
94
95/**
96@name Creation and parent access functions
97@{
98*/
f79cf0f0 99
f5efa812
PP
100/**
101@brief Creates a default CTF IR packet with \p stream as its parent
102 CTF IR stream.
103
104On success, the packet object's trace packet header and stream packet
105context fields are not set. You can set them with resp.
106bt_ctf_packet_set_header() and bt_ctf_packet_set_context().
107
108@param[in] stream Parent CTF IR stream of the packet to create.
109@returns Created packet, or \c NULL on error.
110
111@prenotnull{stream}
112@postsuccessrefcountret1
113*/
f79cf0f0
PP
114extern struct bt_ctf_packet *bt_ctf_packet_create(
115 struct bt_ctf_stream *stream);
116
f5efa812
PP
117/**
118@brief Returns the parent CTF IR stream of the CTF IR packet \p packet.
119
120This function returns a reference to the stream which was used to create
121the packet object in the first place with bt_ctf_packet_create().
122
123@param[in] packet Packet of which to get the parent stream.
124@returns Parent stream of \p packet, or \c NULL on error.
125
126@prenotnull{packet}
127@postsuccessrefcountretinc
128*/
f79cf0f0
PP
129extern struct bt_ctf_stream *bt_ctf_packet_get_stream(
130 struct bt_ctf_packet *packet);
131
f5efa812
PP
132/** @} */
133
134/**
135@name Contained fields functions
136@{
137*/
138
139/**
140@brief Returns the trace packet header field of the CTF IR packet
141 \p packet.
142
143@param[in] packet Packet of which to get the trace packet header
144 field.
145@returns Trace packet header field of \p packet,
146 or \c NULL if the trace packet header
147 field is not set or on error.
148
149@prenotnull{packet}
150@postsuccessrefcountretinc
151
152@sa bt_ctf_packet_set_header(): Sets the trace packet header
153 field of a given packet.
154*/
f79cf0f0
PP
155extern struct bt_ctf_field *bt_ctf_packet_get_header(
156 struct bt_ctf_packet *packet);
157
f5efa812
PP
158/**
159@brief Sets the trace packet header field of the CTF IR packet
160 \p packet to \p header.
161
162The field type of \p header, as returned by bt_ctf_field_get_type(),
163\em must be equivalent to the field type returned by
164bt_ctf_trace_get_packet_header_type() for the parent trace class
165of \p packet.
166
167@param[in] packet Packet of which to set the trace packet header
168 field.
169@param[in] header Trace packet header field.
170@returns 0 on success, or a negative value on error.
171
172@prenotnull{packet}
173@prenotnull{header}
174@prehot{packet}
175@pre \p header has a field type equivalent to the field type returned by
176 bt_ctf_trace_get_packet_header_type() for the parent trace class
177 of \p packet.
178@postrefcountsame{packet}
179@postsuccessrefcountinc{header}
180
181@sa bt_ctf_packet_get_header(): Returns the trace packet header field
182 of a given packet.
183*/
f79cf0f0
PP
184extern int bt_ctf_packet_set_header(
185 struct bt_ctf_packet *packet, struct bt_ctf_field *header);
186
f5efa812
PP
187/**
188@brief Returns the stream packet context field of the CTF IR packet
189 \p packet.
190
191@param[in] packet Packet of which to get the stream packet context
192 field.
193@returns Stream packet context field of \p packet,
194 or \c NULL if the stream packet context
195 field is not set or on error.
196
197@prenotnull{packet}
198@postsuccessrefcountretinc
199
200@sa bt_ctf_packet_set_context(): Sets the stream packet context
201 field of a given packet.
202*/
f79cf0f0 203extern struct bt_ctf_field *bt_ctf_packet_get_context(
f5efa812
PP
204 struct bt_ctf_packet *packet);
205
206/**
207@brief Sets the stream packet context field of the CTF IR packet
208 \p packet to \p context.
f79cf0f0 209
f5efa812
PP
210The field type of \p context, as returned by bt_ctf_field_get_type(),
211\em must be equivalent to the field type returned by
212bt_ctf_stream_class_get_packet_context_type() for the parent stream
213class of \p packet.
214
215@param[in] packet Packet of which to set the stream packet context
216 field.
217@param[in] context Stream packet context field.
218@returns 0 on success, or a negative value on error.
219
220@prenotnull{packet}
221@prenotnull{context}
222@prehot{packet}
223@pre \p context has a field type equivalent to the field type returned
224 by bt_ctf_stream_class_get_packet_context_type() for the parent
225 stream class of \p packet.
226@postrefcountsame{packet}
227@postsuccessrefcountinc{context}
228
229@sa bt_ctf_packet_get_context(): Returns the stream packet context field
230 of a given packet.
231*/
f79cf0f0
PP
232extern int bt_ctf_packet_set_context(
233 struct bt_ctf_packet *packet, struct bt_ctf_field *context);
234
f5efa812
PP
235/** @} */
236
f79cf0f0
PP
237#ifdef __cplusplus
238}
239#endif
240
241#endif /* BABELTRACE_CTF_IR_PACKET_H */
This page took 0.035476 seconds and 4 git commands to generate.