computerの日記

Cisco,SHELL,Qt,C++,Linux,ネットワーク,Windows Scriptなどの発言です

dbus を使ってみる(その2)

こんにちは、私です。

今日は、ここを見てみました。
http://pkpkbook.eha03.biz/?page_id=3976

さて、自分の端末で、コマンドを叩いてみます。

====
存在するパスの一覧を、配列で取得するコマンドです。

system bus について確認してみます。

$ dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames

(Fedora26 での表示結果です)
method return time=1503147498.801389 sender=org.freedesktop.DBus -> destination=:1.128 serial=3 reply_serial=2
array [
string "org.freedesktop.DBus"
string ":1.128"
string ":1.7"
string ":1.9"
string "org.freedesktop.systemd1"
string "org.fedoraproject.FirewallD1"
string "org.freedesktop.ModemManager1"
string "org.freedesktop.NetworkManager"
string "com.redhat.ifcfgrh1"
string "org.freedesktop.RealtimeKit1"
string "org.freedesktop.Accounts"
string ":1.40"
string ":1.41"
string ":1.64"
string "org.freedesktop.PolicyKit1"
string ":1.43"
string "org.bluez"
string ":1.44"
string ":1.46"
string ":1.24"
string ":1.69"
string ":1.26"
string "fi.epitest.hostap.WPASupplicant"
string "org.freedesktop.Avahi"
string "org.freedesktop.UDisks2"
string "org.fedoraproject.SetroubleshootFixit"
string "fi.w1.wpa_supplicant1"
string "org.freedesktop.login1"
string "org.freedesktop.ColorManager"
string ":1.72"
string ":1.50"
string ":1.73"
string ":1.51"
string "org.freedesktop.DisplayManager"
string ":1.30"
string ":1.31"
string ":1.98"
string "org.freedesktop.problems.daemon"
string ":1.10"
string ":1.32"
string ":1.99"
string ":1.11"
string ":1.33"
string "org.freedesktop.UPower"
string ":1.0"
string ":1.35"
string ":1.1"
string ":1.14"
string ":1.36"
string ":1.37"
string ":1.2"
string ":1.15"
string "org.freedesktop.problems"
string ":1.38"
string ":1.3"
string ":1.16"
string ":1.39"
string ":1.4"
string ":1.17"
string ":1.5"
string ":1.18"
string ":1.6"
string ":1.19"
]

session bus について確認してみます。

$ dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames

(Fedora26 での表示結果です)
method return time=1503147450.719214 sender=org.freedesktop.DBus -> destination=:1.119 serial=3 reply_serial=2
array [
string "org.freedesktop.DBus"
string "org.freedesktop.PowerManagement"
string "org.freedesktop.network-manager-applet"
string "org.freedesktop.systemd1"
string "org.xfce.Terminal5"
string "org.xfce.Xfconf"
string "org.gtk.vfs.mountpoint_2756"
string "org.gtk.vfs.Daemon"
string "org.pulseaudio.Server"
string "org.freedesktop.problems.applet"
string ":1.81"
string "org.xfce.Panel"
string ":1.60"
string ":1.61"
string ":1.62"
string "org.gnome.GConf"
string ":1.63"
string "org.a11y.Bus"
string ":1.41"
string "org.gtk.vfs.UDisks2VolumeMonitor"
string ":1.64"
string ":1.20"
string ":1.42"
string ":1.21"
string ":1.43"
string ":1.66"
string ":1.22"
string ":1.44"
string ":1.23"
string ":1.45"
string ":1.46"
string ":1.69"
string ":1.25"
string "org.xfce.xfdesktop"
string ":1.47"
string ":1.26"
string ":1.48"
string ":1.49"
string ":1.27"
string "org.xfce.PowerManager"
string "org.xfce.FileManager"
string ":1.28"
string "com.redhat.imsettings"
string ":1.29"
string "ca.desrt.dconf"
string "org.freedesktop.ReserveDevice1.Audio0"
string ":1.119"
string "org.PulseAudio1"
string "org.xfce.SessionManager"
string "org.gnome.d-feet"
string ":1.70"
string ":1.71"
string "org.xfce.Thunar"
string "org.blueman.Applet"
string ":1.50"
string ":1.51"
string ":1.74"
string "org.gtk.vfs.Metadata"
string ":1.52"
string ":1.75"
string ":1.53"
string ":1.31"
string ":1.76"
string ":1.32"
string ":1.55"
string ":1.56"
string ":1.57"
string ":1.0"
string ":1.58"
string ":1.36"
string ":1.59"
string "org.xfce.SettingsDaemon"
string ":1.38"
string ":1.4"
string ":1.5"
string "org.freedesktop.IBus"
string ":1.19"
]

====
D-Busの仕様にある標準インターフェースを得る方法です。特定のオブジェクトのインターフェースがXML形式で返却されました。

system bus の検索結果です。

$ dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect

