install_properties
Description:
Installs new properties from an array of ParamSpecs.
All properties should be installed during the class initializer. It is possible to install properties after that, but doing so is not recommend, and specifically, is not guaranteed to be thread-safe vs. use of properties on the same type on other threads.
The property id of each property is the index of each ParamSpec in the
pspecs
array.
The property id of 0 is treated specially by Object and it should not be used to store a ParamSpec.
This function should be used if you plan to use a static array of ParamSpecs and
g_object_notify_by_pspec
. For instance, this class initialization:
typedef enum {
PROP_FOO = 1,
PROP_BAR,
N_PROPERTIES
} MyObjectProperty;
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
static void
my_object_class_init (MyObjectClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
obj_properties[PROP_FOO] =
g_param_spec_int ("foo", NULL, NULL,
-1, G_MAXINT,
0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
obj_properties[PROP_BAR] =
g_param_spec_string ("bar", NULL, NULL,
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
gobject_class->set_property = my_object_set_property;
gobject_class->get_property = my_object_get_property;
g_object_class_install_properties (gobject_class,
G_N_ELEMENTS (obj_properties),
obj_properties);
}
allows calling g_object_notify_by_pspec
to notify of property changes:
void
my_object_set_foo (MyObject *self, gint foo)
{
if (self->foo != foo)
{
self->foo = foo;
g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_FOO]);
}
}
Parameters:
this | |
pspecs |
the ParamSpecs array defining the new properties |
n_pspecs |
the length of the ParamSpecs array |