@sthursfield I created the following scripts:
service.py
import gi
from gi.repository import Gio, GLib
node_xml = """
<node>
<interface name='org.gtk.GDBus.TestInterface'>
<annotation name='org.gtk.GDBus.Annotation' value='OnInterface'/>
<annotation name='org.gtk.GDBus.Annotation' value='AlsoOnInterface'/>
<method name='HelloWorld'>
<annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>
<arg type='s' name='greeting' direction='in'/>
<arg type='s' name='response' direction='out'/>
</method>
<method name='EmitSignal'>
<arg type='d' name='speed_in_mph' direction='in'>
<annotation name='org.gtk.GDBus.Annotation' value='OnArg'/>
</arg>
</method>
<method name='GimmeStdout'/>
<signal name='VelocityChanged'>
<annotation name='org.gtk.GDBus.Annotation' value='Onsignal'/>
<arg type='d' name='speed_in_mph'/>
<arg type='s' name='speed_as_string'>
<annotation name='org.gtk.GDBus.Annotation' value='OnArg_NonFirst'/>
</arg>
</signal>
<property type='s' name='FluxCapicitorName' access='read'>
<annotation name='org.gtk.GDBus.Annotation' value='OnProperty'>
<annotation name='org.gtk.GDBus.Annotation' value='OnAnnotation_YesThisIsCrazy'/>
</annotation>
</property>
<property type='s' name='Title' access='readwrite'/>
<property type='s' name='ReadingAlwaysThrowsError' access='read'/>
<property type='s' name='WritingAlwaysThrowsError' access='readwrite'/>
<property type='s' name='OnlyWritable' access='write'/>
<property type='s' name='Foo' access='read'/>
<property type='s' name='Bar' access='read'/>
</interface>
</node>"""
NodeInfo = Gio.DBusNodeInfo.new_for_xml(node_xml)
def on_bus_acquired(conn, name):
conn.register_object(conn,
"/org/Gtk/GDBus/TestInterface",
NodeInfo,
print,
print,
print)
def on_name_acquired(conn, name):
print("Name acquired")
def on_name_lost(conn, name):
print("Name lost")
Gio.bus_own_name(Gio.BusType.SESSION,
"org.gtk.GDBus.TestInterface",
Gio.BusNameOwnerFlags.NONE,
None,
on_name_acquired,
on_name_lost)
GLib.MainLoop().run()
Running it, I got Name acquired.
[details = “client.py”]
import sys
from gi.repository import GLib, Gio
if len(sys.argv) < 2:
sys.stderr.write(“Tell something\n”)
sys.exit(1)
if len(sys.argv) > 2:
sys.stderr.write(“Too many arguments\n”)
sys.exit(1)
connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
proxy = Gio.DBusProxy.new_sync(connection,
Gio.DBusProxyFlags.NONE,
None,
“org.gtk.GDBus.TestInterface”,
“/org/Gtk/GDBus/TestInterface”,
“org.gtk.GDBus.TestInterface”,
None)
try:
proxy.call_sync(“Configure”,
GLib.Variant(“(u)”, (int(sys.argv[1]),)),
Gio.DBusCallFlags.NONE,
-1,
None)
except Exception as e:
sys.stderr.write(“Error: %s\n” % str(e))
else:
print(“Done”)
[/details]
Running it with service.py already running, I got this:
$ python3 client.py 13
Error: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.gtk.GDBus.TestInterface” on object at path /org/Gtk/GDBus/TestInterface (19)
What’s next?