lib: use object pool for event and packet notifications
[babeltrace.git] / lib / graph / notification / discarded-elements.c
index 69b54035987df9384a5df865fa9f4e28ec35802f..0dfd757966dc070740de2a48a0e501970077e331 100644 (file)
@@ -30,6 +30,7 @@
 #include <babeltrace/graph/clock-class-priority-map-internal.h>
 #include <babeltrace/graph/notification-internal.h>
 #include <babeltrace/graph/notification-discarded-elements-internal.h>
+#include <babeltrace/assert-pre-internal.h>
 #include <stdint.h>
 #include <inttypes.h>
 
@@ -52,25 +53,23 @@ void bt_notification_discarded_elements_destroy(struct bt_object *obj)
 
 BT_HIDDEN
 struct bt_notification *bt_notification_discarded_elements_create(
+               struct bt_graph *graph,
                enum bt_notification_type type,
-               struct bt_ctf_stream *stream,
-               struct bt_ctf_clock_value *begin_clock_value,
-               struct bt_ctf_clock_value *end_clock_value,
+               struct bt_stream *stream,
+               struct bt_clock_value *begin_clock_value,
+               struct bt_clock_value *end_clock_value,
                uint64_t count)
 {
        struct bt_notification_discarded_elements *notification;
        struct bt_notification *ret_notif = NULL;
 
-       if (!stream) {
-               BT_LOGW_STR("Invalid parameter: stream is NULL.");
-       }
-
+       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
        BT_LOGD("Creating discarded elements notification object: "
                "type=%s, stream-addr=%p, stream-name=\"%s\", "
                "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
                "count=%" PRIu64,
                bt_notification_type_string(type), stream,
-               bt_ctf_stream_get_name(stream), begin_clock_value,
+               bt_stream_get_name(stream), begin_clock_value,
                end_clock_value, count);
        notification = g_new0(struct bt_notification_discarded_elements, 1);
        if (!notification) {
@@ -79,7 +78,7 @@ struct bt_notification *bt_notification_discarded_elements_create(
        }
 
        bt_notification_init(&notification->parent, type,
-               bt_notification_discarded_elements_destroy);
+               bt_notification_discarded_elements_destroy, NULL);
        ret_notif = &notification->parent;
        notification->stream = bt_get(stream);
        notification->begin_clock_value = bt_get(begin_clock_value);
@@ -90,7 +89,7 @@ struct bt_notification *bt_notification_discarded_elements_create(
                "begin-clock-value-addr=%p, end-clock-value-addr=%p, "
                "count=%" PRIu64 ", addr=%p",
                bt_notification_type_string(type), stream,
-               bt_ctf_stream_get_name(stream), begin_clock_value,
+               bt_stream_get_name(stream), begin_clock_value,
                end_clock_value, count, ret_notif);
        goto end;
 
@@ -102,65 +101,33 @@ end:
 }
 
 BT_HIDDEN
-struct bt_ctf_clock_value *
-bt_notification_discarded_elements_get_begin_clock_value(
+struct bt_clock_value *
+bt_notification_discarded_elements_borrow_begin_clock_value(
                enum bt_notification_type type,
                struct bt_notification *notification)
 {
-       struct bt_ctf_clock_value *clock_value = NULL;
        struct bt_notification_discarded_elements *discarded_elems_notif;
 
-       if (!notification) {
-               BT_LOGW_STR("Invalid parameter: notification is NULL.");
-               goto end;
-       }
-
-       if (bt_notification_get_type(notification) != type) {
-               BT_LOGW("Invalid parameter: notification has not the expected type: "
-                       "addr%p, expected-type=%s, notif-type=%s",
-                       notification, bt_notification_type_string(type),
-                       bt_notification_type_string(
-                               bt_notification_get_type(notification)));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(notification, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
        discarded_elems_notif = container_of(notification,
                        struct bt_notification_discarded_elements, parent);
-       clock_value = bt_get(discarded_elems_notif->begin_clock_value);
-
-end:
-       return clock_value;
+       return discarded_elems_notif->begin_clock_value;
 }
 
 BT_HIDDEN
-struct bt_ctf_clock_value *
-bt_notification_discarded_elements_get_end_clock_value(
+struct bt_clock_value *
+bt_notification_discarded_elements_borrow_end_clock_value(
                enum bt_notification_type type,
                struct bt_notification *notification)
 {
-       struct bt_ctf_clock_value *clock_value = NULL;
        struct bt_notification_discarded_elements *discarded_elems_notif;
 
-       if (!notification) {
-               BT_LOGW_STR("Invalid parameter: notification is NULL.");
-               goto end;
-       }
-
-       if (bt_notification_get_type(notification) != type) {
-               BT_LOGW("Invalid parameter: notification has not the expected type: "
-                       "addr%p, expected-type=%s, notif-type=%s",
-                       notification, bt_notification_type_string(type),
-                       bt_notification_type_string(
-                               bt_notification_get_type(notification)));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(notification, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
        discarded_elems_notif = container_of(notification,
                        struct bt_notification_discarded_elements, parent);
-       clock_value = bt_get(discarded_elems_notif->end_clock_value);
-
-end:
-       return clock_value;
+       return discarded_elems_notif->end_clock_value;
 }
 
 BT_HIDDEN
@@ -168,57 +135,25 @@ int64_t bt_notification_discarded_elements_get_count(
                enum bt_notification_type type,
                struct bt_notification *notification)
 {
-       int64_t count = (int64_t) -1;
        struct bt_notification_discarded_elements *discarded_elems_notif;
 
-       if (!notification) {
-               BT_LOGW_STR("Invalid parameter: notification is NULL.");
-               goto end;
-       }
-
-       if (bt_notification_get_type(notification) != type) {
-               BT_LOGW("Invalid parameter: notification has not the expected type: "
-                       "addr%p, expected-type=%s, notif-type=%s",
-                       notification, bt_notification_type_string(type),
-                       bt_notification_type_string(
-                               bt_notification_get_type(notification)));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(notification, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
        discarded_elems_notif = container_of(notification,
                        struct bt_notification_discarded_elements, parent);
-       count = discarded_elems_notif->count;
-
-end:
-       return count;
+       return discarded_elems_notif->count;
 }
 
 BT_HIDDEN
-struct bt_ctf_stream *bt_notification_discarded_elements_get_stream(
+struct bt_stream *bt_notification_discarded_elements_borrow_stream(
                enum bt_notification_type type,
                struct bt_notification *notification)
 {
-       struct bt_ctf_stream *stream = NULL;
        struct bt_notification_discarded_elements *discarded_elems_notif;
 
-       if (!notification) {
-               BT_LOGW_STR("Invalid parameter: notification is NULL.");
-               goto end;
-       }
-
-       if (bt_notification_get_type(notification) != type) {
-               BT_LOGW("Invalid parameter: notification has not the expected type: "
-                       "addr%p, expected-type=%s, notif-type=%s",
-                       notification, bt_notification_type_string(type),
-                       bt_notification_type_string(
-                               bt_notification_get_type(notification)));
-               goto end;
-       }
-
+       BT_ASSERT_PRE_NON_NULL(notification, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, type);
        discarded_elems_notif = container_of(notification,
                        struct bt_notification_discarded_elements, parent);
-       stream = bt_get(discarded_elems_notif->stream);
-
-end:
-       return stream;
+       return discarded_elems_notif->stream;
 }
This page took 0.030728 seconds and 4 git commands to generate.