Blame docs/reference/gio/gdbus.xml

Packit ae235b
<refentry id="gdbus" lang="en">
Packit ae235b
Packit ae235b
<refentryinfo>
Packit ae235b
  <title>gdbus</title>
Packit ae235b
  <productname>GIO</productname>
Packit ae235b
  <authorgroup>
Packit ae235b
    <author>
Packit ae235b
      <contrib>Developer</contrib>
Packit ae235b
      <firstname>David</firstname>
Packit ae235b
      <surname>Zeuthen</surname>
Packit ae235b
      <email>zeuthen@gmail.com</email>
Packit ae235b
    </author>
Packit ae235b
  </authorgroup>
Packit ae235b
</refentryinfo>
Packit ae235b
Packit ae235b
<refmeta>
Packit ae235b
  <refentrytitle>gdbus</refentrytitle>
Packit ae235b
  <manvolnum>1</manvolnum>
Packit ae235b
  <refmiscinfo class="manual">User Commands</refmiscinfo>
Packit ae235b
</refmeta>
Packit ae235b
Packit ae235b
<refnamediv>
Packit ae235b
  <refname>gdbus</refname>
Packit ae235b
  <refpurpose>Tool for working with D-Bus objects</refpurpose>
Packit ae235b
</refnamediv>
Packit ae235b
Packit ae235b
<refsynopsisdiv>
Packit ae235b
  <cmdsynopsis>
Packit ae235b
    <command>gdbus</command>
Packit ae235b
    <arg choice="plain">introspect</arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--system</arg>
Packit ae235b
      <arg choice="plain">--session</arg>
Packit ae235b
      <arg choice="plain">--address <replaceable>address</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">--dest <replaceable>bus_name</replaceable></arg>
Packit ae235b
    <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--xml</arg>
Packit ae235b
    </group>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--recurse</arg>
Packit ae235b
    </group>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--only-properties</arg>
Packit ae235b
    </group>
Packit ae235b
  </cmdsynopsis>
Packit ae235b
  <cmdsynopsis>
Packit ae235b
    <command>gdbus</command>
Packit ae235b
    <arg choice="plain">monitor</arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--system</arg>
Packit ae235b
      <arg choice="plain">--session</arg>
Packit ae235b
      <arg choice="plain">--address <replaceable>address</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">--dest <replaceable>bus_name</replaceable></arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
  </cmdsynopsis>
Packit ae235b
  <cmdsynopsis>
Packit ae235b
    <command>gdbus</command>
Packit ae235b
    <arg choice="plain">call</arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--system</arg>
Packit ae235b
      <arg choice="plain">--session</arg>
Packit ae235b
      <arg choice="plain">--address <replaceable>address</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">--dest <replaceable>bus_name</replaceable></arg>
Packit ae235b
    <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
Packit ae235b
    <arg choice="plain">--method <replaceable>org.project.InterfaceName.MethodName</replaceable></arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--timeout <replaceable>seconds</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">ARG1</arg>
Packit ae235b
    <arg choice="plain" rep="repeat">ARG2</arg>
Packit ae235b
  </cmdsynopsis>
Packit ae235b
  <cmdsynopsis>
Packit ae235b
    <command>gdbus</command>
Packit ae235b
    <arg choice="plain">emit</arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--system</arg>
Packit ae235b
      <arg choice="plain">--session</arg>
Packit ae235b
      <arg choice="plain">--address <replaceable>address</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
Packit ae235b
    <arg choice="plain">--signal <replaceable>org.project.InterfaceName.SignalName</replaceable></arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--dest <replaceable>unique_bus_name</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">ARG1</arg>
Packit ae235b
    <arg choice="plain" rep="repeat">ARG2</arg>
Packit ae235b
  </cmdsynopsis>
Packit ae235b
  <cmdsynopsis>
Packit ae235b
    <command>gdbus</command>
Packit ae235b
    <arg choice="plain">wait</arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--system</arg>
Packit ae235b
      <arg choice="plain">--session</arg>
Packit ae235b
      <arg choice="plain">--address <replaceable>address</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain">--activate <replaceable>bus_name</replaceable></arg>
Packit ae235b
    <group>
Packit ae235b
      <arg choice="plain">--timeout <replaceable>seconds</replaceable></arg>
Packit ae235b
    </group>
Packit ae235b
    <arg choice="plain"><replaceable>bus_name</replaceable></arg>
Packit ae235b
  </cmdsynopsis>
Packit ae235b
  <cmdsynopsis>
Packit ae235b
    <command>gdbus</command>
Packit ae235b
    <arg choice="plain">help</arg>
Packit ae235b
  </cmdsynopsis>
