本文介绍了QDBusAbstractAdaptor对象不导出已实现的dbus接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我有一个由qdbusxml2cpp生成的适配器类。我称为PairingAgentAdaptor的工具和一个带有实现的方法(PairingAgent)的类,该类作为适配器类实例化时的参数给出。

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.

我可以将对象注册为新对象代理,并且BlueZ守护程序说我的代理已注册。如果我尝试将手机与计算机配对,则BlueZ守护进程会说:对象路径'/ pairing / agent'上没有这样的接口'org.bluez.Agent1'。

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 regardsMichael

代码:

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

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
};


推荐答案

我现在知道了。 :)

我的第一个错误:

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的接口错误。正确的是:

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>

这篇关于QDBusAbstractAdaptor对象不导出已实现的dbus接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 21:15