weston-debug: Make it easier to separate weston_debug_stream
authorMarius Vlad <marius.vlad@collabora.com>
Fri, 21 Jun 2019 11:57:02 +0000 (14:57 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Thu, 18 Jul 2019 07:49:39 +0000 (10:49 +0300)
This way we can split easier weston_debug_stream into a separate file.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
libweston/weston-debug.c
libweston/weston-log-internal.h

index 6ca92ef2ef04fc6ce2a145d8a50d3be474072d56..ed41850e8f17db69b9211df0b91707b57f57a5cf 100644 (file)
@@ -240,19 +240,52 @@ weston_log_subscription_remove(struct weston_log_subscription *sub)
        sub->source = NULL;
 }
 
-
-static struct weston_log_scope *
-get_scope(struct weston_log_context *log_ctx, const char *name)
+/** Look-up the scope from the scope list  stored in the log context, by
+ * matching against the \c name.
+ *
+ * @param log_ctx
+ * @param name the scope name, see weston_compositor_add_log_scope()
+ * @returns NULL if none found, or a pointer to a weston_log_scope
+ *
+ * @internal
+ */
+struct weston_log_scope *
+weston_log_get_scope(struct weston_log_context *log_ctx, const char *name)
 {
        struct weston_log_scope *scope;
-
        wl_list_for_each(scope, &log_ctx->scope_list, compositor_link)
                if (strcmp(name, scope->name) == 0)
                        return scope;
-
        return NULL;
 }
 
+/** Wrapper to invoke the weston_log_scope_cb. Allows to call the begin_cb of
+ * a log scope.
+ *
+ * @internal
+ */
+void
+weston_log_run_begin_cb(struct weston_log_scope *scope)
+{
+       if (scope->begin_cb)
+               scope->begin_cb(scope, scope->user_data);
+}
+
+/** Advertise the log scope name and the log scope description
+ *
+ * This is only used by the weston-debug protocol!
+ *
+ * @internal
+ */
+void
+weston_debug_protocol_advertise_scopes(struct weston_log_context *log_ctx,
+                                      struct wl_resource *res)
+{
+       struct weston_log_scope *scope;
+       wl_list_for_each(scope, &log_ctx->scope_list, compositor_link)
+               weston_debug_v1_send_available(res, scope->name, scope->desc);
+}
+
 static void
 stream_close_unlink(struct weston_debug_stream *stream)
 {
@@ -379,7 +412,7 @@ stream_create(struct weston_log_context *log_ctx, const char *name,
 
        sub = weston_log_subscription_create(&stream->base, name);
 
-       scope = get_scope(log_ctx, name);
+       scope = weston_log_get_scope(log_ctx, name);
        if (scope) {
                weston_log_subscription_add(scope, sub);
                if (scope->begin_cb)
@@ -475,7 +508,6 @@ bind_weston_debug(struct wl_client *client,
                   void *data, uint32_t version, uint32_t id)
 {
        struct weston_log_context *log_ctx = data;
-       struct weston_log_scope *scope;
        struct wl_resource *resource;
 
        resource = wl_resource_create(client,
@@ -488,10 +520,7 @@ bind_weston_debug(struct wl_client *client,
        wl_resource_set_implementation(resource, &weston_debug_impl,
                                       log_ctx, NULL);
 
-       wl_list_for_each(scope, &log_ctx->scope_list, compositor_link) {
-               weston_debug_v1_send_available(resource, scope->name,
-                                              scope->desc);
-       }
+       weston_debug_protocol_advertise_scopes(log_ctx, resource);
 }
 
 /**
@@ -664,7 +693,7 @@ weston_compositor_add_log_scope(struct weston_log_context *log_ctx,
                return NULL;
        }
 
-       if (get_scope(log_ctx, name)){
+       if (weston_log_get_scope(log_ctx, name)){
                weston_log("Error: debug scope named '%s' is already registered.\n",
                           name);
                return NULL;
index b1ea5273faaa6e6333e365b9dfed491fd72bace9..84f1f10aa987dbd7080655c96bc61190aad58595 100644 (file)
@@ -77,4 +77,14 @@ weston_log_subscription_add(struct weston_log_scope *scope,
 void
 weston_log_subscription_remove(struct weston_log_subscription *sub);
 
+struct weston_log_scope *
+weston_log_get_scope(struct weston_log_context *log_ctx, const char *name);
+
+void
+weston_log_run_begin_cb(struct weston_log_scope *scope);
+
+void
+weston_debug_protocol_advertise_scopes(struct weston_log_context *log_ctx,
+                                      struct wl_resource *res);
+
 #endif /* WESTON_LOG_INTERNAL_H */