Pergunta

I'm trying to implement a pairing agent for BlueZ v5.5 with Qt and its DBus functionality.

I have an adaptor class that is generated by the qdbusxml2cpp tool that I called PairingAgentAdaptor and a class with the implemented methods (PairingAgent) that I give as parameter on instantiation of the adaptor class.

I can register the object as a new agent and the BlueZ daemon says that my agent is registered. If I try to pair my phone with the computer, the BlueZ daemon says: "No such interface 'org.bluez.Agent1' at object path '/pairing/agent'."

I have no idea what I'm doing wrong. Could you please give me some hints?

Kind regards Michael


Code:

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
};
Foi útil?

Solução

I've got it now. :)

My first mistake:

PairingAgent pairingAgent;
PairingAgentAdaptor pairingAgentAdaptor(&pairingAgent);

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

It has to be

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

My second mistake: I got the wrong interface for org.bluez.Agent1. The right one is:

<!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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top