bt_clock_class_create(): accept mandatory trace class
[babeltrace.git] / lib / trace-ir / trace-class.c
index 1d2c80974d02e8363cc77961a49ec0ad766e18c8..78a7161bb56c2c632521115364bcf8cfcf80ad00 100644 (file)
@@ -1,8 +1,7 @@
 /*
+ * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * Author: Jérémie Galarneau <jeremie.galarneau@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
  * in the Software without restriction, including without limitation the rights
@@ -46,7 +45,6 @@
 #include <babeltrace/value.h>
 #include <babeltrace/value-const.h>
 #include <babeltrace/value-internal.h>
-#include <babeltrace/object.h>
 #include <babeltrace/types.h>
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/assert-internal.h>
@@ -98,11 +96,12 @@ void free_packet_header_field(struct bt_field_wrapper *field_wrapper,
        bt_field_wrapper_destroy(field_wrapper);
 }
 
-struct bt_trace_class *bt_trace_class_create(void)
+struct bt_trace_class *bt_trace_class_create(bt_self_component *self_comp)
 {
        struct bt_trace_class *tc = NULL;
        int ret;
 
+       BT_ASSERT_PRE_NON_NULL(self_comp, "Self component");
        BT_LOGD_STR("Creating default trace class object.");
        tc = g_new0(struct bt_trace_class, 1);
        if (!tc) {
@@ -158,7 +157,8 @@ const char *bt_trace_class_get_name(const struct bt_trace_class *tc)
        return tc->name.value;
 }
 
-int bt_trace_class_set_name(struct bt_trace_class *tc, const char *name)
+enum bt_trace_class_status bt_trace_class_set_name(
+               struct bt_trace_class *tc, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
@@ -166,7 +166,7 @@ int bt_trace_class_set_name(struct bt_trace_class *tc, const char *name)
        g_string_assign(tc->name.str, name);
        tc->name.value = tc->name.str->str;
        BT_LIB_LOGV("Set trace class's name: %!+T", tc);
-       return 0;
+       return BT_TRACE_CLASS_STATUS_OK;
 }
 
 bt_uuid bt_trace_class_get_uuid(const struct bt_trace_class *tc)
@@ -196,8 +196,8 @@ bool trace_has_environment_entry(const struct bt_trace_class *tc, const char *na
 }
 
 static
-int set_environment_entry(struct bt_trace_class *tc, const char *name,
-               struct bt_value *value)
+enum bt_trace_class_status set_environment_entry(struct bt_trace_class *tc,
+               const char *name, struct bt_value *value)
 {
        int ret;
 
@@ -210,11 +210,12 @@ int set_environment_entry(struct bt_trace_class *tc, const char *name,
                "%![tc-]+T, entry-name=\"%s\"", tc, name);
        ret = bt_attributes_set_field_value(tc->environment, name,
                value);
-       bt_value_freeze(value);
        if (ret) {
+               ret = BT_TRACE_CLASS_STATUS_NOMEM;
                BT_LIB_LOGE("Cannot set trace class's environment entry: "
                        "%![tc-]+T, entry-name=\"%s\"", tc, name);
        } else {
+               bt_value_freeze(value);
                BT_LIB_LOGV("Set trace class's environment entry: "
                        "%![tc-]+T, entry-name=\"%s\"", tc, name);
        }
@@ -222,7 +223,7 @@ int set_environment_entry(struct bt_trace_class *tc, const char *name,
        return ret;
 }
 
-int bt_trace_class_set_environment_entry_string(
+enum bt_trace_class_status bt_trace_class_set_environment_entry_string(
                struct bt_trace_class *tc, const char *name, const char *value)
 {
        int ret;
@@ -245,8 +246,8 @@ end:
        return ret;
 }
 
-int bt_trace_class_set_environment_entry_integer(struct bt_trace_class *tc,
-               const char *name, int64_t value)
+enum bt_trace_class_status bt_trace_class_set_environment_entry_integer(
+               struct bt_trace_class *tc, const char *name, int64_t value)
 {
        int ret;
        struct bt_value *value_obj;
@@ -255,7 +256,7 @@ int bt_trace_class_set_environment_entry_integer(struct bt_trace_class *tc,
        value_obj = bt_value_integer_create_init(value);
        if (!value_obj) {
                BT_LOGE_STR("Cannot create an integer value object.");
-               ret = -1;
+               ret = BT_TRACE_CLASS_STATUS_NOMEM;
                goto end;
        }
 
@@ -359,7 +360,7 @@ const struct bt_field_class *bt_trace_class_borrow_packet_header_field_class_con
        return tc->packet_header_fc;
 }
 
-int bt_trace_class_set_packet_header_field_class(
+enum bt_trace_class_status bt_trace_class_set_packet_header_field_class(
                struct bt_trace_class *tc,
                struct bt_field_class *field_class)
 {
@@ -382,6 +383,12 @@ int bt_trace_class_set_packet_header_field_class(
                field_class);
        ret = bt_resolve_field_paths(field_class, &resolve_ctx);
        if (ret) {
+               /*
+                * This is the only reason for which
+                * bt_resolve_field_paths() can fail: anything else
+                * would be because a precondition is not satisfied.
+                */
+               ret = BT_TRACE_CLASS_STATUS_NOMEM;
                goto end;
        }
 
@@ -420,3 +427,13 @@ void bt_trace_class_set_assigns_automatic_stream_class_id(struct bt_trace_class
        BT_LIB_LOGV("Set trace class's automatic stream class ID "
                "assignment property: %!+T", tc);
 }
+
+void bt_trace_class_get_ref(const struct bt_trace_class *trace_class)
+{
+       bt_object_get_ref(trace_class);
+}
+
+void bt_trace_class_put_ref(const struct bt_trace_class *trace_class)
+{
+       bt_object_put_ref(trace_class);
+}
This page took 0.026638 seconds and 4 git commands to generate.