77struct confd confd ;
88
99
10- uint32_t core_hook_prio (void )
11- {
12- static uint32_t hook_prio = CB_PRIO_PASSIVE ;
13-
14- return hook_prio -- ;
15- }
16-
1710int core_startup_save (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
1811 const char * xpath , sr_event_t event , unsigned request_id , void * priv )
1912{
13+ sr_event_t last_event = -1 ;
14+ static unsigned int last_request = -1 ;
15+ if (last_event == event && last_request == request_id )
16+ return SR_ERR_OK ;
17+ last_event = event ;
18+ last_request = request_id ;
19+
2020 /* skip in bootstrap, triggered by load script to initialize startup datastore */
2121 if (systemf ("runlevel >/dev/null 2>&1" ))
2222 return SR_ERR_OK ;
@@ -27,59 +27,6 @@ int core_startup_save(sr_session_ctx_t *session, uint32_t sub_id, const char *mo
2727 return SR_ERR_OK ;
2828}
2929
30- static const char * ev2str (sr_event_t ev )
31- {
32- switch (ev ) {
33- case SR_EV_UPDATE : return "UPDATE" ;
34- case SR_EV_CHANGE : return "CHANGE" ;
35- case SR_EV_DONE : return "DONE" ;
36- case SR_EV_ABORT : return "ABORT" ;
37- case SR_EV_ENABLED : return "ENABLED" ;
38- case SR_EV_RPC : return "ABORT" ;
39- default :
40- break ;
41- }
42-
43- return "UNKNOWN" ;
44- }
45-
46- int core_pre_hook (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
47- const char * xpath , sr_event_t event , unsigned request_id , void * priv )
48- {
49- return 0 ;
50- }
51-
52- /*
53- * Run on UPDATE to see how many modules have changes in the inbound changeset
54- * Run on DONE, after the last module callback has run, to activate changes.
55- * For details, see https://github.com/sysrepo/sysrepo/issues/2188
56- */
57- int core_post_hook (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
58- const char * xpath , sr_event_t event , unsigned request_id , void * priv )
59- {
60- static size_t num_changes = 0 ;
61-
62- switch (event ) {
63- case SR_EV_CHANGE :
64- num_changes ++ ;
65- return SR_ERR_OK ;
66- case SR_EV_ABORT :
67- num_changes = 0 ;
68- return SR_ERR_OK ;
69- case SR_EV_DONE :
70- num_changes -- ;
71- if (num_changes > 0 )
72- return SR_ERR_OK ;
73- break ;
74- default :
75- ERROR ("core_post_hook() should not be called with event %s" , ev2str (event ));
76- return SR_ERR_SYS ;
77- }
78-
79-
80- return SR_ERR_OK ;
81- }
82-
8330static confd_dependency_t add_dependencies (struct lyd_node * * diff , const char * xpath , const char * value )
8431{
8532 struct lyd_node * new_node = NULL ;
@@ -203,17 +150,17 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
203150 const char * xpath , sr_event_t event , uint32_t request_id , void * _confd )
204151{
205152 struct lyd_node * diff = NULL , * config = NULL ;
206- static uint32_t last_event = -1 ;
153+ static sr_event_t last_event = -1 ;
207154 struct confd * confd = _confd ;
208- static uint32_t last_id = 0 ;
155+ static uint32_t last_request = 0 ;
209156 confd_dependency_t result ;
210157 sr_data_t * cfg = NULL ;
211158 int rc = SR_ERR_OK ;
212159 int max_dep = 10 ;
213160
214- if (request_id == last_id && last_event == event )
161+ if (request_id == last_request && last_event == event )
215162 return SR_ERR_OK ;
216- last_id = request_id ;
163+ last_request = request_id ;
217164 last_event = event ;
218165
219166 if (event == SR_EV_CHANGE || event == SR_EV_DONE ) {
@@ -304,8 +251,11 @@ static int change_cb(sr_session_ctx_t *session, uint32_t sub_id, const char *mod
304251 return rc ;
305252}
306253
307- static int subscribe_module (char * model , struct confd * confd , int flags ) {
308- 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 );
254+ static inline int subscribe_module (char * model , struct confd * confd , int flags ) {
255+ return sr_module_change_subscribe (confd -> session , model , "//." , change_cb , confd ,
256+ CB_PRIO_PRIMARY , SR_SUBSCR_CHANGE_ALL_MODULES | SR_SUBSCR_DEFAULT | flags , & confd -> sub ) &&
257+ sr_module_change_subscribe (confd -> startup , model , "//." , core_startup_save , NULL ,
258+ CB_PRIO_PASSIVE , SR_SUBSCR_PASSIVE | SR_SUBSCR_CHANGE_ALL_MODULES , & confd -> sub );
309259}
310260
311261int sr_plugin_init_cb (sr_session_ctx_t * session , void * * priv )
0 commit comments