lib: add internal object pool API and use it; adapt plugins/tests
[babeltrace.git] / include / babeltrace / ctf-ir / packet.h
... / ...
CommitLineData
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/* For bt_get() */
32#include <babeltrace/ref.h>
33
34#include <stdint.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/**
41@defgroup ctfirpacket CTF IR packet
42@ingroup ctfir
43@brief CTF IR packet.
44
45@code
46#include <babeltrace/ctf-ir/packet.h>
47@endcode
48
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
58\link ctfirstream CTF IR stream\endlink with bt_packet_create(). The
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
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
66class and stream class.
67
68You can attach a packet object to a \link ctfirevent CTF IR
69event\endlink object with bt_event_set_packet().
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/**
95@struct bt_packet
96@brief A CTF IR packet.
97@sa ctfirpacket
98*/
99struct bt_packet;
100struct bt_packet_header_field;
101struct bt_packet_context_field;
102struct bt_stream;
103
104/**
105@name Creation and parent access functions
106@{
107*/
108
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.
115bt_packet_set_header() and bt_packet_set_context().
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*/
123extern struct bt_packet *bt_packet_create(struct bt_stream *stream);
124
125extern struct bt_stream *bt_packet_borrow_stream(struct bt_packet *packet);
126
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
131the packet object in the first place with bt_packet_create().
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}
137@postrefcountsame{packet}
138@postsuccessrefcountretinc
139*/
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}
146
147/** @} */
148
149/**
150@name Contained fields functions
151@{
152*/
153
154extern
155struct bt_field *bt_packet_borrow_header(struct bt_packet *packet);
156
157extern
158int bt_packet_move_header(struct bt_packet *packet,
159 struct bt_packet_header_field *header);
160
161extern
162struct bt_field *bt_packet_borrow_context(struct bt_packet *packet);
163
164extern
165int bt_packet_move_context(struct bt_packet *packet,
166 struct bt_packet_context_field *context);
167
168/** @} */
169
170/** @} */
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* BABELTRACE_CTF_IR_PACKET_H */
This page took 0.024696 seconds and 4 git commands to generate.