【问题标题】:DBus - How can I list all services (bus name) in the system bus?DBus - 如何列出系统总线中的所有服务(总线名称)?
【发布时间】:2012-04-05 05:48:44
【问题描述】:

我想创建一个连接到 dbus --system bus 的程序并列出所有连接的服务 (bus_names)。就像“qdbus”一样。

有人可以帮助我吗?

我的 dbus 版本是 dbus-1.2.24,我正在用 C 编程(没有绑定)。

【问题讨论】:

    标签: ipc introspection dbus


    【解决方案1】:

    您可能想看看Qt DBus List Names example

    QDBusConnection bus = QDBusConnection::sessionBus();
    QDBusInterface dbus_iface("org.freedesktop.DBus", "/org/freedesktop/DBus",
                              "org.freedesktop.DBus", bus);
    qDebug() << dbus_iface.call("ListNames").arguments().at(0);
    

    下面是一个使用命令行的例子:

    # qdbus --literal --system org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames
    {"org.freedesktop.DBus", ":1.23", ":1.31", "org.freedesktop.Avahi", ":1.24", ":1.26"}
    # dbus-send --system --dest=org.freedesktop.DBus --print-reply=literal /org/freedesktop/DBus org.freedesktop.DBus.ListNames
       array [
          org.freedesktop.DBus      :1.23      org.freedesktop.Avahi      :1.24      :1.33      :1.26   ]
    

    您可能还想直接转到 qt 源代码中的源代码 tools/qdbus/qdbus/qdbus.cpp。您会注意到,如果args.empty() 它调用printServiceNames(),它只返回在系统总线接口上调用的registeredServiceNames() 的结果。然后,该代码执行以下操作:

    QDBusReply<QStringList> QDBusConnectionInterface::registeredServiceNames() const
    {
        return internalConstCall(QDBus::AutoDetect, QLatin1String("ListNames"));
    }
    

    现在我们绕了一圈。

    【讨论】:

    猜你喜欢
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2015-12-11
    • 2013-01-06
    • 2021-06-23
    相关资源
    最近更新 更多