DBus [DRAFT]
Created at 2017-05-08T21:26:28+09:00

TODO

  • system startup
  • security model
  • python client example
  • Linux desktop (freedesktop, gnome) example
$ gdbus introspect --system --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --recurse
node /org/freedesktop/DBus {
  interface org.freedesktop.DBus {
    methods:
      Hello(out s arg_0);
      RequestName(in  s arg_0,
                  in  u arg_1,
                  out u arg_2);
      ReleaseName(in  s arg_0,
                  out u arg_1);
      StartServiceByName(in  s arg_0,
                         in  u arg_1,
                         out u arg_2);
      UpdateActivationEnvironment(in  a{ss} arg_0);
      NameHasOwner(in  s arg_0,
                   out b arg_1);
      ListNames(out as arg_0);
      ListActivatableNames(out as arg_0);
      AddMatch(in  s arg_0);
      RemoveMatch(in  s arg_0);
      GetNameOwner(in  s arg_0,
                   out s arg_1);
      ListQueuedOwners(in  s arg_0,
                       out as arg_1);
      GetConnectionUnixUser(in  s arg_0,
                            out u arg_1);
      GetConnectionUnixProcessID(in  s arg_0,
                                 out u arg_1);
      GetAdtAuditSessionData(in  s arg_0,
                             out ay arg_1);
      GetConnectionSELinuxSecurityContext(in  s arg_0,
                                          out ay arg_1);
      ReloadConfig();
      GetId(out s arg_0);
      GetConnectionCredentials(in  s arg_0,
                               out a{sv} arg_1);
    signals:
      NameOwnerChanged(s arg_0,
                       s arg_1,
                       s arg_2);
      NameLost(s arg_0);
      NameAcquired(s arg_0);
    properties:
  };
  interface org.freedesktop.DBus.Introspectable {
    methods:
      Introspect(out s arg_0);
    signals:
    properties:
  };
  interface org.freedesktop.DBus.Monitoring {
    methods:
      BecomeMonitor(in  as arg_0,
                    in  u arg_1);
    signals:
    properties:
  };
  interface org.freedesktop.DBus.Debug.Stats {
    methods:
      GetStats(out a{sv} arg_0);
      GetConnectionStats(in  s arg_0,
                         out a{sv} arg_1);
      GetAllMatchRules(out a{sas} arg_0);
    signals:
    properties:
  };
};
$ gdbus call --session --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames
(['org.freedesktop.DBus', ':1.315', ':1.7', ':1.8', 'org.gnome.GConf', 'org.freedesktop.systemd1', 'org.a11y.Bus', ':1.10', 'org.gtk.vfs.Daemon', ':1.0', ':1.1', 'org.PulseAudio1', 'org.pulseaudio.Server', ':1.15', ':1.16', ':1.3', ':1.17', ':1.4', ':1.6'],)
$ gdbus call --system --dest org.freedesktop.DBus --object-path /org/freedesktop/DBus --method org.freedesktop.DBus.ListNames
(['org.freedesktop.DBus', 'org.freedesktop.login1', ':1.1737', 'org.freedesktop.ColorManager', ':1.3044', 'org.freedesktop.systemd1', ':1.20', 'org.freedesktop.PolicyKit1', ':1.7633', ':1.32', ':1.43', ':1.21', 'org.freedesktop.NetworkManager', 'org.freedesktop.UPower', ':1.0', 'org.freedesktop.UDisks2', ':1.24', ':1.1', ':1.2', ':1.27', ':1.6309', 'fi.epitest.hostap.WPASupplicant', ':1.1503', ':1.18', ':1.5', 'fi.w1.wpa_supplicant1', 'org.freedesktop.Accounts', 'org.freedesktop.RealtimeKit1', ':1.1504', ':1.6'],)
$ dbus-send --system --dest=org.freedesktop.DBus --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
method return time=1495721062.191429 sender=org.freedesktop.DBus -> destination=:1.8185 serial=3 reply_serial=2
   array [
      string "org.freedesktop.DBus"
      string "org.freedesktop.login1"
      string ":1.1737"
      string "org.freedesktop.ColorManager"
      string ":1.3044"
      string "org.freedesktop.systemd1"
      string ":1.20"
      string "org.freedesktop.PolicyKit1"
      string ":1.32"
      string ":1.43"
      string ":1.21"
      string "org.freedesktop.NetworkManager"
      string "org.freedesktop.UPower"
      string ":1.0"
      string "org.freedesktop.UDisks2"
      string ":1.24"
      string ":1.1"
      string ":1.2"
      string ":1.27"
      string ":1.8185"
      string ":1.6309"
      string "fi.epitest.hostap.WPASupplicant"
      string ":1.1503"
      string ":1.18"
      string ":1.5"
      string "fi.w1.wpa_supplicant1"
      string "org.freedesktop.Accounts"
      string "org.freedesktop.RealtimeKit1"
      string ":1.1504"
      string ":1.6"
   ]
