From b319a2df9d711fca96c86fd5071994faebc186ac Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 25 May 2023 16:44:08 +0200 Subject: [PATCH] src/confd: refactor commit done hook into a pre and post hook Signed-off-by: Joachim Wiberg --- src/confd/src/core.c | 8 +++++++- src/confd/src/core.h | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/confd/src/core.c b/src/confd/src/core.c index 23f00e35..2f877de4 100644 --- a/src/confd/src/core.c +++ b/src/confd/src/core.c @@ -21,12 +21,18 @@ int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *mo return SR_ERR_OK; } +int core_pre_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module, + const char *xpath, sr_event_t event, unsigned request_id, void *priv) +{ + return 0; +} + /* * Run on UPDATE to see how many modules have changes in the inbound changeset * Run on DONE, after the last module callback has run, to activate changes. * For details, see https://github.com/sysrepo/sysrepo/issues/2188 */ -int core_commit_done(sr_session_ctx_t *session, uint32_t sub_id, const char *module, +int core_post_hook(sr_session_ctx_t *session, uint32_t sub_id, const char *module, const char *xpath, sr_event_t event, unsigned request_id, void *priv) { static int num_changes = 0; diff --git a/src/confd/src/core.h b/src/confd/src/core.h index c9ebe6b2..3b436b03 100644 --- a/src/confd/src/core.h +++ b/src/confd/src/core.h @@ -73,7 +73,8 @@ struct confd { }; uint32_t core_hook_prio (void); -int core_commit_done (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *); +int core_pre_hook (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *); +int core_post_hook (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *); int core_startup_save (sr_session_ctx_t *, uint32_t, const char *, const char *, sr_event_t, unsigned, void *); static inline int register_change(sr_session_ctx_t *session, const char *module, const char *xpath, @@ -82,6 +83,11 @@ static inline int register_change(sr_session_ctx_t *session, const char *module, struct confd *confd = (struct confd *)arg; int rc; + if (!flags) { + sr_module_change_subscribe(confd->session, module, xpath, core_pre_hook, NULL, + 0, SR_SUBSCR_PASSIVE, sub); + } + rc = sr_module_change_subscribe(session, module, xpath, cb, arg, CB_PRIO_PRIMARY, flags | SR_SUBSCR_DEFAULT, sub); if (rc) { @@ -97,7 +103,7 @@ static inline int register_change(sr_session_ctx_t *session, const char *module, * the startup-save hook for running -> startup copying. */ if (!flags) { - sr_module_change_subscribe(confd->session, module, xpath, core_commit_done, NULL, + sr_module_change_subscribe(confd->session, module, xpath, core_post_hook, NULL, core_hook_prio(), SR_SUBSCR_PASSIVE, sub); sr_module_change_subscribe(confd->startup, module, xpath, core_startup_save, NULL, core_hook_prio(), SR_SUBSCR_PASSIVE, sub);