初探dbus(1)

本文记录了对dbus的初次探索,只是工作过程,如果对dbus不了解,则可以先看看

http://blog.csdn.net/fmddlmyy/archive/2008/12/23/3585730.aspx

1、以shallon用户登录ubuntu

2、su - 获得Root的权限

3、获取Dbus的原码,使用DBUS有几种方式,
(1)原始的C level的API,为了兼容旧有程序而存在,不推荐使用
(2)GLIB的Binding 推荐使用,GLIB是一种以C语言得语法模拟C++的开发类库,我们将选用它。
(3)Python的及其他语言的Binding


4、获取Dbus-GLIB的原码,其运行例子代码下边要用到

git clone git://anongit.freedesktop.org/git/dbus/dbus-glib

5、编译Dbus-GLIB中的example目录,不用编译DBUS和DBUS-GLIB,因为我的机器ubuntu上已经安装好,并缺省就运行了DBUS的进程。

5.1编译脚本自动使用dbus-binding-tool 生成接口描述文件对应的头文件

dbus-binding-tool --prefix=some_object --mode=glib-server --output=example-service-glue.h ./example-service.xml
dbus-binding-tool --prefix=test_object --mode=glib-server --output=example-signal-emitter-glue.h ./example-signal-emitter.xml


6运行example-signal-recipient向Session bus发送消息,下面如实的记录了排错的过程

6.1./example-signal-recipient
Couldn't connect to session bus: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.

6.2看样子Dbus依赖X11的环境,于是设置环境变量,再运行
export DISPLAY=:0.0

 ./example-signal-recipient
Couldn't connect to session bus: dbus-launch failed to autolaunch D-Bus session: No protocol specified
Autolaunch error: X11 initialization failed.

6.3查看DBUS的进程启动的owner,Session Bus为本地用户

108       4685     1  0 08:31 ?        00:00:13 /bin/dbus-daemon --system
shallon   5652     1  0 08:36 ?        00:00:00 /usr/bin/dbus-launch --exit-with-session /usr/bin/pulse-session /usr/bin/seahorse-agent --execute x-session-manager
shallon   5655     1  0 08:36 ?        00:00:00 //bin/dbus-daemon --fork --print-pid 6 --print-address 9 --session
 
6.4怀疑是环境问题,退出 su -的环境,使用su root进去再运行

 ./example-signal-recipient
Couldn't connect to session bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.


6.5查询网上资料,发现Session bus需要访问启动用户所在home目录的隐藏文件夹/home/shallon/.dbus/,该目录的所有者为shallon,于是退出su 使用shallon用户的环境运行

6.6成功运行
第一个终端:
shallon@shallon-laptop:~/open_source/dbus-glib/dbus/examples$ ./example-signal-recipient
Received signal and it says: Hello
Received signal and it says: Hello
第二个终端:
shallon@shallon-laptop:~/open_source/dbus-glib/dbus/examples$ ./example-signal-emitter
test service running
第三个终端使用 dbus-monitor看到

method call sender=:1.86 -> dest=org.designfu.TestService path=/org/designfu/TestService/object; interface=org.designfu.TestService; member=emitHelloSignal
signal sender=:1.87 -> dest=(null destination) path=/org/designfu/TestService/object; interface=org.designfu.TestService; member=HelloSignal
   string "Hello"
method call sender=:1.86 -> dest=org.designfu.TestService path=/org/designfu/TestService/object; interface=org.designfu.TestService; member=emitHelloSignal
signal sender=:1.87 -> dest=(null destination) path=/org/designfu/TestService/object; interface=org.designfu.TestService; member=HelloSignal
   string "Hello"

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值