lib: add internal object pool API and use it; adapt plugins/tests
[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
094ff7c0
PP
31/* For bt_get() */
32#include <babeltrace/ref.h>
33
f79cf0f0
PP
34#include <stdint.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
f5efa812
PP
40/**
41@defgroup ctfirpacket CTF IR packet
42@ingroup ctfir
43@brief CTF IR packet.
44
6dd2bd0c
PP
45@code
46#include <babeltrace/ctf-ir/packet.h>
47@endcode
48
f5efa812
PP
49A CTF IR <strong><em>packet</em></strong> is a container of packet
50fields, that is, of the <strong>trace packet header</strong> and
51<strong>stream packet context</strong> fields.
52
53As a reminder, here's the structure of a CTF packet:
54
55@imgpacketstructure
56
57You can create a CTF IR packet \em from a
50842bdc 58\link ctfirstream CTF IR stream\endlink with bt_packet_create(). The
f5efa812
PP
59stream you use to create a packet object becomes its parent.
60
61When you set the trace packet header and stream packet context fields of
50842bdc
PP
62a packet with resp. bt_packet_set_header() and
63bt_packet_set_context(), their field type \em must be equivalent to
64the field types returned by resp. bt_trace_get_packet_header_type()
65and bt_stream_class_get_packet_context_type() for its parent trace
f5efa812
PP
66class and stream class.
67
68You can attach a packet object to a \link ctfirevent CTF IR
50842bdc 69event\endlink object with bt_event_set_packet().
f5efa812
PP
70
71As with any Babeltrace object, CTF IR packet objects have
72<a href="https://en.wikipedia.org/wiki/Reference_counting">reference
73counts</a>. See \ref refs to learn more about the reference counting
74management of Babeltrace objects.
75
76bt_notification_event_create() \em freezes its event parameter on
77success, which in turns freezes the event's associated packet object.
78This is the only way that a CTF IR packet object can be frozen.
79You cannot modify a frozen packet: it is considered immutable,
80except for \link refs reference counting\endlink.
81
82@sa ctfirstream
83@sa ctfirstreamclass
84@sa ctfirtraceclass
85
86@file
87@brief CTF IR packet type and functions.
88@sa ctfirpacket
89
90@addtogroup ctfirpacket
91@{
92*/
93
94/**
50842bdc 95@struct bt_packet
f5efa812
PP
96@brief A CTF IR packet.
97@sa ctfirpacket
98*/
50842bdc 99struct bt_packet;
312c056a
PP
100struct bt_packet_header_field;
101struct bt_packet_context_field;
50842bdc 102struct bt_stream;
f5efa812
PP
103
104/**
105@name Creation and parent access functions
106@{
107*/
f79cf0f0 108
f5efa812
PP
109/**
110@brief Creates a default CTF IR packet with \p stream as its parent
111 CTF IR stream.
112
113On success, the packet object's trace packet header and stream packet
114context fields are not set. You can set them with resp.
50842bdc 115bt_packet_set_header() and bt_packet_set_context().
f5efa812
PP
116
117@param[in] stream Parent CTF IR stream of the packet to create.
118@returns Created packet, or \c NULL on error.
119
120@prenotnull{stream}
121@postsuccessrefcountret1
122*/
312c056a 123extern struct bt_packet *bt_packet_create(struct bt_stream *stream);
f79cf0f0 124
312c056a 125extern struct bt_stream *bt_packet_borrow_stream(struct bt_packet *packet);
094ff7c0 126
f5efa812
PP
127/**
128@brief Returns the parent CTF IR stream of the CTF IR packet \p packet.
129
130This function returns a reference to the stream which was used to create
50842bdc 131the packet object in the first place with bt_packet_create().
f5efa812
PP
132
133@param[in] packet Packet of which to get the parent stream.
134@returns Parent stream of \p packet, or \c NULL on error.
135
136@prenotnull{packet}
c2f29fb9 137@postrefcountsame{packet}
f5efa812
PP
138@postsuccessrefcountretinc
139*/
094ff7c0
PP
140static inline
141struct bt_stream *bt_packet_get_stream(
142 struct bt_packet *packet)
143{
144 return bt_get(bt_packet_borrow_stream(packet));
145}
f79cf0f0 146
f5efa812
PP
147/** @} */
148
149/**
150@name Contained fields functions
151@{
152*/
153
094ff7c0
PP
154extern
155struct bt_field *bt_packet_borrow_header(struct bt_packet *packet);
156
312c056a
PP
157extern
158int bt_packet_move_header(struct bt_packet *packet,
159 struct bt_packet_header_field *header);
f5efa812 160
312c056a
PP
161extern
162struct bt_field *bt_packet_borrow_context(struct bt_packet *packet);
f5efa812 163
312c056a
PP
164extern
165int bt_packet_move_context(struct bt_packet *packet,
166 struct bt_packet_context_field *context);
f79cf0f0 167
f5efa812
PP
168/** @} */
169
a0491f93
PP
170/** @} */
171
f79cf0f0
PP
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* BABELTRACE_CTF_IR_PACKET_H */
This page took 0.04489 seconds and 4 git commands to generate.