ubuntu12.04 安裝dbus
1.下載下傳dubs
下載下傳https://dbus.freedesktop.org/releases/dbus/
dbus-1.8.0.tar.gz
2.配置編譯
./configure –prefix=/home/xx/dbus/install/ (安裝目錄)
make
make install
3.使用
dbus-daemon是一個背景程序,負責消息的轉發
./dbus-daemon –config-file=../etc/dbus-1/session.conf –print-address
會列印一個類似unix:abstract=/tmp/dbus-eW4m3qv5Pv,guid=48fba668e981b73068475c035acda368的值
每次啟動的值都不一樣
dbus-launch 是啟動配置dbus-daemon的程式
4.編譯應用程式dbus.c
gcc dbus.c -o dbus -I /home/xx/dbus/install/include/dbus-1.0/ -I /home/xx/dbus/install/lib/dbus-1.0/include/ -L /home/xx/dbus/install/lib/ -l dbus-1
/home/xx/dbus/install/include/dbus-1.0/ 為了找到dbus/dbus.h
/home/xx/dbus/install/lib/dbus-1.0/include/ 為了找到dbus-arch-deps.h
-L 指定動态庫的目錄
-l 要連結的動态庫
5.測試
先運作dbus-launch列印
./dbus-launch
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Pwy1U2h5hv,guid=9aa4b7bd692f6ffa512384615acdafb8
DBUS_SESSION_BUS_PID=9735
導出環境變量
export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-Pwy1U2h5hv,guid=9aa4b7bd692f6ffa512384615acdafb8
運作應用程式
./dbus send “hello test”
Sending signal with value hello test
Signal Sent
./dbus receive
Listening for signals
Match rule sent
Got Signal with value hello test
6.Dbus 調試工具 D-feet
安裝 apt-get install d-feet
使用:填寫Bus Address
7.dbus-send的使用
dbus-send :發送資訊到message bus
dbus-send [--system | --session] [--dest=NAME] [--print-reply] [--type=TYPE]
path> [contents ...]
--system :指系統總線(System Bus),用于系統Linux和使用者程式間進行通信
--session:指會話總線(Session Bus),用于桌面使用者程式之間的通信
如果不指定選項,預設使用--session
--dest :是必須的選項,是準備發往bus上的名字描述
--dest= 連接配接名 對象路徑 接口名.方法名 參數類型:參數值 參數類型:參數值
支援的參數類型包括:string, int32, uint32, double, byte, boolean。
--print-reply:列印接收到的傳回資訊
--type=TYPE:指定"method_call"或者"signal"(預設是signal)
eg:
dbus-send --system --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.ListActivatableNames
連接配接名:org.freedesktop.DBus
對象路徑:/
接口名.方法名org.freedesktop.DBus.ListActivatableNames
傳回:
method return sender=org.freedesktop.DBus -> dest=:1.217 reply_serial=2
array [
string "org.freedesktop.DBus"
string "com.ubuntu.LanguageSelector"
string "org.freedesktop.ColorManager"
string "com.hp.hplip"
string "com.ubuntu.USBCreator"
string "com.ubuntu.SoftwareProperties"
string "org.freedesktop.Avahi"
string "org.freedesktop.PolicyKit1"
string "org.debian.apt"
string "org.freedesktop.hostname1"
string "org.gnome.CPUFreqSelector"
string "org.freedesktop.ConsoleKit"
string "com.ubuntu.DeviceDriver"
string "org.freedesktop.UPower"
string "org.freedesktop.PackageKit"
string "org.freedesktop.UDisks"
string "org.freedesktop.ModemManager"
string "com.ubuntu.SystemService"
string "fi.epitest.hostap.WPASupplicant"
string "org.debian.AptXapianIndex"
string "org.freedesktop.RealtimeKit1"
string "fi.w1.wpa_supplicant1"
string "org.freedesktop.Accounts"
string "com.ubuntu.WhoopsiePreferences"
string "org.freedesktop.locale1"
string "org.gnome.SettingsDaemon.DateTimeMechanism"
string "org.freedesktop.nm_dispatcher"
string "org.opensuse.CupsPkHelper.Mechanism"
]
8.dbus-monitor使用
填寫interface接口名監聽
$ dbus-monitor --session "inter"
signal sender=org.freedesktop.DBus -> dest=:1.1716 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.1716"
method call sender=:1.1717 -> dest=com.example.dbus serial=2 path=/; interface=com.example.dbus.Interface; member=add
int32 5
int32 8