我正在尝试使用 Qt 及其 DBus 功能为 BlueZ v5.5 实现配对代理。
我有一个由我称为 PairingAgentAdaptor 的 qdbusxml2cpp 工具生成的适配器类和一个具有实现方法 (PairingAgent) 的类,我在适配器类的实例化时作为参数给出。
我可以将对象注册为新代理,BlueZ 守护进程说我的代理已注册。如果我尝试将手机与计算机配对,BlueZ 守护程序会显示:“对象路径 '/pairing/agent' 中没有这样的接口 'org.bluez.Agent1'。”
我不知道我做错了什么。你能给我一些提示吗?
亲切的问候迈克尔
代码:
主文件
// 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();
}
配对代理适配器.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
};