代码之家  ›  专栏  ›  技术社区  ›  Adriano_Pinaffo

如何在没有桌面环境的CentOS中使用dbus

  •  0
  • Adriano_Pinaffo  · 技术社区  · 7 年前

    我的系统是一个没有图形用户界面的centos。我有一个服务器应用程序,它“监听”会话中的方法调用 dbus . 显然效果不错。我有 pydbus python3-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的方法。有人能帮忙吗?

    0 回复  |  直到 7 年前
        1
  •  0
  •   Philip Withnall    7 年前

    除非在从客户端调用该方法时您的服务已经在运行,否则您将需要为它启用服务激活,这涉及到编写 org.mybus.demo.test.service /usr/share/dbus-1/services . 见 the specification

    [D-BUS Service]
    Name=org.mybus.demo.test
    Exec=/path/to/your/application.py
    
    推荐文章