D-Bus GLib bindings - unable to get code from the ground

I played with GLib D-Bus bindings, trying to get something (something) to work with very limited success. I am trying to get Ross Burton sample code to compile and run, but continue to face new and exciting difficulties.

Can you help debug this code or, if that fails, point me to some example of a D-Bus GLib code that works?

Since Ross code is outdated, I replaced the line

dbus_g_object_class_install_info (G_OBJECT_CLASS (echo_class), &dbus_glib_echo_object_info); 

from

 dbus_g_object_type_install_info (G_OBJECT_TYPE (echo_class), &dbus_glib_echo_object_info); 

for his comments on this article, but made no other changes than updating the include directories to match the setting in my field.

When I run the server executable, I get the following error:

 ** (process:11747): CRITICAL **: dbus_g_object_type_install_info: assertion `G_TYPE_IS_CLASSED (object_type) || G_TYPE_IS_INTERFACE (object_type)' failed 

The stack trace at this point, according to gdb,

 #0 0x0000003b5f40b440 in dbus_g_object_type_install_info () from /usr/lib64/libdbus-glib-1.so.2 #1 0x0000003b5722909c in g_type_class_ref () from /lib64/libgobject-2.0.so.0 #2 0x0000003b57229798 in g_type_create_instance () from /lib64/libgobject-2.0.so.0 #3 0x0000000000400f16 in main (argc=<value optimized out>, argv=0x7fff156497d8) at EchoObject.c:111 

I am not sure what is going wrong, or what should be done when debugging. I would like to get the basic code for sending and receiving messages about calling the D-Bus method, so I can see how everything should work in my application.

I am using D-Bus 0.73.

Update . Given the lack of success on my part and the lack of an answer here, I am now looking at dropping D-Bus and looking for another IPC mechanism.

Update 2 . In the end, I went with a UNIX approach called sockets, which does exactly what I need to do a total of 280 lines of code (plus test code).

+4
source share
2 answers

In the next line

 dbus_g_object_type_install_info (G_OBJECT_TYPE (echo_class), &dbus_glib_echo_object_info); 

you need to use the macro G_OBJECT_CLASS_TYPE () instead of G_OBJECT_TYPE ().

This is because echo_class is an instance of EchoClass, which is the "class structure" in the GObject world. G_OBJECT_TYPE () is for "object structures", which will be an Echo structure in the above example.

I know this answer is a way to be late for @me_and, but maybe someone will find it useful.

+3
source

dbus-glib is quite ... unpleasant to use, and it is mostly not supported at this point. You should probably use its upcoming replacement, GDBus, which will be included in the next stable GLib release. Check out Lowlevel D-Bus Support and D-Bus Highlevel Support in the documentation section for more details.

+2
source

All Articles