| 1 | #ifndef BABELTRACE_CTF_IR_PACKET_INTERNAL_H |
| 2 | #define BABELTRACE_CTF_IR_PACKET_INTERNAL_H |
| 3 | |
| 4 | /* |
| 5 | * Babeltrace - CTF IR: Stream packet internal |
| 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 | |
| 28 | #include <stdbool.h> |
| 29 | #include <babeltrace/assert-internal.h> |
| 30 | #include <babeltrace/ctf-ir/packet.h> |
| 31 | #include <babeltrace/ctf-ir/fields.h> |
| 32 | #include <babeltrace/ctf-ir/stream.h> |
| 33 | #include <babeltrace/ctf-ir/field-wrapper-internal.h> |
| 34 | #include <babeltrace/object-internal.h> |
| 35 | #include <babeltrace/babeltrace-internal.h> |
| 36 | #include <babeltrace/ctf-ir/clock-value-set-internal.h> |
| 37 | |
| 38 | struct bt_packet_prop_uint64 { |
| 39 | enum bt_packet_property_availability avail; |
| 40 | uint64_t value; |
| 41 | }; |
| 42 | |
| 43 | struct bt_packet { |
| 44 | struct bt_object base; |
| 45 | struct bt_field_wrapper *header; |
| 46 | struct bt_field_wrapper *context; |
| 47 | struct bt_stream *stream; |
| 48 | struct bt_clock_value_set begin_cv_set; |
| 49 | struct bt_clock_value_set end_cv_set; |
| 50 | struct bt_packet_prop_uint64 discarded_event_counter; |
| 51 | struct bt_packet_prop_uint64 seq_num; |
| 52 | struct bt_packet_prop_uint64 discarded_event_count; |
| 53 | struct bt_packet_prop_uint64 discarded_packet_count; |
| 54 | bool props_are_set; |
| 55 | |
| 56 | struct { |
| 57 | /* |
| 58 | * We keep this here to avoid keeping a reference on the |
| 59 | * previous packet object: those properties are |
| 60 | * snapshots of the previous packet's properties when |
| 61 | * calling bt_packet_create(). We know that the previous |
| 62 | * packet's properties do not change afterwards because |
| 63 | * we freeze the previous packet when bt_packet_create() |
| 64 | * is successful. |
| 65 | */ |
| 66 | enum bt_packet_previous_packet_availability avail; |
| 67 | struct bt_packet_prop_uint64 discarded_event_counter; |
| 68 | struct bt_packet_prop_uint64 seq_num; |
| 69 | struct { |
| 70 | enum bt_packet_property_availability avail; |
| 71 | |
| 72 | /* Owned by this (copy of previous packet's or NULL) */ |
| 73 | struct bt_clock_value *cv; |
| 74 | } default_end_cv; |
| 75 | } prev_packet_info; |
| 76 | |
| 77 | int frozen; |
| 78 | }; |
| 79 | |
| 80 | BT_HIDDEN |
| 81 | void _bt_packet_set_is_frozen(struct bt_packet *packet, bool is_frozen); |
| 82 | |
| 83 | #ifdef BT_DEV_MODE |
| 84 | # define bt_packet_set_is_frozen _bt_packet_set_is_frozen |
| 85 | #else |
| 86 | # define bt_packet_set_is_frozen(_packet, _is_frozen) |
| 87 | #endif /* BT_DEV_MODE */ |
| 88 | |
| 89 | BT_HIDDEN |
| 90 | struct bt_packet *bt_packet_new(struct bt_stream *stream); |
| 91 | |
| 92 | BT_HIDDEN |
| 93 | void bt_packet_recycle(struct bt_packet *packet); |
| 94 | |
| 95 | BT_HIDDEN |
| 96 | void bt_packet_destroy(struct bt_packet *packet); |
| 97 | |
| 98 | /* |
| 99 | * Sets a packet's properties using its current context fields and its |
| 100 | * previous packet's snapshotted properties (if any). The packet context |
| 101 | * field must not be modified until the packet is recycled. |
| 102 | * |
| 103 | * This function does NOT set the `props_are_set` flag (does not |
| 104 | * validate the properties): call bt_packet_validate_properties() to |
| 105 | * mark the properties as definitely cached. |
| 106 | */ |
| 107 | BT_HIDDEN |
| 108 | int bt_packet_set_properties(struct bt_packet *packet); |
| 109 | |
| 110 | static inline |
| 111 | void bt_packet_invalidate_properties(struct bt_packet *packet) |
| 112 | { |
| 113 | BT_ASSERT(packet); |
| 114 | packet->props_are_set = false; |
| 115 | } |
| 116 | |
| 117 | static inline |
| 118 | void bt_packet_validate_properties(struct bt_packet *packet) |
| 119 | { |
| 120 | BT_ASSERT(packet); |
| 121 | packet->props_are_set = true; |
| 122 | } |
| 123 | |
| 124 | #endif /* BABELTRACE_CTF_IR_PACKET_INTERNAL_H */ |