How to create a new GType using dbus-Glib?

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Mar 23 07:03:34 PDT 2012


On 23/03/12 09:53, ben ayed wiem wrote:
> But when I want to use the interface to send a "SetSpeed" event
> using the method "SendEventName", I need to create a new GTYPE
> "DBUS_TYPE_G_INIT16_ARRAY" which is an array of int16.

dbus-glib does not support 16-bit integer types (it pretends to, but
what it actually sends on D-Bus is the corresponding 32-bit type).

Please use GDBus, part of GIO >= 2.26, for D-Bus in GLib-based code -
dbus-glib is rubbish (I think I can safely say that, as its de facto
maintainer these days).

> I found this function 
> "#define
> DBUS_TYPE_G_INIT16_ARRAY (dbus_g_type_get_collection("GArray",Int16))" 
> but it doesn't know the type Int16.

That's not how you use it. The second argument is a GType as defined by
GObject, not a C type name (see the GObject documentation for background
information on GTypes), so you'd need to find the right GType.

When you tried to find the right GType in GObject for a 16-bit integer,
you'd discover that there is no G_TYPE_INT16 - which is why dbus-glib
doesn't support 16-bit integers. (There is a G_TYPE_INT and a
G_TYPE_INT64, though - those are the right sort of thing to use for the
second argument.)

Regards,
    S


More information about the dbus mailing list