Add `-internal` suffix to all internal header files
[babeltrace.git] / lib / component / notification / event.c
index 93833a22f55fce24e1add9bed4ce9ed56cad7322..a9fbf48bd56a6c9c8183f3380e0d100db92fe05a 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/compiler.h>
-#include <babeltrace/component/notification/event-internal.h>
+#include <babeltrace/compiler-internal.h>
+#include <babeltrace/ctf-ir/event.h>
+#include <babeltrace/ctf-ir/event-internal.h>
+#include <babeltrace/ctf-ir/event-class.h>
+#include <babeltrace/ctf-ir/stream-class.h>
+#include <babeltrace/ctf-ir/trace.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
+#include <babeltrace/graph/notification-event-internal.h>
 
 static
 void bt_notification_event_destroy(struct bt_object *obj)
@@ -34,19 +40,71 @@ void bt_notification_event_destroy(struct bt_object *obj)
                        (struct bt_notification_event *) obj;
 
        BT_PUT(notification->event);
+       BT_PUT(notification->cc_prio_map);
        g_free(notification);
 }
 
-struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event)
+static
+bool validate_clock_classes(struct bt_notification_event *notif)
 {
-       struct bt_notification_event *notification;
+       /*
+        * For each clock class found in the event's trace, get the
+        * event's clock value for this clock class, and if it exists,
+        * make sure that this clock class has a priority in the
+        * notification's clock class priority map.
+        */
+       bool is_valid = true;
+       int ret;
+       int count;
+       size_t i;
+       struct bt_ctf_event_class *event_class = NULL;
+       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_ctf_trace *trace = NULL;
+       uint64_t prio;
+
+       event_class = bt_ctf_event_get_class(notif->event);
+       assert(event_class);
+       stream_class = bt_ctf_event_class_get_stream_class(event_class);
+       assert(stream_class);
+       trace = bt_ctf_stream_class_get_trace(stream_class);
+       assert(trace);
+       count = bt_ctf_trace_get_clock_class_count(trace);
+       assert(count >= 0);
+
+       for (i = 0; i < count; i++) {
+               struct bt_ctf_clock_class *clock_class =
+                       bt_ctf_trace_get_clock_class(trace, i);
+
+               assert(clock_class);
+               ret = bt_clock_class_priority_map_get_clock_class_priority(
+                       notif->cc_prio_map, clock_class, &prio);
+               bt_put(clock_class);
+               if (ret) {
+                       is_valid = false;
+                       goto end;
+               }
+       }
+
+end:
+       bt_put(trace);
+       bt_put(stream_class);
+       bt_put(event_class);
+       return is_valid;
+}
 
-       if (!event) {
+struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event,
+               struct bt_clock_class_priority_map *cc_prio_map)
+{
+       struct bt_notification_event *notification = NULL;
+
+       if (!event || !cc_prio_map) {
+               goto error;
+       }
+
+       if (!bt_ctf_event_borrow_packet(event)) {
                goto error;
        }
 
-       // FIXME - Validate that the event is associated to a packet
-       //         and freeze the event.
        notification = g_new0(struct bt_notification_event, 1);
        if (!notification) {
                goto error;
@@ -55,8 +113,15 @@ struct bt_notification *bt_notification_event_create(struct bt_ctf_event *event)
                        BT_NOTIFICATION_TYPE_EVENT,
                        bt_notification_event_destroy);
        notification->event = bt_get(event);
+       notification->cc_prio_map = bt_get(cc_prio_map);
+       if (!validate_clock_classes(notification)) {
+               goto error;
+       }
+
+       bt_ctf_event_freeze(notification->event);
        return &notification->parent;
 error:
+       bt_put(notification);
        return NULL;
 }
 
@@ -76,3 +141,22 @@ struct bt_ctf_event *bt_notification_event_get_event(
 end:
        return event;
 }
+
+extern struct bt_clock_class_priority_map *
+bt_notification_event_get_clock_class_priority_map(
+               struct bt_notification *notification)
+{
+       struct bt_clock_class_priority_map *cc_prio_map = NULL;
+       struct bt_notification_event *event_notification;
+
+       if (bt_notification_get_type(notification) !=
+                       BT_NOTIFICATION_TYPE_EVENT) {
+               goto end;
+       }
+
+       event_notification = container_of(notification,
+                       struct bt_notification_event, parent);
+       cc_prio_map = bt_get(event_notification->cc_prio_map);
+end:
+       return cc_prio_map;
+}
This page took 0.023981 seconds and 4 git commands to generate.