0

I am implementing a dbus server, and to simplify things, I decided to use gdbus-codegen.

This hello world example and it's repository are going to generate header and source files. Then it do this to connect the signal to the function:

g_signal_connect (interface, 
                  "handle-hello-world", 
                  G_CALLBACK (on_handle_hello_world), NULL);

My questions are next:

  • what is the function GType min_min_bus_gdbus_get_type (void) supposed to do? It is declared, but not defined in generated files.
  • instead of connecting signal to a callback function (as described above), can I somehow use the struct MinMinBusGDBUSIface, declared in the generated header?

Any example that I found on the net, are having these two things (*_get_type (void) function declaration, and struct *Iface declared in the generated header. How to use them?

BЈовић
  • 62,405
  • 41
  • 173
  • 273

1 Answers1

0

After playing with the example, finally I figured out the answers, and how to gain access to the interface structure, and how to set it. This is nowhere to be found, and is not documented anywhere.


After looking into the generated source file, the function GType min_min_bus_gdbus_get_type (void) may be defined in a huge macro garble, but I am not sure of it's functionality, and how to use it.


There is a way to access the struct MinMinBusGDBUSIface by use of the MIN_MIN_BUS_GDBUS_GET_IFACE macro (again in the generated header).

To set the function callback, this line in the example:

g_signal_connect (interface, 
                  "handle-hello-world", 
                  G_CALLBACK (on_handle_hello_world), NULL);

can be replaced by:

MinMinBusGDBUSIface* iface = MIN_MIN_BUS_GDBUS_GET_IFACE(interface);
iface->handle_hello_world = &on_handle_hello_world;

and the callback has to be modified to has the same signature as the function callback:

static gboolean
on_handle_hello_world (MinMinBusGDBUS *interface, 
                       GDBusMethodInvocation *invocation,
                       const gchar *greeting)
BЈовић
  • 62,405
  • 41
  • 173
  • 273
  • “This is nowhere to be found, and is not documented anywhere.” It _is_ documented: the GObject manual. This is a standard GObject type definition, and the assumption is that if you’re using `gdbus-codegen`, you have read about how to use GObject. Here’s the manual: https://developer.gnome.org/gobject/stable/index.html – Philip Withnall Aug 16 '17 at 22:35
  • @PhilipWithnall Thanks. There is not even one example showing this. All are with "g_signal_connect" – BЈовић Aug 17 '17 at 06:13