2

次のように、この 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

イントロスペクション 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}')

「注釈名 = ..」XML タグ (イントロスペクション XML を参照) が、このメソッドが見つからない理由ですか? ブラウザー経由でブラウジングするitmm://192.168.1.1/query?version=1.0と、コマンド ライン パラメーターを使用してアプリケーションが起動されますが、D-Bus サービス経由では起動されず、それが私の要件です。これをFirefoxまたはGoogle Chromeブラウザでデバッグする方法はありますか?

4

1 に答える 1

1

QT の D-Bus バインディングを使用して D-Bus サービスを実装します。私の問題は

  1. D-Bus インターフェイスを実装した私のクラスはQDBusAbstractAdaptorを継承していませんでした。
  2. エクスポートされるメソッドは次のようにマークされていませんでした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);
    }
}

D-Bus デバッグ ツール


これらのツールは、D-Bus の問題のデバッグに役立ちました。
dbus-monitor - バス上のトラフィックを盗聴します

gapplication - サービスをデバッグできますDBusActivatable

于 2016-04-28T02:58:59.613 に答える