QDBusAbstractAdaptor对象不导出已实现的dbus接口

时间:2013-06-09 12:44:35

标签: qt interface dbus bluez qtdbus

我正在尝试使用Qt及其DBus功能实现BlueZ v5.5的配对代理。

我有一个由qdbusxml2cpp工具生成的适配器类,我调用了PairingAgentAdaptor和一个带有实现方法的类(PairingAgent),我将其作为适配器类实例化的参数。

我可以将对象注册为新代理,BlueZ守护程序表示我的代理已注册。如果我尝试将手机与电脑配对,BlueZ守护程序会说:“对象路径'/ pairing / agent'没有这样的界面'org.bluez.Agent1'。”

我不知道我做错了什么。你能给我一些提示吗?

亲切的问候 迈克尔


代码:

的main.cpp

// built using Qt 4.8.2

#include <QCoreApplication>
#include <bluedevil/bluedevil.h> // schaal's port to BlueZ 5

#define AGENT_PATH "/pairing/agent"

[...]

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    PairingAgent pairingAgent;
    PairingAgentAdaptor pairingAgentAdaptor(&pairingAgent);

    bool registerSuccess = QDBusConnection::systemBus().registerObject(QString(AGENT_PATH), &pairingAgentAdaptor);

    if (registerSuccess) {
        cout << "Registered as " << AGENT_PATH << endl;
    } else {
        QDBusConnection::systemBus().unregisterObject(QString(AGENT_PATH), QDBusConnection::UnregisterTree);

        registerSuccess = QDBusConnection::systemBus().registerObject(QString(AGENT_PATH), &pairingAgentAdaptor);

        if (registerSuccess) {
            cout << "Registered as " << AGENT_PATH << " (round 2)" << endl;
        } else {
            cerr << "Registering of " << AGENT_PATH << " failed." << endl;
            exit(1);
        }
    }

    Manager* const manager = Manager::self();
    manager->registerAgent(QString(AGENT_PATH), Manager::DisplayOnly);

    return app.exec();
}

pairingagentadaptor.h

[...]

/*
 * Adaptor class for interface org.bluez.Agent1
 */
class PairingAgentAdaptor: public QDBusAbstractAdaptor {
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.bluez.Agent1")
    Q_CLASSINFO("D-Bus Introspection", ""
"  <interface name=\"org.bluez.Agent1\">\n"
"    <method name=\"Release\"/>\n"
"    <method name=\"RequestPinCode\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"out\" type=\"s\"/>\n"
"    </method>\n"
"    <method name=\"DisplayPinCode\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"in\" type=\"s\"/>\n"
"    </method>\n"
"    <method name=\"RequestPasskey\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"out\" type=\"u\"/>\n"
"    </method>\n"
"    <method name=\"DisplayPasskey\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"in\" type=\"u\"/>\n"
"    </method>\n"
"    <method name=\"RequestConfirmation\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"in\" type=\"u\"/>\n"
"    </method>\n"
"    <method name=\"RequestAuthorization\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"in\" type=\"u\"/>\n"
"    </method>\n"
"    <method name=\"AuthorizeService\">\n"
"      <arg direction=\"in\" type=\"o\"/>\n"
"      <arg direction=\"in\" type=\"s\"/>\n"
"    </method>\n"
"    <method name=\"Cancel\"/>\n"
"  </interface>\n"
        "")
public:
    PairingAgentAdaptor(QObject *parent);
    virtual ~PairingAgentAdaptor();

public: // PROPERTIES
public Q_SLOTS: // METHODS
    void AuthorizeService(const QDBusObjectPath &in0, const QString &in1);
    void Cancel();
    void DisplayPasskey(const QDBusObjectPath &in0, uint in1);
    void DisplayPinCode(const QDBusObjectPath &in0, const QString &in1);
    void Release();
    void RequestAuthorization(const QDBusObjectPath &in0, uint in1);
    void RequestConfirmation(const QDBusObjectPath &in0, uint in1);
    uint RequestPasskey(const QDBusObjectPath &in0);
    QString RequestPinCode(const QDBusObjectPath &in0);
Q_SIGNALS: // SIGNALS
};

1 个答案:

答案 0 :(得分:3)

我现在知道了。 :)

我的第一个错误:

PairingAgent pairingAgent;
PairingAgentAdaptor pairingAgentAdaptor(&pairingAgent);

bool registerSuccess = QDBusConnection::systemBus().registerObject(QString(AGENT_PATH), &pairingAgentAdaptor);

必须是

bool registerSuccess = QDBusConnection::systemBus().registerObject(QString(AGENT_PATH), &pairingAgent); // NEVER the adaptor!!!

我的第二个错误:我得到了org.bluez.Agent1的错误界面。正确的是:

<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
    <interface name="org.bluez.Agent1">
        <method name="Release" />
        <method name="RequestPinCode">
            <arg direction="in" type="o" />
            <arg direction="out" type="s" />
        </method>
        <method name="DisplayPinCode">
            <arg direction="in" type="o" />
            <arg direction="in" type="s" />
        </method>
        <method name="RequestPasskey">
            <arg direction="in" type="o" />
            <arg direction="out" type="u" />
        </method>
        <method name="DisplayPasskey">
            <arg direction="in" type="o" />
            <arg direction="in" type="u" />
            <arg direction="in" type="q" />
        </method>
        <method name="RequestConfirmation">
            <arg direction="in" type="o" />
            <arg direction="in" type="u" />
        </method>
        <method name="RequestAuthorization">
            <arg direction="in" type="o" />
        </method>
        <method name="AuthorizeService">
            <arg direction="in" type="o" />
            <arg direction="in" type="s" />
        </method>
        <method name="Cancel" />
    </interface>
</node>