亲爱的SO社区大家好 :)
我正在尝试在我的树莓派上使用DBus。 当我处于Pi桌面环境(startx)时,来自libdbus-c++-1的示例代码可以正常工作。
我在互联网上进行了研究,并在stackoverflow上找到了一些示例,但它们没有帮助到我 :[.
然而,当我处于Shell模式时,我会收到错误消息。
./client
terminate called after throwing an instance of 'DBus::Error'
what(): /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
Aborted
我也尝试了。
eval 'dbus-launch --auto-syntax' ./client
eval 'dbus-launch --auto-syntax' ./server
但是它不起作用,服务器应用程序正在启动消息守护程序,但客户端无法访问。此外,守护程序仍然处于活动状态。
我得到:
terminate called after throwing an instance of 'DBus::Error'
what(): The name org.freedesktop.DBus.Examples.Echo was not provided by any .service files
call1: Aborted
另外它没有显示在服务列表中。
之后我尝试了另一个命令
DISPLAY=":0" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/dbus/system_bus_socket" ./server
我得到了:
terminate called after throwing an instance of 'DBus::Error'
what(): Connection ":1.10" is not allowed to own the service "org.freedesktop.DBus.Examples.Echo" due to security policies in the configuration file
Aborted
在那之后仍然无法工作,我找到了一种方法可以编译不包含X11代码的dbus。
./configure --with-x=no
很遗憾,它没有效果。我仍然需要X11来启动我的应用程序......我做错了什么吗?但是像命令这样的东西
eval 'dbus-launch --auto-syntax' dbus-monitor
如何在不启动X11的情况下启动我的应用程序,因为我不需要也不想要它。 感谢您的帮助和时间。
敬礼 oOm
更新 我现在感觉有点傻,但我找到了一种无需x11的运行方式。
首先,您需要启动一个dbus会话守护程序。
dbus-launch
这将提示您检索 DBUS_SESSION_BUS_ADRESS。
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9rMVHdByuH,guid=10592ff7107f13dd241a02af531ab357
DBUS_SESSION_BUS_PID=2465
之后,您可以像这样启动C++应用程序
DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-9rMVHdByuH,guid=10592ff7107f13dd241a02af531ab357" ./server
您可以使用注册的服务
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
同时监控信息
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6aT4DZgmA1,guid=b1231a014a7b10e74e04f8ba531abdf9 dbus-monitor
但有一个问题尚未解决,如何自动完成呢?