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

邮差的信 提交于 2019-12-06 08:08:43

引自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文件里面的名字,
对象名字一般是含斜线的,
接口名字不一定非得和服务的名字一样。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!