D-bus service name and interface name
David Sommerseth
dbus at lists.topphemmelig.net
Tue Nov 14 14:21:35 UTC 2017
On 14/11/17 10:41, Ravi Kumar Kandati wrote:
> Hi ,
>
> I am using low-level D-bus API in our source. I am registering the
> name(dbus_bus_request_name) and object
> path(dbus_connection_register_object_path).
>
> While refering bluez documentation for D-bus, I have seen service name
> and interface name. What is the significance of service name when
> compare to interface name?
Service name is typically a specific service you connect to to perform
some actions. Think if it like a hostname for services.
Interfaces is trickier to explain (at least for me). But you can think
of it as a group of methods, signals and properties inside a D-Bus
object.
See the example below, where an active network connection managed by
NetworkManager is being introspected. The object path ("address")
defines which connection is being queried.
(I've added some blank lines in between for clarity)
$ gdbus introspect --system \
--dest org.freedesktop.NetworkManager \
--object-path /org/freedesktop/NetworkManager/ActiveConnection/1
node /org/freedesktop/NetworkManager/ActiveConnection/1 {
interface org.freedesktop.DBus.Properties {
methods:
Get(in s interface_name,
in s property_name,
out v value);
GetAll(in s interface_name,
out a{sv} properties);
Set(in s interface_name,
in s property_name,
in v value);
signals:
PropertiesChanged(s interface_name,
a{sv} changed_properties,
as invalidated_properties);
properties:
};
interface org.freedesktop.DBus.Introspectable {
methods:
Introspect(out s xml_data);
signals:
properties:
};
interface org.freedesktop.DBus.Peer {
methods:
Ping();
GetMachineId(out s machine_uuid);
signals:
properties:
};
interface org.freedesktop.NetworkManager.Connection.Active {
methods:
signals:
StateChanged(u state,
u reason);
PropertiesChanged(a{sv} properties);
properties:
readonly o Connection = '/org/freedesktop/NetworkManager/Settings/16';
readonly o SpecificObject = '/';
readonly s Id = 'virbr0';
readonly s Uuid = 'fca4bac8-2029-4ae2-a132-93fb2a6140c6';
readonly s Type = 'bridge';
readonly ao Devices = ['/org/freedesktop/NetworkManager/Devices/4'];
readonly u State = 2;
readonly b Default = false;
readonly o Ip4Config = '/org/freedesktop/NetworkManager/IP4Config/5';
readonly o Dhcp4Config = '/';
readonly b Default6 = false;
readonly o Ip6Config = '/org/freedesktop/NetworkManager/IP6Config/5';
readonly o Dhcp6Config = '/';
readonly b Vpn = false;
readonly o Master = '/';
};
};
This enlists 4 different interfaces, where each have a quite different
set of methods, signals and properties. But they all is found inside
the same D-Bus object (defined by object-path). And this D-Bus object
is provided by the org.freedesktop.NetworkManager service (destination,
in D-Bus speak).
It might be a bit more clearer when you start to want to query the
object properties. To retrieve the value of for example the
Uuid property in the org.freedesktop.NetworkManager.Connection.Active
interface, you need to go via the org.freedesktop.DBus.Properties
interface.
$ gdbus call --system \
--dest org.freedesktop.NetworkManager \
--object-path /org/freedesktop/NetworkManager/ActiveConnection/1 \
--method org.freedesktop.DBus.Properties.Get \
org.freedesktop.NetworkManager.Connection.Active Uuid
(<'fca4bac8-2029-4ae2-a132-93fb2a6140c6'>)
What happens here is that you connect to the
org.freedesktop.NetworkManager service (--dest) on the system bus
(--system) and accesses the object provided by --object-path. You
call a method called Get inside the org.freedesktop.DBus.Properties
interface. This method requires two arguments, the interface of
property you want to retrieve and the property name itself. So
we provide org.freedesktop.NetworkManager.Connection.Active as
the interface and Uuid as the property name.
I hope this helped ... otherwise, there's plenty of other smart
developers on this list as well.
--
kind regards,
David Sommerseth
More information about the dbus
mailing list