/* void setAttribute (in nsIAtom name, in AString newValue); */ NS_IMETHODIMP xgGtkElement::SetAttribute (nsIAtom *name, const nsAString &newValue) { GOM_ASTRING_TO_GSTRING_RETURN (value, newValue, NS_ERROR_INVALID_ARG); GParamSpec *spec; guint signal_id; if (!Resolve (name, &spec, &signal_id)) { return NS_ERROR_FAILURE; } if (!spec) { return NS_ERROR_FAILURE; } GError *error = NULL; GValue gval = { 0 }; if (G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (spec)) == G_TYPE_OBJECT) { g_warning (GOM_LOC ("Attribute %s.%s is a %s, which a string cannot be converted to"), G_OBJECT_TYPE_NAME (mObject), spec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (spec))); return NS_ERROR_FAILURE; } else if (gtk_builder_value_from_string (NULL, spec, value, &gval, &error)) { g_object_set_property (mObject, spec->name, &gval); g_value_unset (&gval); } else { g_warning (GOM_LOC ("Could not get value from string: '%s'"), value); return NS_ERROR_FAILURE; } return NS_OK; }
static void e_bind_properties_transfer (GObject *src_object, GParamSpec *src_pspec, GObject *dst_object, GParamSpec *dst_pspec, GlideBindingTransform transform, gpointer user_data) { const gchar *src_name; const gchar *dst_name; gboolean result; GValue src_value = { 0, }; GValue dst_value = { 0, }; src_name = g_param_spec_get_name (src_pspec); dst_name = g_param_spec_get_name (dst_pspec); g_value_init (&src_value, G_PARAM_SPEC_VALUE_TYPE (src_pspec)); g_object_get_property (src_object, src_name, &src_value); g_value_init (&dst_value, G_PARAM_SPEC_VALUE_TYPE (dst_pspec)); result = (*transform) (&src_value, &dst_value, user_data); g_value_unset (&src_value); g_return_if_fail (result); g_param_value_validate (dst_pspec, &dst_value); g_object_set_property (dst_object, dst_name, &dst_value); g_value_unset (&dst_value); }
static VALUE rg_set_child_property(VALUE self, VALUE child, VALUE prop_name, VALUE val) { GParamSpec* pspec; const char* name; if (SYMBOL_P(prop_name)) { name = rb_id2name(SYM2ID(prop_name)); } else { StringValue(prop_name); name = StringValuePtr(prop_name); } pspec = goo_canvas_item_class_find_child_property(G_OBJECT_GET_CLASS(RVAL2GOBJ(self)), name); if (!pspec) rb_raise(rb_eRuntimeError, "No such child property: %s", name); #define _SET_PROP_FOR_TYPE(gtype, ctype, val) \ case gtype: \ goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, (ctype)(val), NULL); \ break; switch (G_TYPE_FUNDAMENTAL(G_PARAM_SPEC_VALUE_TYPE(pspec))) { _SET_PROP_FOR_TYPE(G_TYPE_CHAR, gchar, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_UCHAR, guchar, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_BOOLEAN, gboolean, RTEST(val)); _SET_PROP_FOR_TYPE(G_TYPE_INT, gint, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_UINT, guint, NUM2UINT(val)); _SET_PROP_FOR_TYPE(G_TYPE_LONG, glong, NUM2LONG(val)); _SET_PROP_FOR_TYPE(G_TYPE_ULONG, gulong, NUM2ULONG(val)); _SET_PROP_FOR_TYPE(G_TYPE_INT64, gint64, rbglib_num_to_int64(val)); _SET_PROP_FOR_TYPE(G_TYPE_UINT64, guint64, rbglib_num_to_uint64(val)); _SET_PROP_FOR_TYPE(G_TYPE_ENUM, gint, rbgobj_get_enum(val, G_PARAM_SPEC_VALUE_TYPE(pspec))); _SET_PROP_FOR_TYPE(G_TYPE_FLAGS, guint, rbgobj_get_flags(val, G_PARAM_SPEC_VALUE_TYPE(pspec))); _SET_PROP_FOR_TYPE(G_TYPE_FLOAT, gfloat, NUM2DBL(val)); _SET_PROP_FOR_TYPE(G_TYPE_DOUBLE, gdouble, NUM2DBL(val)); case G_TYPE_STRING: { if (SYMBOL_P(val)) val = rb_funcall(val, rb_intern("to_s"), 0); goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, StringValuePtr(val), NULL); break; } default: g_warning("rb_goo_canvas_item_set_child_property: unsupported type: %s\n", g_type_name(G_PARAM_SPEC_VALUE_TYPE(pspec))); return Qnil; } #undef _SET_PROP_FOR_TYPE G_CHILD_ADD(child, val); return self; }
static void set_sysfs_uint (const char *iface, GObject *obj, const char *obj_prop, const char *dir, const char *sysfs_prop, gboolean default_if_zero, gboolean user_hz_compensate) { char *path, *s; GParamSpec *pspec; GValue val = { 0 }; guint32 uval = 0; pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), obj_prop); g_return_if_fail (pspec != NULL); /* Get the property's value */ g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_object_get_property (obj, obj_prop, &val); if (G_VALUE_HOLDS_BOOLEAN (&val)) uval = g_value_get_boolean (&val) ? 1 : 0; else if (G_VALUE_HOLDS_UINT (&val)) { uval = g_value_get_uint (&val); /* zero means "unspecified" for some NM properties but isn't in the * allowed kernel range, so reset the property to the default value. */ if (default_if_zero && uval == 0) { g_value_unset (&val); g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_param_value_set_default (pspec, &val); uval = g_value_get_uint (&val); } } else g_assert_not_reached (); g_value_unset (&val); /* Linux kernel bridge interfaces use 'centiseconds' for time-based values. * In reality it's not centiseconds, but depends on HZ and USER_HZ, which * is almost always works out to be a multiplier of 100, so we can assume * centiseconds. See clock_t_to_jiffies(). */ if (user_hz_compensate) uval *= 100; path = g_strdup_printf ("/sys/class/net/%s/%s/%s", iface, dir, sysfs_prop); s = g_strdup_printf ("%u", uval); /* FIXME: how should failure be handled? */ nm_utils_do_sysctl (path, s); g_free (path); g_free (s); }
static inline void tidy_stylable_set_property_internal (TidyStylable *stylable, GParamSpec *pspec, const GValue *value, GObjectNotifyQueue *nqueue) { GValue tmp_value = { 0, }; g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); if (!g_value_transform (value, &tmp_value)) g_warning ("unable to set property `%s' of type `%s' from value of type `%s'", pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), G_VALUE_TYPE_NAME (value)); else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION)) { gchar *contents = g_strdup_value_contents (value); g_warning ("value \"%s\" of type `%s' is invalid or out of range for property `%s' of type `%s'", contents, G_VALUE_TYPE_NAME (value), pspec->name, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec))); g_free (contents); } else { TidyStyle *style = tidy_stylable_get_style (stylable); gchar *real_name; real_name = g_strconcat (g_param_spec_get_qdata (pspec, quark_real_owner), "::", pspec->name, NULL); if (!tidy_style_has_property (style, real_name)) tidy_style_add_property (style, real_name, G_PARAM_SPEC_VALUE_TYPE (pspec)); tidy_style_set_property (style, real_name, &tmp_value); g_object_notify_queue_add (G_OBJECT (stylable), nqueue, pspec); g_free (real_name); } g_value_unset (&tmp_value); }
static GitgDataBinding * gitg_data_binding_create(gpointer source, gchar const *source_property, gpointer dest, gchar const *dest_property, GitgDataBindingConversion source_to_dest, GitgDataBindingConversion dest_to_source, gpointer userdata, GitgDataBindingFlags flags) { g_return_val_if_fail(G_IS_OBJECT(source), NULL); g_return_val_if_fail(G_IS_OBJECT(dest), NULL); GObjectClass *sclass = G_OBJECT_GET_CLASS(source); GObjectClass *dclass = G_OBJECT_GET_CLASS(dest); GParamSpec *sspec = g_object_class_find_property(sclass, source_property); if (!sspec) { g_warning("No such source property found: %s", source_property); return NULL; } GParamSpec *dspec = g_object_class_find_property(dclass, dest_property); if (!dspec) { g_warning("No such dest property found: %s", dest_property); return NULL; } GitgDataBinding *binding = g_slice_new0(GitgDataBinding); binding->flags = flags; binding_fill(&binding->source, source, source_property, G_PARAM_SPEC_VALUE_TYPE(sspec), source_to_dest, userdata); binding_fill(&binding->dest, dest, dest_property, G_PARAM_SPEC_VALUE_TYPE(dspec), dest_to_source, userdata); binding_connect(binding, &binding->source); if (flags & GITG_DATA_BINDING_MUTUAL) binding_connect(binding, &binding->dest); g_object_weak_ref(binding->source.object, (GWeakNotify)on_data_binding_destroy, binding); g_object_weak_ref(binding->dest.object, (GWeakNotify)on_data_binding_destroy, binding); /* initial value */ on_data_binding_changed(binding->source.object, NULL, binding); return binding; }
static void commit_option (NMDevice *device, NMSetting *setting, const Option *option, gboolean slave) { int ifindex = nm_device_get_ifindex (device); GParamSpec *pspec; GValue val = G_VALUE_INIT; guint32 uval = 0; gs_free char *value = NULL; g_assert (setting); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (setting), option->name); g_assert (pspec); /* Get the property's value */ g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_object_get_property ((GObject *) setting, option->name, &val); if (G_VALUE_HOLDS_BOOLEAN (&val)) uval = g_value_get_boolean (&val) ? 1 : 0; else if (G_VALUE_HOLDS_UINT (&val)) { uval = g_value_get_uint (&val); /* zero means "unspecified" for some NM properties but isn't in the * allowed kernel range, so reset the property to the default value. */ if (option->default_if_zero && uval == 0) { g_value_unset (&val); g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_param_value_set_default (pspec, &val); uval = g_value_get_uint (&val); } /* Linux kernel bridge interfaces use 'centiseconds' for time-based values. * In reality it's not centiseconds, but depends on HZ and USER_HZ, which * is almost always works out to be a multiplier of 100, so we can assume * centiseconds. See clock_t_to_jiffies(). */ if (option->user_hz_compensate) uval *= 100; } else g_assert_not_reached (); g_value_unset (&val); value = g_strdup_printf ("%u", uval); if (slave) nm_platform_slave_set_option (ifindex, option->sysname, value); else nm_platform_master_set_option (ifindex, option->sysname, value); }
static GstElement * create_payloader_for_caps (const GstCaps * caps) { GList *payloader_list, *filtered_list, *l; GstElementFactory *payloader_factory = NULL; GstElement *payloader = NULL; payloader_list = gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_PAYLOADER, GST_RANK_NONE); filtered_list = gst_element_factory_list_filter (payloader_list, caps, GST_PAD_SRC, FALSE); for (l = filtered_list; l != NULL && payloader_factory == NULL; l = l->next) { payloader_factory = GST_ELEMENT_FACTORY (l->data); if (gst_element_factory_get_num_pad_templates (payloader_factory) != 2) payloader_factory = NULL; } if (payloader_factory != NULL) { payloader = gst_element_factory_create (payloader_factory, NULL); } if (payloader) { GParamSpec *pspec; pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (payloader), "config-interval"); if (pspec != NULL && G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_UINT) { g_object_set (payloader, "config-interval", 1, NULL); } pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (payloader), "picture-id-mode"); if (pspec != NULL && G_TYPE_IS_ENUM (G_PARAM_SPEC_VALUE_TYPE (pspec))) { /* Set picture id so that remote peer can determine continuity if */ /* there are lost FEC packets and if it has to NACK them */ g_object_set (payloader, "picture-id-mode", PICTURE_ID_15_BIT, NULL); } } gst_plugin_feature_list_free (filtered_list); gst_plugin_feature_list_free (payloader_list); return payloader; }
static VALUE _params_setup(VALUE arg, struct param_setup_arg *param_setup_arg) { guint index; VALUE name, val; GParamSpec* pspec; index = param_setup_arg->index; if (index >= param_setup_arg->param_size) rb_raise(rb_eArgError, "too many parameters"); name = rb_ary_entry(arg, 0); val = rb_ary_entry(arg, 1); if (SYMBOL_P(name)) param_setup_arg->params[index].name = rb_id2name(SYM2ID(name)); else param_setup_arg->params[index].name = StringValuePtr(name); pspec = g_object_class_find_property( param_setup_arg->gclass, param_setup_arg->params[index].name); if (!pspec) rb_raise(rb_eArgError, "No such property: %s", param_setup_arg->params[index].name); g_value_init(&(param_setup_arg->params[index].value), G_PARAM_SPEC_VALUE_TYPE(pspec)); rbgobj_rvalue_to_gvalue(val, &(param_setup_arg->params[index].value)); param_setup_arg->index++; return Qnil; }
/* Looking for construct-time optional output args. Append them to out. */ static void * vo_get_optional_arg( const char *name, PElement *value, Vo *vo, PElement *out ) { GParamSpec *pspec; VipsArgumentClass *argument_class; VipsArgumentInstance *argument_instance; if( vips_object_get_argument( vo->object, name, &pspec, &argument_class, &argument_instance ) ) return( NULL ); if( !(argument_class->flags & VIPS_ARGUMENT_REQUIRED) && (argument_class->flags & VIPS_ARGUMENT_OUTPUT) && argument_instance->assigned ) { GType type = G_PARAM_SPEC_VALUE_TYPE( pspec ); GValue gvalue = { 0 }; PElement lhs; if( !heap_list_add( vo->rc->heap, out, &lhs ) ) return( value ); g_value_init( &gvalue, type ); g_object_get_property( G_OBJECT( vo->object ), name, &gvalue ); if( !heap_gvalue_to_ip( &gvalue, &lhs ) ) { g_value_unset( &gvalue ); return( value ); } g_value_unset( &gvalue ); (void) heap_list_next( out ); } return( NULL ); }
/* Looking for required output args ... append to out. */ static void * vo_get_required_output( VipsObject *object, GParamSpec *pspec, VipsArgumentClass *argument_class, VipsArgumentInstance *argument_instance, Vo *vo, PElement *out ) { if( (argument_class->flags & VIPS_ARGUMENT_REQUIRED) && (argument_class->flags & VIPS_ARGUMENT_OUTPUT) && argument_instance->assigned ) { const char *name = g_param_spec_get_name( pspec ); GType type = G_PARAM_SPEC_VALUE_TYPE( pspec ); PElement lhs; GValue value = { 0 }; if( !heap_list_add( vo->rc->heap, out, &lhs ) ) return( object ); g_value_init( &value, type ); g_object_get_property( G_OBJECT( object ), name, &value ); if( !heap_gvalue_to_ip( &value, &lhs ) ) { g_value_unset( &value ); return( object ); } g_value_unset( &value ); (void) heap_list_next( out ); } return( NULL ); }
static VALUE rg_style_get_property(VALUE self, VALUE prop_name) { GParamSpec* pspec = NULL; const char* name; if (SYMBOL_P(prop_name)) { name = rb_id2name(SYM2ID(prop_name)); } else { name = RVAL2CSTR(prop_name); } pspec = gtk_widget_class_find_style_property((GtkWidgetClass*)g_type_class_ref(RVAL2GTYPE(self)), name); if (!pspec) rb_raise(rb_eval_string("GLib::NoPropertyError"), "No such property: %s", name); else { // FIXME: use rb_ensure to call g_value_unset() GValue gval = G_VALUE_INIT; VALUE ret; g_value_init(&gval, G_PARAM_SPEC_VALUE_TYPE(pspec)); gtk_widget_style_get_property(GTK_WIDGET(RVAL2GOBJ(self)), name, &gval); ret = GVAL2RVAL(&gval); g_value_unset(&gval); return ret; } }
/* * gst_controlled_property_new: * @object: for which object the controlled property should be set up * @name: the name of the property to be controlled * * Private method which initializes the fields of a new controlled property * structure. * * Returns: a freshly allocated structure or %NULL */ static GstControlledProperty * gst_controlled_property_new (GObject * object, const gchar * name) { GstControlledProperty *prop = NULL; GParamSpec *pspec; GST_INFO ("trying to put property '%s' under control", name); /* check if the object has a property of that name */ if ((pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), name))) { GST_DEBUG (" psec->flags : 0x%08x", pspec->flags); /* check if this param is witable && controlable && !construct-only */ g_return_val_if_fail ((pspec->flags & (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE | G_PARAM_CONSTRUCT_ONLY)) == (G_PARAM_WRITABLE | GST_PARAM_CONTROLLABLE), NULL); if ((prop = g_slice_new (GstControlledProperty))) { prop->pspec = pspec; prop->name = pspec->name; prop->csource = NULL; prop->disabled = FALSE; memset (&prop->last_value, 0, sizeof (GValue)); g_value_init (&prop->last_value, G_PARAM_SPEC_VALUE_TYPE (prop->pspec)); } } else { GST_WARNING ("class '%s' has no property '%s'", G_OBJECT_TYPE_NAME (object), name); } return prop; }
static void tidy_stylable_set_valist (TidyStylable *stylable, const gchar *first_property_name, va_list varargs) { GObjectNotifyQueue *nqueue; const gchar *name; g_object_ref (stylable); nqueue = g_object_notify_queue_freeze (G_OBJECT (stylable), &property_notify_context); name = first_property_name; while (name) { GParamSpec *pspec; GValue value = { 0, }; gchar *error; pspec = tidy_stylable_find_property (stylable, name); if (!pspec) { g_warning ("%s: no style property named `%s' found for class `%s'", G_STRLOC, name, g_type_name (G_OBJECT_TYPE (stylable))); break; } if (!(pspec->flags & G_PARAM_WRITABLE) || (pspec->flags & G_PARAM_CONSTRUCT_ONLY)) { g_warning ("Style property `%s' of class `%s' is not writable", pspec->name, g_type_name (G_OBJECT_TYPE (stylable))); break; } g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); G_VALUE_COLLECT (&value, varargs, 0, &error); if (error) { g_warning ("%s: %s", G_STRLOC, error); g_free (error); g_value_unset (&value); break; } tidy_stylable_set_property_internal (stylable, pspec, &value, nqueue); g_value_unset (&value); name = va_arg (varargs, gchar*); } g_object_notify_queue_thaw (G_OBJECT (stylable), nqueue); g_object_unref (stylable); }
static void gobj_mark(gpointer ptr) { GObject* gobj = ptr; guint n_properties; GParamSpec** properties; GValue gval = {0,}; guint i; properties = g_object_class_list_properties(G_OBJECT_GET_CLASS(gobj), &n_properties); for (i = 0; i < n_properties; i++) { GParamSpec* pspec = properties[i]; GType value_type = G_PARAM_SPEC_VALUE_TYPE(pspec); if (G_TYPE_FUNDAMENTAL(value_type) != G_TYPE_OBJECT) continue; if (!(pspec->flags & G_PARAM_READABLE)) continue; /* FIXME: exclude types that doesn't have identity. */ { g_value_init(&gval, value_type); g_object_get_property(gobj, pspec->name, &gval); rbgobj_gc_mark_gvalue(&gval); g_value_unset(&gval); } } g_free(properties); }
static VALUE rbgio_gasyncinitiable_new_async_parameters_initialize(VALUE key_value, struct rbgio_gasyncinitable_new_async_data *data) { VALUE key, value; GParamSpec *spec; if (data->index >= data->n_parameters) rb_raise(rb_eArgError, "too many parameters (%d >= %d)", data->index, data->n_parameters); key = rb_ary_entry(key_value, 0); value = rb_ary_entry(key_value, 1); data->parameters[data->index].name = SYMBOL_P(key) ? rb_id2name(SYM2ID(key)) : StringValuePtr(key); spec = g_object_class_find_property(data->gclass, data->parameters[data->index].name); if (spec == NULL) rb_raise(rb_eArgError, "%s: no such property", data->parameters[data->index].name); g_value_init(&(data->parameters[data->index].value), G_PARAM_SPEC_VALUE_TYPE(spec)); rbgobj_rvalue_to_gvalue(value, &(data->parameters[data->index].value)); data->index++; return Qnil; }
json_t *json_gobject_serialize (GObject *gobject) { json_t *object = json_object(); GParamSpec **pspecs; guint n_pspecs, i; pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (gobject), &n_pspecs); for (i=0; i!=n_pspecs; ++i) { json_t *node; GParamSpec *pspec = pspecs[i]; GValue value = { 0, }; g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_object_get_property(gobject, pspec->name, &value); node=json_serialize_pspec (&value); if (node) json_object_set_new (object, pspec->name, node); g_value_unset (&value); } g_free (pspecs); return object; }
void gog_object_set_arg (char const *name, char const *val, GogObject *obj) { GParamSpec *pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj), name); GType prop_type; GValue res = { 0 }; gboolean success = TRUE; if (pspec == NULL) { g_warning ("unknown property `%s' for class `%s'", name, G_OBJECT_TYPE_NAME (obj)); return; } prop_type = G_PARAM_SPEC_VALUE_TYPE (pspec); if (val == NULL && G_TYPE_FUNDAMENTAL (prop_type) != G_TYPE_BOOLEAN) { g_warning ("could not convert NULL to type `%s' for property `%s'", g_type_name (prop_type), pspec->name); return; } if (!gsf_xml_gvalue_from_str (&res, prop_type, val)) success = FALSE; if (!success) { g_warning ("could not convert string to type `%s' for property `%s'", g_type_name (prop_type), pspec->name); } else g_object_set_property (G_OBJECT (obj), name, &res); g_value_unset (&res); }
static void * vips_operation_class_usage_arg( VipsObjectClass *object_class, GParamSpec *pspec, VipsArgumentClass *argument_class, VipsBuf *buf, VipsOperationClassUsage *usage ) { /* Only show construct args ... others are internal. */ if( usage->required == ((argument_class->flags & VIPS_ARGUMENT_REQUIRED) != 0) && (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) && !(argument_class->flags & VIPS_ARGUMENT_DEPRECATED) ) { if( usage->message && usage->n == 0 ) vips_buf_appendf( buf, "%s\n", usage->message ); if( usage->oftype ) { vips_buf_appendf( buf, " %-12s - %s, %s %s\n", g_param_spec_get_name( pspec ), g_param_spec_get_blurb( pspec ), (argument_class->flags & VIPS_ARGUMENT_INPUT) ? _( "input" ) : _( "output" ), g_type_name( G_PARAM_SPEC_VALUE_TYPE( pspec ) ) ); } else { if( usage->n > 0 ) vips_buf_appends( buf, " " ); vips_buf_appends( buf, g_param_spec_get_name( pspec ) ); } usage->n += 1; } return( NULL ); }
void gegl_operation_context_take_object (GeglOperationContext *context, const gchar *padname, GObject *data) { GParamSpec *pspec; /* FIXME: check that there isn't already an existing * output object/value set? */ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (context->operation)), padname); if (pspec) { GValue value = {0, }; g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_value_take_object (&value, data); gegl_operation_context_set_property (context, padname, &value); g_value_unset (&value); } else { g_warning ("%s: No paramspec found for pad '%s' on \"%s\"\n", G_STRFUNC, padname, gegl_operation_get_name (context->operation)); } }
/** * gst_controller_get: * @self: the controller object which handles the properties * @property_name: the name of the property to get * @timestamp: the time the control-change should be read from * * Gets the value for the given controller-handled property at the requested * time. * * Returns: the GValue of the property at the given time, or %NULL if the * property isn't handled by the controller */ GValue * gst_controller_get (GstController * self, gchar * property_name, GstClockTime timestamp) { GstControlledProperty *prop; GValue *val = NULL; g_return_val_if_fail (GST_IS_CONTROLLER (self), NULL); g_return_val_if_fail (property_name, NULL); g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (timestamp), NULL); g_mutex_lock (self->lock); if ((prop = gst_controller_find_controlled_property (self, property_name))) { val = g_new0 (GValue, 1); g_value_init (val, G_PARAM_SPEC_VALUE_TYPE (prop->pspec)); if (prop->csource) { gboolean res; /* get current value via control source */ res = gst_control_source_get_value (prop->csource, timestamp, val); if (!res) { g_free (val); val = NULL; } } else { g_object_get_property (self->object, prop->name, val); } } g_mutex_unlock (self->lock); return val; }
void gegl_operation_context_set_property (GeglOperationContext *context, const gchar *property_name, const GValue *value) { GParamSpec *pspec; GValue *storage; g_return_if_fail (context != NULL); pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (context->operation)), property_name); if (!pspec) { g_warning ("%s: node %s has no pad|property named '%s'", G_STRFUNC, GEGL_OPERATION_GET_CLASS (context->operation)->name, property_name); } /* if the value already exists in the context it will be reused */ storage = gegl_operation_context_add_value (context, property_name, G_PARAM_SPEC_VALUE_TYPE(pspec)); /* storage needs to have the correct type */ g_value_copy (value, storage); }
static VALUE value_convert(int argc, VALUE* argv, VALUE self) { GParamSpec* pspec = rbgobj_get_param_spec(self); VALUE src, strict_validation; VALUE src_type; VALUE result = Qnil; GValue src_value = {0,}; GValue dest_value = {0,}; gboolean b; rb_scan_args(argc, argv, "21", &src, &src_type, &strict_validation); /* FIXME: use rb_ensure to ensure following g_value_unset() call*/ g_value_init(&src_value, rbgobj_gtype_get(src_type)); g_value_init(&dest_value, G_PARAM_SPEC_VALUE_TYPE(pspec)); rbgobj_rvalue_to_gvalue(src, &src_value); b = g_param_value_convert(rbgobj_get_param_spec(self), &src_value, &dest_value, RVAL2CBOOL(strict_validation)); if (b) result = rbgobj_gvalue_to_rvalue(&dest_value); g_value_unset(&src_value); g_value_unset(&dest_value); if (b) return result; else rb_raise(rb_eTypeError, "can't convert"); }
/* Cell packing parsing */ static void gtk_cell_layout_buildable_set_cell_property (GtkCellArea *area, GtkBuilder *builder, GtkCellRenderer *cell, gchar *name, const gchar *value) { GParamSpec *pspec; GValue gvalue = G_VALUE_INIT; GError *error = NULL; pspec = gtk_cell_area_class_find_cell_property (GTK_CELL_AREA_GET_CLASS (area), name); if (!pspec) { g_warning ("%s does not have a property called %s", g_type_name (G_OBJECT_TYPE (area)), name); return; } if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error)) { g_warning ("Could not read property %s:%s with value %s of type %s: %s", g_type_name (G_OBJECT_TYPE (area)), name, value, g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), error->message); g_error_free (error); return; } gtk_cell_area_cell_set_property (area, cell, name, &gvalue); g_value_unset (&gvalue); }
static void check_property (const char *output, GParamSpec *pspec, GValue *value) { GValue default_value = G_VALUE_INIT; char *v, *dv, *msg; if (g_param_value_defaults (pspec, value)) return; g_value_init (&default_value, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_param_value_set_default (pspec, &default_value); v = g_strdup_value_contents (value); dv = g_strdup_value_contents (&default_value); msg = g_strdup_printf ("%s %s.%s: %s != %s\n", output, g_type_name (pspec->owner_type), pspec->name, dv, v); g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); g_free (msg); g_free (v); g_free (dv); g_value_unset (&default_value); }
static void * vips_object_equal_arg( VipsObject *object, GParamSpec *pspec, VipsArgumentClass *argument_class, VipsArgumentInstance *argument_instance, void *a, void *b ) { VipsObject *other = (VipsObject *) a; if( (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) && (argument_class->flags & VIPS_ARGUMENT_INPUT) && argument_instance->assigned ) { const char *name = g_param_spec_get_name( pspec ); GType type = G_PARAM_SPEC_VALUE_TYPE( pspec ); GValue v1 = { 0, }; GValue v2 = { 0, }; gboolean equal; g_value_init( &v1, type ); g_value_init( &v2, type ); g_object_get_property( G_OBJECT( object ), name, &v1 ); g_object_get_property( G_OBJECT( other ), name, &v2 ); equal = vips_value_equal( pspec, &v1, &v2 ); g_value_unset( &v1 ); g_value_unset( &v2 ); if( !equal ) return( object ); } return( NULL ); }
/** * clutter_container_child_get: * @container: a #ClutterContainer * @actor: a #ClutterActor that is a child of @container. * @first_prop: name of the first property to be set. * @...: value for the first property, followed optionally by more name/value * pairs terminated with NULL. * * Gets @container specific properties of an actor. * * In general, a copy is made of the property contents and the caller is * responsible for freeing the memory in the appropriate manner for the type, for * instance by calling free() or g_object_unref(). * * Since: 0.8 */ void clutter_container_child_get (ClutterContainer *container, ClutterActor *actor, const gchar *first_prop, ...) { GObjectClass *klass; const gchar *name; va_list var_args; g_return_if_fail (CLUTTER_IS_CONTAINER (container)); g_return_if_fail (CLUTTER_IS_ACTOR (actor)); klass = G_OBJECT_GET_CLASS (container); va_start (var_args, first_prop); name = first_prop; while (name) { GValue value = G_VALUE_INIT; gchar *error = NULL; GParamSpec *pspec; pspec = clutter_container_class_find_child_property (klass, name); if (!pspec) { g_warning ("%s: container '%s' has no child property named '%s'", G_STRLOC, G_OBJECT_TYPE_NAME (container), name); break; } if (!(pspec->flags & G_PARAM_READABLE)) { g_warning ("%s: child property '%s' of container '%s' is not readable", G_STRLOC, pspec->name, G_OBJECT_TYPE_NAME (container)); break; } g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); container_get_child_property (container, actor, &value, pspec); G_VALUE_LCOPY (&value, var_args, 0, &error); if (error) { g_warning ("%s: %s", G_STRLOC, error); free (error); g_value_unset (&value); break; } g_value_unset (&value); name = va_arg (var_args, gchar*); } va_end (var_args); }
/** * ags_parameter_grow: * @object_type: the #GType of the object's properties * @params: the #GParameter array * @n_params: location to store new size * @...: a %NULL-terminated list of properties name and value * * Grow parameter array of @object_type object. This function is mainly used to * prepare a #GParameter array to instantiate a new #GObject by using g_object_newv(). * * Returns: the resized GParameter array * * Since: 2.0.0 */ GParameter* ags_parameter_grow(GType object_type, GParameter *params, guint *n_params, ...) { //Thank you gimp GObjectClass *object_class; gchar *param_name; va_list ap; object_class = g_type_class_ref (object_type); va_start(ap, n_params); param_name = va_arg (ap, gchar *); while (param_name) { gchar *error; GParamSpec *pspec; error = NULL; pspec = g_object_class_find_property(object_class, param_name); if (! pspec) { g_warning ("%s: object class `%s' has no property named `%s'", G_STRFUNC, g_type_name (object_type), param_name); break; } if(params != NULL){ params = g_renew (GParameter, params, *n_params + 1); }else{ params = g_new(GParameter, 1); } params[*n_params].name = param_name; params[*n_params].value.g_type = 0; g_value_init (¶ms[*n_params].value, G_PARAM_SPEC_VALUE_TYPE (pspec)); G_VALUE_COLLECT (¶ms[*n_params].value, ap, 0, &error); if (error) { g_warning ("%s: %s", G_STRFUNC, error); g_free (error); g_value_unset (¶ms[*n_params].value); break; } *n_params = *n_params + 1; param_name = va_arg (ap, gchar *); } return(params); }
static void gst_xvidenc_init (GstXvidEnc * xvidenc) { GParamSpec **pspecs; guint i, num_props; /* create the sink pad */ xvidenc->sinkpad = gst_pad_new_from_static_template (&sink_template, "sink"); gst_element_add_pad (GST_ELEMENT (xvidenc), xvidenc->sinkpad); gst_pad_set_chain_function (xvidenc->sinkpad, GST_DEBUG_FUNCPTR (gst_xvidenc_chain)); gst_pad_set_setcaps_function (xvidenc->sinkpad, GST_DEBUG_FUNCPTR (gst_xvidenc_setcaps)); gst_pad_set_getcaps_function (xvidenc->sinkpad, GST_DEBUG_FUNCPTR (gst_xvidenc_getcaps)); gst_pad_set_event_function (xvidenc->sinkpad, GST_DEBUG_FUNCPTR (gst_xvidenc_handle_sink_event)); /* create the src pad */ xvidenc->srcpad = gst_pad_new_from_static_template (&src_template, "src"); gst_element_add_pad (GST_ELEMENT (xvidenc), xvidenc->srcpad); gst_pad_use_fixed_caps (xvidenc->srcpad); /* init properties. */ xvidenc->width = xvidenc->height = xvidenc->csp = -1; xvidenc->par_width = xvidenc->par_height = 1; /* set defaults for user properties */ pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (xvidenc), &num_props); for (i = 0; i < num_props; ++i) { GValue val = { 0, }; GParamSpec *pspec = pspecs[i]; /* only touch those that are really ours; i.e. should have some qdata */ if (!g_param_spec_get_qdata (pspec, xvidenc_pspec_quark)) continue; g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec)); g_param_value_set_default (pspec, &val); g_object_set_property (G_OBJECT (xvidenc), g_param_spec_get_name (pspec), &val); g_value_unset (&val); } g_free (pspecs); /* set xvid handle to NULL */ xvidenc->handle = NULL; /* get a queue to keep time info if frames get delayed */ xvidenc->delay = NULL; /* cache some xvid data so need not rebuild for each frame */ xvidenc->xframe_cache = NULL; }
/** * tidy_stylable_set_property: * @stylable: a #TidyStylable * @property_name: the name of the property to set * @value: an initialized #GValue * * Sets the property @property_name with @value. */ void tidy_stylable_set_property (TidyStylable *stylable, const gchar *property_name, const GValue *value) { GObjectNotifyQueue *nqueue; GParamSpec *pspec; g_return_if_fail (TIDY_IS_STYLABLE (stylable)); g_return_if_fail (property_name != NULL); g_return_if_fail (value != NULL); g_object_ref (stylable); nqueue = g_object_notify_queue_freeze (G_OBJECT (stylable), &property_notify_context); pspec = tidy_stylable_find_property (stylable, property_name); if (!pspec) { g_warning ("Stylable class `%s' doesn't have a property named `%s'", g_type_name (G_OBJECT_TYPE (stylable)), property_name); } else if (!(pspec->flags & G_PARAM_WRITABLE)) { g_warning ("Style property `%s' of class `%s' is not readable", pspec->name, g_type_name (G_OBJECT_TYPE (stylable))); } else if (G_VALUE_TYPE (value) != G_PARAM_SPEC_VALUE_TYPE (pspec)) { g_warning ("Passed value is not of the requested type `%s' for " "the style property `%s' of class `%s'", g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), pspec->name, g_type_name (G_OBJECT_TYPE (stylable))); } else tidy_stylable_set_property_internal (stylable, pspec, value, nqueue); g_object_notify_queue_thaw (G_OBJECT (stylable), nqueue); g_object_unref (stylable); }