/*
- * packet.c
- *
- * Babeltrace trace IR - Stream packet
- *
- * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
+ * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
#include <babeltrace/lib-logging-internal.h>
#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/trace-ir/fields-internal.h>
+#include <babeltrace/trace-ir/field-internal.h>
+#include <babeltrace/trace-ir/packet-const.h>
#include <babeltrace/trace-ir/packet.h>
#include <babeltrace/trace-ir/packet-internal.h>
#include <babeltrace/trace-ir/field-wrapper-internal.h>
#include <babeltrace/trace-ir/stream-class.h>
#include <babeltrace/trace-ir/stream.h>
#include <babeltrace/trace-ir/stream-internal.h>
-#include <babeltrace/trace-ir/clock-value-internal.h>
+#include <babeltrace/trace-ir/clock-snapshot-internal.h>
#include <babeltrace/trace-ir/trace-internal.h>
#include <babeltrace/object-internal.h>
-#include <babeltrace/ref.h>
#include <babeltrace/assert-internal.h>
#include <inttypes.h>
return packet->stream;
}
+const struct bt_stream *bt_packet_borrow_stream_const(
+ const struct bt_packet *packet)
+{
+ return bt_packet_borrow_stream((void *) packet);
+}
+
struct bt_field *bt_packet_borrow_header_field(struct bt_packet *packet)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
return packet->header_field ? packet->header_field->field : NULL;
}
+const struct bt_field *bt_packet_borrow_header_field_const(
+ const struct bt_packet *packet)
+{
+ return bt_packet_borrow_header_field((void *) packet);
+}
+
struct bt_field *bt_packet_borrow_context_field(struct bt_packet *packet)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
return packet->context_field ? packet->context_field->field : NULL;
}
+const struct bt_field *bt_packet_borrow_context_field_const(
+ const struct bt_packet *packet)
+{
+ return bt_packet_borrow_context_field((void *) packet);
+}
+
BT_HIDDEN
-void _bt_packet_set_is_frozen(struct bt_packet *packet, bool is_frozen)
+void _bt_packet_set_is_frozen(const struct bt_packet *packet, bool is_frozen)
{
if (!packet) {
return;
is_frozen);
}
- packet->frozen = is_frozen;
+ ((struct bt_packet *) packet)->frozen = is_frozen;
}
static inline
bt_field_reset(packet->context_field->field);
}
- if (packet->default_beginning_cv) {
- bt_clock_value_reset(packet->default_beginning_cv);
+ if (packet->default_beginning_cs) {
+ bt_clock_snapshot_reset(packet->default_beginning_cs);
}
- if (packet->default_end_cv) {
- bt_clock_value_reset(packet->default_end_cv);
+ if (packet->default_end_cs) {
+ bt_clock_snapshot_reset(packet->default_end_cs);
}
reset_counter_snapshots(packet);
static
void recycle_header_field(struct bt_field_wrapper *header_field,
- struct bt_trace *trace)
+ struct bt_trace_class *tc)
{
BT_ASSERT(header_field);
BT_LIB_LOGD("Recycling packet header field: "
- "addr=%p, %![trace-]+t, %![field-]+f", header_field,
- trace, header_field->field);
- bt_object_pool_recycle_object(&trace->packet_header_field_pool,
+ "addr=%p, %![tc-]+T, %![field-]+f", header_field,
+ tc, header_field->field);
+ bt_object_pool_recycle_object(&tc->packet_header_field_pool,
header_field);
}
* 2. Move the stream reference to our `stream`
* variable so that we can set the packet's stream member
* to NULL before recycling it. We CANNOT do this after
- * we put the stream reference because this bt_put()
+ * we put the stream reference because this bt_object_put_ref()
* could destroy the stream, also destroying its
* packet pool, thus also destroying our packet object (this
* would result in an invalid write access).
if (packet->stream) {
BT_LOGD_STR("Recycling packet's header field.");
recycle_header_field(packet->header_field,
- bt_stream_class_borrow_trace_inline(
+ bt_stream_class_borrow_trace_class_inline(
packet->stream->class));
} else {
bt_field_wrapper_destroy(packet->header_field);
}
+
+ packet->header_field = NULL;
}
if (packet->context_field) {
} else {
bt_field_wrapper_destroy(packet->context_field);
}
+
+ packet->context_field = NULL;
}
- if (packet->default_beginning_cv) {
- BT_LOGD_STR("Recycling beginning clock value.");
- bt_clock_value_recycle(packet->default_beginning_cv);
+ if (packet->default_beginning_cs) {
+ BT_LOGD_STR("Recycling beginning clock snapshot.");
+ bt_clock_snapshot_recycle(packet->default_beginning_cs);
+ packet->default_beginning_cs = NULL;
}
- if (packet->default_end_cv) {
- BT_LOGD_STR("Recycling end clock value.");
- bt_clock_value_recycle(packet->default_end_cv);
+ if (packet->default_end_cs) {
+ BT_LOGD_STR("Recycling end clock snapshot.");
+ bt_clock_snapshot_recycle(packet->default_end_cs);
+ packet->default_end_cs = NULL;
}
BT_LOGD_STR("Putting packet's stream.");
- bt_put(packet->stream);
+ BT_OBJECT_PUT_REF_AND_RESET(packet->stream);
g_free(packet);
}
struct bt_packet *bt_packet_new(struct bt_stream *stream)
{
struct bt_packet *packet = NULL;
- struct bt_trace *trace = NULL;
+ struct bt_trace_class *trace_class = NULL;
BT_ASSERT(stream);
BT_LIB_LOGD("Creating packet object: %![stream-]+s", stream);
bt_object_init_shared(&packet->base,
(bt_object_release_func) bt_packet_recycle);
- packet->stream = bt_get(stream);
- trace = bt_stream_class_borrow_trace_inline(stream->class);
- BT_ASSERT(trace);
+ packet->stream = stream;
+ bt_object_get_no_null_check(stream);
+ trace_class = bt_stream_class_borrow_trace_class_inline(stream->class);
+ BT_ASSERT(trace_class);
- if (trace->packet_header_fc) {
+ if (trace_class->packet_header_fc) {
BT_LOGD_STR("Creating initial packet header field.");
packet->header_field = bt_field_wrapper_create(
- &trace->packet_header_field_pool,
- trace->packet_header_fc);
+ &trace_class->packet_header_field_pool,
+ trace_class->packet_header_fc);
if (!packet->header_field) {
BT_LOGE_STR("Cannot create packet header field wrapper.");
goto error;
}
if (stream->class->default_clock_class) {
- if (stream->class->packets_have_default_beginning_cv) {
- packet->default_beginning_cv = bt_clock_value_create(
+ if (stream->class->packets_have_default_beginning_cs) {
+ packet->default_beginning_cs = bt_clock_snapshot_create(
stream->class->default_clock_class);
- if (!packet->default_beginning_cv) {
- /* bt_clock_value_create() logs errors */
+ if (!packet->default_beginning_cs) {
+ /* bt_clock_snapshot_create() logs errors */
goto error;
}
}
- if (stream->class->packets_have_default_end_cv) {
- packet->default_end_cv = bt_clock_value_create(
+ if (stream->class->packets_have_default_end_cs) {
+ packet->default_end_cs = bt_clock_snapshot_create(
stream->class->default_clock_class);
- if (!packet->default_end_cv) {
- /* bt_clock_value_create() logs errors */
+ if (!packet->default_end_cs) {
+ /* bt_clock_snapshot_create() logs errors */
goto error;
}
}
goto end;
error:
- BT_PUT(packet);
+ BT_OBJECT_PUT_REF_AND_RESET(packet);
end:
return packet;
}
end:
- return packet;
+ return (void *) packet;
}
int bt_packet_move_header_field(struct bt_packet *packet,
struct bt_packet_header_field *header_field)
{
- struct bt_trace *trace;
+ struct bt_trace_class *tc;
struct bt_field_wrapper *field_wrapper = (void *) header_field;
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
BT_ASSERT_PRE_NON_NULL(field_wrapper, "Header field");
BT_ASSERT_PRE_PACKET_HOT(packet);
- trace = bt_stream_class_borrow_trace_inline(packet->stream->class);
- BT_ASSERT_PRE(trace->packet_header_fc,
- "Trace has no packet header field classe: %!+t",
- trace);
+ tc = bt_stream_class_borrow_trace_class_inline(packet->stream->class);
+ BT_ASSERT_PRE(tc->packet_header_fc,
+ "Trace class has no packet header field class: %!+T", tc);
BT_ASSERT_PRE(field_wrapper->field->class ==
- trace->packet_header_fc,
+ tc->packet_header_fc,
"Unexpected packet header field's class: "
"%![fc-]+F, %![expected-fc-]+F", field_wrapper->field->class,
- trace->packet_header_fc);
+ tc->packet_header_fc);
/* Recycle current header field: always exists */
BT_ASSERT(packet->header_field);
- recycle_header_field(packet->header_field, trace);
+ recycle_header_field(packet->header_field, tc);
/* Move new field */
packet->header_field = field_wrapper;
BT_ASSERT_PRE_HOT(packet, "Packet", ": %!+a", packet);
stream_class = packet->stream->class;
BT_ASSERT_PRE(stream_class->packet_context_fc,
- "Stream class has no packet context field classe: %!+S",
+ "Stream class has no packet context field class: %!+S",
stream_class);
BT_ASSERT_PRE(field_wrapper->field->class ==
stream_class->packet_context_fc,
return 0;
}
-int bt_packet_set_default_beginning_clock_value(struct bt_packet *packet,
+void bt_packet_set_default_beginning_clock_snapshot(struct bt_packet *packet,
uint64_t value_cycles)
{
struct bt_stream_class *sc;
BT_ASSERT_PRE(sc->default_clock_class,
"Packet's stream class has no default clock class: "
"%![packet-]+a, %![sc-]+S", packet, sc);
- BT_ASSERT_PRE(sc->packets_have_default_beginning_cv,
+ BT_ASSERT_PRE(sc->packets_have_default_beginning_cs,
"Packet's stream class indicates that its packets have "
- "no default beginning clock value: %![packet-]+a, %![sc-]+S",
+ "no default beginning clock snapshot: %![packet-]+a, %![sc-]+S",
packet, sc);
- BT_ASSERT(packet->default_beginning_cv);
- bt_clock_value_set_value_inline(packet->default_beginning_cv, value_cycles);
- BT_LIB_LOGV("Set packet's default beginning clock value: "
- "%![packet-]+a, value=%" PRIu64, value_cycles);
- return 0;
+ BT_ASSERT(packet->default_beginning_cs);
+ bt_clock_snapshot_set_value_inline(packet->default_beginning_cs,
+ value_cycles);
+ BT_LIB_LOGV("Set packet's default beginning clock snapshot: "
+ "%![packet-]+a, value=%" PRIu64, packet, value_cycles);
}
-enum bt_clock_value_status bt_packet_borrow_default_beginning_clock_value(
- struct bt_packet *packet, struct bt_clock_value **clock_value)
+enum bt_clock_snapshot_status bt_packet_borrow_default_beginning_clock_snapshot(
+ const struct bt_packet *packet,
+ const struct bt_clock_snapshot **clock_snapshot)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
- BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)");
- *clock_value = packet->default_beginning_cv;
- return BT_CLOCK_VALUE_STATUS_KNOWN;
+ BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot (output)");
+ *clock_snapshot = packet->default_beginning_cs;
+ return BT_CLOCK_SNAPSHOT_STATUS_KNOWN;
}
-int bt_packet_set_default_end_clock_value(struct bt_packet *packet,
+void bt_packet_set_default_end_clock_snapshot(struct bt_packet *packet,
uint64_t value_cycles)
{
struct bt_stream_class *sc;
BT_ASSERT_PRE(sc->default_clock_class,
"Packet's stream class has no default clock class: "
"%![packet-]+a, %![sc-]+S", packet, sc);
- BT_ASSERT_PRE(sc->packets_have_default_end_cv,
+ BT_ASSERT_PRE(sc->packets_have_default_end_cs,
"Packet's stream class indicates that its packets have "
- "no default end clock value: %![packet-]+a, %![sc-]+S",
+ "no default end clock snapshot: %![packet-]+a, %![sc-]+S",
packet, sc);
- BT_ASSERT(packet->default_end_cv);
- bt_clock_value_set_value_inline(packet->default_end_cv, value_cycles);
- BT_LIB_LOGV("Set packet's default end clock value: "
- "%![packet-]+a, value=%" PRIu64, value_cycles);
- return 0;
+ BT_ASSERT(packet->default_end_cs);
+ bt_clock_snapshot_set_value_inline(packet->default_end_cs, value_cycles);
+ BT_LIB_LOGV("Set packet's default end clock snapshot: "
+ "%![packet-]+a, value=%" PRIu64, packet, value_cycles);
}
-enum bt_clock_value_status bt_packet_borrow_default_end_clock_value(
- struct bt_packet *packet, struct bt_clock_value **clock_value)
+enum bt_clock_snapshot_status bt_packet_borrow_default_end_clock_snapshot(
+ const struct bt_packet *packet,
+ const struct bt_clock_snapshot **clock_snapshot)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
- BT_ASSERT_PRE_NON_NULL(clock_value, "Clock value (output)");
- *clock_value = packet->default_end_cv;
- return BT_CLOCK_VALUE_STATUS_KNOWN;
+ BT_ASSERT_PRE_NON_NULL(clock_snapshot, "Clock snapshot (output)");
+ *clock_snapshot = packet->default_end_cs;
+ return BT_CLOCK_SNAPSHOT_STATUS_KNOWN;
}
enum bt_property_availability bt_packet_get_discarded_event_counter_snapshot(
- struct bt_packet *packet, uint64_t *value)
+ const struct bt_packet *packet, uint64_t *value)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
BT_ASSERT_PRE_NON_NULL(value, "Value (output)");
return packet->discarded_event_counter_snapshot.base.avail;
}
-int bt_packet_set_discarded_event_counter_snapshot(struct bt_packet *packet,
+void bt_packet_set_discarded_event_counter_snapshot(struct bt_packet *packet,
uint64_t value)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
"Packet's stream's discarded event counter is not enabled: "
"%![packet-]+a", packet);
bt_property_uint_set(&packet->discarded_event_counter_snapshot, value);
- return 0;
}
enum bt_property_availability bt_packet_get_packet_counter_snapshot(
- struct bt_packet *packet, uint64_t *value)
+ const struct bt_packet *packet, uint64_t *value)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
BT_ASSERT_PRE_NON_NULL(value, "Value (output)");
return packet->packet_counter_snapshot.base.avail;
}
-int bt_packet_set_packet_counter_snapshot(struct bt_packet *packet,
+void bt_packet_set_packet_counter_snapshot(struct bt_packet *packet,
uint64_t value)
{
BT_ASSERT_PRE_NON_NULL(packet, "Packet");
"Packet's stream's packet counter is not enabled: "
"%![packet-]+a", packet);
bt_property_uint_set(&packet->packet_counter_snapshot, value);
- return 0;
+}
+
+void bt_packet_get_ref(const struct bt_packet *packet)
+{
+ bt_object_get_ref(packet);
+}
+
+void bt_packet_put_ref(const struct bt_packet *packet)
+{
+ bt_object_put_ref(packet);
}