From 02e6cf705e1535f3cab0ffde554efb29e01ccead Mon Sep 17 00:00:00 2001 From: Samuel Gauthier Date: Tue, 19 Dec 2023 12:19:21 +0100 Subject: [PATCH] subscription: add support for filter_origin Add support for the new SR_SUBSCR_FILTER_ORIG flag. Signed-off-by: Samuel Gauthier --- cffi/cdefs.h | 3 +++ sysrepo/session.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cffi/cdefs.h b/cffi/cdefs.h index 8f25640..e38e64b 100644 --- a/cffi/cdefs.h +++ b/cffi/cdefs.h @@ -208,6 +208,9 @@ typedef enum sr_subscr_flag_e { SR_SUBSCR_ENABLED, SR_SUBSCR_UPDATE, SR_SUBSCR_OPER_MERGE, + SR_SUBSCR_THREAD_SUSPEND, + SR_SUBSCR_OPER_POLL_DIFF, + SR_SUBSCR_FILTER_ORIG, ... } sr_subscr_flag_t; diff --git a/sysrepo/session.py b/sysrepo/session.py index 6af0be7..2b43e42 100644 --- a/sysrepo/session.py +++ b/sysrepo/session.py @@ -326,6 +326,7 @@ def subscribe_module_change( passive: bool = False, done_only: bool = False, enabled: bool = False, + filter_origin: bool = False, private_data: Any = None, asyncio_register: bool = False, include_implicit_defaults: bool = True, @@ -359,6 +360,9 @@ def subscribe_module_change( :arg enabled: The subscriber wants to be notified about the current configuration at the moment of subscribing. + :arg filter_origin: + Filter events on the originator side to unburden the subscriber, but + results in 0 value for filtered-out changes in the subscriber infos. :arg private_data: Private context passed to the callback function, opaque to sysrepo. :arg asyncio_register: @@ -390,7 +394,11 @@ def subscribe_module_change( if asyncio_register: no_thread = True # we manage our own event loop flags = _subscribe_flags( - no_thread=no_thread, passive=passive, done_only=done_only, enabled=enabled + no_thread=no_thread, + passive=passive, + done_only=done_only, + enabled=enabled, + filter_origin=filter_origin, ) check_call( @@ -444,6 +452,7 @@ def subscribe_module_change_unsafe( passive: bool = False, done_only: bool = False, enabled: bool = False, + filter_origin: bool = False, private_data: Any = None, asyncio_register: bool = False, ) -> None: @@ -478,6 +487,9 @@ def subscribe_module_change_unsafe( :arg enabled: The subscriber wants to be notified about the current configuration at the moment of subscribing. + :arg filter_origin: + Filter events on the originator side to unburden the subscriber, but + results in 0 value for filtered-out changes in the subscriber infos. :arg private_data: Private context passed to the callback function, opaque to sysrepo. :arg asyncio_register: @@ -503,7 +515,11 @@ def subscribe_module_change_unsafe( if asyncio_register: no_thread = True # we manage our own event loop flags = _subscribe_flags( - no_thread=no_thread, passive=passive, done_only=done_only, enabled=enabled + no_thread=no_thread, + passive=passive, + done_only=done_only, + enabled=enabled, + filter_origin=filter_origin, ) check_call( lib.sr_module_change_subscribe, @@ -1615,7 +1631,12 @@ def _get_oper_flags(no_state=False, no_config=False, no_subs=False, no_stored=Fa # ------------------------------------------------------------------------------------- def _subscribe_flags( - no_thread=False, passive=False, done_only=False, enabled=False, oper_merge=False + no_thread=False, + passive=False, + done_only=False, + enabled=False, + oper_merge=False, + filter_origin=False, ): flags = 0 if no_thread: @@ -1628,6 +1649,8 @@ def _subscribe_flags( flags |= lib.SR_SUBSCR_ENABLED if oper_merge: flags |= lib.SR_SUBSCR_OPER_MERGE + if filter_origin: + flags |= lib.SR_SUBSCR_FILTER_ORIG return flags