$ dbus-send --session --dest=org.freedesktop.DBus --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
method return time=1495721072.160197 sender=org.freedesktop.DBus -> destination=:1.340 serial=3 reply_serial=2
   array [
      string "org.freedesktop.DBus"
      string ":1.7"
      string "org.freedesktop.ReserveDevice1.Audio0"
      string ":1.8"
      string "org.gnome.GConf"
      string "org.freedesktop.systemd1"
      string "org.a11y.Bus"
      string ":1.10"
      string ":1.340"
      string "org.gtk.vfs.Daemon"
      string ":1.0"
      string ":1.1"
      string "org.PulseAudio1"
      string "org.pulseaudio.Server"
      string ":1.15"
      string ":1.16"
      string ":1.3"
      string ":1.17"
      string ":1.4"
      string ":1.6"
   ]
>>> from dbus import *
>>> pprint(sorted(map(str, SystemBus().list_names())))
[':1.0',
  ...
 ':1.98',
 'fi.epitest.hostap.WPASupplicant',
 'fi.w1.wpa_supplicant1',
 'org.bluez',
 'org.freedesktop.Accounts',
 'org.freedesktop.Avahi',
 'org.freedesktop.ColorManager',
 'org.freedesktop.DBus',
 'org.freedesktop.DisplayManager',
 'org.freedesktop.ModemManager1',
 'org.freedesktop.NetworkManager',
 'org.freedesktop.NetworkManager.dnsmasq',
 'org.freedesktop.PackageKit',
 'org.freedesktop.PolicyKit1',
 'org.freedesktop.RealtimeKit1',
 'org.freedesktop.UDisks2',
 'org.freedesktop.UPower',
 'org.freedesktop.fwupd',
 'org.freedesktop.login1',
 'org.freedesktop.resolve1',
 'org.freedesktop.systemd1',
 'org.freedesktop.thermald']
