Notes of GDBus
Conceptions:
– D-BUS is an IPC method. what is IPC ?
– It is common on Linux-like platform
– High level API implemented by dbus-glib, python … so on.
– server – client services
Notice: use GDBus instead of dbus-glib: comparing
→ GDBus: https://developer.gnome.org/gio/stable/
Then following are some code snippets and configuration examples.
TO-DO:
– system.conf (push under the etc/dbus-1/system.d/)
– makefile
– implement server and client
Server & Client example:
pre-define:
Object: g_dbus_connection_register_object
Interface name
Service name
Initial:
– g_queue_new
– g_dbus_node_info_new_for_xml: method calls, signals
– g_bus_own_name
– GDBusConnection
Flows:
– Response: g_dbus_method_invocation_return_value
– Error handlers
…
https://linoxide.com/how-tos/d-bus-ipc-mechanism-linux/
system.conf:
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root or user avahi can own the Avahi service -->
<policy user="root">
<allow own="test.dbuscall.dest"/>
<allow own="test.dbuscall.source"/>
</policy>
<!-- Allow anyone to invoke methods on Avahi server, except SetHostName -->
<policy context="default">
<allow send_destination="test.dbuscall.dest"/> <!--server -->
<allow receive_sender="test.dbuscall.source"/> <!--client-->
</policy>
</busconfig>
makefile:
NEW!!
library: gio-unix-2.0
ref: https://developer.gnome.org/gio/stable/ch03.html
OLD …
libaries: dbus dbus-glib
source/header: dbus-1.0 glib-2.0
ref: https://developer.gnome.org/glib/stable/glib-compiling.html
How to test your configuration?
a. add test-dbus.conf under /etc/dbus-1/system.d
adb shell
mount -o rw,remount /
adb push /test-dbus.conf /etc/dbus-1/system.d
b. You need two terminals
terminal i.:
adb shell
./data/gio_server_test
terminal ii:
adb shell
dbus-send –system –print-reply –type=method_call –dest=org.gtk.GDBus.TestServer /org/gtk/GDBus/TestObject org.gtk.GDBus.TestInterface.HelloWorld string:’HiHi’
References:
Tutorial:
https://dbus.freedesktop.org/doc/dbus-tutorial.html
Introductions:
http://takluyver.github.io/posts/understanding-dbus.html
http://ops9.blogspot.com/2013/08/d-bus.html
GDBus:
https://www.freedesktop.org/wiki/Software/DBusBindings/
https://developer.gnome.org/gio/stable/gdbus-convenience.html
https://developer.gnome.org/gio/stable/gdbus-lowlevel.html
Last modified 1yr ago