Commit | Line | Data |
---|---|---|
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 | ||
9a844f3c PP |
31 | /* For bt_get() */ |
32 | #include <babeltrace/ref.h> | |
33 | ||
f79cf0f0 PP |
34 | #include <stdint.h> |
35 | ||
36 | #ifdef __cplusplus | |
37 | extern "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 |
49 | A CTF IR <strong><em>packet</em></strong> is a container of packet |
50 | fields, that is, of the <strong>trace packet header</strong> and | |
51 | <strong>stream packet context</strong> fields. | |
52 | ||
53 | As a reminder, here's the structure of a CTF packet: | |
54 | ||
55 | @imgpacketstructure | |
56 | ||
57 | You can create a CTF IR packet \em from a | |
50842bdc | 58 | \link ctfirstream CTF IR stream\endlink with bt_packet_create(). The |
f5efa812 PP |
59 | stream you use to create a packet object becomes its parent. |
60 | ||
61 | When you set the trace packet header and stream packet context fields of | |
50842bdc PP |
62 | a packet with resp. bt_packet_set_header() and |
63 | bt_packet_set_context(), their field type \em must be equivalent to | |
64 | the field types returned by resp. bt_trace_get_packet_header_type() | |
65 | and bt_stream_class_get_packet_context_type() for its parent trace | |
f5efa812 PP |
66 | class and stream class. |
67 | ||
68 | You can attach a packet object to a \link ctfirevent CTF IR | |
50842bdc | 69 | event\endlink object with bt_event_set_packet(). |
f5efa812 PP |
70 | |
71 | As with any Babeltrace object, CTF IR packet objects have | |
72 | <a href="https://en.wikipedia.org/wiki/Reference_counting">reference | |
73 | counts</a>. See \ref refs to learn more about the reference counting | |
74 | management of Babeltrace objects. | |
75 | ||
76 | bt_notification_event_create() \em freezes its event parameter on | |
77 | success, which in turns freezes the event's associated packet object. | |
78 | This is the only way that a CTF IR packet object can be frozen. | |
79 | You cannot modify a frozen packet: it is considered immutable, | |
80 | except 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 | 99 | struct bt_packet; |
a7252d9c PP |
100 | struct bt_packet_header_field; |
101 | struct bt_packet_context_field; | |
50842bdc | 102 | struct 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 | ||
113 | On success, the packet object's trace packet header and stream packet | |
114 | context fields are not set. You can set them with resp. | |
50842bdc | 115 | bt_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 | */ | |
a7252d9c | 123 | extern struct bt_packet *bt_packet_create(struct bt_stream *stream); |
f79cf0f0 | 124 | |
a7252d9c | 125 | extern struct bt_stream *bt_packet_borrow_stream(struct bt_packet *packet); |
9a844f3c | 126 | |
f5efa812 PP |
127 | /** |
128 | @brief Returns the parent CTF IR stream of the CTF IR packet \p packet. | |
129 | ||
130 | This function returns a reference to the stream which was used to create | |
50842bdc | 131 | the 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 | */ | |
9a844f3c PP |
140 | static inline |
141 | struct 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 | ||
9a844f3c PP |
154 | extern |
155 | struct bt_field *bt_packet_borrow_header(struct bt_packet *packet); | |
156 | ||
a7252d9c PP |
157 | extern |
158 | int bt_packet_move_header(struct bt_packet *packet, | |
159 | struct bt_packet_header_field *header); | |
f5efa812 | 160 | |
a7252d9c PP |
161 | extern |
162 | struct bt_field *bt_packet_borrow_context(struct bt_packet *packet); | |
f5efa812 | 163 | |
a7252d9c PP |
164 | extern |
165 | int 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 */ |