(Fedora26 での表示結果です)
method return time=1503147306.197404 sender=org.freedesktop.DBus -> destination=:1.127 serial=3 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus">
<method name="Hello">
<arg direction="out" type="s"/>
</method>
<method name="RequestName">
<arg direction="in" type="s"/>
<arg direction="in" type="u"/>
<arg direction="out" type="u"/>
</method>
<method name="ReleaseName">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="StartServiceByName">
<arg direction="in" type="s"/>
<arg direction="in" type="u"/>
<arg direction="out" type="u"/>
</method>
<method name="UpdateActivationEnvironment">
<arg direction="in" type="a{ss}"/>
</method>
<method name="NameHasOwner">
<arg direction="in" type="s"/>
<arg direction="out" type="b"/>
</method>
<method name="ListNames">
<arg direction="out" type="as"/>
</method>
<method name="ListActivatableNames">
<arg direction="out" type="as"/>
</method>
<method name="AddMatch">
<arg direction="in" type="s"/>
</method>
<method name="RemoveMatch">
<arg direction="in" type="s"/>
</method>
<method name="GetNameOwner">
<arg direction="in" type="s"/>
<arg direction="out" type="s"/>
</method>
<method name="ListQueuedOwners">
<arg direction="in" type="s"/>
<arg direction="out" type="as"/>
</method>
<method name="GetConnectionUnixUser">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="GetConnectionUnixProcessID">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="GetAdtAuditSessionData">
<arg direction="in" type="s"/>
<arg direction="out" type="ay"/>
</method>
<method name="GetConnectionSELinuxSecurityContext">
<arg direction="in" type="s"/>
<arg direction="out" type="ay"/>
</method>
<method name="ReloadConfig">
</method>
<method name="GetId">
<arg direction="out" type="s"/>
</method>
<method name="GetConnectionCredentials">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<property name="Features" type="as" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="Interfaces" type="as" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<signal name="NameOwnerChanged">
<arg type="s"/>
<arg type="s"/>
<arg type="s"/>
</signal>
<signal name="NameLost">
<arg type="s"/>
</signal>
<signal name="NameAcquired">
<arg type="s"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg direction="in" type="s"/>
<arg direction="in" type="s"/>
<arg direction="out" type="v"/>
</method>
<method name="GetAll">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<method name="Set">
<arg direction="in" type="s"/>
<arg direction="in" type="s"/>
<arg direction="in" type="v"/>
</method>
<signal name="PropertiesChanged">
<arg type="s" name="interface_name"/>
<arg type="a{sv}" name="changed_properties"/>
<arg type="as" name="invalidated_properties"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Monitoring">
<method name="BecomeMonitor">
<arg direction="in" type="as"/>
<arg direction="in" type="u"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Debug.Stats">
<method name="GetStats">
<arg direction="out" type="a{sv}"/>
</method>
<method name="GetConnectionStats">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<method name="GetAllMatchRules">
<arg direction="out" type="a{sas}"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="GetMachineId">
<arg direction="out" type="s"/>
</method>
<method name="Ping">
</method>
</interface>
</node>
"
session bus の検索結果です。

$ dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect

(Fedora26の表示結果です)
method return time=1503147700.526298 sender=org.freedesktop.DBus -> destination=:1.120 serial=3 reply_serial=2
string "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus">
<method name="Hello">
<arg direction="out" type="s"/>
</method>
<method name="RequestName">
<arg direction="in" type="s"/>
<arg direction="in" type="u"/>
<arg direction="out" type="u"/>
</method>
<method name="ReleaseName">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="StartServiceByName">
<arg direction="in" type="s"/>
<arg direction="in" type="u"/>
<arg direction="out" type="u"/>
</method>
<method name="UpdateActivationEnvironment">
<arg direction="in" type="a{ss}"/>
</method>
<method name="NameHasOwner">
<arg direction="in" type="s"/>
<arg direction="out" type="b"/>
</method>
<method name="ListNames">
<arg direction="out" type="as"/>
</method>
<method name="ListActivatableNames">
<arg direction="out" type="as"/>
</method>
<method name="AddMatch">
<arg direction="in" type="s"/>
</method>
<method name="RemoveMatch">
<arg direction="in" type="s"/>
</method>
<method name="GetNameOwner">
<arg direction="in" type="s"/>
<arg direction="out" type="s"/>
</method>
<method name="ListQueuedOwners">
<arg direction="in" type="s"/>
<arg direction="out" type="as"/>
</method>
<method name="GetConnectionUnixUser">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="GetConnectionUnixProcessID">
<arg direction="in" type="s"/>
<arg direction="out" type="u"/>
</method>
<method name="GetAdtAuditSessionData">
<arg direction="in" type="s"/>
<arg direction="out" type="ay"/>
</method>
<method name="GetConnectionSELinuxSecurityContext">
<arg direction="in" type="s"/>
<arg direction="out" type="ay"/>
</method>
<method name="ReloadConfig">
</method>
<method name="GetId">
<arg direction="out" type="s"/>
</method>
<method name="GetConnectionCredentials">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<property name="Features" type="as" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<property name="Interfaces" type="as" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
</property>
<signal name="NameOwnerChanged">
<arg type="s"/>
<arg type="s"/>
<arg type="s"/>
</signal>
<signal name="NameLost">
<arg type="s"/>
</signal>
<signal name="NameAcquired">
<arg type="s"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg direction="in" type="s"/>
<arg direction="in" type="s"/>
<arg direction="out" type="v"/>
</method>
<method name="GetAll">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<method name="Set">
<arg direction="in" type="s"/>
<arg direction="in" type="s"/>
<arg direction="in" type="v"/>
</method>
<signal name="PropertiesChanged">
<arg type="s" name="interface_name"/>
<arg type="a{sv}" name="changed_properties"/>
<arg type="as" name="invalidated_properties"/>
</signal>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Monitoring">
<method name="BecomeMonitor">
<arg direction="in" type="as"/>
<arg direction="in" type="u"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Debug.Stats">
<method name="GetStats">
<arg direction="out" type="a{sv}"/>
</method>
<method name="GetConnectionStats">
<arg direction="in" type="s"/>
<arg direction="out" type="a{sv}"/>
</method>
<method name="GetAllMatchRules">
<arg direction="out" type="a{sas}"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Peer">
<method name="GetMachineId">
<arg direction="out" type="s"/>
</method>
<method name="Ping">
</method>
</interface>
</node>
"

お疲れさまです。私、でした。
次回をお楽しみに。