+ assert(packet);
+
+ packet_context = bt_ctf_packet_get_context(packet);
+ if (!packet_context) {
+ goto end;
+ }
+
+ if (!bt_ctf_field_is_structure(packet_context)) {
+ goto end;
+ }
+
+ timestamp_begin = bt_ctf_field_structure_get_field(
+ packet_context, "timestamp_begin");
+ if (!timestamp_begin || !bt_ctf_field_is_integer(timestamp_begin)) {
+ goto end;
+ }
+ timestamp_end = bt_ctf_field_structure_get_field(
+ packet_context, "timestamp_end");
+ if (!timestamp_end || !bt_ctf_field_is_integer(timestamp_end)) {
+ goto end;
+ }
+
+ ret = ns_from_integer_field(timestamp_begin, &pkt_begin_ns);
+ if (ret) {
+ goto end;
+ }
+ ret = ns_from_integer_field(timestamp_end, &pkt_end_ns);
+ if (ret) {
+ goto end;
+ }
+
+ begin_ns = begin->set ? begin->value : INT64_MIN;
+ end_ns = end->set ? end->value : INT64_MAX;
+
+ /*
+ * Accept if there is any overlap between the selected region and the
+ * packet.
+ */
+ in_range = (pkt_end_ns >= begin_ns) && (pkt_begin_ns <= end_ns);
+end:
+ bt_put(packet);
+ bt_put(packet_context);
+ bt_put(timestamp_begin);
+ bt_put(timestamp_end);
+ return in_range;
+}
+
+/* Return true if the notification should be forwarded. */
+static
+bool evaluate_notification(struct bt_notification *notification,
+ struct trimmer_bound *begin, struct trimmer_bound *end)
+{
+ bool in_range = true;
+ enum bt_notification_type type;
+
+ type = bt_notification_get_type(notification);
+ switch (type) {
+ case BT_NOTIFICATION_TYPE_EVENT:
+ in_range = evaluate_event_notification(notification, begin,
+ end);
+ break;
+ case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
+ case BT_NOTIFICATION_TYPE_PACKET_END:
+ in_range = evaluate_packet_notification(notification, begin,
+ end);
+ break;