Q: How to update connection user_data
Alec Leamas
leamas.alec at gmail.com
Mon Aug 28 08:00:23 UTC 2023
Dear list,
This is my first attempts to actually code any DBus stuff. The first
stop is to create some unit tests. This mostly seems to work using the
the "official" example code, notably [1].
However, I run into problems trying to use the "user_data" pointer
provided to g_bus_own_name(). If I read the documents correctly
(probably not...) this argument to g_bus_own_name is will later be
visible in the method call handler, in my case indeed named
HandleMethodCall().
Which works fine in my first unit test. This test ends up in
if (owner_id) g_bus_unown_name(owner_id);
g_dbus_node_info_unref(introspection_data);
In next unit test, I once again invoke g_bus_own_name() with a new
user_data value. However, in HandleMethodCall() the user_data is still
the same as in the first test -> crash.
For the moment, I work around this using a new static_user_data variable
which makes the updated pointer available in a static context. Needless
to say, this is far from satisfactory.
Any clues out there how I could persuade gdbus to update the user_data
pointer?
Complete code in [2]. The relevant parts are include/dbus_handler.cpp,
src/dbus_handler.cpp and test/tests.cpp.
Cheers!
--alec
[1]
https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-server.c
[2] https://github.com/leamas/OpenCPN/tree/user_data
More information about the dbus
mailing list