0

我的系统是没有gui的centos。我有一个服务器应用程序,它“监听”会话中的方法调用dbus。它显然工作正常。我已经安装好了pydbuspython3-gobject我也有dbus-launch工作。这是服务器应用程序:

from pydbus import SessionBus
from gi.repository import GLib
import time

# Variables / Constants / Instantiation...
bus = SessionBus()
BUS = "org.mybus.demo.test"
loop = GLib.MainLoop()
message_count = 0

class DBusService_XML():
    """
    DBus Service XML Definition.
    type = "i" for integer, "s" for string, "d" for double, "as" list of string data.
    """
    dbus = """
    <node>
        <interface name="{}">
            <method name='greeting'>
                <arg type="s" name="input" direction="in">
                </arg>
                <arg type="s" name="output" direction="out">
                </arg>
            </method>
        </interface>
    </node>
    """.format(BUS)

    def greeting(self, clientName):
        "Receive and send arg"
        print("{} is asking for name".format(clientName))
        return "Hello {}, Im Kyle".format(clientName)

if __name__ == "__main__":
    bus.publish(BUS, DBusService_XML())
    loop.run()

现在为了调用该服务器方法,从另一个终端(同一个用户)我尝试使用我的客户端应用程序,但失败了,然后我尝试gdbus了失败的应用程序,错误如下:

# dbus-launch gdbus call --session --dest org.mybus.demo.test --object-path /org/mybus/demo/test --method org.mybus.demo.test.greeting "Julia"
Error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.mybus.demo.test was not provided by any .service files

从另一台具有桌面环境的机器上一切正常。我四处搜寻,但找不到在那种情况下使用 dbus 的方法。任何人都可以帮忙吗?

4

1 回答 1

0

除非您从客户端调用该方法时您的服务已经在运行,否则您将需要为其启用服务激活,这包括编写一个org.mybus.demo.test.service文件并将其放入/usr/share/dbus-1/services. 请参阅规范。它可能看起来像:

[D-BUS Service]
Name=org.mybus.demo.test
Exec=/path/to/your/application.py
于 2019-04-15T20:33:14.173 回答