summaryrefslogtreecommitdiff
path: root/libpeas/peas-utils.c
diff options
context:
space:
mode:
authorFabian Orccon <cfoch.fabian@gmail.com>2017-01-30 12:01:43 -0500
committerChristian Hergert <chergert@redhat.com>2019-10-24 13:57:32 -0700
commit936959ba46bd5205d7f439d9168cf8334f9ed2d3 (patch)
tree62329c79230546b28258d8df4866510043069998 /libpeas/peas-utils.c
parentf7aae3257e5654a9c3be9bad85dcf5e7a12be6ed (diff)
downloadlibpeas-936959ba46bd5205d7f439d9168cf8334f9ed2d3.tar.gz
extension-set: adds peas_extension_set_new_with_properties()
Adds a new introspectable variant of peas_extension_set_new() for language bindings. Fixes #8
Diffstat (limited to 'libpeas/peas-utils.c')
-rw-r--r--libpeas/peas-utils.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libpeas/peas-utils.c b/libpeas/peas-utils.c
index e0dcf49..31e9a55 100644
--- a/libpeas/peas-utils.c
+++ b/libpeas/peas-utils.c
@@ -182,6 +182,60 @@ find_param_spec_for_prerequisites (const gchar *name,
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gboolean
+peas_utils_properties_array_to_parameter_list (GType exten_type,
+ guint n_properties,
+ const gchar **prop_names,
+ const GValue *prop_values,
+ GParameter *parameters)
+{
+ guint i;
+ gpointer *ifaces;
+ GObjectClass *base_class;
+
+ g_return_val_if_fail (n_properties == 0 || prop_names != NULL, FALSE);
+ g_return_val_if_fail (n_properties == 0 || prop_values != NULL, FALSE);
+ g_return_val_if_fail (n_properties == 0 || parameters != NULL, FALSE);
+
+ ifaces = get_base_class_and_interfaces (exten_type, &base_class);
+ memset (parameters, 0, sizeof (GParameter) * n_properties);
+ for (i = 0; i < n_properties; i++)
+ {
+ GParamSpec *pspec;
+ if (prop_names[i] == NULL)
+ {
+ g_warning ("The property name at index %u should not be NULL.", i);
+ goto error;
+ }
+ if (!G_IS_VALUE (&prop_values[i]))
+ {
+ g_warning ("The property value at index %u should be an initialized GValue.", i);
+ goto error;
+ }
+ pspec = find_param_spec_for_prerequisites (prop_names[i], base_class,
+ ifaces);
+ if (!pspec)
+ {
+ g_warning ("%s: type '%s' has no property named '%s'",
+ G_STRFUNC, g_type_name (exten_type), prop_names[i]);
+ goto error;
+ }
+
+ parameters[i].name = prop_names[i];
+
+ g_value_init (&parameters[i].value,
+ G_VALUE_TYPE (&prop_values[i]));
+ g_value_copy (&prop_values[i], &parameters[i].value);
+ }
+ return TRUE;
+
+error:
+ n_properties = i;
+ for (i = 0; i < n_properties; i++)
+ g_value_unset (&parameters[i].value);
+ return FALSE;
+}
+
+gboolean
peas_utils_valist_to_parameter_list (GType exten_type,
const gchar *first_property,
va_list args,