From 4333c94531acd9379c5ae36a847ce70c755be115 Mon Sep 17 00:00:00 2001 From: Julian Bouzas <julian.bouzas@collabora.com> Date: Mon, 24 Jun 2019 10:52:02 -0400 Subject: [PATCH] endpoint: add async initable interface boilerplate --- lib/wp/endpoint.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++- lib/wp/endpoint.h | 4 ++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/lib/wp/endpoint.c b/lib/wp/endpoint.c index 8a30c5e8..12853e0b 100644 --- a/lib/wp/endpoint.c +++ b/lib/wp/endpoint.c @@ -113,7 +113,37 @@ enum { static guint32 signals[NUM_SIGNALS]; -G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (WpEndpoint, wp_endpoint, G_TYPE_OBJECT) +static void wp_endpoint_async_initable_init (gpointer iface, + gpointer iface_data); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (WpEndpoint, wp_endpoint, G_TYPE_OBJECT, + G_ADD_PRIVATE (WpEndpoint) + G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, + wp_endpoint_async_initable_init)) + +static void +wp_endpoint_init_async (GAsyncInitable *initable, int io_priority, + GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data) +{ +} + +static gboolean +wp_endpoint_init_finish (GAsyncInitable *initable, GAsyncResult *result, + GError **error) +{ + g_return_val_if_fail (g_task_is_valid (result, initable), FALSE); + + return g_task_propagate_boolean (G_TASK (result), error); +} + +static void +wp_endpoint_async_initable_init (gpointer iface, gpointer iface_data) +{ + GAsyncInitableIface *ai_iface = iface; + + ai_iface->init_async = wp_endpoint_init_async; + ai_iface->init_finish = wp_endpoint_init_finish; +} static void wp_endpoint_init (WpEndpoint * self) @@ -253,6 +283,22 @@ wp_endpoint_class_init (WpEndpointClass * klass) G_TYPE_NONE, 1, G_TYPE_UINT); } +/** + * wp_endpoint_new_finish: + * @initable: the #GAsyncInitable from the callback + * @res: the #GAsyncResult from the callback + * @error: return location for errors, or NULL to ignore + * + * Finishes the async construction of #WpEndpoint. + */ +WpEndpoint * +wp_endpoint_new_finish (GObject *initable, GAsyncResult *res, + GError **error) +{ + GAsyncInitable *ai = G_ASYNC_INITABLE(initable); + return WP_ENDPOINT(g_async_initable_new_finish(ai, res, error)); +} + /** * wp_endpoint_register: * @self: the endpoint diff --git a/lib/wp/endpoint.h b/lib/wp/endpoint.h index 1364b776..4c5c4b5a 100644 --- a/lib/wp/endpoint.h +++ b/lib/wp/endpoint.h @@ -9,6 +9,8 @@ #ifndef __WIREPLUMBER_ENDPOINT_H__ #define __WIREPLUMBER_ENDPOINT_H__ +#include <gio/gio.h> + #include "core.h" G_BEGIN_DECLS @@ -37,6 +39,8 @@ struct _WpEndpointClass const gchar * (*get_endpoint_link_factory) (WpEndpoint * self); }; +WpEndpoint * wp_endpoint_new_finish (GObject *initable, GAsyncResult *res, + GError **error); void wp_endpoint_register (WpEndpoint * self); void wp_endpoint_unregister (WpEndpoint * self); GPtrArray * wp_endpoint_find (WpCore * core, const gchar * media_class_lookup); -- GitLab