Event class API: use status
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 8 Dec 2018 19:54:23 +0000 (14:54 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
include/babeltrace/trace-ir/event-class-const.h
include/babeltrace/trace-ir/event-class.h
lib/trace-ir/event-class.c

index 8acad21561c45c4aa280b22a88d0ca93b9c86302..b7e559e24b1b13d113f35a4adb9c788c3c83079b 100644 (file)
 extern "C" {
 #endif
 
+enum bt_event_class_status {
+       BT_EVENT_CLASS_STATUS_OK = 0,
+       BT_EVENT_CLASS_STATUS_NOMEM = -12,
+};
+
 enum bt_event_class_log_level {
        BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY,
        BT_EVENT_CLASS_LOG_LEVEL_ALERT,
index 2b4a42549e24b545105f793378a2f5fd9bc9350c..be6bcf9b11b6614b3fc4aff40b8b397fd5dbbf85 100644 (file)
@@ -27,7 +27,7 @@
  * http://www.efficios.com/ctf
  */
 
-/* For enum bt_event_class_log_level */
+/* For enum bt_event_class_status, enum bt_event_class_log_level */
 #include <babeltrace/trace-ir/event-class-const.h>
 
 /* For bt_event_class, bt_stream_class */
@@ -48,22 +48,22 @@ extern bt_event_class *bt_event_class_create_with_id(
 extern bt_stream_class *bt_event_class_borrow_stream_class(
                bt_event_class *event_class);
 
-extern int bt_event_class_set_name(bt_event_class *event_class,
-               const char *name);
+extern enum bt_event_class_status bt_event_class_set_name(
+               bt_event_class *event_class, const char *name);
 
 extern void bt_event_class_set_log_level(
                bt_event_class *event_class,
                enum bt_event_class_log_level log_level);
 
-extern int bt_event_class_set_emf_uri(
+extern enum bt_event_class_status bt_event_class_set_emf_uri(
                bt_event_class *event_class,
                const char *emf_uri);
 
-extern int bt_event_class_set_specific_context_field_class(
-               bt_event_class *event_class,
+extern enum bt_event_class_status
+bt_event_class_set_specific_context_field_class(bt_event_class *event_class,
                bt_field_class *field_class);
 
-extern int bt_event_class_set_payload_field_class(
+extern enum bt_event_class_status bt_event_class_set_payload_field_class(
                bt_event_class *event_class,
                bt_field_class *field_class);
 
index 7c09f78bf468305fce15d568124a392e9086b137..b15ee7ad2163ab39b55fefc39e2eb7d79144c229 100644 (file)
@@ -192,8 +192,8 @@ const char *bt_event_class_get_name(const struct bt_event_class *event_class)
        return event_class->name.value;
 }
 
-int bt_event_class_set_name(struct bt_event_class *event_class,
-               const char *name)
+enum bt_event_class_status bt_event_class_set_name(
+               struct bt_event_class *event_class, const char *name)
 {
        BT_ASSERT_PRE_NON_NULL(event_class, "Event class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
@@ -201,7 +201,7 @@ int bt_event_class_set_name(struct bt_event_class *event_class,
        g_string_assign(event_class->name.str, name);
        event_class->name.value = event_class->name.str->str;
        BT_LIB_LOGV("Set event class's name: %!+E", event_class);
-       return 0;
+       return BT_EVENT_CLASS_STATUS_OK;
 }
 
 uint64_t bt_event_class_get_id(const struct bt_event_class *event_class)
@@ -238,7 +238,7 @@ const char *bt_event_class_get_emf_uri(const struct bt_event_class *event_class)
        return event_class->emf_uri.value;
 }
 
-int bt_event_class_set_emf_uri(
+enum bt_event_class_status bt_event_class_set_emf_uri(
                struct bt_event_class *event_class,
                const char *emf_uri)
 {
@@ -248,7 +248,7 @@ int bt_event_class_set_emf_uri(
        g_string_assign(event_class->emf_uri.str, emf_uri);
        event_class->emf_uri.value = event_class->emf_uri.str->str;
        BT_LIB_LOGV("Set event class's EMF URI: %!+E", event_class);
-       return 0;
+       return BT_EVENT_CLASS_STATUS_OK;
 }
 
 struct bt_stream_class *bt_event_class_borrow_stream_class(
@@ -273,7 +273,7 @@ bt_event_class_borrow_specific_context_field_class_const(
        return event_class->specific_context_fc;
 }
 
-int bt_event_class_set_specific_context_field_class(
+enum bt_event_class_status bt_event_class_set_specific_context_field_class(
                struct bt_event_class *event_class,
                struct bt_field_class *field_class)
 {
@@ -307,6 +307,12 @@ int bt_event_class_set_specific_context_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_EVENT_CLASS_STATUS_NOMEM;
                goto end;
        }
 
@@ -329,7 +335,7 @@ const struct bt_field_class *bt_event_class_borrow_payload_field_class_const(
        return event_class->payload_fc;
 }
 
-int bt_event_class_set_payload_field_class(
+enum bt_event_class_status bt_event_class_set_payload_field_class(
                struct bt_event_class *event_class,
                struct bt_field_class *field_class)
 {
@@ -364,6 +370,12 @@ int bt_event_class_set_payload_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_EVENT_CLASS_STATUS_NOMEM;
                goto end;
        }
 
This page took 0.02761 seconds and 4 git commands to generate.