QDBusAbstractAdaptor 对象不导出实现的 dbus 接口
Posted
技术标签:
【中文标题】QDBusAbstractAdaptor 对象不导出实现的 dbus 接口【英文标题】:QDBusAbstractAdaptor object does not export implemented dbus interface 【发布时间】:2013-06-05 06:34:01 【问题描述】:我正在尝试为 BlueZ v5.5 与 Qt 及其 DBus 功能实现配对代理。
我有一个适配器类,它由我称为 PairingAgentAdaptor 的 qdbusxml2cpp 工具生成,还有一个具有实现方法 (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
;
【问题讨论】:
您是否使用 qdbusviewer 来验证适配器是否按预期显示?我对 BlueZ 不熟悉,但守护进程是否肯定在系统总线上而不是会话总线上? org.bluez 出现在系统总线上,当我将其注册为新代理时,它会识别我的应用程序。 【参考方案1】:我现在明白了。 :)
我的第一个错误:
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>
【讨论】:
以上是关于QDBusAbstractAdaptor 对象不导出实现的 dbus 接口的主要内容,如果未能解决你的问题,请参考以下文章
gradle 打war包的问题(我想编译的时候使用tomcat的jar包,但是打war包的时候不导tomcat的包,如何做)