lib: trace IR, values: reset pointers to `NULL` on destruction
[babeltrace.git] / lib / trace-ir / event-class.c
index 18a72f70c624201fbcbb10ce1f3a98374c625d48..685c09c32b2153ce2d65bad7072a05e590de81f0 100644 (file)
@@ -1,8 +1,4 @@
 /*
- * event-class.c
- *
- * Babeltrace trace IR - Event class
- *
  * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
 #include <babeltrace/assert-pre-internal.h>
 #include <babeltrace/trace-ir/clock-value-internal.h>
 #include <babeltrace/trace-ir/fields-internal.h>
-#include <babeltrace/trace-ir/field-types.h>
-#include <babeltrace/trace-ir/field-types-internal.h>
+#include <babeltrace/trace-ir/field-classes.h>
+#include <babeltrace/trace-ir/field-classes-internal.h>
+#include <babeltrace/trace-ir/private-event-class.h>
 #include <babeltrace/trace-ir/event-class.h>
 #include <babeltrace/trace-ir/event-class-internal.h>
 #include <babeltrace/trace-ir/event-internal.h>
+#include <babeltrace/trace-ir/private-stream-class.h>
 #include <babeltrace/trace-ir/stream-class.h>
 #include <babeltrace/trace-ir/stream-class-internal.h>
 #include <babeltrace/trace-ir/trace-internal.h>
 #include <babeltrace/trace-ir/utils-internal.h>
 #include <babeltrace/trace-ir/resolve-field-path-internal.h>
-#include <babeltrace/ref.h>
+#include <babeltrace/object.h>
 #include <babeltrace/trace-ir/attributes-internal.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/endian-internal.h>
@@ -53,7 +51,8 @@
 #include <stdlib.h>
 
 #define BT_ASSERT_PRE_EVENT_CLASS_HOT(_ec) \
-       BT_ASSERT_PRE_HOT((_ec), "Event class", ": %!+E", (_ec))
+       BT_ASSERT_PRE_HOT(((struct bt_event_class *) (_ec)),            \
+               "Event class", ": %!+E", (_ec))
 
 static
 void destroy_event_class(struct bt_object *obj)
@@ -64,16 +63,18 @@ void destroy_event_class(struct bt_object *obj)
 
        if (event_class->name.str) {
                g_string_free(event_class->name.str, TRUE);
+               event_class->name.str = NULL;
        }
 
        if (event_class->emf_uri.str) {
                g_string_free(event_class->emf_uri.str, TRUE);
+               event_class->emf_uri.str = NULL;
        }
 
-       BT_LOGD_STR("Putting context field type.");
-       bt_put(event_class->specific_context_ft);
-       BT_LOGD_STR("Putting payload field type.");
-       bt_put(event_class->payload_ft);
+       BT_LOGD_STR("Putting context field classe.");
+       BT_OBJECT_PUT_REF_AND_RESET(event_class->specific_context_fc);
+       BT_LOGD_STR("Putting payload field classe.");
+       BT_OBJECT_PUT_REF_AND_RESET(event_class->payload_fc);
        bt_object_pool_finalize(&event_class->event_pool);
        g_free(obj);
 }
@@ -161,30 +162,34 @@ struct bt_event_class *create_event_class_with_id(
        goto end;
 
 error:
-       BT_PUT(event_class);
+       BT_OBJECT_PUT_REF_AND_RESET(event_class);
 
 end:
        return event_class;
 }
 
-struct bt_event_class *bt_event_class_create(
-               struct bt_stream_class *stream_class)
+struct bt_private_event_class *bt_private_event_class_create(
+               struct bt_private_stream_class *priv_stream_class)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
        BT_ASSERT_PRE(stream_class->assigns_automatic_event_class_id,
                "Stream class does not automatically assigns event class IDs: "
                "%![sc-]+S", stream_class);
-       return create_event_class_with_id(stream_class,
+       return (void *) create_event_class_with_id((void *) stream_class,
                (uint64_t) stream_class->event_classes->len);
 }
 
-struct bt_event_class *bt_event_class_create_with_id(
-               struct bt_stream_class *stream_class, uint64_t id)
+struct bt_private_event_class *bt_private_event_class_create_with_id(
+               struct bt_private_stream_class *priv_stream_class, uint64_t id)
 {
+       struct bt_stream_class *stream_class = (void *) priv_stream_class;
+
        BT_ASSERT_PRE(!stream_class->assigns_automatic_event_class_id,
                "Stream class automatically assigns event class IDs: "
                "%![sc-]+S", stream_class);
-       return create_event_class_with_id(stream_class, id);
+       return (void *) create_event_class_with_id((void *) stream_class, id);
 }
 
 const char *bt_event_class_get_name(struct bt_event_class *event_class)
@@ -193,9 +198,11 @@ const char *bt_event_class_get_name(struct bt_event_class *event_class)
        return event_class->name.value;
 }
 
-int bt_event_class_set_name(struct bt_event_class *event_class,
+int bt_private_event_class_set_name(struct bt_private_event_class *priv_event_class,
                const char *name)
 {
+       struct bt_event_class *event_class = (void *) priv_event_class;
+
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
@@ -222,15 +229,17 @@ enum bt_property_availability bt_event_class_get_log_level(
        return event_class->log_level.base.avail;
 }
 
-int bt_event_class_set_log_level(struct bt_event_class *event_class,
+void bt_private_event_class_set_log_level(
+               struct bt_private_event_class *priv_event_class,
                enum bt_event_class_log_level log_level)
 {
+       struct bt_event_class *event_class = (void *) priv_event_class;
+
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
        bt_property_uint_set(&event_class->log_level,
                (uint64_t) log_level);
        BT_LIB_LOGV("Set event class's log level: %!+E", event_class);
-       return 0;
 }
 
 const char *bt_event_class_get_emf_uri(struct bt_event_class *event_class)
@@ -239,9 +248,12 @@ const char *bt_event_class_get_emf_uri(struct bt_event_class *event_class)
        return event_class->emf_uri.value;
 }
 
-int bt_event_class_set_emf_uri(struct bt_event_class *event_class,
+int bt_private_event_class_set_emf_uri(
+               struct bt_private_event_class *priv_event_class,
                const char *emf_uri)
 {
+       struct bt_event_class *event_class = (void *) priv_event_class;
+
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(emf_uri, "EMF URI");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
@@ -258,18 +270,36 @@ struct bt_stream_class *bt_event_class_borrow_stream_class(
        return bt_event_class_borrow_stream_class_inline(event_class);
 }
 
-struct bt_field_type *bt_event_class_borrow_specific_context_field_type(
+struct bt_private_stream_class *
+bt_private_event_class_borrow_stream_class(
+               struct bt_private_event_class *event_class)
+{
+       return (void *) bt_event_class_borrow_stream_class(
+               (void *) event_class);
+}
+
+struct bt_field_class *bt_event_class_borrow_specific_context_field_class(
                struct bt_event_class *event_class)
 {
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
-       return event_class->specific_context_ft;
+       return event_class->specific_context_fc;
 }
 
-int bt_event_class_set_specific_context_field_type(
-               struct bt_event_class *event_class,
-               struct bt_field_type *field_type)
+struct bt_private_field_class *
+bt_private_event_class_borrow_specific_context_field_class(
+               struct bt_private_event_class *event_class)
+{
+       return (void *) bt_event_class_borrow_specific_context_field_class(
+               (void *) event_class);
+}
+
+int bt_private_event_class_set_specific_context_field_class(
+               struct bt_private_event_class *priv_event_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_event_class *event_class = (void *) priv_event_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_stream_class *stream_class;
        struct bt_trace *trace;
        struct bt_resolve_field_path_context resolve_ctx = {
@@ -277,53 +307,63 @@ int bt_event_class_set_specific_context_field_type(
                .packet_context = NULL,
                .event_header = NULL,
                .event_common_context = NULL,
-               .event_specific_context = field_type,
+               .event_specific_context = field_class,
                .event_payload = NULL,
        };
 
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
-       BT_ASSERT_PRE_NON_NULL(field_type, "Field type");
+       BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
-       BT_ASSERT_PRE(bt_field_type_get_type_id(field_type) ==
-               BT_FIELD_TYPE_ID_STRUCTURE,
-               "Specific context field type is not a structure field type: "
-               "%!+F", field_type);
+       BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
+               BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Specific context field classe is not a structure field classe: "
+               "%!+F", field_class);
        stream_class = bt_event_class_borrow_stream_class_inline(
                event_class);
        trace = bt_stream_class_borrow_trace_inline(stream_class);
-       resolve_ctx.packet_header = trace->packet_header_ft;
-       resolve_ctx.packet_context = stream_class->packet_context_ft;
-       resolve_ctx.event_header = stream_class->event_header_ft;
+       resolve_ctx.packet_header = trace->packet_header_fc;
+       resolve_ctx.packet_context = stream_class->packet_context_fc;
+       resolve_ctx.event_header = stream_class->event_header_fc;
        resolve_ctx.event_common_context =
-               stream_class->event_common_context_ft;
+               stream_class->event_common_context_fc;
 
-       ret = bt_resolve_field_paths(field_type, &resolve_ctx);
+       ret = bt_resolve_field_paths(field_class, &resolve_ctx);
        if (ret) {
                goto end;
        }
 
-       bt_field_type_make_part_of_trace(field_type);
-       bt_put(event_class->specific_context_ft);
-       event_class->specific_context_ft = bt_get(field_type);
-       bt_field_type_freeze(field_type);
-       BT_LIB_LOGV("Set event class's specific context field type: %!+E",
+       bt_field_class_make_part_of_trace(field_class);
+       bt_object_put_ref(event_class->specific_context_fc);
+       event_class->specific_context_fc = bt_object_get_ref(field_class);
+       bt_field_class_freeze(field_class);
+       BT_LIB_LOGV("Set event class's specific context field classe: %!+E",
                event_class);
 
 end:
        return ret;
 }
 
-struct bt_field_type *bt_event_class_borrow_payload_field_type(
+struct bt_field_class *bt_event_class_borrow_payload_field_class(
                struct bt_event_class *event_class)
 {
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
-       return event_class->payload_ft;
+       return event_class->payload_fc;
+}
+
+struct bt_private_field_class *bt_private_event_class_borrow_payload_field_class(
+               struct bt_private_event_class *event_class)
+{
+       return (void *) bt_event_class_borrow_payload_field_class(
+               (void *) event_class);
 }
 
-int bt_event_class_set_payload_field_type(struct bt_event_class *event_class,
-               struct bt_field_type *field_type)
+int bt_private_event_class_set_payload_field_class(
+               struct bt_private_event_class *priv_event_class,
+               struct bt_private_field_class *priv_field_class)
 {
        int ret;
+       struct bt_event_class *event_class = (void *) priv_event_class;
+       struct bt_field_class *field_class = (void *) priv_field_class;
        struct bt_stream_class *stream_class;
        struct bt_trace *trace;
        struct bt_resolve_field_path_context resolve_ctx = {
@@ -332,36 +372,36 @@ int bt_event_class_set_payload_field_type(struct bt_event_class *event_class,
                .event_header = NULL,
                .event_common_context = NULL,
                .event_specific_context = NULL,
-               .event_payload = field_type,
+               .event_payload = field_class,
        };
 
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
-       BT_ASSERT_PRE_NON_NULL(field_type, "Field type");
+       BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
        BT_ASSERT_PRE_EVENT_CLASS_HOT(event_class);
-       BT_ASSERT_PRE(bt_field_type_get_type_id(field_type) ==
-               BT_FIELD_TYPE_ID_STRUCTURE,
-               "Payload field type is not a structure field type: %!+F",
-               field_type);
+       BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
+               BT_FIELD_CLASS_TYPE_STRUCTURE,
+               "Payload field classe is not a structure field classe: %!+F",
+               field_class);
        stream_class = bt_event_class_borrow_stream_class_inline(
                event_class);
        trace = bt_stream_class_borrow_trace_inline(stream_class);
-       resolve_ctx.packet_header = trace->packet_header_ft;
-       resolve_ctx.packet_context = stream_class->packet_context_ft;
-       resolve_ctx.event_header = stream_class->event_header_ft;
+       resolve_ctx.packet_header = trace->packet_header_fc;
+       resolve_ctx.packet_context = stream_class->packet_context_fc;
+       resolve_ctx.event_header = stream_class->event_header_fc;
        resolve_ctx.event_common_context =
-               stream_class->event_common_context_ft;
-       resolve_ctx.event_specific_context = event_class->specific_context_ft;
+               stream_class->event_common_context_fc;
+       resolve_ctx.event_specific_context = event_class->specific_context_fc;
 
-       ret = bt_resolve_field_paths(field_type, &resolve_ctx);
+       ret = bt_resolve_field_paths(field_class, &resolve_ctx);
        if (ret) {
                goto end;
        }
 
-       bt_field_type_make_part_of_trace(field_type);
-       bt_put(event_class->payload_ft);
-       event_class->payload_ft = bt_get(field_type);
-       bt_field_type_freeze(field_type);
-       BT_LIB_LOGV("Set event class's payload field type: %!+E", event_class);
+       bt_field_class_make_part_of_trace(field_class);
+       bt_object_put_ref(event_class->payload_fc);
+       event_class->payload_fc = bt_object_get_ref(field_class);
+       bt_field_class_freeze(field_class);
+       BT_LIB_LOGV("Set event class's payload field classe: %!+E", event_class);
 
 end:
        return ret;
@@ -370,7 +410,7 @@ end:
 BT_HIDDEN
 void _bt_event_class_freeze(struct bt_event_class *event_class)
 {
-       /* The field types are already frozen */
+       /* The field classes are already frozen */
        BT_ASSERT(event_class);
        BT_LIB_LOGD("Freezing event class: %!+E", event_class);
        event_class->frozen = true;
This page took 0.031058 seconds and 4 git commands to generate.