comparison libervia/frontends/bridge/dbus_bridge.py @ 4130:02f0adc745c6

core: notifications implementation, first draft: add a new table for notifications, and methods/bridge methods to manipulate them.
author Goffi <goffi@goffi.org>
date Mon, 16 Oct 2023 17:29:31 +0200
parents 26b7ed2817da
children 11f95dfe5b17
comparison
equal deleted inserted replaced
4129:51744ad00a42 4130:02f0adc745c6
559 if callback is not None: 559 if callback is not None:
560 kwargs['timeout'] = const_TIMEOUT 560 kwargs['timeout'] = const_TIMEOUT
561 kwargs['reply_handler'] = callback 561 kwargs['reply_handler'] = callback
562 kwargs['error_handler'] = error_handler 562 kwargs['error_handler'] = error_handler
563 return self.db_core_iface.namespaces_get(**kwargs) 563 return self.db_core_iface.namespaces_get(**kwargs)
564
565 def notification_add(self, type_, body_plain, body_rich, title, is_global, requires_action, arg_6, priority, expire_at, extra, callback=None, errback=None):
566 if callback is None:
567 error_handler = None
568 else:
569 if errback is None:
570 errback = log.error
571 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
572 kwargs={}
573 if callback is not None:
574 kwargs['timeout'] = const_TIMEOUT
575 kwargs['reply_handler'] = callback
576 kwargs['error_handler'] = error_handler
577 return self.db_core_iface.notification_add(type_, body_plain, body_rich, title, is_global, requires_action, arg_6, priority, expire_at, extra, **kwargs)
578
579 def notification_delete(self, id_, is_global, profile_key, callback=None, errback=None):
580 if callback is None:
581 error_handler = None
582 else:
583 if errback is None:
584 errback = log.error
585 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
586 kwargs={}
587 if callback is not None:
588 kwargs['timeout'] = const_TIMEOUT
589 kwargs['reply_handler'] = callback
590 kwargs['error_handler'] = error_handler
591 return self.db_core_iface.notification_delete(id_, is_global, profile_key, **kwargs)
592
593 def notifications_expired_clean(self, limit_timestamp, profile_key, callback=None, errback=None):
594 if callback is None:
595 error_handler = None
596 else:
597 if errback is None:
598 errback = log.error
599 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
600 kwargs={}
601 if callback is not None:
602 kwargs['timeout'] = const_TIMEOUT
603 kwargs['reply_handler'] = callback
604 kwargs['error_handler'] = error_handler
605 return self.db_core_iface.notifications_expired_clean(limit_timestamp, profile_key, **kwargs)
606
607 def notifications_get(self, filters, profile_key, callback=None, errback=None):
608 if callback is None:
609 error_handler = None
610 else:
611 if errback is None:
612 errback = log.error
613 error_handler = lambda err:errback(dbus_to_bridge_exception(err))
614 kwargs={}
615 if callback is not None:
616 kwargs['timeout'] = const_TIMEOUT
617 kwargs['reply_handler'] = callback
618 kwargs['error_handler'] = error_handler
619 return str(self.db_core_iface.notifications_get(filters, profile_key, **kwargs))
564 620
565 def param_get_a(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None): 621 def param_get_a(self, name, category, attribute="value", profile_key="@DEFAULT@", callback=None, errback=None):
566 if callback is None: 622 if callback is None:
567 error_handler = None 623 error_handler = None
568 else: 624 else:
1269 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret) 1325 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1270 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err)) 1326 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1271 self.db_core_iface.namespaces_get(timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler) 1327 self.db_core_iface.namespaces_get(timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1272 return fut 1328 return fut
1273 1329
1330 def notification_add(self, type_, body_plain, body_rich, title, is_global, requires_action, arg_6, priority, expire_at, extra):
1331 loop = asyncio.get_running_loop()
1332 fut = loop.create_future()
1333 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1334 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1335 self.db_core_iface.notification_add(type_, body_plain, body_rich, title, is_global, requires_action, arg_6, priority, expire_at, extra, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1336 return fut
1337
1338 def notification_delete(self, id_, is_global, profile_key):
1339 loop = asyncio.get_running_loop()
1340 fut = loop.create_future()
1341 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1342 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1343 self.db_core_iface.notification_delete(id_, is_global, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1344 return fut
1345
1346 def notifications_expired_clean(self, limit_timestamp, profile_key):
1347 loop = asyncio.get_running_loop()
1348 fut = loop.create_future()
1349 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1350 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1351 self.db_core_iface.notifications_expired_clean(limit_timestamp, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1352 return fut
1353
1354 def notifications_get(self, filters, profile_key):
1355 loop = asyncio.get_running_loop()
1356 fut = loop.create_future()
1357 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1358 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))
1359 self.db_core_iface.notifications_get(filters, profile_key, timeout=const_TIMEOUT, reply_handler=reply_handler, error_handler=error_handler)
1360 return fut
1361
1274 def param_get_a(self, name, category, attribute="value", profile_key="@DEFAULT@"): 1362 def param_get_a(self, name, category, attribute="value", profile_key="@DEFAULT@"):
1275 loop = asyncio.get_running_loop() 1363 loop = asyncio.get_running_loop()
1276 fut = loop.create_future() 1364 fut = loop.create_future()
1277 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret) 1365 reply_handler = lambda ret=None: loop.call_soon_threadsafe(fut.set_result, ret)
1278 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err)) 1366 error_handler = lambda err: loop.call_soon_threadsafe(fut.set_exception, dbus_to_bridge_exception(err))