88struct confd confd ;
99
1010
11- uint32_t core_hook_prio (void )
12- {
13- static uint32_t hook_prio = CB_PRIO_PASSIVE ;
14-
15- return hook_prio -- ;
16- }
17-
1811int core_startup_save (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
1912 const char * xpath , sr_event_t event , unsigned request_id , void * priv )
2013{
14+ sr_event_t last_event = -1 ;
15+ static unsigned int last_request = -1 ;
16+ if (last_event == event && last_request == request_id )
17+ return SR_ERR_OK ;
18+ last_event = event ;
19+ last_request = request_id ;
20+
2121 /* skip in bootstrap, triggered by load script to initialize startup datastore */
2222 if (systemf ("runlevel >/dev/null 2>&1" ))
2323 return SR_ERR_OK ;
@@ -28,59 +28,6 @@ int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *mo
2828 return SR_ERR_OK ;
2929}
3030
31- static const char * ev2str (sr_event_t ev )
32- {
33- switch (ev ) {
34- case SR_EV_UPDATE : return "UPDATE" ;
35- case SR_EV_CHANGE : return "CHANGE" ;
36- case SR_EV_DONE : return "DONE" ;
37- case SR_EV_ABORT : return "ABORT" ;
38- case SR_EV_ENABLED : return "ENABLED" ;
39- case SR_EV_RPC : return "ABORT" ;
40- default :
41- break ;
42- }
43-
44- return "UNKNOWN" ;
45- }
46-
47- int core_pre_hook (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
48- const char * xpath , sr_event_t event , unsigned request_id , void * priv )
49- {
50- return 0 ;
51- }
52-
53- /*
54- * Run on UPDATE to see how many modules have changes in the inbound changeset
55- * Run on DONE, after the last module callback has run, to activate changes.
56- * For details, see https://github.com/sysrepo/sysrepo/issues/2188
57- */
58- int core_post_hook (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
59- const char * xpath , sr_event_t event , unsigned request_id , void * priv )
60- {
61- static size_t num_changes = 0 ;
62-
63- switch (event ) {
64- case SR_EV_CHANGE :
65- num_changes ++ ;
66- return SR_ERR_OK ;
67- case SR_EV_ABORT :
68- num_changes = 0 ;
69- return SR_ERR_OK ;
70- case SR_EV_DONE :
71- num_changes -- ;
72- if (num_changes > 0 )
73- return SR_ERR_OK ;
74- break ;
75- default :
76- ERROR ("core_post_hook() should not be called with event %s" , ev2str (event ));
77- return SR_ERR_SYS ;
78- }
79-
80-
81- return SR_ERR_OK ;
82- }
83-
8431static confd_dependency_t add_dependencies (struct lyd_node * * diff , const char * xpath , const char * value )
8532{
8633 struct lyd_node * new_node = NULL ;
@@ -204,17 +151,17 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
204151 const char * xpath , sr_event_t event , uint32_t request_id , void * _confd )
205152{
206153 struct lyd_node * diff = NULL , * config = NULL ;
207- static uint32_t last_event = -1 ;
154+ static sr_event_t last_event = -1 ;
208155 struct confd * confd = _confd ;
209- static uint32_t last_id = 0 ;
156+ static uint32_t last_request = 0 ;
210157 confd_dependency_t result ;
211158 sr_data_t * cfg = NULL ;
212159 int rc = SR_ERR_OK ;
213160 int max_dep = 10 ;
214161
215- if (request_id == last_id && last_event == event )
162+ if (request_id == last_request && last_event == event )
216163 return SR_ERR_OK ;
217- last_id = request_id ;
164+ last_request = request_id ;
218165 last_event = event ;
219166
220167 if (event == SR_EV_CHANGE || event == SR_EV_DONE ) {
@@ -316,8 +263,11 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
316263 return rc ;
317264}
318265
319- static int subscribe_module (char * model , struct confd * confd , int flags ) {
320- return sr_module_change_subscribe (confd -> session , model , "//." , change_cb , confd , CB_PRIO_PRIMARY , SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags , & confd -> sub );
266+ static inline int subscribe_module (char * model , struct confd * confd , int flags ) {
267+ return sr_module_change_subscribe (confd -> session , model , "//." , change_cb , confd ,
268+ CB_PRIO_PRIMARY , SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags , & confd -> sub ) &&
269+ sr_module_change_subscribe (confd -> startup , model , "//." , core_startup_save , NULL ,
270+ CB_PRIO_PASSIVE , SR_SUBSCR_PASSIVE | SR_SUBSCR_CHANGE_ALL_MODULES , & confd -> sub );
321271}
322272
323273int sr_plugin_init_cb (sr_session_ctx_t * session , void * * priv )
0 commit comments