From 04198820f14d3bf688b3a6a3f628586a676aab02 Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Thu, 16 Jun 2022 15:27:31 -0400 Subject: [PATCH] device: add new wp_spa_device_managed_object_new_iterator API --- lib/wp/device.c | 17 +++++++++++++++++ lib/wp/device.h | 3 +++ modules/module-lua-scripting/api/api.c | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/lib/wp/device.c b/lib/wp/device.c index 680e4371..966a8977 100644 --- a/lib/wp/device.c +++ b/lib/wp/device.c @@ -638,6 +638,23 @@ wp_spa_device_get_properties (WpSpaDevice * self) return wp_properties_ref (self->properties); } +/*! + * \brief Iterates through all the objects managed by this device. + * + * \ingroup wpspadevice + * \param self the spa device + * \returns (transfer full): a WpIterator that iterates over all the objects + * managed by this device + * \since 0.4.11 + */ +WpIterator * +wp_spa_device_new_managed_object_iterator (WpSpaDevice * self) +{ + g_return_val_if_fail (WP_IS_SPA_DEVICE (self), NULL); + return wp_iterator_new_ptr_array (g_ptr_array_ref (self->managed_objs), + G_TYPE_OBJECT); +} + /*! * \brief Gets one of the objects managed by this device. * diff --git a/lib/wp/device.h b/lib/wp/device.h index 4a1fc85d..41d7fc5d 100644 --- a/lib/wp/device.h +++ b/lib/wp/device.h @@ -57,6 +57,9 @@ WpSpaDevice * wp_spa_device_new_from_spa_factory (WpCore * core, WP_API WpProperties * wp_spa_device_get_properties (WpSpaDevice * self); +WP_API +WpIterator * wp_spa_device_new_managed_object_iterator (WpSpaDevice * self); + WP_API GObject * wp_spa_device_get_managed_object (WpSpaDevice * self, guint id); diff --git a/modules/module-lua-scripting/api/api.c b/modules/module-lua-scripting/api/api.c index b1e240b3..80a56347 100644 --- a/modules/module-lua-scripting/api/api.c +++ b/modules/module-lua-scripting/api/api.c @@ -910,6 +910,14 @@ spa_device_new (lua_State *L) return d ? 1 : 0; } +static int +spa_device_iterate_managed_objects (lua_State *L) +{ + WpSpaDevice *device = wplua_checkobject (L, 1, WP_TYPE_SPA_DEVICE); + WpIterator *it = wp_spa_device_new_managed_object_iterator (device); + return push_wpiterator (L, it); +} + static int spa_device_get_managed_object (lua_State *L) { @@ -934,6 +942,7 @@ spa_device_store_managed_object (lua_State *L) } static const luaL_Reg spa_device_methods[] = { + { "iterate_managed_objects", spa_device_iterate_managed_objects }, { "get_managed_object", spa_device_get_managed_object }, { "store_managed_object", spa_device_store_managed_object }, { NULL, NULL }