From 37134df7c8dbbe1f10f768459355f665bd2f59f8 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis <george.kiagiadakis@collabora.com> Date: Sun, 15 Nov 2020 20:23:48 +0200 Subject: [PATCH] iterator: make private stuff public, cleanup private.h further There is no good reason to keep them private --- lib/wp/configuration.c | 2 +- lib/wp/core.c | 2 +- lib/wp/debug.c | 1 + lib/wp/iterator.c | 23 ++++++++++++++++++++++- lib/wp/iterator.h | 21 +++++++++++++++++++++ lib/wp/metadata.c | 1 - lib/wp/module.c | 2 +- lib/wp/object-interest.c | 3 ++- lib/wp/object-manager.c | 3 ++- lib/wp/plugin.c | 2 +- lib/wp/private.h | 19 ------------------- lib/wp/properties.c | 1 - lib/wp/si-factory.c | 2 +- 13 files changed, 53 insertions(+), 29 deletions(-) diff --git a/lib/wp/configuration.c b/lib/wp/configuration.c index 4b046349..5303d353 100644 --- a/lib/wp/configuration.c +++ b/lib/wp/configuration.c @@ -16,7 +16,7 @@ #include "configuration.h" #include "debug.h" -#include "private.h" +#include "private/registry.h" struct _WpConfiguration { diff --git a/lib/wp/core.c b/lib/wp/core.c index e5517fe5..7f9ccd39 100644 --- a/lib/wp/core.c +++ b/lib/wp/core.c @@ -28,7 +28,7 @@ #include "core.h" #include "wp.h" -#include "private.h" +#include "private/registry.h" #include <pipewire/pipewire.h> diff --git a/lib/wp/debug.c b/lib/wp/debug.c index edc568b7..78ac2cbd 100644 --- a/lib/wp/debug.c +++ b/lib/wp/debug.c @@ -13,6 +13,7 @@ #include "debug.h" #include "spa-pod.h" +#include "proxy.h" #include "private.h" #include <pipewire/pipewire.h> #include <spa/support/log.h> diff --git a/lib/wp/iterator.c b/lib/wp/iterator.c index 21d73ca3..cdd54dd0 100644 --- a/lib/wp/iterator.c +++ b/lib/wp/iterator.c @@ -8,8 +8,8 @@ #define G_LOG_DOMAIN "wp-iterator" -#include "private.h" #include "iterator.h" +#include <spa/utils/defs.h> struct _WpIterator { @@ -58,6 +58,19 @@ wp_iterator_default_foreach (WpIterator *self, WpIteratorForeachFunc func, return wp_iterator_fold (self, foreach_fold_func, NULL, &d); } +/** + * wp_iterator_new: + * @methods: method implementations for the new iterator + * @user_size: size of the user_data structure to be allocated + * + * Constructs an iterator that uses the provided @methods to implement its API. + * The WpIterator structure is internally allocated with @user_size additional + * space at the end. A pointer to this space can be retrieved with + * wp_iterator_get_user_data() and is available for implementation-specific + * storage. + * + * Returns: (transfer full): a new custom iterator + */ WpIterator * wp_iterator_new (const WpIteratorMethods *methods, size_t user_size) { @@ -73,6 +86,14 @@ wp_iterator_new (const WpIteratorMethods *methods, size_t user_size) return self; } +/** + * wp_iterator_get_user_data: + * @self: an iterator object + * + * Note: this only for use by implementations of WpIterator + * + * Returns: a pointer to the implementation-specific storage area + */ gpointer wp_iterator_get_user_data (WpIterator *self) { diff --git a/lib/wp/iterator.h b/lib/wp/iterator.h index 613ae2f7..ffa34799 100644 --- a/lib/wp/iterator.h +++ b/lib/wp/iterator.h @@ -46,6 +46,18 @@ WP_API GType wp_iterator_get_type (void); typedef struct _WpIterator WpIterator; +typedef struct _WpIteratorMethods WpIteratorMethods; + +struct _WpIteratorMethods +{ + void (*reset) (WpIterator *self); + gboolean (*next) (WpIterator *self, GValue *item); + gboolean (*fold) (WpIterator *self, WpIteratorFoldFunc func, + GValue *ret, gpointer data); + gboolean (*foreach) (WpIterator *self, WpIteratorForeachFunc func, + gpointer data); + void (*finalize) (WpIterator *self); +}; /* ref count */ @@ -76,6 +88,15 @@ gboolean wp_iterator_foreach (WpIterator *self, WpIteratorForeachFunc func, WP_API WpIterator * wp_iterator_new_ptr_array (GPtrArray * items, GType item_type); +WP_API +WpIterator * wp_iterator_new (const WpIteratorMethods * methods, + size_t user_size); + +/* private */ + +WP_API +gpointer wp_iterator_get_user_data (WpIterator * self); + G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpIterator, wp_iterator_unref) G_END_DECLS diff --git a/lib/wp/metadata.c b/lib/wp/metadata.c index c578c8c3..7ff81b3e 100644 --- a/lib/wp/metadata.c +++ b/lib/wp/metadata.c @@ -18,7 +18,6 @@ #include "debug.h" #include "error.h" #include "wpenums.h" -#include "private.h" #include <pipewire/pipewire.h> #include <pipewire/extensions/metadata.h> diff --git a/lib/wp/module.c b/lib/wp/module.c index 05f4746a..6c84b152 100644 --- a/lib/wp/module.c +++ b/lib/wp/module.c @@ -44,7 +44,7 @@ #include "module.h" #include "debug.h" #include "error.h" -#include "private.h" +#include "private/registry.h" #include <gmodule.h> #define WP_MODULE_INIT_SYMBOL "wireplumber__module_init" diff --git a/lib/wp/object-interest.c b/lib/wp/object-interest.c index b9f7a70a..2c268413 100644 --- a/lib/wp/object-interest.c +++ b/lib/wp/object-interest.c @@ -18,7 +18,8 @@ #include "proxy-interfaces.h" #include "debug.h" #include "error.h" -#include "private.h" + +#include <pipewire/pipewire.h> struct constraint { diff --git a/lib/wp/object-manager.c b/lib/wp/object-manager.c index 51b3232d..85c07c86 100644 --- a/lib/wp/object-manager.c +++ b/lib/wp/object-manager.c @@ -41,7 +41,8 @@ #include "object-manager.h" #include "debug.h" -#include "private.h" +#include "private/registry.h" + #include <pipewire/pipewire.h> /* WpObjectManager */ diff --git a/lib/wp/plugin.c b/lib/wp/plugin.c index e5d0edb9..62dc4e41 100644 --- a/lib/wp/plugin.c +++ b/lib/wp/plugin.c @@ -14,7 +14,7 @@ #define G_LOG_DOMAIN "wp-plugin" #include "plugin.h" -#include "private.h" +#include "private/registry.h" enum { PROP_0, diff --git a/lib/wp/private.h b/lib/wp/private.h index 33447682..792bb977 100644 --- a/lib/wp/private.h +++ b/lib/wp/private.h @@ -14,9 +14,7 @@ #include "props.h" #include "proxy.h" #include "session-item.h" -#include "iterator.h" #include "spa-type.h" -#include "private/registry.h" #include <stdint.h> #include <pipewire/pipewire.h> @@ -31,23 +29,6 @@ struct spa_pod_builder; void wp_props_handle_proxy_param_event (WpProps * self, guint32 id, WpSpaPod * pod); -/* iterator */ - -struct _WpIteratorMethods { - void (*reset) (WpIterator *self); - gboolean (*next) (WpIterator *self, GValue *item); - gboolean (*fold) (WpIterator *self, WpIteratorFoldFunc func, - GValue *ret, gpointer data); - gboolean (*foreach) (WpIterator *self, WpIteratorForeachFunc func, - gpointer data); - void (*finalize) (WpIterator *self); -}; -typedef struct _WpIteratorMethods WpIteratorMethods; - -WpIterator * wp_iterator_new (const WpIteratorMethods *methods, - size_t user_size); -gpointer wp_iterator_get_user_data (WpIterator *self); - /* spa pod */ typedef struct _WpSpaPod WpSpaPod; diff --git a/lib/wp/properties.c b/lib/wp/properties.c index 0b137866..a8ea6726 100644 --- a/lib/wp/properties.c +++ b/lib/wp/properties.c @@ -40,7 +40,6 @@ #define G_LOG_DOMAIN "wp-properties" #include "properties.h" -#include "private.h" #include <errno.h> #include <pipewire/properties.h> diff --git a/lib/wp/si-factory.c b/lib/wp/si-factory.c index 74c0cec8..85ec51a8 100644 --- a/lib/wp/si-factory.c +++ b/lib/wp/si-factory.c @@ -14,7 +14,7 @@ #define G_LOG_DOMAIN "wp-si-factory" #include "si-factory.h" -#include "private.h" +#include "private/registry.h" enum { PROP_0, -- GitLab