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