>>> pprint(sorted(map(str, SessionBus().list_names())))
[':1.0',
 ...
 ':1.98',
 'ca.desrt.dconf',
 'com.canonical.URLDispatcher',
 'com.canonical.Unity.WindowStack',
 'com.ubuntu.Upstart',
 'org.PulseAudio1',
 'org.a11y.Bus',
 'org.ayatana.bamf',
 'org.freedesktop.DBus',
 'org.freedesktop.FileManager1',
 'org.freedesktop.IBus',
 'org.freedesktop.Notifications',
 'org.freedesktop.ScreenSaver',
 'org.freedesktop.Telepathy.AccountManager',
 'org.freedesktop.Telepathy.ChannelDispatcher',
 'org.freedesktop.Telepathy.Client.GnomeShell._3a1_2e54.n0',
 'org.freedesktop.Telepathy.MissionControl5',
 'org.freedesktop.Tracker1',
 'org.freedesktop.Tracker1.Miner.Applications',
 'org.freedesktop.Tracker1.Miner.Extract',
 'org.freedesktop.Tracker1.Miner.Files',
 'org.freedesktop.Tracker1.Miner.Files.Index',
 'org.freedesktop.Tracker1.Miner.Userguides',
 'org.freedesktop.secrets',
 'org.freedesktop.systemd1',
 'org.gnome.Caribou.Keyboard',
 'org.gnome.DejaDup.Monitor',
 'org.gnome.EvolutionAlarmNotify',
 'org.gnome.GConf',
 'org.gnome.Identity',
 'org.gnome.Magnifier',
 'org.gnome.Mutter.DisplayConfig',
 'org.gnome.Mutter.IdleMonitor',
 'org.gnome.Nautilus',
 'org.gnome.OnlineAccounts',
 'org.gnome.Panel',
 'org.gnome.ScreenSaver',
 'org.gnome.SessionManager',
 'org.gnome.SettingsDaemon',
 'org.gnome.SettingsDaemon.Power',
 'org.gnome.SettingsDaemon.Rfkill',
 'org.gnome.SettingsDaemon.Sharing',
 'org.gnome.SettingsDaemon.Smartcard',
 'org.gnome.SettingsDaemon.Wacom',
 'org.gnome.SettingsDaemon.XRANDR',
 'org.gnome.Shell',
 'org.gnome.Shell.AudioDeviceSelection',
 'org.gnome.Shell.CalendarServer',
 'org.gnome.Shell.Screencast',
 'org.gnome.Shell.Screenshot',
 'org.gnome.Software',
 'org.gnome.Terminal',
 'org.gnome.evolution.dataserver.AddressBook9',
 'org.gnome.evolution.dataserver.Calendar7',
 'org.gnome.evolution.dataserver.Sources5',
 'org.gnome.evolution.dataserver.Subprocess.Backend.AddressBookx3317x2',
 'org.gnome.evolution.dataserver.Subprocess.Backend.Calendarx3270x2',
 'org.gnome.evolution.dataserver.Subprocess.Backend.Calendarx3270x3',
 'org.gnome.keyring',
 'org.gnome.keyring.SystemPrompter',
 'org.gnome.zeitgeist.Engine',
 'org.gnome.zeitgeist.SimpleIndexer',
 'org.gnome.zeitgeist.datahub',
 'org.gtk.MountOperationHandler',
 'org.gtk.Notifications',
 'org.gtk.vfs.AfcVolumeMonitor',
 'org.gtk.vfs.Daemon',
 'org.gtk.vfs.GPhoto2VolumeMonitor',
 'org.gtk.vfs.GoaVolumeMonitor',
 'org.gtk.vfs.MTPVolumeMonitor',
 'org.gtk.vfs.Metadata',
 'org.gtk.vfs.UDisks2VolumeMonitor',
 'org.gtk.vfs.mountpoint_3290',
 'org.gtk.vfs.mountpoint_3356',
 'org.gtk.vfs.mountpoint_http',
 'org.kde.ActivityManager',
 'org.kde.JobViewServer',
 'org.kde.StatusNotifierItem-3197-1',
 'org.kde.kcookiejar5',
 'org.kde.kded',
 'org.kde.kded5',
 'org.kde.kglobalaccel',
 'org.kde.klauncher',
 'org.kde.klauncher5',
 'org.kde.klipper',
 'org.kde.kuiserver',
 'org.kde.kwalletd5',
 'org.kde.okular-13571',
 'org.pulseaudio.Server',
 'org.shutter-project.Shutter']

>>> obj = SessionBus().get_object('org.gnome.Shell', '/org/gnome/Shell')
>>> xml = obj.get_dbus_method('Introspect', dbus_interface='org.freedesktop.DBus.Introspectable')()
>>> print(str(xml))
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
                      "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.50.2 -->
<node>
  # list of interfaces this object supports
  # these are "standard interface"
  <interface name="org.freedesktop.DBus.Introspectable">
    <method name="Introspect">
      <arg type="s" name="xml_data" direction="out"/>
      ...
  <interface name="org.freedesktop.DBus.Peer">
    <method name="Ping"/>
    ...
  # these are org.gnome.Shell specific interfaces
  <interface name="org.gnome.Shell">
    <method name="Eval">
      <arg type="s" name="script" direction="in">
      </arg>
      <arg type="b" name="success" direction="out">
      </arg>
      <arg type="s" name="result" direction="out">
      </arg>
    </method>
    ...
    <signal name="AcceleratorActivated">
      <arg type="u" name="action">
      </arg>
      <arg type="a{sv}" name="parameters">
      </arg>
    </signal>
    ...
    <property type="b" name="OverviewActive" access="readwrite">
    </property>
    ...
  </interface>
  <interface name="org.gnome.Shell.Extensions">
    <method name="ListExtensions">
      <arg type="a{sa{sv}}" name="extensions" direction="out">
      </arg>
      ...
  # here, child object paths
  <node name="Screencast"/>
  <node name="Screenshot"/>
  ...
</node>

References