diff --git a/lib/wp/plugin-registry.c b/lib/wp/plugin-registry.c index f5bdee5b..d868c0b3 100644 --- a/lib/wp/plugin-registry.c +++ b/lib/wp/plugin-registry.c @@ -11,6 +11,7 @@ typedef struct { gsize block_size; + GType gtype; const WpPluginMetadata *metadata; WpPlugin *instance; } PluginData; @@ -90,6 +91,7 @@ compare_ranks (const WpPluginMetadata * a, const WpPluginMetadata * b) /** * wp_plugin_registry_register_with_metadata: (skip) + * @plugin_type: the #GType of the #WpPlugin subclass * @metadata: the metadata * @metadata_size: the sizeof (@metadata), to allow ABI-compatible future * expansion of the structure @@ -100,6 +102,7 @@ compare_ranks (const WpPluginMetadata * a, const WpPluginMetadata * b) */ void wp_plugin_registry_register_with_metadata (WpPluginRegistry * self, + GType plugin_type, const WpPluginMetadata * metadata, gsize metadata_size) { @@ -107,7 +110,7 @@ wp_plugin_registry_register_with_metadata (WpPluginRegistry * self, g_return_if_fail (WP_IS_PLUGIN_REGISTRY (self)); g_return_if_fail (metadata_size == sizeof (WpPluginMetadata)); - g_return_if_fail (g_type_is_a (metadata->gtype, wp_plugin_get_type ())); + g_return_if_fail (g_type_is_a (plugin_type, wp_plugin_get_type ())); g_return_if_fail (metadata->name != NULL); g_return_if_fail (metadata->description != NULL); g_return_if_fail (metadata->author != NULL); @@ -117,6 +120,7 @@ wp_plugin_registry_register_with_metadata (WpPluginRegistry * self, data = g_slice_alloc (sizeof (PluginData)); data->block_size = sizeof (PluginData); + data->gtype = plugin_type; data->metadata = metadata; data->instance = NULL; @@ -165,9 +169,9 @@ wp_plugin_registry_register (WpPluginRegistry * self, data = g_slice_alloc (sizeof (PluginData) + sizeof (WpPluginMetadata)); data->block_size = sizeof (PluginData) + sizeof (WpPluginMetadata); + data->gtype = plugin_type; metadata = (WpPluginMetadata *) ((guint8 *) data) + sizeof (PluginData); - metadata->gtype = plugin_type; metadata->rank = rank; metadata->name = g_string_chunk_insert (self->metadata_strings, name); metadata->description = g_string_chunk_insert (self->metadata_strings, @@ -187,7 +191,7 @@ wp_plugin_registry_register (WpPluginRegistry * self, static inline void make_plugin (WpPluginRegistry * self, PluginData * plugin_data) { - plugin_data->instance = g_object_new (plugin_data->metadata->gtype, + plugin_data->instance = g_object_new (plugin_data->gtype, "registry", self, "metadata", plugin_data->metadata, NULL); } diff --git a/lib/wp/plugin-registry.h b/lib/wp/plugin-registry.h index 4d0c604a..21deef69 100644 --- a/lib/wp/plugin-registry.h +++ b/lib/wp/plugin-registry.h @@ -21,6 +21,7 @@ G_DECLARE_FINAL_TYPE (WpPluginRegistry, wp_plugin_registry, WP, PLUGIN_REGISTRY, WpPluginRegistry * wp_plugin_registry_new (void); void wp_plugin_registry_register_with_metadata (WpPluginRegistry * self, + GType plugin_type, const WpPluginMetadata * metadata, gsize metadata_size); diff --git a/lib/wp/plugin.h b/lib/wp/plugin.h index 09928acf..9a6a33f5 100644 --- a/lib/wp/plugin.h +++ b/lib/wp/plugin.h @@ -40,7 +40,6 @@ typedef enum { /** * WpPluginMetadata: (skip) - * @gtype: the #GType of the plugin * @rank: the rank of the plugin * @name: the name of the plugin * @description: plugin description @@ -56,10 +55,7 @@ typedef enum { struct _WpPluginMetadata { union { - struct { - GType gtype; - guint rank; - }; + guint rank; gpointer _unused_for_alignment[2]; }; const gchar *name; @@ -190,67 +186,20 @@ const WpPluginMetadata * wp_plugin_get_metadata (WpPlugin * self); #define WP_MODULE_INIT_SYMBOL wireplumber__module_init /** - * WP_MODULE_DEFINE: (skip) + * WP_PLUGIN_DEFINE_TYPE: (skip) * - * A convenience macro to register modules in C/C++. - * A module can contain multiple plugins, which are meant to be registered - * with WP_PLUGIN_REGISTER in the place of @plugin_reg - * - * Example usage: - * |[ - * WP_MODULE_DEFINE ( - * WP_PLUGIN_REGISTER ( - * MY_PLUGIN_TYPE, - * WP_PLUGIN_RANK_PLATFORM_OVERRIDE, - * "myplugin", - * "A custom policy plugin for Awesome Platform", - * "George Kiagiadakis ", - * "LGPL-2.1-or-later", - * "3.0.1", - * "https://awesome-platform.example" - * ); - * WP_PLUGIN_REGISTER ( - * SECONDARY_PLUGIN_TYPE, - * WP_PLUGIN_RANK_PLATFORM_OVERRIDE - 1, - * "secondaryplugin", - * "A secondary policy plugin for Awesome Platform", - * "George Kiagiadakis ", - * "LGPL-2.1-or-later", - * "3.0.1", - * "https://awesome-platform.example" - * ); - * ) - * ]| + * Convenience macro for defining a #WpPlugin subclass in a module */ -#define WP_MODULE_DEFINE(plugin_reg) \ - G_MODULE_EXPORT void \ - WP_MODULE_INIT_SYMBOL (WpPluginRegistry * registry) \ - { \ - plugin_reg; \ - } - -/** - * WP_PLUGIN_REGISTER: (skip) - * - * A convenience macro to register plugins in C/C++. - * See WP_MODULE_DEFINE() for a usage example. - * See wp_plugin_registry_register() for a description of the parameters. - */ -#define WP_PLUGIN_REGISTER(gtype_, rank_, name_, description_, author_, license_, version_, origin_) \ - G_STMT_START \ - static const WpPluginMetadata plugin_metadata = { \ - .gtype = gtype_, \ - .rank = rank_, \ - .name = name_, \ - .description = description_, \ - .author = author_, \ - .license = license_, \ - .version = version_, \ - .origin = origin_ \ - }; \ - wp_plugin_registry_register_with_metadata (registry, &plugin_metadata, \ - sizeof (plugin_metadata)); \ - G_STMT_END +#define WP_PLUGIN_DEFINE_TYPE(TN, t_n) \ + typedef struct _##TN { \ + WpPlugin parent; \ + } TN; \ + \ + typedef struct _##TN##Class { \ + WpPluginClass parent; \ + } TN##Class; \ + \ + G_DEFINE_TYPE_WITH_PRIVATE (TN, t_n, wp_plugin_get_type ()) G_END_DECLS