lib: add internal object pool API and use it; adapt plugins/tests
[babeltrace.git] / lib / ctf-ir / event-class.c
index 6764d43855e8c18d1d5c97d13de6592b1ac44646..57402e3474133bc5e712af3bbcd5564adb952c5a 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "EVENT-CLASS"
+#include <babeltrace/lib-logging-internal.h>
+
+#include <babeltrace/assert-pre-internal.h>
+#include <babeltrace/ctf-ir/clock-value-internal.h>
 #include <babeltrace/ctf-ir/fields-internal.h>
 #include <babeltrace/ctf-ir/field-types-internal.h>
 #include <babeltrace/ctf-ir/event-class.h>
 #include <babeltrace/ctf-ir/event-class-internal.h>
+#include <babeltrace/ctf-ir/event-internal.h>
 #include <babeltrace/ctf-ir/stream-class.h>
 #include <babeltrace/ctf-ir/stream-class-internal.h>
 #include <babeltrace/ctf-ir/trace-internal.h>
 #include <babeltrace/ctf-ir/validation-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/utils-internal.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/ctf-ir/attributes-internal.h>
-#include <babeltrace/compiler.h>
-#include <babeltrace/endian.h>
+#include <babeltrace/compiler-internal.h>
+#include <babeltrace/endian-internal.h>
+#include <babeltrace/types.h>
+#include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
 #include <inttypes.h>
+#include <stdlib.h>
 
