利用dbus-send在命令行下给程序发送消息,调用其相应的函数

来源:互联网 发布:网络用语td是什么意思 编辑:程序博客网 时间:2024/06/11 11:14

引自maemo diab教程
p189-195
通过Dbus命令行的方法,可以调用程序中的某一个函数:
如下:
run-standalone.sh dbus-send --print-reply /
--type=method_call --dest=com.nokia.hello_world_app /
/com/nokia/hello_world_app com.nokia.hello_world_app.hello_world_dialog_show

这句话的意思是:
调用服务名字(/usr/share/dbus-1/service/里面相应的service文件):com.nokia.hello_world_app
调用的服务名字下面的一个对象为:/com/nokia/hello_world_app
调用该对象接口(com.nokia.hello_world_app)下面的一个函数(hello_world_dialog_show),这个函数没有参数,在源代码里面可以看到这个函数的定义。如果有参数的话,如下类似的调用:

run-standalone.sh dbus-send --print-reply /
--type=method_call --dest=org.freedesktop.Notifications /
/org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog
string:’Hello, world!’ uint32:0 string:’NAO OK!’

这里的函数有三个参数:string,uint32,string


run-standalone.sh dbus-send --print-reply /
--type=method_call --dest=org.gnome.PowerManager /
/org/gnome/PowerManager org.gnome.PowerManager.myTest

在这里,服务名字就是service文件里面的名字,
对象名字一般是含斜线的,
接口名字不一定非得和服务的名字一样。

原创粉丝点击