-bool compare_notifications(struct bt_notification *a, struct bt_notification *b,
- void *unused)
-{
- static int notification_priorities[] = {
- [BT_NOTIFICATION_TYPE_NEW_TRACE] = 0,
- [BT_NOTIFICATION_TYPE_NEW_STREAM_CLASS] = 1,
- [BT_NOTIFICATION_TYPE_NEW_EVENT_CLASS] = 2,
- [BT_NOTIFICATION_TYPE_PACKET_BEGIN] = 3,
- [BT_NOTIFICATION_TYPE_PACKET_END] = 4,
- [BT_NOTIFICATION_TYPE_EVENT] = 5,
- [BT_NOTIFICATION_TYPE_END_OF_TRACE] = 6,
- };
- int a_prio, b_prio;
- enum bt_notification_type a_type, b_type;
-
- assert(a && b);
- a_type = bt_notification_get_type(a);
- b_type = bt_notification_get_type(b);
- assert(a_type > BT_NOTIFICATION_TYPE_ALL);
- assert(a_type < BT_NOTIFICATION_TYPE_NR);
- assert(b_type > BT_NOTIFICATION_TYPE_ALL);
- assert(b_type < BT_NOTIFICATION_TYPE_NR);
-
- a_prio = notification_priorities[a_type];
- b_prio = notification_priorities[b_type];
-
- if (likely((a_type == b_type) && a_type == BT_NOTIFICATION_TYPE_EVENT)) {
- return compare_event_notifications(a, b);
- }
-
- if (unlikely(a_prio != b_prio)) {
- return a_prio < b_prio;
- }
-
- /* Notification types are equal, but not of type "event". */
- switch (a_type) {
- case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
- case BT_NOTIFICATION_TYPE_PACKET_END:
- case BT_NOTIFICATION_TYPE_STREAM_END:
- {
- int64_t a_sc_id, b_sc_id;
- struct bt_ctf_stream *a_stream, *b_stream;
- struct bt_ctf_stream_class *a_sc, *b_sc;
-
- a_stream = internal_bt_notification_get_stream(a);
- b_stream = internal_bt_notification_get_stream(b);
- assert(a_stream && b_stream);
-
- a_sc = bt_ctf_stream_get_class(a_stream);
- b_sc = bt_ctf_stream_get_class(b_stream);
- assert(a_sc && b_sc);
-
- a_sc_id = bt_ctf_stream_class_get_id(a_sc);
- b_sc_id = bt_ctf_stream_class_get_id(b_sc);
- assert(a_sc_id >= 0 && b_sc_id >= 0);
- bt_put(a_sc);
- bt_put(a_stream);
- bt_put(b_sc);
- bt_put(b_stream);
- return a_sc_id < b_sc_id;
- }
- case BT_NOTIFICATION_TYPE_NEW_TRACE:
- case BT_NOTIFICATION_TYPE_END_OF_TRACE:
- /* Impossible to have two separate traces. */
- default:
- assert(0);
- }
-
- assert(0);
- return a < b;