-static
-void bt_ctf_event_class_destroy(struct bt_object *obj);
-
-struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name)
+BT_HIDDEN
+void bt_event_class_common_finalize(struct bt_object *obj)
 {
-       int ret;
-       struct bt_value *obj = NULL;
-       struct bt_ctf_event_class *event_class = NULL;
+       struct bt_event_class_common *event_class;
 
-       if (bt_ctf_validate_identifier(name)) {
-               goto error;
-       }
+       event_class = container_of(obj, struct bt_event_class_common, base);
+       BT_LOGD("Finalizing common event class: addr=%p, name=\"%s\", id=%" PRId64,
+               event_class, bt_event_class_common_get_name(event_class),
+               bt_event_class_common_get_id(event_class));
 
-       event_class = g_new0(struct bt_ctf_event_class, 1);
-       if (!event_class) {
-               goto error;
+       if (event_class->name) {
+               g_string_free(event_class->name, TRUE);
        }
 
-       event_class->id = -1;
-       bt_object_init(event_class, bt_ctf_event_class_destroy);
-       event_class->fields = bt_ctf_field_type_structure_create();
-       if (!event_class->fields) {
-               goto error;
+       if (event_class->emf_uri) {
+               g_string_free(event_class->emf_uri, TRUE);
        }
 
-       event_class->attributes = bt_ctf_attributes_create();
-       if (!event_class->attributes) {
-               goto error;
-       }
+       BT_LOGD_STR("Putting context field type.");
+       bt_put(event_class->context_field_type);
+       BT_LOGD_STR("Putting payload field type.");
+       bt_put(event_class->payload_field_type);
+}
 
-       obj = bt_value_integer_create_init(-1);
-       if (!obj) {
-               goto error;
-       }
+BT_HIDDEN
+int bt_event_class_common_initialize(struct bt_event_class_common *event_class,
+               const char *name, bt_object_release_func release_func,
+               bt_field_type_structure_create_func ft_struct_create_func)
+{
+       int ret = 0;
 
-       ret = bt_ctf_attributes_set_field_value(event_class->attributes,
-               "id", obj);
-       if (ret) {
+       BT_LOGD("Initializing common event class object: name=\"%s\"",
+               name);
+       bt_object_init(event_class, release_func);
+       event_class->payload_field_type = ft_struct_create_func();
+       if (!event_class->payload_field_type) {
+               BT_LOGE_STR("Cannot create event class's initial payload field type object.");
                goto error;
        }
 
-       BT_PUT(obj);
-
-       obj = bt_value_string_create_init(name);
-       if (!obj) {
+       event_class->id = -1;
+       event_class->name = g_string_new(name);
+       if (!event_class->name) {
+               BT_LOGE_STR("Failed to allocate a GString.");
                goto error;
        }
 
-       ret = bt_ctf_attributes_set_field_value(event_class->attributes,
-               "name", obj);
-       if (ret) {
+       event_class->emf_uri = g_string_new(NULL);
+       if (!event_class->emf_uri) {
+               BT_LOGE_STR("Failed to allocate a GString.");
                goto error;
        }
 
-       BT_PUT(obj);
-
-       return event_class;
+       event_class->log_level = BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED;
+       BT_LOGD("Initialized common event class object: addr=%p, name=\"%s\"",
+               event_class, bt_event_class_common_get_name(event_class));
+       return ret;
 
 error:
-        BT_PUT(event_class);
-       BT_PUT(obj);
-       return event_class;
+       ret = -1;
+       return ret;
 }
 
-const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class)
+static
+void bt_event_class_destroy(struct bt_object *obj)
 {
-       struct bt_value *obj = NULL;
-       const char *name = NULL;
-
-       if (!event_class) {
-               goto end;
-       }
-
-       if (event_class->name) {
-               name = event_class->name;
-               goto end;
-       }
+       struct bt_event_class *event_class = (void *) obj;
 
-       obj = bt_ctf_attributes_get_field_value(event_class->attributes,
-               BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX);
-       if (!obj) {
-               goto end;
-       }
-
-       if (bt_value_string_get(obj, &name)) {
-               name = NULL;
-       }
-
-end:
-       BT_PUT(obj);
-       return name;
+       BT_LOGD("Destroying event class: addr=%p", obj);
+       bt_event_class_common_finalize(obj);
+       bt_object_pool_finalize(&event_class->event_pool);
+       g_free(obj);
 }
 
-int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class)
+static
+void free_event(struct bt_event *event,
+               struct bt_event_class *event_class)
 {
-       struct bt_value *obj = NULL;
-       int64_t ret = 0;
-
-       if (!event_class) {
-               ret = -1;
-               goto end;
-       }
-
-       if (event_class->id >= 0) {
-               ret = event_class->id;
-               goto end;
-       }
-
-       obj = bt_ctf_attributes_get_field_value(event_class->attributes,
-               BT_CTF_EVENT_CLASS_ATTR_ID_INDEX);
-       if (!obj) {
-               goto end;
-       }
-
-       if (bt_value_integer_get(obj, &ret)) {
-               ret = -1;
-       }
-
-       if (ret < 0) {
-               /* means ID is not set */
-               ret = -1;
-               goto end;
-       }
-
-end:
-       BT_PUT(obj);
-       return ret;
+       bt_event_destroy(event);
 }
 
-int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class,
-               uint32_t id)
+struct bt_event_class *bt_event_class_create(const char *name)
 {
-       int ret = 0;
-       struct bt_value *obj = NULL;
-       struct bt_ctf_stream_class *stream_class = NULL;
-
-
-       if (!event_class) {
-               ret = -1;
-               goto end;
-       }
-
-       stream_class = bt_ctf_event_class_get_stream_class(event_class);
-       if (stream_class) {
-               /*
-                * We don't allow changing the id if the event class has already
-                * been added to a stream class.
-                */
-               ret = -1;
-               goto end;
-       }
+       int ret;
+       struct bt_event_class *event_class = NULL;
 
-       obj = bt_ctf_attributes_get_field_value(event_class->attributes,
-               BT_CTF_EVENT_CLASS_ATTR_ID_INDEX);
-       if (!obj) {
-               goto end;
+       if (!name) {
+               BT_LOGW_STR("Invalid parameter: name is NULL.");
+               goto error;
        }
 
-       if (bt_value_integer_set(obj, id)) {
-               ret = -1;
-               goto end;
+       BT_LOGD("Creating event class object: name=\"%s\"",
+               name);
+       event_class = g_new0(struct bt_event_class, 1);
+       if (!event_class) {
+               BT_LOGE_STR("Failed to allocate one event class.");
+               goto error;
        }
 
-end:
-       BT_PUT(obj);
-       BT_PUT(stream_class);
-       return ret;
-}
-
-int bt_ctf_event_class_set_attribute(
-               struct bt_ctf_event_class *event_class, const char *name,
-               struct bt_value *value)
-{
-       int ret = 0;
-
-       if (!event_class || !name || !value || event_class->frozen) {
-               ret = -1;
-               goto end;
+       ret = bt_event_class_common_initialize(BT_TO_COMMON(event_class),
+               name, bt_event_class_destroy,
+               (bt_field_type_structure_create_func)
+                       bt_field_type_structure_create);
+       if (ret) {
+               goto error;
        }
 
-       if (!strcmp(name, "id") || !strcmp(name, "loglevel") ||
-                       !strcmp(name, "stream_id")) {
-               if (!bt_value_is_integer(value)) {
-                       ret = -1;
-                       goto end;
-               }
-       } else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri") ||
-                       !strcmp(name, "loglevel_string")) {
-               if (!bt_value_is_string(value)) {
-                       ret = -1;
-                       goto end;
-               }
-       } else {
-               /* unknown attribute */
-               ret = -1;
-               goto end;
+       ret = bt_object_pool_initialize(&event_class->event_pool,
+               (bt_object_pool_new_object_func) bt_event_new,
+               (bt_object_pool_destroy_object_func) free_event,
+               event_class);
+       if (ret) {
+               BT_LOGE("Failed to initialize event pool: ret=%d",
+                       ret);
+               goto error;
        }
 
-       /* "id" special case: >= 0 */
-       if (!strcmp(name, "id")) {
-               int64_t val;
-
-               ret = bt_value_integer_get(value, &val);
+       BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
+               event_class, bt_event_class_get_name(event_class));
+       goto end;
 
-               if (ret) {
-                       goto end;
-               }
-
-               if (val < 0) {
-                       ret = -1;
-                       goto end;
-               }
-       }
-
-       ret = bt_ctf_attributes_set_field_value(event_class->attributes,
-                       name, value);
+error:
+       bt_put(event_class);
 
 end:
-       return ret;
+       return event_class;
 }
 
-int bt_ctf_event_class_get_attribute_count(
-               struct bt_ctf_event_class *event_class)
+const char *bt_event_class_get_name(struct bt_event_class *event_class)
 {
-       int ret = 0;
-
-       if (!event_class) {
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_ctf_attributes_get_count(event_class->attributes);
-
-end:
-       return ret;
+       return bt_event_class_common_get_name(BT_TO_COMMON(event_class));
 }
 
-const char *
-bt_ctf_event_class_get_attribute_name(
-               struct bt_ctf_event_class *event_class, int index)
+int64_t bt_event_class_get_id(struct bt_event_class *event_class)
 {
-       const char *ret;
-
-       if (!event_class) {
-               ret = NULL;
-               goto end;
-       }
-
-       ret = bt_ctf_attributes_get_field_name(event_class->attributes, index);
-
-end:
-       return ret;
+       return bt_event_class_common_get_id(BT_TO_COMMON(event_class));
 }
 
-struct bt_value *
-bt_ctf_event_class_get_attribute_value(struct bt_ctf_event_class *event_class,
-               int index)
+int bt_event_class_set_id(struct bt_event_class *event_class, uint64_t id)
 {
-       struct bt_value *ret;
-
-       if (!event_class) {
-               ret = NULL;
-               goto end;
-       }
-
-       ret = bt_ctf_attributes_get_field_value(event_class->attributes, index);
-
-end:
-       return ret;
+       return bt_event_class_common_set_id(BT_TO_COMMON(event_class), id);
 }
 
-struct bt_value *
-bt_ctf_event_class_get_attribute_value_by_name(
-               struct bt_ctf_event_class *event_class, const char *name)
+enum bt_event_class_log_level bt_event_class_get_log_level(
+               struct bt_event_class *event_class)
 {
-       struct bt_value *ret;
-
-       if (!event_class || !name) {
-               ret = NULL;
-               goto end;
-       }
-
-       ret = bt_ctf_attributes_get_field_value_by_name(event_class->attributes,
-               name);
-
-end:
-       return ret;
-
+       return bt_event_class_common_get_log_level(BT_TO_COMMON(event_class));
 }
 
-struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class(
-               struct bt_ctf_event_class *event_class)
+int bt_event_class_set_log_level(struct bt_event_class *event_class,
+               enum bt_event_class_log_level log_level)
 {
-       return event_class ?
-               bt_get(bt_ctf_event_class_borrow_stream_class(event_class)) :
-               NULL;
+       return bt_event_class_common_set_log_level(BT_TO_COMMON(event_class),
+               log_level);
 }
 
-struct bt_ctf_field_type *bt_ctf_event_class_get_payload_type(
-               struct bt_ctf_event_class *event_class)
+const char *bt_event_class_get_emf_uri(struct bt_event_class *event_class)
 {
-       struct bt_ctf_field_type *payload = NULL;
-
-       if (!event_class) {
-               goto end;
-       }
-
-       bt_get(event_class->fields);
-       payload = event_class->fields;
-end:
-       return payload;
+       return bt_event_class_common_get_emf_uri(BT_TO_COMMON(event_class));
 }
 
-int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class *event_class,
-               struct bt_ctf_field_type *payload)
+int bt_event_class_set_emf_uri(struct bt_event_class *event_class,
+               const char *emf_uri)
 {
-       int ret = 0;
-
-       if (!event_class) {
-               ret = -1;
-               goto end;
-       }
-
-       if (payload && bt_ctf_field_type_get_type_id(payload) !=
-                       BT_CTF_FIELD_TYPE_ID_STRUCT) {
-               ret = -1;
-               goto end;
-       }
-
-       bt_put(event_class->fields);
-       event_class->fields = bt_get(payload);
-end:
-       return ret;
+       return bt_event_class_common_set_emf_uri(BT_TO_COMMON(event_class),
+               emf_uri);
 }
 
-int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class,
-               struct bt_ctf_field_type *type,
-               const char *name)
+struct bt_stream_class *bt_event_class_borrow_stream_class(
+               struct bt_event_class *event_class)
 {
-       int ret = 0;
-
-       if (!event_class || !type || bt_ctf_validate_identifier(name) ||
-               event_class->frozen) {
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_ctf_field_type_get_type_id(event_class->fields) !=
-               BT_CTF_FIELD_TYPE_ID_STRUCT) {
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_ctf_field_type_structure_add_field(event_class->fields,
-               type, name);
-end:
-       return ret;
+       BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
+       return BT_FROM_COMMON(
+               bt_event_class_common_borrow_stream_class(BT_TO_COMMON(
+                       event_class)));
 }
 
-int bt_ctf_event_class_get_field_count(
-               struct bt_ctf_event_class *event_class)
+struct bt_field_type *bt_event_class_borrow_payload_field_type(
+               struct bt_event_class *event_class)
 {
-       int ret;
-
-       if (!event_class) {
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_ctf_field_type_get_type_id(event_class->fields) !=
-               BT_CTF_FIELD_TYPE_ID_STRUCT) {
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_ctf_field_type_structure_get_field_count(event_class->fields);
-end:
-       return ret;
+       return BT_FROM_COMMON(bt_event_class_common_borrow_payload_field_type(
+               BT_TO_COMMON(event_class)));
 }
 
-int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class,
-               const char **field_name, struct bt_ctf_field_type **field_type,
-               int index)
+int bt_event_class_set_payload_field_type(struct bt_event_class *event_class,
+               struct bt_field_type *field_type)
 {
-       int ret;
-
-       if (!event_class || index < 0) {
-               ret = -1;
-               goto end;
-       }
-
-       if (bt_ctf_field_type_get_type_id(event_class->fields) !=
-               BT_CTF_FIELD_TYPE_ID_STRUCT) {
-               ret = -1;
-               goto end;
-       }
-
-       ret = bt_ctf_field_type_structure_get_field(event_class->fields,
-               field_name, field_type, index);
-end:
-       return ret;
+       return bt_event_class_common_set_payload_field_type(
+               BT_TO_COMMON(event_class), (void *) field_type);
 }
 
-struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(
-               struct bt_ctf_event_class *event_class, const char *name)
+struct bt_field_type *bt_event_class_borrow_context_field_type(
+               struct bt_event_class *event_class)
 {
-       GQuark name_quark;
-       struct bt_ctf_field_type *field_type = NULL;
-
-       if (!event_class || !name) {
-               goto end;
-       }
-
-       if (bt_ctf_field_type_get_type_id(event_class->fields) !=
-               BT_CTF_FIELD_TYPE_ID_STRUCT) {
-               goto end;
-       }
-
-       name_quark = g_quark_try_string(name);
-       if (!name_quark) {
-               goto end;
-       }
-
-       /*
-        * No need to increment field_type's reference count since getting it
-        * from the structure already does.
-        */
-       field_type = bt_ctf_field_type_structure_get_field_type_by_name(
-               event_class->fields, name);
-end:
-       return field_type;
+       return BT_FROM_COMMON(bt_event_class_common_borrow_context_field_type(
+               BT_TO_COMMON(event_class)));
 }
 
-struct bt_ctf_field_type *bt_ctf_event_class_get_context_type(
-               struct bt_ctf_event_class *event_class)
+int bt_event_class_set_context_field_type(
+               struct bt_event_class *event_class,
+               struct bt_field_type *field_type)
 {
-       struct bt_ctf_field_type *context_type = NULL;
-
-       if (!event_class || !event_class->context) {
-               goto end;
-       }
-
-       bt_get(event_class->context);
-       context_type = event_class->context;
-end:
-       return context_type;
+       return bt_event_class_common_set_context_field_type(
+               BT_TO_COMMON(event_class), (void *) field_type);
 }
 
-int bt_ctf_event_class_set_context_type(
-               struct bt_ctf_event_class *event_class,
-               struct bt_ctf_field_type *context)
+BT_HIDDEN
+void bt_event_class_common_freeze(struct bt_event_class_common *event_class)
 {
-       int ret = 0;
-
-       if (!event_class || event_class->frozen) {
-               ret = -1;
-               goto end;
-       }
+       BT_ASSERT(event_class);
 
-       if (context && bt_ctf_field_type_get_type_id(context) !=
-                       BT_CTF_FIELD_TYPE_ID_STRUCT) {
-               ret = -1;
-               goto end;
+       if (event_class->frozen) {
+               return;
        }
 
-       bt_put(event_class->context);
-       event_class->context = bt_get(context);
-end:
-       return ret;
-
-}
-
-void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class)
-{
-       bt_get(event_class);
-}
-
-void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class)
-{
-       bt_put(event_class);
+       BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64,
+               event_class, bt_event_class_common_get_name(event_class),
+               bt_event_class_common_get_id(event_class));
+       event_class->frozen = 1;
+       BT_LOGD_STR("Freezing event class's context field type.");
+       bt_field_type_common_freeze(event_class->context_field_type);
+       BT_LOGD_STR("Freezing event class's payload field type.");
+       bt_field_type_common_freeze(event_class->payload_field_type);
 }
 
 BT_HIDDEN
-int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class *event_class,
-               uint32_t stream_id)
+int bt_event_class_common_validate_single_clock_class(
+               struct bt_event_class_common *event_class,
+               struct bt_clock_class **expected_clock_class)
 {
        int ret = 0;
-       struct bt_value *obj;
 
-       obj = bt_value_integer_create_init(stream_id);
-
-       if (!obj) {
-               ret = -1;
+       BT_ASSERT(event_class);
+       BT_ASSERT(expected_clock_class);
+       ret = bt_field_type_common_validate_single_clock_class(
+               event_class->context_field_type,
+               expected_clock_class);
+       if (ret) {
+               BT_LOGW("Event class's context field type "
+                       "is not recursively mapped to the "
+                       "expected clock class: "
+                       "event-class-addr=%p, "
+                       "event-class-name=\"%s\", "
+                       "event-class-id=%" PRId64 ", "
+                       "ft-addr=%p",
+                       event_class,
+                       bt_event_class_common_get_name(event_class),
+                       event_class->id,
+                       event_class->context_field_type);
+               goto end;
+       }
+
+       ret = bt_field_type_common_validate_single_clock_class(
+               event_class->payload_field_type,
+               expected_clock_class);
+       if (ret) {
+               BT_LOGW("Event class's payload field type "
+                       "is not recursively mapped to the "
+                       "expected clock class: "
+                       "event-class-addr=%p, "
+                       "event-class-name=\"%s\", "
+                       "event-class-id=%" PRId64 ", "
+                       "ft-addr=%p",
+                       event_class,
+                       bt_event_class_common_get_name(event_class),
+                       event_class->id,
+                       event_class->payload_field_type);
                goto end;
        }
 
-       ret = bt_ctf_attributes_set_field_value(event_class->attributes,
-               "stream_id", obj);
-
-       if (event_class->frozen) {
-               bt_ctf_attributes_freeze(event_class->attributes);
-       }
-
 end:
-       BT_PUT(obj);
        return ret;
 }
 
-static
-void bt_ctf_event_class_destroy(struct bt_object *obj)
-{
-       struct bt_ctf_event_class *event_class;
-
-       event_class = container_of(obj, struct bt_ctf_event_class, base);
-       bt_ctf_attributes_destroy(event_class->attributes);
-       bt_put(event_class->context);
-       bt_put(event_class->fields);
-       g_free(event_class);
-}
-
-BT_HIDDEN
-void bt_ctf_event_class_freeze(struct bt_ctf_event_class *event_class)
-{
-       assert(event_class);
-       event_class->frozen = 1;
-       event_class->name = bt_ctf_event_class_get_name(event_class);
-       event_class->id = bt_ctf_event_class_get_id(event_class);
-       bt_ctf_field_type_freeze(event_class->context);
-       bt_ctf_field_type_freeze(event_class->fields);
-       bt_ctf_attributes_freeze(event_class->attributes);
-}
-
 BT_HIDDEN
-int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
-               struct metadata_context *context)
+int bt_event_class_update_event_pool_clock_values(
+               struct bt_event_class *event_class)
 {
-       int i;
-       int count;
        int ret = 0;
-       struct bt_value *attr_value = NULL;
+       uint64_t i;
+       struct bt_stream_class *stream_class =
+               bt_event_class_borrow_stream_class(event_class);
 
-       assert(event_class);
-       assert(context);
+       BT_ASSERT(stream_class->common.clock_class);
 
-       context->current_indentation_level = 1;
-       g_string_assign(context->field_name, "");
-       g_string_append(context->string, "event {\n");
-       count = bt_ctf_event_class_get_attribute_count(event_class);
+       for (i = 0; i < event_class->event_pool.size; i++) {
+               struct bt_clock_value *cv;
+               struct bt_event *event =
+                       event_class->event_pool.objects->pdata[i];
 
-       if (count < 0) {
-               ret = -1;
-               goto end;
-       }
-
-       for (i = 0; i < count; ++i) {
-               const char *attr_name = NULL;
-
-               attr_name = bt_ctf_event_class_get_attribute_name(
-                       event_class, i);
-               attr_value = bt_ctf_event_class_get_attribute_value(
-                       event_class, i);
+               BT_ASSERT(event);
 
-               if (!attr_name || !attr_value) {
-                       ret = -1;
-                       goto end;
+               cv = g_hash_table_lookup(event->clock_values,
+                       stream_class->common.clock_class);
+               if (cv) {
+                       continue;
                }
 
-               switch (bt_value_get_type(attr_value)) {
-               case BT_VALUE_TYPE_INTEGER:
-               {
-                       int64_t value;
-
-                       ret = bt_value_integer_get(attr_value, &value);
-
-                       if (ret) {
-                               goto end;
-                       }
-
-                       g_string_append_printf(context->string,
-                               "\t%s = %" PRId64 ";\n", attr_name, value);
-                       break;
-               }
-
-               case BT_VALUE_TYPE_STRING:
-               {
-                       const char *value;
-
-                       ret = bt_value_string_get(attr_value, &value);
-
-                       if (ret) {
-                               goto end;
-                       }
-
-                       g_string_append_printf(context->string,
-                               "\t%s = \"%s\";\n", attr_name, value);
-                       break;
-               }
-
-               default:
-                       /* should never happen */
-                       assert(false);
-                       break;
-               }
-
-               BT_PUT(attr_value);
-       }
-
-       if (event_class->context) {
-               g_string_append(context->string, "\tcontext := ");
-               ret = bt_ctf_field_type_serialize(event_class->context,
-                       context);
-               if (ret) {
+               cv = bt_clock_value_create(stream_class->common.clock_class);
+               if (!cv) {
+                       BT_LIB_LOGE("Cannot create clock value from clock class: "
+                               "%![cc-]+K", stream_class->common.clock_class);
+                       ret = -1;
                        goto end;
                }
-               g_string_append(context->string, ";\n");
-       }
 
-       if (event_class->fields) {
-               g_string_append(context->string, "\tfields := ");
-               ret = bt_ctf_field_type_serialize(event_class->fields, context);
-               if (ret) {
-                       goto end;
-               }
-               g_string_append(context->string, ";\n");
+               g_hash_table_insert(event->clock_values,
+                       stream_class->common.clock_class, cv);
        }
 
-       g_string_append(context->string, "};\n\n");
 end:
-       context->current_indentation_level = 0;
-       BT_PUT(attr_value);
        return ret;
 }
This page took 0.034568 seconds and 4 git commands to generate.