lib: make graph API const-correct
[babeltrace.git] / lib / graph / notification / stream.c
index 40c245b53b7d4e231bfa446de8aff130433f1b43..92336b27318c99572cae8d59a8f4cf1bcb41a8a0 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * Babeltrace Plug-in Stream-related Notifications
- *
  * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
 #define BT_LOG_TAG "NOTIF-STREAM"
 #include <babeltrace/lib-logging-internal.h>
 
+#include <babeltrace/assert-pre-internal.h>
 #include <babeltrace/compiler-internal.h>
-#include <babeltrace/ctf-ir/stream-internal.h>
+#include <babeltrace/trace-ir/stream-internal.h>
+#include <babeltrace/trace-ir/stream-class.h>
+#include <babeltrace/trace-ir/stream-class-internal.h>
+#include <babeltrace/graph/notification-stream.h>
+#include <babeltrace/graph/notification-stream-const.h>
 #include <babeltrace/graph/notification-stream-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/object.h>
 #include <inttypes.h>
 
 static
@@ -38,46 +43,32 @@ void bt_notification_stream_end_destroy(struct bt_object *obj)
        struct bt_notification_stream_end *notification =
                        (struct bt_notification_stream_end *) obj;
 
-       BT_LOGD("Destroying stream end notification: addr=%p",
+       BT_LIB_LOGD("Destroying stream end notification: %!+n",
                notification);
-       BT_LOGD_STR("Putting stream.");
-       BT_PUT(notification->stream);
+       BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
+       BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
+
+       if (notification->default_cv) {
+               bt_clock_value_recycle(notification->default_cv);
+               notification->default_cv = NULL;
+       }
+
        g_free(notification);
 }
 
 struct bt_notification *bt_notification_stream_end_create(
-               struct bt_ctf_stream *stream)
+               struct bt_self_notification_iterator *self_notif_iter,
+               struct bt_stream *stream)
 {
        struct bt_notification_stream_end *notification;
-       struct bt_ctf_stream_class *stream_class;
-
-       if (!stream) {
-               BT_LOGW_STR("Invalid parameter: stream is NULL.");
-               goto error;
-       }
-
-       stream_class = bt_ctf_stream_borrow_stream_class(stream);
-       assert(stream_class);
-
-       if (stream->pos.fd >= 0) {
-               BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
-                       "stream-addr=%p, stream-name=\"%s\", "
-                       "stream-class-addr=%p, stream-class-name\"%s\", "
-                       "stream-class-id=%" PRId64,
-                       stream, bt_ctf_stream_get_name(stream), stream_class,
-                       bt_ctf_stream_class_get_name(stream_class),
-                       bt_ctf_stream_class_get_id(stream_class));
-               goto error;
-       }
-
-       BT_LOGD("Creating stream end notification object: "
-               "stream-addr=%p, stream-name=\"%s\", "
-               "stream-class-addr=%p, stream-class-name=\"%s\", "
-               "stream-class-id=%" PRId64,
-               stream, bt_ctf_stream_get_name(stream),
-               stream_class,
-               bt_ctf_stream_class_get_name(stream_class),
-               bt_ctf_stream_class_get_id(stream_class));
+       struct bt_stream_class *stream_class;
+
+       BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
+       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+       stream_class = bt_stream_borrow_class(stream);
+       BT_ASSERT(stream_class);
+       BT_LIB_LOGD("Creating stream end notification object: "
+               "%![stream-]+s, %![sc-]+S", stream, stream_class);
        notification = g_new0(struct bt_notification_stream_end, 1);
        if (!notification) {
                BT_LOGE_STR("Failed to allocate one stream end notification.");
@@ -86,46 +77,66 @@ struct bt_notification *bt_notification_stream_end_create(
 
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_STREAM_END,
-                       bt_notification_stream_end_destroy);
-       notification->stream = bt_get(stream);
-       BT_LOGD("Created stream end notification object: "
-               "stream-addr=%p, stream-name=\"%s\", "
-               "stream-class-addr=%p, stream-class-name=\"%s\", "
-               "stream-class-id=%" PRId64 ", addr=%p",
-               stream, bt_ctf_stream_get_name(stream),
-               stream_class,
-               bt_ctf_stream_class_get_name(stream_class),
-               bt_ctf_stream_class_get_id(stream_class), notification);
-       return &notification->parent;
+                       bt_notification_stream_end_destroy, NULL);
+       notification->stream = stream;
+       bt_object_get_no_null_check(notification->stream);
+       BT_LIB_LOGD("Created stream end notification object: "
+               "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
+               stream, stream_class);
+
+       return (void *) &notification->parent;
 error:
        return NULL;
 }
 
