+ struct trimmer_iterator *trim_it;
+
+ trim_it = bt_notification_iterator_get_private_data(iterator);
+ assert(trim_it);
+
+ if (!trim_it->current_notification) {
+ enum bt_notification_iterator_status it_ret;
+
+ it_ret = trimmer_iterator_next(iterator);
+ if (it_ret) {
+ goto end;
+ }
+ }
+end:
+ return bt_get(trim_it->current_notification);
+}
+
+/*
+ * Remove me. This is a temporary work-around due to our inhability to use
+ * libbabeltrace-ctf from libbabeltrace-plugin.
+ */
+static
+struct bt_ctf_stream *internal_bt_notification_get_stream(
+ struct bt_notification *notification)
+{
+ struct bt_ctf_stream *stream = NULL;
+
+ assert(notification);
+ switch (bt_notification_get_type(notification)) {
+ case BT_NOTIFICATION_TYPE_EVENT:
+ {
+ struct bt_ctf_event *event;
+
+ event = bt_notification_event_get_event(notification);
+ stream = bt_ctf_event_get_stream(event);
+ bt_put(event);
+ break;
+ }
+ case BT_NOTIFICATION_TYPE_PACKET_START:
+ {
+ struct bt_ctf_packet *packet;
+
+ packet = bt_notification_packet_start_get_packet(notification);
+ stream = bt_ctf_packet_get_stream(packet);
+ bt_put(packet);
+ break;
+ }
+ case BT_NOTIFICATION_TYPE_PACKET_END:
+ {
+ struct bt_ctf_packet *packet;
+
+ packet = bt_notification_packet_end_get_packet(notification);
+ stream = bt_ctf_packet_get_stream(packet);
+ bt_put(packet);
+ break;
+ }
+ case BT_NOTIFICATION_TYPE_STREAM_END:
+ stream = bt_notification_stream_end_get_stream(notification);
+ break;
+ default:
+ goto end;
+ }
+end:
+ return stream;
+}
+
+/* Return true if the notification should be forwarded. */
+static
+bool evaluate_notification(struct bt_notification *notification,
+ struct trimmer *trimmer, struct trimmer_iterator *it)
+{
+ bool ret = true;
+ struct bt_ctf_clock *clock = NULL;
+ enum bt_notification_type type;
+ struct bt_ctf_trace *trace = NULL;
+ struct bt_ctf_stream *stream = NULL;
+ struct bt_ctf_stream_class *stream_class = NULL;
+ struct bt_ctf_clock_value *clock_value = NULL;
+
+ stream = internal_bt_notification_get_stream(notification);
+ if (!stream) {
+ goto end;
+ }
+
+ stream_class = bt_ctf_stream_get_class(stream);
+ assert(stream_class);
+ trace = bt_ctf_stream_class_get_trace(stream_class);
+ assert(trace);
+
+ type = bt_notification_get_type(notification);
+ switch (type) {
+ case BT_NOTIFICATION_TYPE_EVENT:
+ {
+ int64_t ts;
+ int clock_ret;
+ struct bt_ctf_event *event;
+
+ clock = bt_ctf_trace_get_clock(trace, 0);
+ if (!clock) {
+ goto end;
+ }
+
+ event = bt_notification_event_get_event(notification);
+ assert(event);
+ clock_value = bt_ctf_event_get_clock_value(event, clock);
+ if (!clock_value) {
+ printf_error("Failed to retrieve clock value\n");
+ bt_put(event);
+ goto end;
+ }
+
+ clock_ret = bt_ctf_clock_value_get_value_ns_from_epoch(
+ clock_value, &ts);
+ if (clock_ret) {
+ printf_error("Failed to retrieve clock value timestamp\n");
+ goto end;
+ }
+
+ if (trimmer->begin.set && ts < trimmer->begin.value) {
+ ret = false;
+ }
+ if (trimmer->end.set && ts > trimmer->end.value) {
+ ret = false;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+end:
+ bt_put(clock);
+ bt_put(trace);
+ bt_put(stream);
+ bt_put(clock_value);
+ return ret;