weston-log: Add a subscription iterator
authorMarius Vlad <marius.vlad@collabora.com>
Tue, 6 Aug 2019 16:22:53 +0000 (19:22 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Thu, 17 Oct 2019 16:42:55 +0000 (19:42 +0300)
Helper to retrieve next available subscription as to avoid exposing the
subscription, which is an opaque (internal) class of the logging
framework.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Suggested-by: Daniel Stone <daniel.stone@collabora.com>
include/libweston/weston-log.h
libweston/weston-log.c

index bda0b7d29cb2c0eecbd9dae116baf3a270719033..3a437b270a214e7fac10d59a67978ac61822bebb 100644 (file)
@@ -122,6 +122,10 @@ weston_log_subscriber_destroy_flight_rec(struct weston_log_subscriber *sub);
 void
 weston_log_subscriber_display_flight_rec(struct weston_log_subscriber *sub);
 
+struct weston_log_subscription *
+weston_log_subscription_iterate(struct weston_log_scope *scope,
+                               struct weston_log_subscription *sub_iter);
+
 #ifdef  __cplusplus
 }
 #endif
index de5220e1162c88e5d6f1fa83bef8a4601a58090c..9415f053c1ada170c4f33c366202ccd75bb4ab60 100644 (file)
@@ -927,3 +927,36 @@ weston_log_subscribe(struct weston_log_context *log_ctx,
                 */
                weston_log_subscription_create_pending(subscriber, scope_name, log_ctx);
 }
+
+/** Iterate over all subscriptions in a scope
+ *
+ * @param scope the scope for which you want to iterate
+ * @param sub_iter the iterator, use NULL to start from the 'head'
+ * @returns the next subscription from the log scope
+ *
+ * This is (quite) useful when 'log_scope' and 'log_subscription' are opaque. Do note
+ * that \c sub_iter needs to be NULL-initialized before calling this function.
+ *
+ */
+WL_EXPORT struct weston_log_subscription *
+weston_log_subscription_iterate(struct weston_log_scope *scope,
+                               struct weston_log_subscription *sub_iter)
+{
+       struct wl_list *list = &scope->subscription_list;
+       struct wl_list *node;
+
+       /* go to the next item in the list or if not set starts with the head */
+       if (sub_iter)
+               node = sub_iter->source_link.next;
+       else
+               node = list->next;
+
+       assert(node);
+       assert(!sub_iter || node != &sub_iter->source_link);
+
+       /* if we're at the end */
+       if (node == list)
+               return NULL;
+
+       return container_of(node, struct weston_log_subscription, source_link);
+}