Documentation
Overview
引用:
- アプリケーション間は、基本的には 1対1 で通信します。
- 通信の際には、「メッセージ」をやりとりします。
- メッセージには、「メソッド(関数)」と「シグナル」があります。
- メソッドは、相手に何らかの処理をしてもらうためのもので、通常は、処理した結果が戻ってきます。
- シグナルは、相手に何かを通知するためのものです。
- 通信は、バスを介して行われます。
- バスには、「システムバス」と「セッションバス」があります。
- システムバスは、システムとのやりとりで使われます。
- セッションバスは、主にデスクトップ環境で使われます。
- バス名で、通信相手を特定します。
- org.freedesktop.NetworkManagerのような、みんな知っている有名(?)な名前もあれば、使用中のみ有効な : で始まる名前もあります。
- 通信相手は、いくつかの「オブジェクト」を持っています。
- たとえば、NetworkManager は、eth0 などのデバイスや、そのデバイスに対する接続の情報を持っていますが、デバイスも接続もオブジェクトとして扱われます。
- オブジェクトは、「オブジェクトパス」で指定します。
- たとえば、/org/freedesktop/NetworkManager/Devices/0 のように表します。(ちなみにこれは NetworkManager のデバイスです。)
- メッセージはオブジェクトに対して送信されます。
- オブジェクトが受け付けるメッセージは、「インターフェース」で定義されています。
Methods and signals on an object
標準インタフェイス
org.freedesktop.DBus.Peer
- org.freedesktop.DBus.Peer.Ping
- org.freedesktop.DBus.Peer.GetMachineId
org.freedesktop.DBus.Introspectable
- org.freedesktop.DBus.Introspectable.Introspect
org.freedesktop.DBus.Properties
- org.freedesktop.DBus.Properties.Get
- in STRING interface_name
- in STRING property_name
- out VARIANT value
- org.freedesktop.DBus.Properties.Set
- in STRING interface_name
- in STRING property_name
- in VARIANT value
- org.freedesktop.DBus.Properties.GetAll
- in STRING interface_name
- out DICT<STRING,VARIANT> props
Test
グラフィカルdbusデバッガであるd-feetを使用すると、dbusに登録されているバスネームやオブジェクトパスの一覧表示、メソッドの実行などができる。
# なぜかシステムバスのバスネームに org.freedesktop.DBus が出てこない
dbus-sendを使用し、メッセージ通信をテストする。
NAME
dbus-send - Send a message to a message bus
SYNOPSIS
dbus-send [--system | --session] [--dest=NAME] [--print-reply] [--type=TYPE] <destination object path> <mes‐
sage name> [contents ...]
OPTIONS
The following options are supported:
--dest=NAME
Specify the name of the connection to receive the message.
--print-reply
Block for a reply to the message sent, and print any reply received.
--system
Send to the system message bus.
--session
Send to the session message bus. (This is the default.)
--type=TYPE
Specify "method_call" or "signal" (defaults to "signal").
DBusオブジェクトのインタフェイス一覧表示
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.Introspectable.Introspect
システムバスのバスネーム一覧表示
dbus-send --system --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
HALが管理している全てのデバイスネーム取得
dbus-send --system --dest=org.freedesktop.Hal --type=method_call --print-reply /org/freedesktop/Hal/Manager org.freedesktop.Hal.Manager.GetAllDevices
Gnomeが使用しているXのディスプレイネーム取得
dbus-send --system --dest=org.gnome.DisplayManager --type=method_call --print-reply /org/gnome/DisplayManager/Display1 org.gnome.DisplayManager.Display.GetX11DisplayName
Tool implementation
dbus-send
メソッドコールのときのシーケンスを記述する。
コネクションとメッセージのポインタを定義。これらを使用してメッセージ通信を行う。
DBusConnection *connection;
DBusMessage *message;
システムバスorセッションバスを取得する
connection = dbus_bus_get (type, &error);
メッセージを生成する。オブジェクトパス・インタフェイス・メソッドを入力する。
message = dbus_message_new_method_call (NULL,
path,
name,
last_dot + 1);
よくわからないオートスタートフラグ設定
dbus_message_set_auto_start (message, TRUE);
デスト設定。バスネームを入力する。
if (dest && !dbus_message_set_destination (message, dest))
メソッドの引数パラメータをメッセージに付加する
略
メッセージを送信する
reply = dbus_connection_send_with_reply_and_block (connection,
message, reply_timeout,
&error);
メソッドの結果を出力する(--print-replyが付加されていた場合)
print_message (reply, print_reply_literal);
コネクションとメッセージを開放する
dbus_message_unref (message);
dbus_connection_unref (connection);
Note
bus/interface/method register seq
最終更新:2011年09月04日 06:44