dbus: add a helper for sending signals
This commit is contained in:
parent
ba7c62fc0c
commit
1e31e6cba7
|
@ -117,6 +117,11 @@ class _TuhiDBus(GObject.Object):
|
||||||
properties,
|
properties,
|
||||||
inval_props))
|
inval_props))
|
||||||
|
|
||||||
|
def signal(self, name, arg=None, dest=None):
|
||||||
|
if arg is not None:
|
||||||
|
arg = GLib.Variant.new_tuple(arg)
|
||||||
|
self.connection.emit_signal(dest, self.objpath, self.interface, name, arg)
|
||||||
|
|
||||||
|
|
||||||
class TuhiDBusDevice(_TuhiDBus):
|
class TuhiDBusDevice(_TuhiDBus):
|
||||||
"""
|
"""
|
||||||
|
@ -234,9 +239,7 @@ class TuhiDBusDevice(_TuhiDBus):
|
||||||
# other clients
|
# other clients
|
||||||
if sender != self._listening_client[0]:
|
if sender != self._listening_client[0]:
|
||||||
status = GLib.Variant.new_int32(-errno.EAGAIN)
|
status = GLib.Variant.new_int32(-errno.EAGAIN)
|
||||||
status = GLib.Variant.new_tuple(status)
|
self.signal('ListeningStopped', status, dest=sender)
|
||||||
connection.emit_signal(sender, self.objpath, self.interface,
|
|
||||||
"ListeningStopped", status)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
s = connection.signal_subscribe(sender='org.freedesktop.DBus',
|
s = connection.signal_subscribe(sender='org.freedesktop.DBus',
|
||||||
|
@ -273,9 +276,7 @@ class TuhiDBusDevice(_TuhiDBus):
|
||||||
self.notify('listening')
|
self.notify('listening')
|
||||||
|
|
||||||
status = GLib.Variant.new_int32(0)
|
status = GLib.Variant.new_int32(0)
|
||||||
status = GLib.Variant.new_tuple(status)
|
self.signal('ListeningStopped', status, dest=sender)
|
||||||
connection.emit_signal(sender, self.objpath, self.interface,
|
|
||||||
"ListeningStopped", status)
|
|
||||||
self.listening = False
|
self.listening = False
|
||||||
self.notify('listening')
|
self.notify('listening')
|
||||||
|
|
||||||
|
@ -295,8 +296,7 @@ class TuhiDBusDevice(_TuhiDBus):
|
||||||
|
|
||||||
def notify_button_press_required(self):
|
def notify_button_press_required(self):
|
||||||
logger.debug("Sending ButtonPressRequired signal")
|
logger.debug("Sending ButtonPressRequired signal")
|
||||||
self.connection.emit_signal(None, self.objpath, self.interface,
|
self.signal('ButtonPressRequired')
|
||||||
"ButtonPressRequired", None)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "{} - {}".format(self.objpath, self.name)
|
return "{} - {}".format(self.objpath, self.name)
|
||||||
|
@ -396,9 +396,7 @@ class TuhiDBusServer(_TuhiDBus):
|
||||||
# other clients
|
# other clients
|
||||||
if sender != self._searching_client[0]:
|
if sender != self._searching_client[0]:
|
||||||
status = GLib.Variant.new_int32(-errno.EAGAIN)
|
status = GLib.Variant.new_int32(-errno.EAGAIN)
|
||||||
status = GLib.Variant.new_tuple(status)
|
self.signal('SearchStopped', status)
|
||||||
connection.emit_signal(sender, self.objpath, self.interface,
|
|
||||||
"SearchStopped", status)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.is_searching = True
|
self.is_searching = True
|
||||||
|
@ -443,10 +441,7 @@ class TuhiDBusServer(_TuhiDBus):
|
||||||
logger.debug("Search has stopped")
|
logger.debug("Search has stopped")
|
||||||
self.is_searching = False
|
self.is_searching = False
|
||||||
status = GLib.Variant.new_int32(status)
|
status = GLib.Variant.new_int32(status)
|
||||||
status = GLib.Variant.new_tuple(status)
|
self.signal("SearchStopped", status, dest=self._searching_client[0])
|
||||||
self.connection.emit_signal(self._searching_client[0],
|
|
||||||
self.object_path, self.interface,
|
|
||||||
"SearchStopped", status)
|
|
||||||
self._searching_client = None
|
self._searching_client = None
|
||||||
|
|
||||||
for dev in self._devices:
|
for dev in self._devices:
|
||||||
|
@ -475,7 +470,4 @@ class TuhiDBusServer(_TuhiDBus):
|
||||||
|
|
||||||
def _emit_pairable_signal(self, device):
|
def _emit_pairable_signal(self, device):
|
||||||
arg = GLib.Variant.new_object_path(device.objpath)
|
arg = GLib.Variant.new_object_path(device.objpath)
|
||||||
self.connection.emit_signal(self._searching_client[0],
|
self.signal('PairableDevice', arg, dest=self._searching_client[0])
|
||||||
self.objpath, self.interface,
|
|
||||||
"PairableDevice",
|
|
||||||
GLib.Variant.new_tuple(arg))
|
|
||||||
|
|
Loading…
Reference in New Issue