Packit ae235b
</refsynopsisdiv>
Packit ae235b
Packit ae235b
<refsect1>
Packit ae235b
  <title>Description</title>
Packit ae235b
  <para>
Packit ae235b
    <command>gdbus</command> is a simple tool for working with D-Bus objects.
Packit ae235b
  </para>
Packit ae235b
</refsect1>
Packit ae235b
<refsect1>
Packit ae235b
    <title>Commands</title>
Packit ae235b
    <variablelist>
Packit ae235b
      <varlistentry>
Packit ae235b
        <term><option>introspect</option></term>
Packit ae235b
        <listitem><para>
Packit ae235b
          Prints out interfaces and property values for a remote object.
Packit ae235b
          For this to work, the owner of the object needs to implement the
Packit ae235b
          <literal>org.freedesktop.DBus.Introspectable</literal> interface.
Packit ae235b
          If the <option>--xml</option> option is used, the returned
Packit ae235b
          introspection XML is printed, otherwise a parsed pretty
Packit ae235b
          representation is printed.
Packit ae235b
          The <option>--recurse</option> option can be used to
Packit ae235b
          introspect children (and their children and so on) and the
Packit ae235b
          <option>--only-properties</option> option can be used to
Packit ae235b
          only print the interfaces with properties.
Packit ae235b
          </para></listitem>
Packit ae235b
      </varlistentry>
Packit ae235b
      <varlistentry>
Packit ae235b
        <term><option>monitor</option></term>
Packit ae235b
        <listitem><para>
Packit ae235b
          Monitors one or all objects owned by the owner of
Packit ae235b
          <replaceable>bus_name</replaceable>.
Packit ae235b
        </para></listitem>
Packit ae235b
      </varlistentry>
Packit ae235b
      <varlistentry>
Packit ae235b
        <term><option>call</option></term>
Packit ae235b
        <listitem><para>
Packit ae235b
          Invokes a method on a remote object.  Each argument to pass to the
Packit ae235b
          method must be specified as a serialized
Packit ae235b
          <link linkend="GVariant"><type>GVariant</type></link> except that strings do
Packit ae235b
          not need explicit quotes. The return values are printed out as
Packit ae235b
          serialized <link linkend="GVariant"><type>GVariant</type></link>
Packit ae235b
          values.
Packit ae235b
        </para></listitem>
Packit ae235b
      </varlistentry>
Packit ae235b
      <varlistentry>
Packit ae235b
        <term><option>emit</option></term>
Packit ae235b
        <listitem><para>
Packit ae235b
          Emits a signal. Each argument to include in the signal must be specified as a serialized
Packit ae235b
          <link linkend="GVariant"><type>GVariant</type></link> except that strings do
Packit ae235b
          not need explicit quotes.
Packit ae235b
        </para></listitem>
Packit ae235b
      </varlistentry>
Packit ae235b
      <varlistentry>
Packit ae235b
        <term><option>wait</option></term>
Packit ae235b
        <listitem><para>
Packit ae235b
          Waits until <replaceable>bus_name</replaceable> is owned by some
Packit ae235b
          process on the bus. If the <option>--activate</option> is specified,
Packit ae235b
          that bus name will be auto-started first. It may be the same as the
Packit ae235b
          bus name being waited for, or different.
Packit ae235b
        </para></listitem>
Packit ae235b
      </varlistentry>
Packit ae235b
      <varlistentry>
Packit ae235b
        <term><option>help</option></term>
Packit ae235b
        <listitem><para>
Packit ae235b
          Prints help and exit.
Packit ae235b
        </para></listitem>
Packit ae235b
      </varlistentry>
Packit ae235b
    </variablelist>
Packit ae235b
</refsect1>
Packit ae235b
Packit ae235b
<refsect1>
Packit ae235b
  <title>Bash Completion</title>
Packit ae235b
  <para>
Packit ae235b
    <command>gdbus</command> ships with a bash completion script to
Packit ae235b
    complete commands, destinations, bus names, object paths and
Packit ae235b
    interface/method names.
Packit ae235b
  </para>
Packit ae235b
</refsect1>
Packit ae235b
Packit ae235b
<refsect1>
Packit ae235b
  <title>Examples</title>
Packit ae235b
  This shows how to introspect an object - note that the value of each
Packit ae235b
  property is displayed:
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus introspect --system \
Packit ae235b
        --dest org.freedesktop.NetworkManager \
Packit ae235b
        --object-path /org/freedesktop/NetworkManager/Devices/0
