* SOFTWARE.
*/
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/clock-internal.h>
+#define BT_LOG_TAG "STREAM-CLASS"
+#include <babeltrace/lib-logging-internal.h>
+
+#include <babeltrace/assert-pre-internal.h>
#include <babeltrace/ctf-ir/clock-class-internal.h>
-#include <babeltrace/ctf-writer/event.h>
#include <babeltrace/ctf-ir/event-class-internal.h>
-#include <babeltrace/ctf-ir/event-internal.h>
#include <babeltrace/ctf-ir/field-types-internal.h>
#include <babeltrace/ctf-ir/fields-internal.h>
-#include <babeltrace/ctf-writer/stream.h>
#include <babeltrace/ctf-ir/stream-class-internal.h>
-#include <babeltrace/ctf-ir/validation-internal.h>
-#include <babeltrace/ctf-ir/visitor-internal.h>
-#include <babeltrace/ctf-writer/functor-internal.h>
-#include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/utils-internal.h>
+#include <babeltrace/ctf-ir/field-wrapper-internal.h>
+#include <babeltrace/ctf-ir/resolve-field-path-internal.h>
#include <babeltrace/ref.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/align-internal.h>
#include <babeltrace/endian-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/property-internal.h>
#include <inttypes.h>
#include <stdint.h>
+#include <stdbool.h>
-static
-void bt_ctf_stream_class_destroy(struct bt_object *obj);
-static
-int init_event_header(struct bt_ctf_stream_class *stream_class);
-static
-int init_packet_context(struct bt_ctf_stream_class *stream_class);
+#define BT_ASSERT_PRE_STREAM_CLASS_HOT(_sc) \
+ BT_ASSERT_PRE_HOT((_sc), "Stream class", ": %!+S", (_sc))
-struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name)
+static
+void destroy_stream_class(struct bt_object *obj)
{
- struct bt_ctf_stream_class *stream_class =
- bt_ctf_stream_class_create_empty(name);
- int ret;
+ struct bt_stream_class *stream_class = (void *) obj;
- if (!stream_class) {
- goto error;
- }
+ BT_LIB_LOGD("Destroying stream class: %!+S", stream_class);
+ BT_LOGD_STR("Putting default clock class.");
+ bt_put(stream_class->default_clock_class);
- ret = init_event_header(stream_class);
- if (ret) {
- goto error;
+ if (stream_class->event_classes) {
+ BT_LOGD_STR("Destroying event classes.");
+ g_ptr_array_free(stream_class->event_classes, TRUE);
}
- ret = init_packet_context(stream_class);
- if (ret) {
- goto error;
+ if (stream_class->name.str) {
+ g_string_free(stream_class->name.str, TRUE);
}
- return stream_class;
+ BT_LOGD_STR("Putting event header field type.");
+ bt_put(stream_class->event_header_ft);
+ BT_LOGD_STR("Putting packet context field type.");
+ bt_put(stream_class->packet_context_ft);
+ BT_LOGD_STR("Putting event common context field type.");
+ bt_put(stream_class->event_common_context_ft);
+ bt_object_pool_finalize(&stream_class->event_header_field_pool);
+ bt_object_pool_finalize(&stream_class->packet_context_field_pool);
+ g_free(stream_class);
+}
-error:
- BT_PUT(stream_class);
- return stream_class;
+static
+void free_field_wrapper(struct bt_field_wrapper *field_wrapper,
+ struct bt_stream_class *stream_class)
+{
+ bt_field_wrapper_destroy((void *) field_wrapper);
}
-struct bt_ctf_stream_class *bt_ctf_stream_class_create_empty(const char *name)
+BT_ASSERT_PRE_FUNC
+static
+bool stream_class_id_is_unique(struct bt_trace *trace, uint64_t id)
{
- struct bt_ctf_stream_class *stream_class = NULL;
+ uint64_t i;
+ bool is_unique = true;
- if (name && bt_ctf_validate_identifier(name)) {
- goto error;
+ for (i = 0; i < trace->stream_classes->len; i++) {
+ struct bt_stream_class *sc =
+ trace->stream_classes->pdata[i];
+
+ if (sc->id == id) {
+ is_unique = false;
+ goto end;
+ }
}
- stream_class = g_new0(struct bt_ctf_stream_class, 1);
+end:
+ return is_unique;
+}
+
+static
+struct bt_stream_class *create_stream_class_with_id(struct bt_trace *trace,
+ uint64_t id)
+{
+ struct bt_stream_class *stream_class = NULL;
+ int ret;
+
+ BT_ASSERT(trace);
+ BT_ASSERT_PRE(stream_class_id_is_unique(trace, id),
+ "Duplicate stream class ID: %![trace-]+t, id=%" PRIu64,
+ trace, id);
+ BT_LIB_LOGD("Creating stream class object: %![trace-]+t, id=%" PRIu64,
+ trace, id);
+ stream_class = g_new0(struct bt_stream_class, 1);
if (!stream_class) {
+ BT_LOGE_STR("Failed to allocate one stream class.");
goto error;
}
- stream_class->name = g_string_new(name);
- stream_class->event_classes = g_ptr_array_new_with_free_func(
- (GDestroyNotify) bt_object_release);
- if (!stream_class->event_classes) {
- goto error;
- }
+ bt_object_init_shared_with_parent(&stream_class->base,
+ destroy_stream_class);
- stream_class->event_classes_ht = g_hash_table_new_full(g_int64_hash,
- g_int64_equal, g_free, NULL);
+ stream_class->name.str = g_string_new(NULL);
+ if (!stream_class->name.str) {
+ BT_LOGE_STR("Failed to allocate a GString.");
+ ret = -1;
+ goto end;
+ }
- stream_class->packet_context_type = bt_ctf_field_type_structure_create();
- if (!stream_class->packet_context_type) {
+ stream_class->id = id;
+ stream_class->assigns_automatic_event_class_id = true;
+ stream_class->assigns_automatic_stream_id = true;
+ stream_class->event_classes = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_object_try_spec_release);
+ if (!stream_class->event_classes) {
+ BT_LOGE_STR("Failed to allocate a GPtrArray.");
goto error;
}
- stream_class->event_header_type = bt_ctf_field_type_structure_create();
- if (!stream_class->event_header_type) {
+ ret = bt_object_pool_initialize(&stream_class->event_header_field_pool,
+ (bt_object_pool_new_object_func) bt_field_wrapper_new,
+ (bt_object_pool_destroy_object_func) free_field_wrapper,
+ stream_class);
+ if (ret) {
+ BT_LOGE("Failed to initialize event header field pool: ret=%d",
+ ret);
goto error;
}
- stream_class->event_context_type = bt_ctf_field_type_structure_create();
- if (!stream_class->event_context_type) {
+ ret = bt_object_pool_initialize(&stream_class->packet_context_field_pool,
+ (bt_object_pool_new_object_func) bt_field_wrapper_new,
+ (bt_object_pool_destroy_object_func) free_field_wrapper,
+ stream_class);
+ if (ret) {
+ BT_LOGE("Failed to initialize packet context field pool: ret=%d",
+ ret);
goto error;
}
- bt_object_init(stream_class, bt_ctf_stream_class_destroy);
- return stream_class;
+ bt_object_set_parent(&stream_class->base, &trace->base);
+ g_ptr_array_add(trace->stream_classes, stream_class);
+ bt_trace_freeze(trace);
+ BT_LIB_LOGD("Created stream class object: %!+S", stream_class);
+ goto end;
error:
BT_PUT(stream_class);
- return stream_class;
-}
-
-struct bt_ctf_trace *bt_ctf_stream_class_get_trace(
- struct bt_ctf_stream_class *stream_class)
-{
- return stream_class ?
- bt_get(bt_ctf_stream_class_borrow_trace(stream_class)) :
- NULL;
-}
-
-const char *bt_ctf_stream_class_get_name(
- struct bt_ctf_stream_class *stream_class)
-{
- const char *name = NULL;
- if (!stream_class) {
- goto end;
- }
-
- name = stream_class->name->str;
end:
- return name;
+ return stream_class;
}
-int bt_ctf_stream_class_set_name(struct bt_ctf_stream_class *stream_class,
- const char *name)
+struct bt_stream_class *bt_stream_class_create(struct bt_trace *trace)
{
- int ret = 0;
-
- if (!stream_class || stream_class->frozen) {
- ret = -1;
- goto end;
- }
-
- g_string_assign(stream_class->name, name);
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(trace->assigns_automatic_stream_class_id,
+ "Trace does not automatically assigns stream class IDs: "
+ "%![sc-]+t", trace);
+ return create_stream_class_with_id(trace,
+ (uint64_t) trace->stream_classes->len);
}
-struct bt_ctf_clock *bt_ctf_stream_class_get_clock(
- struct bt_ctf_stream_class *stream_class)
+struct bt_stream_class *bt_stream_class_create_with_id(
+ struct bt_trace *trace, uint64_t id)
{
- struct bt_ctf_clock *clock = NULL;
-
- if (!stream_class || !stream_class->clock) {
- goto end;
- }
-
- clock = bt_get(stream_class->clock);
-end:
- return clock;
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
+ BT_ASSERT_PRE(!trace->assigns_automatic_stream_class_id,
+ "Trace automatically assigns stream class IDs: "
+ "%![sc-]+t", trace);
+ return create_stream_class_with_id(trace, id);
}
-int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class,
- struct bt_ctf_clock *clock)
+struct bt_trace *bt_stream_class_borrow_trace(struct bt_stream_class *stream_class)
{
- int ret = 0;
- struct bt_ctf_field_type *timestamp_field = NULL;
-
- if (!stream_class || !clock || stream_class->frozen) {
- ret = -1;
- goto end;
- }
-
- /*
- * Look for a "timestamp" integer field type in the stream
- * class's event header field type and map the stream class's
- * clock's class to that field type if there's no current
- * mapping.
- */
- timestamp_field = bt_ctf_field_type_structure_get_field_type_by_name(
- stream_class->event_header_type, "timestamp");
- if (timestamp_field) {
- struct bt_ctf_clock_class *mapped_clock_class =
- bt_ctf_field_type_integer_get_mapped_clock_class(
- timestamp_field);
-
- if (!mapped_clock_class) {
- ret = bt_ctf_field_type_integer_set_mapped_clock_class(
- timestamp_field, clock->clock_class);
- if (ret) {
- goto end;
- }
- }
-
- BT_PUT(mapped_clock_class);
- }
-
- /* Replace the current clock of this stream class. */
- bt_put(stream_class->clock);
- stream_class->clock = bt_get(clock);
-
-end:
- bt_put(timestamp_field);
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return bt_stream_class_borrow_trace_inline(stream_class);
}
-int64_t bt_ctf_stream_class_get_id(struct bt_ctf_stream_class *stream_class)
+const char *bt_stream_class_get_name(struct bt_stream_class *stream_class)
{
- int64_t ret;
-
- if (!stream_class || !stream_class->id_set) {
- ret = (int64_t) -1;
- goto end;
- }
-
- ret = stream_class->id;
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->name.value;
}
-BT_HIDDEN
-int _bt_ctf_stream_class_set_id(
- struct bt_ctf_stream_class *stream_class, int64_t id)
+int bt_stream_class_set_name(struct bt_stream_class *stream_class,
+ const char *name)
{
- stream_class->id = id;
- stream_class->id_set = 1;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_NON_NULL(name, "Name");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ g_string_assign(stream_class->name.str, name);
+ stream_class->name.value = stream_class->name.str->str;
+ BT_LIB_LOGV("Set stream class's name: %!+S", stream_class);
return 0;
}
-struct event_class_set_stream_class_id_data {
- int64_t stream_class_id;
- int ret;
-};
-
-static
-void event_class_set_stream_id(gpointer event_class, gpointer data)
+uint64_t bt_stream_class_get_id(struct bt_stream_class *stream_class)
{
- struct event_class_set_stream_class_id_data *typed_data = data;
-
- typed_data->ret |= bt_ctf_event_class_set_stream_id(event_class,
- typed_data->stream_class_id);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->id;
}
-BT_HIDDEN
-int bt_ctf_stream_class_set_id_no_check(
- struct bt_ctf_stream_class *stream_class, int64_t id)
-{
- int ret = 0;
- struct event_class_set_stream_class_id_data data =
- { .stream_class_id = id, .ret = 0 };
-
- /*
- * Make sure all event classes have their "stream_id" attribute
- * set to this value.
- */
- g_ptr_array_foreach(stream_class->event_classes,
- event_class_set_stream_id, &data);
- ret = data.ret;
- if (ret) {
- goto end;
- }
-
- ret = _bt_ctf_stream_class_set_id(stream_class, id);
- if (ret) {
- goto end;
- }
-end:
- return ret;
+uint64_t bt_stream_class_get_event_class_count(
+ struct bt_stream_class *stream_class)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (uint64_t) stream_class->event_classes->len;
}
-int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class,
- uint64_t id_param)
+struct bt_event_class *bt_stream_class_borrow_event_class_by_index(
+ struct bt_stream_class *stream_class, uint64_t index)
{
- int ret = 0;
- int64_t id = (int64_t) id_param;
-
- if (!stream_class || stream_class->frozen || id < 0) {
- ret = -1;
- goto end;
- }
-
- ret = bt_ctf_stream_class_set_id_no_check(stream_class, id);
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_VALID_INDEX(index, stream_class->event_classes->len);
+ return g_ptr_array_index(stream_class->event_classes, index);
}
-static
-void event_class_exists(gpointer element, gpointer query)
+struct bt_event_class *bt_stream_class_borrow_event_class_by_id(
+ struct bt_stream_class *trace, uint64_t id)
{
- struct bt_ctf_event_class *event_class_a = element;
- struct search_query *search_query = query;
- struct bt_ctf_event_class *event_class_b = search_query->value;
- int64_t id_a, id_b;
-
- if (search_query->value == element) {
- search_query->found = 1;
- goto end;
- }
-
- /*
- * Two event classes cannot share the same ID in a given
- * stream class.
- */
- id_a = bt_ctf_event_class_get_id(event_class_a);
- id_b = bt_ctf_event_class_get_id(event_class_b);
-
- if (id_a < 0 || id_b < 0) {
- /* at least one ID is not set: will be automatically set later */
- goto end;
- }
-
- if (id_a == id_b) {
- search_query->found = 1;
- goto end;
- }
-
-end:
- return;
-}
-
-int bt_ctf_stream_class_add_event_class(
- struct bt_ctf_stream_class *stream_class,
- struct bt_ctf_event_class *event_class)
-{
- int ret = 0;
- int64_t *event_id = NULL;
- struct bt_ctf_trace *trace = NULL;
- struct bt_ctf_stream_class *old_stream_class = NULL;
- struct bt_ctf_validation_output validation_output = { 0 };
- struct bt_ctf_field_type *packet_header_type = NULL;
- struct bt_ctf_field_type *packet_context_type = NULL;
- struct bt_ctf_field_type *event_header_type = NULL;
- struct bt_ctf_field_type *stream_event_ctx_type = NULL;
- struct bt_ctf_field_type *event_context_type = NULL;
- struct bt_ctf_field_type *event_payload_type = NULL;
- const enum bt_ctf_validation_flag validation_flags =
- BT_CTF_VALIDATION_FLAG_EVENT;
-
- if (!stream_class || !event_class) {
- ret = -1;
- goto end;
- }
-
- trace = bt_ctf_stream_class_get_trace(stream_class);
- if (trace && trace->is_static) {
- ret = -1;
- goto end;
- }
-
- event_id = g_new(int64_t, 1);
- if (!event_id) {
- ret = -1;
- goto end;
- }
-
- /* Check for duplicate event classes */
- struct search_query query = { .value = event_class, .found = 0 };
- g_ptr_array_foreach(stream_class->event_classes, event_class_exists,
- &query);
- if (query.found) {
- ret = -1;
- goto end;
- }
+ struct bt_event_class *event_class = NULL;
+ uint64_t i;
- old_stream_class = bt_ctf_event_class_get_stream_class(event_class);
- if (old_stream_class) {
- /* Event class is already associated to a stream class. */
- ret = -1;
- goto end;
- }
+ BT_ASSERT_PRE_NON_NULL(trace, "Trace");
- if (trace) {
- /*
- * If the stream class is associated with a trace, then
- * both those objects are frozen. Also, this event class
- * is about to be frozen.
- *
- * Therefore the event class must be validated here.
- * The trace and stream class should be valid at this
- * point.
- */
- assert(trace->valid);
- assert(stream_class->valid);
- packet_header_type =
- bt_ctf_trace_get_packet_header_type(trace);
- packet_context_type =
- bt_ctf_stream_class_get_packet_context_type(
- stream_class);
- event_header_type =
- bt_ctf_stream_class_get_event_header_type(stream_class);
- stream_event_ctx_type =
- bt_ctf_stream_class_get_event_context_type(
- stream_class);
- event_context_type =
- bt_ctf_event_class_get_context_type(event_class);
- event_payload_type =
- bt_ctf_event_class_get_payload_type(event_class);
- ret = bt_ctf_validate_class_types(
- trace->environment, packet_header_type,
- packet_context_type, event_header_type,
- stream_event_ctx_type, event_context_type,
- event_payload_type, trace->valid,
- stream_class->valid, event_class->valid,
- &validation_output, validation_flags);
- BT_PUT(packet_header_type);
- BT_PUT(packet_context_type);
- BT_PUT(event_header_type);
- BT_PUT(stream_event_ctx_type);
- BT_PUT(event_context_type);
- BT_PUT(event_payload_type);
-
- if (ret) {
- /*
- * This means something went wrong during the
- * validation process, not that the objects are
- * invalid.
- */
- goto end;
- }
+ for (i = 0; i < trace->event_classes->len; i++) {
+ struct bt_event_class *event_class_candidate =
+ g_ptr_array_index(trace->event_classes, i);
- if ((validation_output.valid_flags & validation_flags) !=
- validation_flags) {
- /* Invalid event class */
- ret = -1;
+ if (event_class_candidate->id == id) {
+ event_class = event_class_candidate;
goto end;
}
}
- /* Only set an event ID if none was explicitly set before */
- *event_id = bt_ctf_event_class_get_id(event_class);
- if (*event_id < 0) {
- if (bt_ctf_event_class_set_id(event_class,
- stream_class->next_event_id++)) {
- ret = -1;
- goto end;
- }
- *event_id = stream_class->next_event_id;
- }
-
- ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id);
- if (ret) {
- goto end;
- }
-
- bt_object_set_parent(event_class, stream_class);
-
- if (trace) {
- /*
- * At this point we know that the function will be
- * successful. Therefore we can replace the event
- * class's field types with what's in the validation
- * output structure and mark this event class as valid.
- */
- bt_ctf_validation_replace_types(NULL, NULL, event_class,
- &validation_output, validation_flags);
- event_class->valid = 1;
-
- /*
- * Put what was not moved in
- * bt_ctf_validation_replace_types().
- */
- bt_ctf_validation_output_put_types(&validation_output);
- }
-
- /* Add to the event classes of the stream class */
- g_ptr_array_add(stream_class->event_classes, event_class);
- g_hash_table_insert(stream_class->event_classes_ht, event_id,
- event_class);
- event_id = NULL;
-
- /* Freeze the event class */
- bt_ctf_event_class_freeze(event_class);
-
- /* Notifiy listeners of the trace's schema modification. */
- if (trace) {
- struct bt_ctf_object obj = { .object = event_class,
- .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS };
-
- (void) bt_ctf_trace_object_modification(&obj, trace);
- }
end:
- BT_PUT(trace);
- BT_PUT(old_stream_class);
- bt_ctf_validation_output_put_types(&validation_output);
- assert(!packet_header_type);
- assert(!packet_context_type);
- assert(!event_header_type);
- assert(!stream_event_ctx_type);
- assert(!event_context_type);
- assert(!event_payload_type);
- g_free(event_id);
-
- return ret;
+ return event_class;
}
-int64_t bt_ctf_stream_class_get_event_class_count(
- struct bt_ctf_stream_class *stream_class)
+struct bt_field_type *bt_stream_class_borrow_packet_context_field_type(
+ struct bt_stream_class *stream_class)
{
- int64_t ret;
-
- if (!stream_class) {
- ret = (int64_t) -1;
- goto end;
- }
-
- ret = (int64_t) stream_class->event_classes->len;
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->packet_context_ft;
}
-struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_index(
- struct bt_ctf_stream_class *stream_class, uint64_t index)
+int bt_stream_class_set_packet_context_field_type(
+ struct bt_stream_class *stream_class,
+ struct bt_field_type *field_type)
{
- struct bt_ctf_event_class *event_class = NULL;
-
- if (!stream_class || index >= stream_class->event_classes->len) {
+ int ret;
+ struct bt_resolve_field_path_context resolve_ctx = {
+ .packet_header = NULL,
+ .packet_context = field_type,
+ .event_header = NULL,
+ .event_common_context = NULL,
+ .event_specific_context = NULL,
+ .event_payload = NULL,
+ };
+
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_NON_NULL(field_type, "Field type");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(bt_field_type_get_type_id(field_type) ==
+ BT_FIELD_TYPE_ID_STRUCTURE,
+ "Packet context field type is not a structure field type: %!+F",
+ field_type);
+ resolve_ctx.packet_header =
+ bt_stream_class_borrow_trace_inline(stream_class)->packet_header_ft;
+ ret = bt_resolve_field_paths(field_type, &resolve_ctx);
+ if (ret) {
goto end;
}
- event_class = g_ptr_array_index(stream_class->event_classes, index);
- bt_get(event_class);
-end:
- return event_class;
-}
-
-struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id(
- struct bt_ctf_stream_class *stream_class, uint64_t id)
-{
- int64_t id_key = (int64_t) id;
- struct bt_ctf_event_class *event_class = NULL;
-
- if (!stream_class || id_key < 0) {
- goto end;
- }
+ bt_field_type_make_part_of_trace(field_type);
+ bt_put(stream_class->packet_context_ft);
+ stream_class->packet_context_ft = bt_get(field_type);
+ bt_field_type_freeze(field_type);
+ BT_LIB_LOGV("Set stream class's packet context field type: %!+S",
+ stream_class);
- event_class = g_hash_table_lookup(stream_class->event_classes_ht,
- &id_key);
- bt_get(event_class);
end:
- return event_class;
+ return ret;
}
-struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(
- struct bt_ctf_stream_class *stream_class)
+struct bt_field_type *bt_stream_class_borrow_event_header_field_type(
+ struct bt_stream_class *stream_class)
{
- struct bt_ctf_field_type *ret = NULL;
-
- if (!stream_class) {
- goto end;
- }
-
- bt_get(stream_class->packet_context_type);
- ret = stream_class->packet_context_type;
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->event_header_ft;
}
-int bt_ctf_stream_class_set_packet_context_type(
- struct bt_ctf_stream_class *stream_class,
- struct bt_ctf_field_type *packet_context_type)
+int bt_stream_class_set_event_header_field_type(
+ struct bt_stream_class *stream_class,
+ struct bt_field_type *field_type)
{
- int ret = 0;
-
- if (!stream_class || stream_class->frozen) {
- ret = -1;
+ int ret;
+ struct bt_resolve_field_path_context resolve_ctx = {
+ .packet_header = NULL,
+ .packet_context = NULL,
+ .event_header = field_type,
+ .event_common_context = NULL,
+ .event_specific_context = NULL,
+ .event_payload = NULL,
+ };
+
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_NON_NULL(field_type, "Field type");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(bt_field_type_get_type_id(field_type) ==
+ BT_FIELD_TYPE_ID_STRUCTURE,
+ "Event header field type is not a structure field type: %!+F",
+ field_type);
+ resolve_ctx.packet_header =
+ bt_stream_class_borrow_trace_inline(stream_class)->packet_header_ft;
+ resolve_ctx.packet_context = stream_class->packet_context_ft;
+ ret = bt_resolve_field_paths(field_type, &resolve_ctx);
+ if (ret) {
goto end;
}
- if (packet_context_type &&
- bt_ctf_field_type_get_type_id(packet_context_type) !=
- BT_CTF_FIELD_TYPE_ID_STRUCT) {
- /* A packet context must be a structure. */
- ret = -1;
- goto end;
- }
+ bt_field_type_make_part_of_trace(field_type);
+ bt_put(stream_class->event_header_ft);
+ stream_class->event_header_ft = bt_get(field_type);
+ bt_field_type_freeze(field_type);
+ BT_LIB_LOGV("Set stream class's event header field type: %!+S",
+ stream_class);
- bt_put(stream_class->packet_context_type);
- bt_get(packet_context_type);
- stream_class->packet_context_type = packet_context_type;
end:
return ret;
}
-struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type(
- struct bt_ctf_stream_class *stream_class)
+struct bt_field_type *bt_stream_class_borrow_event_common_context_field_type(
+ struct bt_stream_class *stream_class)
{
- struct bt_ctf_field_type *ret = NULL;
-
- if (!stream_class || !stream_class->event_header_type) {
- goto end;
- }
-
- bt_get(stream_class->event_header_type);
- ret = stream_class->event_header_type;
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->event_common_context_ft;
}
-int bt_ctf_stream_class_set_event_header_type(
- struct bt_ctf_stream_class *stream_class,
- struct bt_ctf_field_type *event_header_type)
+int bt_stream_class_set_event_common_context_field_type(
+ struct bt_stream_class *stream_class,
+ struct bt_field_type *field_type)
{
- int ret = 0;
-
- if (!stream_class || stream_class->frozen) {
- ret = -1;
+ int ret;
+ struct bt_resolve_field_path_context resolve_ctx = {
+ .packet_header = NULL,
+ .packet_context = NULL,
+ .event_header = NULL,
+ .event_common_context = field_type,
+ .event_specific_context = NULL,
+ .event_payload = NULL,
+ };
+
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_NON_NULL(field_type, "Field type");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(bt_field_type_get_type_id(field_type) ==
+ BT_FIELD_TYPE_ID_STRUCTURE,
+ "Event common context field type is not a structure field type: %!+F",
+ field_type);
+ resolve_ctx.packet_header =
+ bt_stream_class_borrow_trace_inline(stream_class)->packet_header_ft;
+ resolve_ctx.packet_context = stream_class->packet_context_ft;
+ resolve_ctx.event_header = stream_class->event_header_ft;
+ ret = bt_resolve_field_paths(field_type, &resolve_ctx);
+ if (ret) {
goto end;
}
- if (event_header_type &&
- bt_ctf_field_type_get_type_id(event_header_type) !=
- BT_CTF_FIELD_TYPE_ID_STRUCT) {
- /* An event header must be a structure. */
- ret = -1;
- goto end;
- }
+ bt_field_type_make_part_of_trace(field_type);
+ bt_put(stream_class->event_common_context_ft);
+ stream_class->event_common_context_ft = bt_get(field_type);
+ bt_field_type_freeze(field_type);
+ BT_LIB_LOGV("Set stream class's event common context field type: %!+S",
+ stream_class);
- bt_put(stream_class->event_header_type);
- stream_class->event_header_type = bt_get(event_header_type);
end:
return ret;
}
-struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type(
- struct bt_ctf_stream_class *stream_class)
-{
- struct bt_ctf_field_type *ret = NULL;
-
- if (!stream_class || !stream_class->event_context_type) {
- goto end;
- }
-
- bt_get(stream_class->event_context_type);
- ret = stream_class->event_context_type;
-end:
- return ret;
+BT_HIDDEN
+void _bt_stream_class_freeze(struct bt_stream_class *stream_class)
+{
+ /* The field types and default clock class are already frozen */
+ BT_ASSERT(stream_class);
+ BT_LIB_LOGD("Freezing stream class: %!+S", stream_class);
+ stream_class->frozen = true;
+}
+
+int bt_stream_class_set_default_clock_class(
+ struct bt_stream_class *stream_class,
+ struct bt_clock_class *clock_class)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ bt_put(stream_class->default_clock_class);
+ stream_class->default_clock_class = bt_get(clock_class);
+ bt_clock_class_freeze(clock_class);
+ BT_LIB_LOGV("Set stream class's default clock class: %!+S",
+ stream_class);
+ return 0;
}
-int bt_ctf_stream_class_set_event_context_type(
- struct bt_ctf_stream_class *stream_class,
- struct bt_ctf_field_type *event_context_type)
+struct bt_clock_class *bt_stream_class_borrow_default_clock_class(
+ struct bt_stream_class *stream_class)
{
- int ret = 0;
-
- if (!stream_class || stream_class->frozen) {
- ret = -1;
- goto end;
- }
-
- if (event_context_type &&
- bt_ctf_field_type_get_type_id(event_context_type) !=
- BT_CTF_FIELD_TYPE_ID_STRUCT) {
- /* A packet context must be a structure. */
- ret = -1;
- goto end;
- }
-
- bt_put(stream_class->event_context_type);
- stream_class->event_context_type = bt_get(event_context_type);
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->default_clock_class;
}
-void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class)
+bt_bool bt_stream_class_assigns_automatic_event_class_id(
+ struct bt_stream_class *stream_class)
{
- bt_get(stream_class);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->assigns_automatic_event_class_id;
}
-void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class)
+int bt_stream_class_set_assigns_automatic_event_class_id(
+ struct bt_stream_class *stream_class, bt_bool value)
{
- bt_put(stream_class);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ stream_class->assigns_automatic_event_class_id = (bool) value;
+ BT_LIB_LOGV("Set stream class's automatic event class ID "
+ "assignment property: %!+S", stream_class);
+ return 0;
}
-static
-int64_t get_event_class_count(void *element)
+bt_bool bt_stream_class_assigns_automatic_stream_id(
+ struct bt_stream_class *stream_class)
{
- return bt_ctf_stream_class_get_event_class_count(
- (struct bt_ctf_stream_class *) element);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->assigns_automatic_stream_id;
}
-static
-void *get_event_class(void *element, int i)
+int bt_stream_class_set_assigns_automatic_stream_id(
+ struct bt_stream_class *stream_class, bt_bool value)
{
- return bt_ctf_stream_class_get_event_class_by_index(
- (struct bt_ctf_stream_class *) element, i);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ stream_class->assigns_automatic_stream_id = (bool) value;
+ BT_LIB_LOGV("Set stream class's automatic stream ID "
+ "assignment property: %!+S", stream_class);
+ return 0;
}
-static
-int visit_event_class(void *object, bt_ctf_visitor visitor,void *data)
+bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot(
+ struct bt_stream_class *stream_class)
{
- struct bt_ctf_object obj =
- { .object = object,
- .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS };
-
- return visitor(&obj, data);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->packets_have_discarded_event_counter_snapshot;
}
-int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
- bt_ctf_visitor visitor, void *data)
+int bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
+ struct bt_stream_class *stream_class, bt_bool value)
{
- int ret;
- struct bt_ctf_object obj =
- { .object = stream_class,
- .type = BT_CTF_OBJECT_TYPE_STREAM_CLASS };
-
- if (!stream_class || !visitor) {
- ret = -1;
- goto end;
- }
-
- ret = visitor_helper(&obj, get_event_class_count,
- get_event_class,
- visit_event_class, visitor, data);
-end:
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ stream_class->packets_have_discarded_event_counter_snapshot =
+ (bool) value;
+ BT_LIB_LOGV("Set stream class's "
+ "\"packets have discarded event counter snapshot\" property: "
+ "%!+S", stream_class);
+ return 0;
}
-BT_HIDDEN
-void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
+bt_bool bt_stream_class_packets_have_packet_counter_snapshot(
+ struct bt_stream_class *stream_class)
{
- if (!stream_class) {
- return;
- }
-
- stream_class->frozen = 1;
- bt_ctf_field_type_freeze(stream_class->event_header_type);
- bt_ctf_field_type_freeze(stream_class->packet_context_type);
- bt_ctf_field_type_freeze(stream_class->event_context_type);
-
- if (stream_class->clock) {
- bt_ctf_clock_class_freeze(stream_class->clock->clock_class);
- }
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->packets_have_packet_counter_snapshot;
}
-BT_HIDDEN
-int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class,
- struct metadata_context *context)
+int bt_stream_class_set_packets_have_packet_counter_snapshot(
+ struct bt_stream_class *stream_class, bt_bool value)
{
- int ret = 0;
- size_t i;
-
- g_string_assign(context->field_name, "");
- context->current_indentation_level = 1;
- if (!stream_class->id_set) {
- ret = -1;
- goto end;
- }
-
- g_string_append_printf(context->string,
- "stream {\n\tid = %" PRId64 ";\n\tevent.header := ",
- stream_class->id);
- ret = bt_ctf_field_type_serialize(stream_class->event_header_type,
- context);
- if (ret) {
- goto end;
- }
-
- if (stream_class->packet_context_type) {
- g_string_append(context->string, ";\n\n\tpacket.context := ");
- ret = bt_ctf_field_type_serialize(stream_class->packet_context_type,
- context);
- if (ret) {
- goto end;
- }
- }
-
- if (stream_class->event_context_type) {
- g_string_append(context->string, ";\n\n\tevent.context := ");
- ret = bt_ctf_field_type_serialize(
- stream_class->event_context_type, context);
- if (ret) {
- goto end;
- }
- }
-
- g_string_append(context->string, ";\n};\n\n");
- for (i = 0; i < stream_class->event_classes->len; i++) {
- struct bt_ctf_event_class *event_class =
- stream_class->event_classes->pdata[i];
-
- ret = bt_ctf_event_class_serialize(event_class, context);
- if (ret) {
- goto end;
- }
- }
-end:
- context->current_indentation_level = 0;
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ stream_class->packets_have_packet_counter_snapshot =
+ (bool) value;
+ BT_LIB_LOGV("Set stream class's "
+ "\"packets have packet counter snapshot\" property: "
+ "%!+S", stream_class);
+ return 0;
}
-static
-void bt_ctf_stream_class_destroy(struct bt_object *obj)
+bt_bool bt_stream_class_packets_have_default_beginning_clock_value(
+ struct bt_stream_class *stream_class)
{
- struct bt_ctf_stream_class *stream_class;
-
- stream_class = container_of(obj, struct bt_ctf_stream_class, base);
- bt_put(stream_class->clock);
-
- if (stream_class->event_classes_ht) {
- g_hash_table_destroy(stream_class->event_classes_ht);
- }
- if (stream_class->event_classes) {
- g_ptr_array_free(stream_class->event_classes, TRUE);
- }
-
- if (stream_class->name) {
- g_string_free(stream_class->name, TRUE);
- }
-
- bt_put(stream_class->event_header_type);
- bt_put(stream_class->packet_context_type);
- bt_put(stream_class->event_context_type);
- g_free(stream_class);
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->packets_have_default_beginning_cv;
}
-static
-int init_event_header(struct bt_ctf_stream_class *stream_class)
+int bt_stream_class_set_packets_have_default_beginning_clock_value(
+ struct bt_stream_class *stream_class, bt_bool value)
{
- int ret = 0;
- struct bt_ctf_field_type *event_header_type =
- bt_ctf_field_type_structure_create();
- struct bt_ctf_field_type *_uint32_t =
- get_field_type(FIELD_TYPE_ALIAS_UINT32_T);
- struct bt_ctf_field_type *_uint64_t =
- get_field_type(FIELD_TYPE_ALIAS_UINT64_T);
-
- if (!event_header_type) {
- ret = -1;
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(event_header_type,
- _uint32_t, "id");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(event_header_type,
- _uint64_t, "timestamp");
- if (ret) {
- goto end;
- }
-
- BT_MOVE(stream_class->event_header_type, event_header_type);
-end:
- if (ret) {
- bt_put(event_header_type);
- }
-
- bt_put(_uint32_t);
- bt_put(_uint64_t);
- return ret;
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(!value || stream_class->default_clock_class,
+ "Stream class does not have a default clock class: %!+S",
+ stream_class);
+ stream_class->packets_have_default_beginning_cv = (bool) value;
+ BT_LIB_LOGV("Set stream class's "
+ "\"packets have default beginning clock value\" property: "
+ "%!+S", stream_class);
+ return 0;
}
-static
-int init_packet_context(struct bt_ctf_stream_class *stream_class)
+bt_bool bt_stream_class_packets_have_default_end_clock_value(
+ struct bt_stream_class *stream_class)
{
- int ret = 0;
- struct bt_ctf_field_type *packet_context_type =
- bt_ctf_field_type_structure_create();
- struct bt_ctf_field_type *_uint64_t =
- get_field_type(FIELD_TYPE_ALIAS_UINT64_T);
-
- if (!packet_context_type) {
- ret = -1;
- goto end;
- }
-
- /*
- * We create a stream packet context as proposed in the CTF
- * specification.
- */
- ret = bt_ctf_field_type_structure_add_field(packet_context_type,
- _uint64_t, "timestamp_begin");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(packet_context_type,
- _uint64_t, "timestamp_end");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(packet_context_type,
- _uint64_t, "content_size");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(packet_context_type,
- _uint64_t, "packet_size");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(packet_context_type,
- _uint64_t, "events_discarded");
- if (ret) {
- goto end;
- }
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return (bt_bool) stream_class->packets_have_default_end_cv;
+}
- BT_MOVE(stream_class->packet_context_type, packet_context_type);
-end:
- if (ret) {
- bt_put(packet_context_type);
- goto end;
- }
+int bt_stream_class_set_packets_have_default_end_clock_value(
+ struct bt_stream_class *stream_class, bt_bool value)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
+ BT_ASSERT_PRE(!value || stream_class->default_clock_class,
+ "Stream class does not have a default clock class: %!+S",
+ stream_class);
+ stream_class->packets_have_default_end_cv = (bool) value;
+ BT_LIB_LOGV("Set stream class's "
+ "\"packets have default end clock value\" property: "
+ "%!+S", stream_class);
+ return 0;
+}
- bt_put(_uint64_t);
- return ret;
+bt_bool bt_stream_class_default_clock_is_always_known(
+ struct bt_stream_class *stream_class)
+{
+ /* BT_CLOCK_VALUE_STATUS_UNKNOWN is not supported as of 2.0 */
+ return BT_TRUE;
}