gplugin/gplugin

Parents 627dc31a5932
Children 303be9417562
implement gplugin_plugin_info_new as a full fledged function. This is pretty much happy pathed right now but should hold up for awhile. Need more unit tests
--- a/gplugin/gplugin-plugin-info.c Wed Dec 10 01:02:35 2014 -0600
+++ b/gplugin/gplugin-plugin-info.c Wed Dec 10 01:03:13 2014 -0600
@@ -15,6 +15,8 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+#include <gobject/gvaluecollector.h>
+
#include <gplugin/gplugin-plugin-info.h>
#include <gplugin/gplugin-core.h>
@@ -768,7 +770,7 @@
}
/**
- * gplugin_plugin_info_new: (skip)
+ * gplugin_plugin_info_new:
* @id: The id of the plugin
* @abi_version: The GPlugin ABI version that the plugin uses
* @...: name/value pairs of properties to set, followed by %NULL.
@@ -777,6 +779,84 @@
*
* Returns: The new GPluginPluginInfo instance.
*/
+GPluginPluginInfo *
+gplugin_plugin_info_new(const gchar *id, guint32 abi_version, ...) {
+ GObjectClass *obj_class = NULL;
+ GPluginPluginInfo *info = NULL;
+ GParameter *param = NULL, *params = NULL;
+ GSList *l = NULL, *ll = NULL;
+ const gchar *name = NULL;
+ guint n_params = 0;
+ gint i = 0;
+ va_list vargs;
+
+ /* create the GParameter for the id */
+ param = g_new0(GParameter, 1);
+ param->name = "id";
+ g_value_init(&param->value, G_TYPE_STRING);
+ g_value_set_string(&param->value, id);
+ l = g_slist_prepend(l, param);
+
+ /* create the GParameter for the abi_version */
+ param = g_new0(GParameter, 1);
+ param->name = "abi_version";
+ g_value_init(&param->value, G_TYPE_UINT);
+ g_value_set_uint(&param->value, abi_version);
+ l = g_slist_prepend(l, param);
+
+ /* now run through all of the properties and build the rest of the
+ * parameters.
+ */
+ obj_class = g_type_class_ref(GPLUGIN_TYPE_PLUGIN_INFO);
+
+ va_start(vargs, abi_version);
+
+ while((name = va_arg(vargs, const gchar *))) {
+ GParamSpec *pspec = NULL;
+ gchar *error = NULL;
+
+ param = g_new0(GParameter, 1);
+ param->name = name;
+
+ pspec = g_object_class_find_property(obj_class, name);
+
+ G_VALUE_COLLECT_INIT(&param->value, pspec->value_type, vargs, 0, &error);
+
+ if(error) {
+ g_critical("%s: %s", G_STRFUNC, error);
+ g_value_unset(&param->value);
+ g_free(param);
+ g_free(error);
+
+ break;
+ }
+
+ l = g_slist_prepend(l, param);
+ }
+
+ va_end(vargs);
+
+ g_type_class_unref(obj_class);
+
+ /* now allocate params and copy everything into it */
+ n_params = g_slist_length(l);
+
+ params = g_new0(GParameter, n_params);
+ for(ll = l, i = 0; ll; ll = ll->next, i++) {
+ params[i] = *(GParameter *)ll->data;
+ }
+
+ info = g_object_newv(GPLUGIN_TYPE_PLUGIN_INFO, n_params, params);
+
+ g_free(params);
+
+ for(ll = l; ll; ll = ll->next) {
+ g_free(ll->data);
+ }
+
+ return info;
+}
+
/**
* gplugin_plugin_info_get_id:
--- a/gplugin/gplugin-plugin-info.h Wed Dec 10 01:02:35 2014 -0600
+++ b/gplugin/gplugin-plugin-info.h Wed Dec 10 01:03:13 2014 -0600
@@ -57,6 +57,17 @@
GType gplugin_plugin_info_get_type(void);
+/**
+ * gplugin_plugin_info_new:
+ * @id: The ID of the plugin
+ * @abi_version: The ABI version of the plugin
+ * @...: Additional values to set
+ *
+ * Creates a new PluginInfo instance.
+ *
+ * Returns: (transfer full): The new PluginInfo instance.
+ */
+#if 0
#define gplugin_plugin_info_new(id, abi_version, ...) \
GPLUGIN_PLUGIN_INFO( \
g_object_new(GPLUGIN_TYPE_PLUGIN_INFO, \
@@ -64,7 +75,9 @@
"abi-version", (abi_version), \
__VA_ARGS__) \
)
+#endif
+GPluginPluginInfo *gplugin_plugin_info_new(const gchar *id, guint32 abi_version, ...);
const gchar *gplugin_plugin_info_get_id(const GPluginPluginInfo *info);
guint32 gplugin_plugin_info_get_abi_version(const GPluginPluginInfo *info);
gboolean gplugin_plugin_info_get_internal(const GPluginPluginInfo *info);