![]() |
![]() |
![]() |
D-Bus GLib bindings - Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
DBusGTypeSpecializedAppendContext; void (*DBusGTypeSpecializedCollectionAppendFunc) (DBusGTypeSpecializedAppendContext *ctx
,GValue *val
); void (*DBusGTypeSpecializedCollectionEndAppendFunc) (DBusGTypeSpecializedAppendContext *ctx
); gboolean (*DBusGTypeSpecializedCollectionFixedAccessorFunc) (GType type
,gpointer instance
,gpointer *values
,guint *len
); void (*DBusGTypeSpecializedCollectionIterator) (const GValue *value
,gpointer user_data
); void (*DBusGTypeSpecializedCollectionIteratorFunc) (GType type
,gpointer instance
,DBusGTypeSpecializedCollectionIterator iterator
,gpointer user_data
); DBusGTypeSpecializedCollectionVtable; gpointer (*DBusGTypeSpecializedConstructor) (GType type
); gpointer (*DBusGTypeSpecializedCopyFunc) (GType type
,gpointer src
); void (*DBusGTypeSpecializedFreeFunc) (GType type
,gpointer val
); void (*DBusGTypeSpecializedMapAppendFunc) (DBusGTypeSpecializedAppendContext *ctx
,GValue *key
,GValue *val
); void (*DBusGTypeSpecializedMapIterator) (const GValue *key_val
,const GValue *value_val
,gpointer user_data
); void (*DBusGTypeSpecializedMapIteratorFunc) (GType type
,gpointer instance
,DBusGTypeSpecializedMapIterator iterator
,gpointer user_data
); DBusGTypeSpecializedMapVtable; gboolean (*DBusGTypeSpecializedStructGetMember) (GType type
,gpointer instance
,guint member
,GValue *ret_value
); gboolean (*DBusGTypeSpecializedStructSetMember) (GType type
,gpointer instance
,guint member
,const GValue *new_value
); DBusGTypeSpecializedStructVtable; DBusGTypeSpecializedVtable; gboolean dbus_g_type_collection_get_fixed (GValue *value
,gpointer *data_ret
,guint *len_ret
); const DBusGTypeSpecializedCollectionVtable * dbus_g_type_collection_peek_vtable (GType collection_type
); void dbus_g_type_collection_value_iterate (const GValue *value
,DBusGTypeSpecializedCollectionIterator iterator
,gpointer user_data
); GType dbus_g_type_get_collection (const char *container
,GType specialization
); GType dbus_g_type_get_collection_specialization (GType gtype
); GType dbus_g_type_get_map (const char *container
,GType key_specialization
,GType value_specialization
); GType dbus_g_type_get_map_key_specialization (GType gtype
); GType dbus_g_type_get_map_value_specialization (GType gtype
); GType dbus_g_type_get_struct (const char *container
,GType first_type
,...
); GType dbus_g_type_get_struct_member_type (GType gtype
,guint member
); guint dbus_g_type_get_struct_size (GType gtype
); GType dbus_g_type_get_structv (const char *container
,guint num_members
,GType *types
); gboolean dbus_g_type_is_collection (GType gtype
); gboolean dbus_g_type_is_map (GType gtype
); gboolean dbus_g_type_is_struct (GType gtype
); const DBusGTypeSpecializedMapVtable * dbus_g_type_map_peek_vtable (GType map_type
); void dbus_g_type_map_value_iterate (const GValue *value
,DBusGTypeSpecializedMapIterator iterator
,gpointer user_data
); void dbus_g_type_register_collection (const char *name
,const DBusGTypeSpecializedCollectionVtable *vtable
,guint flags
); void dbus_g_type_register_map (const char *name
,const DBusGTypeSpecializedMapVtable *vtable
,guint flags
); void dbus_g_type_register_struct (const char *name
,const DBusGTypeSpecializedStructVtable *vtable
,guint flags
); void dbus_g_type_specialized_collection_append (DBusGTypeSpecializedAppendContext *ctx
,GValue *elt
); void dbus_g_type_specialized_collection_end_append (DBusGTypeSpecializedAppendContext *ctx
); gpointer dbus_g_type_specialized_construct (GType gtype
); void dbus_g_type_specialized_init (void
); void dbus_g_type_specialized_init_append (GValue *value
,DBusGTypeSpecializedAppendContext *ctx
); void dbus_g_type_specialized_map_append (DBusGTypeSpecializedAppendContext *ctx
,GValue *key
,GValue *val
); gboolean dbus_g_type_struct_get (const GValue *value
,guint member
,...
); gboolean dbus_g_type_struct_get_member (const GValue *value
,guint member
,GValue *dest
); const DBusGTypeSpecializedStructVtable * dbus_g_type_struct_peek_vtable (GType struct_type
); gboolean dbus_g_type_struct_set (GValue *value
,guint member
,...
); gboolean dbus_g_type_struct_set_member (GValue *value
,guint member
,const GValue *src
); GVariant * dbus_g_value_build_g_variant (const GValue *value
);
Specialized gtypes are basically a way to allow the definition of recursive GTypes. It allows the definition of 'containers' which is basically a user defined structure capable of holding other data, and a set of functions defining how to access that structure. Containers come in 3 flavors: collections, maps and structs.
A collection is a container that holds an ordered set of items, all of which must be the same type. (This is an array in standard D-Bus terminology.) dbus-glib specialized collections can be GArray (for numeric elements), GPtrArray (for string, object or boxed elements), GSList (for boxed elements, not recommended), or a user-defined type.
A map is a container that holds a set of key/value pairs. The keys have one type, and the values another; the type of the keys must be a numeric or string-like type. (This is a dict (dictionary) or array of dict entry in standard D-Bus terminology.) dbus-glib specialized maps can be GHashTable or a user-defined type.
A struct is a container that holds a fixed number of members, each member
having a predefined type. (This is a struct in
standard D-Bus terminology.) It is analogous to the C struct
keyword, but
dbus-glib does not generally represent D-Bus structs in C structs.
dbus-glib specialized structs can be GValueArray or a user-defined type.
A specialization is a GType detailing a particular container with particular types (a type specialization).
Functions are provided for constructing and manipulating specializations.
This documentation needs splitting into two pages, one for defining new containers and using existing containers. I expect most users to only do the latter. I also need to add some examples.
typedef struct { /* public */ GValue *val; GType specialization_type; } DBusGTypeSpecializedAppendContext;
A context for appending. There are more fields, which are private.
void (*DBusGTypeSpecializedCollectionAppendFunc) (DBusGTypeSpecializedAppendContext *ctx
,GValue *val
);
Implements dbus_g_type_specialized_collection_append()
.
This function should use the val
and specialization_type
members of ctx
.
|
an appending context returned by dbus_g_type_specialized_init_append()
|
|
a value to copy into the collection |
void (*DBusGTypeSpecializedCollectionEndAppendFunc)
(DBusGTypeSpecializedAppendContext *ctx
);
Implements dbus_g_type_specialized_collection_end_append()
.
This function should use the val
and specialization_type
members of ctx
.
|
an appending context returned by dbus_g_type_specialized_init_append()
|
gboolean (*DBusGTypeSpecializedCollectionFixedAccessorFunc) (GType type
,gpointer instance
,gpointer *values
,guint *len
);
Implements dbus_g_type_collection_get_fixed()
for a GValue with type
type
, containing instance
.
|
a specialized collection boxed type |
|
an instance of type
|
|
used to return a pointer to the contents of instance
|
|
used to return the number of elements in instance
|
Returns : |
TRUE on success |
void (*DBusGTypeSpecializedCollectionIterator) (const GValue *value
,gpointer user_data
);
A library-user-supplied function, called for each element in the
collection when dbus_g_type_collection_value_iterate()
is called.
|
an element of the collection |
|
the data supplied when calling
dbus_g_type_collection_value_iterate()
|
void (*DBusGTypeSpecializedCollectionIteratorFunc) (GType type
,gpointer instance
,DBusGTypeSpecializedCollectionIterator iterator
,gpointer user_data
);
Implements dbus_g_type_collection_value_iterate()
for a GValue with
type type
, containing instance
.
|
a specialized collection boxed type |
|
an instance of type
|
|
the function to call for each element |
|
data to pass to iterator
|
typedef struct { DBusGTypeSpecializedVtable base_vtable; DBusGTypeSpecializedCollectionFixedAccessorFunc fixed_accessor; DBusGTypeSpecializedCollectionIteratorFunc iterator; DBusGTypeSpecializedCollectionAppendFunc append_func; DBusGTypeSpecializedCollectionEndAppendFunc end_append_func; } DBusGTypeSpecializedCollectionVtable;
A table of methods used to implement specialized collection behaviour
on user-defined types. At least iterator
and append_func
must be
implemented.
DBusGTypeSpecializedVtable |
base methods shared between collections and other types |
DBusGTypeSpecializedCollectionFixedAccessorFunc |
if not NULL , provides access to the contents of this
collection, as documented for dbus_g_type_collection_get_fixed()
|
iterates through the members of instance
|
|
DBusGTypeSpecializedCollectionAppendFunc |
appends a new member to instance
|
DBusGTypeSpecializedCollectionEndAppendFunc |
if not NULL , called after each group of calls to
the append_func
|
gpointer (*DBusGTypeSpecializedConstructor) (GType type
);
|
a specialized boxed type |
Returns : |
a new instance of type
|
gpointer (*DBusGTypeSpecializedCopyFunc) (GType type
,gpointer src
);
Copies src
according to type
. This is analogous to GBoxedCopyFunc, but
can use information from type
(for instance to copy each element of a
collection).
|
a specialized boxed type |
|
an instance of type
|
Returns : |
a deep copy of src
|
void (*DBusGTypeSpecializedFreeFunc) (GType type
,gpointer val
);
Frees val
according to type
. This is analogous to GBoxedFreeFunc, but
can use information from type
(for instance to free the contents of a
container before freeing the actual container).
|
a specialized boxed type |
|
an instance of type
|
void (*DBusGTypeSpecializedMapAppendFunc) (DBusGTypeSpecializedAppendContext *ctx
,GValue *key
,GValue *val
);
Implements dbus_g_type_specialized_map_append()
.
This function should use the val
and specialization_type
members of ctx
,
and replace any existing value with key equal to key
.
|
an appending context returned by dbus_g_type_specialized_init_append()
|
|
a key to add to the collection |
|
a value to add to the collection |
void (*DBusGTypeSpecializedMapIterator) (const GValue *key_val
,const GValue *value_val
,gpointer user_data
);
A library-user-supplied function, called for each key/value pair in the
collection when dbus_g_type_map_value_iterate()
is called.
|
a key from the map |
|
a value from the map |
|
the data supplied when calling
dbus_g_type_map_value_iterate()
|
void (*DBusGTypeSpecializedMapIteratorFunc) (GType type
,gpointer instance
,DBusGTypeSpecializedMapIterator iterator
,gpointer user_data
);
Implements dbus_g_type_map_value_iterate()
for a GValue with
type type
, containing instance
.
|
a specialized map boxed type |
|
an instance of type
|
|
the function to call for each key/value pair |
|
data to pass to iterator
|
typedef struct { DBusGTypeSpecializedVtable base_vtable; DBusGTypeSpecializedMapIteratorFunc iterator; DBusGTypeSpecializedMapAppendFunc append_func; } DBusGTypeSpecializedMapVtable;
A table of methods used to implement specialized collection behaviour on user-defined types. Both methods must be implemented.
DBusGTypeSpecializedVtable |
base methods shared between maps and other types |
DBusGTypeSpecializedMapIteratorFunc |
iterates through the members of instance
|
DBusGTypeSpecializedMapAppendFunc |
adds a new key/value pair to instance
|
gboolean (*DBusGTypeSpecializedStructGetMember) (GType type
,gpointer instance
,guint member
,GValue *ret_value
);
Implements dbus_g_type_struct_get_member()
for a GValue with type type
,
containing instance
.
gboolean (*DBusGTypeSpecializedStructSetMember) (GType type
,gpointer instance
,guint member
,const GValue *new_value
);
Implements dbus_g_type_struct_set_member()
for a GValue with type type
,
containing instance
.
typedef struct { DBusGTypeSpecializedVtable base_vtable; DBusGTypeSpecializedStructGetMember get_member; DBusGTypeSpecializedStructSetMember set_member; } DBusGTypeSpecializedStructVtable;
A table of methods used to implement specialized collection behaviour on user-defined types. Both methods must be implemented.
DBusGTypeSpecializedVtable |
base methods shared between maps and other types |
DBusGTypeSpecializedStructGetMember |
returns a member by its index |
DBusGTypeSpecializedStructSetMember |
sets a member by its index |
typedef struct { DBusGTypeSpecializedConstructor constructor; DBusGTypeSpecializedFreeFunc free_func; DBusGTypeSpecializedCopyFunc copy_func; GDestroyNotify simple_free_func; /* for type-independent freeing if possible */ } DBusGTypeSpecializedVtable;
A table of methods used to implement specialized container behaviour on
user-defined collections, maps and structs. Exactly one of free_func
and
simple_free_func
must be implemented; the other must be NULL
.
constructor
and copy_func
must always be implemented.
There are additional members, which are reserved for future expansion and
must be NULL
.
DBusGTypeSpecializedConstructor |
returns a new, blank instance of the type
|
DBusGTypeSpecializedFreeFunc |
if not NULL , frees the type instance val
|
DBusGTypeSpecializedCopyFunc |
returns a "deep copy" of the type instance val
|
GDestroyNotify |
if not NULL , frees its argument |
gboolean dbus_g_type_collection_get_fixed (GValue *value
,gpointer *data_ret
,guint *len_ret
);
Calling this function is likely to be a bad idea. Consider using
dbus_g_type_collection_value_iterate()
instead.
On success, data_ret
is a pointer to the underlying data in a collection
of fixed-length fundamental types. Knowledge of the underlying data model
of the collection is needed in order to use data_ret
correctly.
It is an error to call this function on a specialized type that is not a
collection, or on a collection that does not have a fixed_accessor
in its
DBusGTypeSpecializedCollectionVtable.
Specialized GArrays are the only types provided by dbus-glib that can be used with this function; user-defined types might also work.
|
a GValue containing a boxed specialized collection
that has a fixed_accessor in its vtable |
|
used to return a pointer to the fixed data, which must not be modified (for instance, for a GArray of gint, this would point to an array of gint) |
|
used to return the length (counting collection elements, not bytes: in a GArray containing one gint, this would be 1) |
Returns : |
TRUE on success |
const DBusGTypeSpecializedCollectionVtable * dbus_g_type_collection_peek_vtable
(GType collection_type
);
Peek the vtable for a given collection specialization
|
a gtype of a collection specialization |
Returns : |
the vtable |
void dbus_g_type_collection_value_iterate (const GValue *value
,DBusGTypeSpecializedCollectionIterator iterator
,gpointer user_data
);
Calls the given function for each element of the collection.
The function is passed a GValue containing the element and the given
user_data
parameter. The collection may not be modified while iterating over
it.
|
a GValue holding a collection type. |
|
a function to call for each element |
|
user data to pass to the iterator
|
GType dbus_g_type_get_collection (const char *container
,GType specialization
);
Gets a GType for a particular collection instance, creating the type if not already created.
GType dbus_g_type_get_collection_specialization
(GType gtype
);
Return the type of each element in collections of type gtype
.
It is an error to call this function on a non-collection type.
|
a collection GType, as created by dbus_g_type_get_collection()
|
Returns : |
the element type for a given collection GType. |
GType dbus_g_type_get_map (const char *container
,GType key_specialization
,GType value_specialization
);
Gets a GType for a particular map instance, creating the type if not already created.
GType dbus_g_type_get_map_key_specialization
(GType gtype
);
Return the type of the keys in maps of type gtype
.
It is an error to call this function on a non-map type.
|
a map GType, as created by dbus_g_type_get_map()
|
Returns : |
the key type for a given map GType. |
GType dbus_g_type_get_map_value_specialization
(GType gtype
);
Return the type of the values in maps of type gtype
.
It is an error to call this function on a non-map type.
|
a map GType, as created by dbus_g_type_get_map() . |
Returns : |
the value type for a given map GType. |
GType dbus_g_type_get_struct (const char *container
,GType first_type
,...
);
Varags methsod to get a GType for a particular struct instance, creating the type if not already created.
GType dbus_g_type_get_struct_member_type (GType gtype
,guint member
);
Get the type of a member of a specialized struct. It is an error to call this function on a non-struct type.
|
a struct GType, as created with dbus_g_type_get_struct()
|
|
the index of a struct member |
Returns : |
the type for a given member of a struct GType,
or G_TYPE_INVALID if member >= dbus_g_type_get_struct_size()
|
guint dbus_g_type_get_struct_size (GType gtype
);
Get the number of members in a specialized struct. It is an error to call this function on a non-struct type.
|
a struct GType, as created with dbus_g_type_get_struct() . |
Returns : |
the number of members in a given struct GType. |
GType dbus_g_type_get_structv (const char *container
,guint num_members
,GType *types
);
Gets a GType for a particular struct instance, creating the type if not already created.
|
a string specifying a registered struct type |
|
number of members in the struct |
|
an array specufying a GType for each struct element |
Returns : |
the GType of that instance |
gboolean dbus_g_type_is_collection (GType gtype
);
Tests if a given GType is a collection.
|
a GType to test |
Returns : |
true if the given GType is a collection |
gboolean dbus_g_type_is_map (GType gtype
);
Tests if a given GType is a map,
i.e. it was created with dbus_g_type_get_map()
.
|
a GType to test |
Returns : |
true if the given GType is a map |
gboolean dbus_g_type_is_struct (GType gtype
);
Tests if a given GType is a struct,
i.e. it was created with dbus_g_type_get_struct()
|
a GType to test |
Returns : |
true if the given GType is a struct |
const DBusGTypeSpecializedMapVtable * dbus_g_type_map_peek_vtable
(GType map_type
);
Peek the vtable for a given map specialization
|
a gtype of a map specialization |
Returns : |
the vtable |
void dbus_g_type_map_value_iterate (const GValue *value
,DBusGTypeSpecializedMapIterator iterator
,gpointer user_data
);
Calls the given function for each key/value pair of the map.
The function is passed two GValues containing the key/value pair and the given
user_data
parameter. The map may not be modified while iterating over
it.
|
a GValue holding a specialized map |
|
a function to call for each element |
|
user data to pass to the iterator
|
void dbus_g_type_register_collection (const char *name
,const DBusGTypeSpecializedCollectionVtable *vtable
,guint flags
);
Defines a new collection container.
|
The name of a new collection container |
|
the vtable defining the new container |
|
As yet unused. |
void dbus_g_type_register_map (const char *name
,const DBusGTypeSpecializedMapVtable *vtable
,guint flags
);
Defines a new map container.
|
The name of a new map container |
|
the vtable defining the new container |
|
As yet unused. |
void dbus_g_type_register_struct (const char *name
,const DBusGTypeSpecializedStructVtable *vtable
,guint flags
);
Defines a new struct container.
|
The name of a new struct container |
|
the vtable defining the new container |
|
As yet unused. |
void dbus_g_type_specialized_collection_append (DBusGTypeSpecializedAppendContext *ctx
,GValue *elt
);
Appends a given element to the end of a collection.
|
a context created by dbus_g_type_specialized_init_append()
for a GValue containing a collection |
|
a GValue containing an element to append to the collection |
void dbus_g_type_specialized_collection_end_append
(DBusGTypeSpecializedAppendContext *ctx
);
Finish appending elements to a given collection
|
a context created by dbus_g_type_specialized_init_append()
for a GValue containing a collection |
gpointer dbus_g_type_specialized_construct (GType gtype
);
Create an instance of a given specialized type. The structure created and returned will depend on the container type of the GType. E.g. If the given type was created by dbus_g_type_get_collection("GArray", G_TYPE_INT), then this will return a GArray with element_size of sizeof(int)
|
a specialized GType, as created by dbus_g_type_get_collection() ,
dbus_g_type_get_map() or dbus_g_type_get_struct()
|
Returns : |
a pointer to a newly constructed instance of the given type. |
void dbus_g_type_specialized_init (void
);
Initialize dbus-glib specialized GTypes.
In older versions of dbus-glib, it was necessary to do this before instantiating or registering any specialized type. It is now done automatically whenever necessary.
void dbus_g_type_specialized_init_append (GValue *value
,DBusGTypeSpecializedAppendContext *ctx
);
Create a new context for adding elements to a collection or key/value pairs to a map. You generally don't need or want to use this..
|
a GValue containing an instance of specialized type |
|
a DBusGTypeSpecializedAppendContext in which to return a new appending context. |
void dbus_g_type_specialized_map_append (DBusGTypeSpecializedAppendContext *ctx
,GValue *key
,GValue *val
);
Inserts the given key/value pair into the map instance.
|
a context created by dbus_g_type_specialized_init_append()
for a GValue containing a map |
|
a GValue containing a key, whose contents will be stolen by ctx
|
|
a GValue containing a value, whose contents will be stolen by ctx
|
gboolean dbus_g_type_struct_get (const GValue *value
,guint member
,...
);
Collects the selected values of this struct into the return locations provided.
gboolean dbus_g_type_struct_get_member (const GValue *value
,guint member
,GValue *dest
);
Fetches a given member of a given struct instance. dest
must be initialised
was the correct type for that member, e.g. as returned by
dbus_g_type_get_struct_member_type
const DBusGTypeSpecializedStructVtable * dbus_g_type_struct_peek_vtable
(GType struct_type
);
Peek the vtable for a given struct specialization
|
a gtype of a struct specialization |
Returns : |
the vtable |
gboolean dbus_g_type_struct_set (GValue *value
,guint member
,...
);
Sets the selected members of the struct in value
.
gboolean dbus_g_type_struct_set_member (GValue *value
,guint member
,const GValue *src
);
Sets a given member of a struct to a new value. The type of src
must match
the existing type of member
member of the struct.
GVariant * dbus_g_value_build_g_variant (const GValue *value
);
Recurses value
and converts its contents to a GVariant.
The value must either be a simple value (integer, string, boolean,
object path etc.) or a specialized container registered with
dbus_g_type_get_collection()
, dbus_g_type_get_map()
or
dbus_g_type_get_struct()
. Providing any other type is a programming error
(including as a child type).