In this blog we extent our previous example list HCI controller using GDBUS method to get the properties of the Adapter. We will examine the Adapter properties both by using “GetManagedObject” and also using “GetAll” method in org.freedesktop.DBus.Properties interface.
Code:
In our previous example we have used GetManagedObject and filtered the output only to view Adapter related information (Adapter MAC address and Name). Here we further extended the iteration to view the property of all the interfaces. The same information can also obtained from “GetAll” method in properties interface.
Most important things to note in this sample is the signature which is used to parse the output. For GetManagedObjects we have “a{oa{sa{sv}}}” and GetAll we have {sv}. To understand the format used by DBUS for marshalling and serializing the data one must understand the DBUS type systems. Explaining the complete type system and it’s organization in DBUS is beyond the scope of this blog, but will be covered in dedicated future blog for DBUS specification.
For now, a{oa{sa{sv}}} means,
a{0 – array of object paths (i.e. like int a[10] – array of 10 integers). For example, /org/bluez, /org/bluez/hci0, /org/bluez/hci1, /org/bluez/hci1/dev_XX_YY_ZZ_AA_BB_CC
a{s – array of interfaces. For example, org.bluez.ProfileManager1, org.bluez.Adapter1. Note that our previous curly braces is not closed yet, which means “array of object paths, where each object path may have array of interfaces”. Something like “array of arrays”
a{s – array of properties. Which means, “for each interface, we have array of properties”.
v – variant value. Variant as literally meaning, it can be string, integer, boolean, array of string or even array of arrays. So this details will be part of the software, in our case it’s Bluez. To have specific examples, Adapter Name is a string, Powered is boolean and UUID’s is array of strings.
For GetAll we have “{sv}“, which is again the same representation as in GetManagedObjects for “array of properties name and it’s values in variant”. One can always use “g_variant_get_type_string” to get the exact signature of the data before processing the data.
The same output of GetAll can be observed using dbus-send command. Try the following command after adjusting the adapter path.
dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/org/bluez/hci0' org.freedesktop.DBus.Properties.GetAll string:"org.bluez.Adapter1"
The `dbus-send` command at the bottom seems to have had some sort of auto-formatting applied to it. It should be: `dbus-send –system –print-reply –type=method_call –dest=’org.bluez’ ‘/org/bluez/hci0’ org.freedesktop.DBus.Properties.GetAll string:”org.bluez.Adapter1″`
Thanks for pointing it David Frey. I have removed the auto-formatting.