我使用此com.example.appname.desktop文件实现了一个应用程序,如下所示:
$ cat /usr/local/share/applications/com.example.appname.desktop
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=appname
Exec=/opt/app/appname %u
DBusActivatable=true
Categories=Network;
MimeType=x-scheme-handler/itmm;
NoDisplay=false
$ cat /usr/share/dbus-1/services/com.example.appname.service
[D-BUS Service]
Name=com.example.appname
Exec=/opt/app/appname
Introspection XML看起来像这样:
$ qdbus com.example.appname /com/example/appname org.freedesktop.DBus.Introspectable.Introspect
<!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.freedesktop.Application">
<method name="ActivateAction">
<arg name="action_name" type="s" direction="in"/>
<arg name="parameter" type="av" direction="in"/>
<arg name="platform_data" type="a{sv}" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In2" value="QVariantMap"/>
</method>
<method name="Activate">
<arg name="platform_data" type="a{sv}" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
</method>
<method name="Open">
<arg name="uris" type="as" direction="in"/>
<arg name="platform_data" type="a{sv}" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface_name" type="s" direction="in"/>
<arg name="property_name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
----<snipped>-----
但是当我尝试启动该方法时,它给了我一个错误:
$ gapplication launch com.example.appname
error sending Activate message to application: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such method 'Activate' in interface 'org.freedesktop.Application' at object path '/com/example/appname' (signature 'a{sv}')
“annotation name = ..”XML标签(参见内省XML)找不到此方法的原因?
通过浏览器浏览itmm://192.168.1.1/query?version=1.0
使用命令行参数启动应用程序,但它不是通过D-Bus服务启动的,这就是我的要求。有没有办法通过firefox或谷歌浏览器浏览器进行调试?
答案 0 :(得分:1)
我使用QT的D-Bus绑定来实现D-Bus服务。我的问题是
public slots
我原来的课程如下所示:
class DBusService : public Application
{
QOBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Application")
public:
void Activate(QMap<QString, QVariant> platform_data)
{
Q_UNUSED(platform_data);
}
void Open(QStringList uris, QMap<QString, QVariant> platform_data)
{
Q_UNUSED(platform_data);
if( ! uris.size() ) {
return;
}
QUrl url(uris[0]);
//use url
}
}
以下作品之一:
class DBusService : public QDBusAbstractAdaptor //<----- Inherit from this class
{
QOBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Application")
public slots: // <------ mark public slots
void Activate(QMap<QString, QVariant> platform_data)
{
Q_UNUSED(platform_data);
}
void Open(QStringList uris, QMap<QString, QVariant> platform_data)
{
Q_UNUSED(platform_data);
if( ! uris.size() ) {
return;
}
QUrl url(uris[0]);
qApp->MyCustomMethod(url);
}
}
gapplication - 允许您调试DBusActivatable
服务。