Skip to content

Commit

Permalink
subscription: add support for filter_origin
Browse files Browse the repository at this point in the history
Add support for the new SR_SUBSCR_FILTER_ORIG flag.

Signed-off-by: Samuel Gauthier <[email protected]>
  • Loading branch information
samuel-gauthier authored and rjarry committed Jan 26, 2024
1 parent 2e67e25 commit 02e6cf7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
29 changes: 26 additions & 3 deletions sysrepo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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


Expand Down

0 comments on commit 02e6cf7

Please sign in to comment.