-struct bt_ctf_stream *bt_notification_stream_end_get_stream(
+struct bt_stream *bt_notification_stream_end_borrow_stream(
                struct bt_notification *notification)
 {
        struct bt_notification_stream_end *stream_end;
-       struct bt_ctf_stream *stream = NULL;
 
-       if (!notification) {
-               BT_LOGW_STR("Invalid parameter: notification is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(notification, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
+               BT_NOTIFICATION_TYPE_STREAM_END);
+       stream_end = (void *) notification;
+       return stream_end->stream;
+}
 
-       if (notification->type != BT_NOTIFICATION_TYPE_STREAM_END) {
-               BT_LOGW("Invalid parameter: notification is not a stream end notification: "
-                       "addr%p, notif-type=%s",
-                       notification, bt_notification_type_string(
-                               bt_notification_get_type(notification)));
-               goto end;
-       }
+const struct bt_stream *bt_notification_stream_end_borrow_stream_const(
+               const struct bt_notification *notification)
+{
+       return bt_notification_stream_end_borrow_stream(
+               (void *) notification);
+}
 
-       stream_end = container_of(notification,
-                       struct bt_notification_stream_end, parent);
-       stream = bt_get(stream_end->stream);
+void bt_notification_stream_end_set_default_clock_value(
+               struct bt_notification *notif, uint64_t value_cycles)
+{
+       struct bt_notification_stream_end *se_notif = (void *) notif;
+
+       BT_ASSERT_PRE_NON_NULL(notif, "Notification");
+       BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
+       BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
+               "Notification's stream class has no default clock class: "
+               "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
+
+       /* TODO: have the object already created */
+       se_notif->default_cv = bt_clock_value_create(
+               se_notif->stream->class->default_clock_class);
+       BT_ASSERT(se_notif->default_cv);
+       bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
+       BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
+               "value=%" PRIu64, value_cycles);
+}
+
+struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
+               struct bt_notification *notif)
+{
+       struct bt_notification_stream_end *stream_end = (void *) notif;
 
-end:
-       return stream;
+       BT_ASSERT_PRE_NON_NULL(notif, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
+       return stream_end->default_cv;
 }
 
 static
@@ -134,46 +145,32 @@ void bt_notification_stream_begin_destroy(struct bt_object *obj)
        struct bt_notification_stream_begin *notification =
                        (struct bt_notification_stream_begin *) obj;
 
-       BT_LOGD("Destroying stream beginning notification: addr=%p",
+       BT_LIB_LOGD("Destroying stream beginning notification: %!+n",
                notification);
-       BT_LOGD_STR("Putting stream.");
-       BT_PUT(notification->stream);
+       BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
+       BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
+
+       if (notification->default_cv) {
+               bt_clock_value_recycle(notification->default_cv);
+               notification->default_cv = NULL;
+       }
+
        g_free(notification);
 }
 
 struct bt_notification *bt_notification_stream_begin_create(
-               struct bt_ctf_stream *stream)
+               struct bt_self_notification_iterator *self_notif_iter,
+               struct bt_stream *stream)
 {
        struct bt_notification_stream_begin *notification;
-       struct bt_ctf_stream_class *stream_class;
-
-       if (!stream) {
-               BT_LOGW_STR("Invalid parameter: stream is NULL.");
-               goto error;
-       }
-
-       stream_class = bt_ctf_stream_borrow_stream_class(stream);
-       assert(stream_class);
-
-       if (stream->pos.fd >= 0) {
-               BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
-                       "stream-addr=%p, stream-name=\"%s\", "
-                       "stream-class-addr=%p, stream-class-name\"%s\", "
-                       "stream-class-id=%" PRId64,
-                       stream, bt_ctf_stream_get_name(stream), stream_class,
-                       bt_ctf_stream_class_get_name(stream_class),
-                       bt_ctf_stream_class_get_id(stream_class));
-               goto error;
-       }
-
-       BT_LOGD("Creating stream beginning notification object: "
-               "stream-addr=%p, stream-name=\"%s\", "
-               "stream-class-addr=%p, stream-class-name=\"%s\", "
-               "stream-class-id=%" PRId64,
-               stream, bt_ctf_stream_get_name(stream),
-               stream_class,
-               bt_ctf_stream_class_get_name(stream_class),
-               bt_ctf_stream_class_get_id(stream_class));
+       struct bt_stream_class *stream_class;
+
+       BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
+       BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+       stream_class = bt_stream_borrow_class(stream);
+       BT_ASSERT(stream_class);
+       BT_LIB_LOGD("Creating stream beginning notification object: "
+               "%![stream-]+s, %![sc-]+S", stream, stream_class);
        notification = g_new0(struct bt_notification_stream_begin, 1);
        if (!notification) {
                BT_LOGE_STR("Failed to allocate one stream beginning notification.");
@@ -182,44 +179,64 @@ struct bt_notification *bt_notification_stream_begin_create(
 
        bt_notification_init(&notification->parent,
                        BT_NOTIFICATION_TYPE_STREAM_BEGIN,
-                       bt_notification_stream_begin_destroy);
-       notification->stream = bt_get(stream);
-       BT_LOGD("Created stream beginning notification object: "
-               "stream-addr=%p, stream-name=\"%s\", "
-               "stream-class-addr=%p, stream-class-name=\"%s\", "
-               "stream-class-id=%" PRId64 ", addr=%p",
-               stream, bt_ctf_stream_get_name(stream),
-               stream_class,
-               bt_ctf_stream_class_get_name(stream_class),
-               bt_ctf_stream_class_get_id(stream_class), notification);
-       return &notification->parent;
+                       bt_notification_stream_begin_destroy, NULL);
+       notification->stream = stream;
+       bt_object_get_no_null_check(notification->stream);
+       BT_LIB_LOGD("Created stream beginning notification object: "
+               "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
+               stream, stream_class);
+       return (void *) &notification->parent;
 error:
        return NULL;
 }
 
