tools: sync ratbagd.py from Piper - drop async commit

ratbagd now implements commit as normal always-successful call with a
potential Resync signal later if something failed on the device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2018-12-13 11:58:49 +10:00
parent abe99fec6a
commit 9b2614109f
3 changed files with 13 additions and 53 deletions

View File

@@ -310,23 +310,15 @@ class RatbagdDevice(metaclass=MetaRatbag):
"""
return open(self.get_svg(theme))
def commit(self, callback=None):
def commit(self):
"""Commits all changes made to the device.
This is an async call to DBus and this method does not return
anything. Any success or failure code is reported to the callback
provided when ratbagd finishes writing to the device. Note that upon
failure, the device is automatically resynchronized by ratbagd and no
further interaction is required by the client; clients can thus treat a
commit as being always successful.
@param callback The function to call with the result of the commit, as
a function that takes the return value of the Commit
method.
This is implemented asynchronously inside ratbagd. Hence, we just call
this method and always succeed. Any failure is handled inside ratbagd
by emitting the Resync signal, which automatically resynchronizes the
device. No further interaction is required by the client.
"""
r = libratbag.ratbag_device_commit(self._device)
if callback is not None:
callback(r)
return libratbag.ratbag_device_commit(self._device)
class RatbagdProfile(metaclass=MetaRatbag):

View File

@@ -622,15 +622,10 @@ link = 'link'
################################################################################
def commit_cb(status):
if not status == RatbagErrorCode.RATBAG_SUCCESS:
print("Could not commit changes to the device")
def commit(device, args):
if args.nocommit:
return
device.commit(commit_cb)
device.commit()
def color(string):

View File

@@ -186,27 +186,6 @@ class _RatbagdDBus(GObject.GObject):
# update
self._proxy.set_cached_property(property, val)
def _dbus_call_async(self, method, type, *value, callback):
# The callback handler to unwrap the data
def callback_handler(obj, result, user_callback):
try:
res = obj.call_finish(result)
res = res.unpack()[0] # Result is always a tuple
user_callback(res)
except GLib.Error as e:
# Unrecognized error code; print the message to stderr and raise
# the GLib.Error.
print(e.message, file=sys.stderr)
raise
# Calls a method asynchronously on the bus, using the given method
# name, type signature and values. The callback is invoked when the
# method finishes
val = GLib.Variant("({})".format(type), value)
self._proxy.call(method, val,
Gio.DBusCallFlags.NO_AUTO_START,
500, None, callback_handler, callback)
def _dbus_call(self, method, type, *value):
# Calls a method synchronously on the bus, using the given method name,
# type signature and values.
@@ -426,21 +405,15 @@ class RatbagdDevice(_RatbagdDBus):
"""
return self._dbus_call("GetSvg", "s", theme)
def commit(self, callback):
def commit(self):
"""Commits all changes made to the device.
This is an async call to DBus and this method does not return
anything. Any success or failure code is reported to the callback
provided when ratbagd finishes writing to the device. Note that upon
failure, the device is automatically resynchronized by ratbagd and no
further interaction is required by the client; clients can thus treat a
commit as being always successful.
@param callback The function to call with the result of the commit, as
a function that takes the return value of the Commit
method.
This is implemented asynchronously inside ratbagd. Hence, we just call
this method and always succeed. Any failure is handled inside ratbagd
by emitting the Resync signal, which automatically resynchronizes the
device. No further interaction is required by the client.
"""
self._dbus_call_async("Commit", "", callback=callback)
self._dbus_call("Commit", "")
for profile in self._profiles:
if profile.dirty:
profile._dirty = False