Packit ae235b
node /org/freedesktop/NetworkManager/Devices/0 {
Packit ae235b
  interface org.freedesktop.DBus.Introspectable {
Packit ae235b
    methods:
Packit ae235b
      Introspect(out s data);
Packit ae235b
  };
Packit ae235b
  interface org.freedesktop.DBus.Properties {
Packit ae235b
    methods:
Packit ae235b
      Get(in  s interface,
Packit ae235b
          in  s propname,
Packit ae235b
          out v value);
Packit ae235b
      Set(in  s interface,
Packit ae235b
          in  s propname,
Packit ae235b
          in  v value);
Packit ae235b
      GetAll(in  s interface,
Packit ae235b
             out a{sv} props);
Packit ae235b
  };
Packit ae235b
  interface org.freedesktop.NetworkManager.Device.Wired {
Packit ae235b
    signals:
Packit ae235b
      PropertiesChanged(a{sv} arg_0);
Packit ae235b
    properties:
Packit ae235b
      readonly b Carrier = false;
Packit ae235b
      readonly u Speed = 0;
Packit ae235b
      readonly s HwAddress = '00:1D:72:88:BE:97';
Packit ae235b
  };
Packit ae235b
  interface org.freedesktop.NetworkManager.Device {
Packit ae235b
    methods:
Packit ae235b
      Disconnect();
Packit ae235b
    signals:
Packit ae235b
      StateChanged(u arg_0,
Packit ae235b
                   u arg_1,
Packit ae235b
                   u arg_2);
Packit ae235b
    properties:
Packit ae235b
      readonly u DeviceType = 1;
Packit ae235b
      readonly b Managed = true;
Packit ae235b
      readwrite o Ip6Config = '/';
Packit ae235b
      readwrite o Dhcp4Config = '/';
Packit ae235b
      readwrite o Ip4Config = '/';
Packit ae235b
      readonly u State = 2;
Packit ae235b
      readwrite u Ip4Address = 0;
Packit ae235b
      readonly u Capabilities = 3;
Packit ae235b
      readonly s Driver = 'e1000e';
Packit ae235b
      readwrite s Interface = 'eth0';
Packit ae235b
      readonly s Udi = '/sys/devices/pci0000:00/0000:00:19.0/net/eth0';
Packit ae235b
  };
Packit ae235b
};
Packit ae235b
</programlisting>
Packit ae235b
<para>
Packit ae235b
  The <option>--recurse</option> and <option>--only-properties</option> options can be useful when wanting to inspect all objects owned by a particular process:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus introspect --system --dest org.freedesktop.UPower --object-path / --recurse  --only-properties 
Packit ae235b
node / {
Packit ae235b
  node /org {
Packit ae235b
    node /org/freedesktop {
Packit ae235b
      node /org/freedesktop/UPower {
Packit ae235b
        interface org.freedesktop.UPower {
Packit ae235b
          properties:
Packit ae235b
            readonly b IsDocked = true;
Packit ae235b
            readonly b LidForceSleep = false;
Packit ae235b
            readonly b LidIsPresent = false;
Packit ae235b
            readonly b LidIsClosed = false;
Packit ae235b
            readonly b OnLowBattery = false;
Packit ae235b
            readonly b OnBattery = false;
Packit ae235b
            readonly b CanHibernate = true;
Packit ae235b
            readonly b CanSuspend = true;
Packit ae235b
            readonly s DaemonVersion = '0.9.10';
Packit ae235b
        };
Packit ae235b
        node /org/freedesktop/UPower/Policy {
Packit ae235b
        };
Packit ae235b
        node /org/freedesktop/UPower/Wakeups {
Packit ae235b
          interface org.freedesktop.UPower.Wakeups {
Packit ae235b
            properties:
Packit ae235b
              readonly b HasCapability = true;
Packit ae235b
          };
Packit ae235b
        };
Packit ae235b
      };
Packit ae235b
    };
Packit ae235b
  };
Packit ae235b
};
Packit ae235b
</programlisting>
Packit ae235b
<para>
Packit ae235b
  In a similar fashion, the <option>introspect</option> command can be
Packit ae235b
  used to learn details about the <literal>Notify</literal> method:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
[...]
Packit ae235b
  interface org.freedesktop.Notifications {
Packit ae235b
    methods:
Packit ae235b
      GetServerInformation(out s return_name,
Packit ae235b
                           out s return_vendor,
Packit ae235b
                           out s return_version,
Packit ae235b
                           out s return_spec_version);
Packit ae235b
      GetCapabilities(out as return_caps);
Packit ae235b
      CloseNotification(in  u id);
Packit ae235b
      Notify(in  s app_name,
Packit ae235b
             in  u id,
Packit ae235b
             in  s icon,
Packit ae235b
             in  s summary,
Packit ae235b
             in  s body,
Packit ae235b
             in  as actions,
Packit ae235b
             in  a{sv} hints,
Packit ae235b
             in  i timeout,
Packit ae235b
             out u return_id);
Packit ae235b
  };
