diff --git a/include/libweston/weston-log.h b/include/libweston/weston-log.h index bda0b7d29..3a437b270 100644 --- a/include/libweston/weston-log.h +++ b/include/libweston/weston-log.h @@ -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 diff --git a/libweston/weston-log.c b/libweston/weston-log.c index de5220e11..9415f053c 100644 --- a/libweston/weston-log.c +++ b/libweston/weston-log.c @@ -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); +}