-struct bt_ctf_stream *bt_notification_stream_begin_get_stream(
+struct bt_stream *bt_notification_stream_begin_borrow_stream(
                struct bt_notification *notification)
 {
        struct bt_notification_stream_begin *stream_begin;
-       struct bt_ctf_stream *stream = NULL;
 
-       if (!notification) {
-               BT_LOGW_STR("Invalid parameter: notification is NULL.");
-               goto end;
-       }
+       BT_ASSERT_PRE_NON_NULL(notification, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
+               BT_NOTIFICATION_TYPE_STREAM_BEGIN);
+       stream_begin = (void *) notification;
+       return stream_begin->stream;
+}
 
-       if (notification->type != BT_NOTIFICATION_TYPE_STREAM_BEGIN) {
-               BT_LOGW("Invalid parameter: notification is not a stream beginning notification: "
-                       "addr%p, notif-type=%s",
-                       notification, bt_notification_type_string(
-                               bt_notification_get_type(notification)));
-               goto end;
-       }
+const struct bt_stream *bt_notification_stream_begin_borrow_stream_const(
+               const struct bt_notification *notification)
+{
+       return bt_notification_stream_begin_borrow_stream(
+               (void *) notification);
+}
 
-       stream_begin = container_of(notification,
-                       struct bt_notification_stream_begin, parent);
-       stream = bt_get(stream_begin->stream);
+void bt_notification_stream_begin_set_default_clock_value(
+               struct bt_notification *notif,
+               uint64_t value_cycles)
+{
+       struct bt_notification_stream_begin *sb_notif = (void *) notif;
+
+       BT_ASSERT_PRE_NON_NULL(notif, "Notification");
+       BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
+       BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
+               "Notification's stream class has no default clock class: "
+               "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
+
+       /* TODO: have the object already created */
+       sb_notif->default_cv = bt_clock_value_create(
+               sb_notif->stream->class->default_clock_class);
+       BT_ASSERT(sb_notif->default_cv);
+       bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
+       BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
+               "value=%" PRIu64, value_cycles);
+}
+
+struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
+               struct bt_notification *notif)
+{
+       struct bt_notification_stream_begin *stream_begin = (void *) notif;
 
-end:
-       return stream;
+       BT_ASSERT_PRE_NON_NULL(notif, "Notification");
+       BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
+       return stream_begin->default_cv;
 }
This page took 0.026513 seconds and 4 git commands to generate.