Packit ae235b
[...]
Packit ae235b
</programlisting>
Packit ae235b
<para>
Packit ae235b
  With this information, it's easy to use the <option>call</option>
Packit ae235b
  command to display a notification
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus call --session \
Packit ae235b
             --dest org.freedesktop.Notifications \
Packit ae235b
             --object-path /org/freedesktop/Notifications \
Packit ae235b
             --method org.freedesktop.Notifications.Notify \
Packit ae235b
             my_app_name \
Packit ae235b
             42 \
Packit ae235b
             gtk-dialog-info \
Packit ae235b
             "The Summary" \
Packit ae235b
             "Here's the body of the notification" \
Packit ae235b
             [] \
Packit ae235b
             {} \
Packit ae235b
             5000
Packit ae235b
(uint32 12,)
Packit ae235b
</programlisting>
Packit ae235b
<para>
Packit ae235b
  Monitoring all objects on a service:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus monitor --system --dest org.freedesktop.ConsoleKit
Packit ae235b
Monitoring signals from all objects owned by org.freedesktop.ConsoleKit
Packit ae235b
The name org.freedesktop.ConsoleKit is owned by :1.15
Packit ae235b
/org/freedesktop/ConsoleKit/Session2: org.freedesktop.ConsoleKit.Session.ActiveChanged (false,)
Packit ae235b
/org/freedesktop/ConsoleKit/Seat1: org.freedesktop.ConsoleKit.Seat.ActiveSessionChanged ('',)
Packit ae235b
/org/freedesktop/ConsoleKit/Session2: org.freedesktop.ConsoleKit.Session.ActiveChanged (true,)
Packit ae235b
/org/freedesktop/ConsoleKit/Seat1: org.freedesktop.ConsoleKit.Seat.ActiveSessionChanged ('/org/freedesktop/ConsoleKit/Session2',)
Packit ae235b
</programlisting>
Packit ae235b
<para>
Packit ae235b
  Monitoring a single object on a service:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus monitor --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/AccessPoint/4141
Packit ae235b
Monitoring signals on object /org/freedesktop/NetworkManager/AccessPoint/4141 owned by org.freedesktop.NetworkManager
Packit ae235b
The name org.freedesktop.NetworkManager is owned by :1.5
Packit ae235b
/org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x5c>},)
Packit ae235b
/org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x64>},)
Packit ae235b
/org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x5e>},)
Packit ae235b
/org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x64>},)
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
<para>
Packit ae235b
  Emitting a signal:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus emit --session --object-path /foo --signal org.bar.Foo "['foo', 'bar', 'baz']"
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
<para>
Packit ae235b
  Emitting a signal to a specific process:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus emit --session --object-path /bar --signal org.bar.Bar someString --dest :1.42
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
<para>
Packit ae235b
  Waiting for a well-known name to be owned on the bus; this will
Packit ae235b
  <emphasis>not</emphasis> auto-start the service:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus wait --session org.bar.SomeName
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
<para>
Packit ae235b
  Auto-starting then waiting for a well-known name to be owned on the bus:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus wait --session --activate org.bar.SomeName
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
<para>
Packit ae235b
  Auto-starting a different service, then waiting for a well-known name to be
Packit ae235b
  owned on the bus. This is useful in situations where
Packit ae235b
  <replaceable>SomeName</replaceable> is not directly activatable:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus wait --session --activate org.bar.PrerequisiteName org.bar.SomeName
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
<para>
Packit ae235b
  Waiting for a well-known name and giving up after 30 seconds. By default,
Packit ae235b
  the timeout is disabled; or set <option>--timeout</option> to 0 to disable it:
Packit ae235b
</para>
Packit ae235b
<programlisting>
Packit ae235b
$ gdbus wait --session --timeout 30 org.bar.SomeName
Packit ae235b
</programlisting>
Packit ae235b
Packit ae235b
</refsect1>
Packit ae235b
Packit ae235b
<refsect1>
Packit ae235b
  <title>Bugs</title>
Packit ae235b
  <para>
Packit ae235b
    Please send bug reports to either the distribution bug tracker
Packit ae235b
    or the upstream bug tracker at
Packit ae235b
    <ulink url="https://bugzilla.gnome.org/enter_bug.cgi?product=glib"/>.
Packit ae235b
  </para>
Packit ae235b
</refsect1>
Packit ae235b
Packit ae235b
<refsect1>
Packit ae235b
  <title>See Also</title>
Packit ae235b
  <para>
Packit ae235b
    <citerefentry>
Packit ae235b
      <refentrytitle>dbus-send</refentrytitle><manvolnum>1</manvolnum>
Packit ae235b
    </citerefentry>
Packit ae235b
  </para>
Packit ae235b
</refsect1>
Packit ae235b
Packit ae235b
</refentry>
Packit ae235b