- Restructure plugin module using a "module struct" rather than global variables.

This include plugin module init and exit functions
  New type: clixon_plugin_t exposed via public API while struct clixon_plugin is private
- Makefile changes for static linkage using "LINKAGE=static"
- Moved nacm external init to later stage in backend_main
This commit is contained in:
Olof hagsand 2021-04-19 09:39:07 +02:00
parent 7ebb538ebf
commit b88722fa25
29 changed files with 557 additions and 345 deletions

View file

@ -78,10 +78,9 @@ LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB)
LIBS = -L$(top_srcdir)/lib/src $(top_srcdir)/lib/src/$(CLIXON_LIB) @LIBS@
CPPFLAGS = @CPPFLAGS@
ifeq ($(LINKAGE),dynamic)
CPPFLAGS = @CPPFLAGS@ -fPIC
else
CPPFLAGS = @CPPFLAGS@
CPPFLAGS += -fPIC
endif
INCLUDES = -I. -I$(top_srcdir)/lib/src -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
@ -139,6 +138,7 @@ $(top_srcdir)/lib/src/$(CLIXON_LIB):
clean:
rm -f $(LIBOBJ) *.core $(APPL) $(APPOBJ) *.o $(MYLIB) $(MYLIBSO) $(MYLIBLINK) # extra .o to clean residue if with_restconf changes
rm -f *.gcda *.gcno *.gcov # coverage
distclean: clean
rm -f Makefile *~ .depend
@ -201,4 +201,3 @@ depend:
$(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(APPFCGI) $(APPSRC) > .depend
#include .depend

View file

@ -247,8 +247,9 @@ restconf_terminate(clicon_handle h)
clicon_debug(1, "%s", __FUNCTION__);
if ((fs = clicon_socket_get(h)) != -1)
close(fs);
clixon_plugin_exit_all(h);
rpc_callback_delete_all(h);
/* Delete all plugins, and RPC callbacks */
clixon_plugin_module_exit(h);
clicon_rpc_close_session(h);
if ((yspec = clicon_dbspec_yang(h)) != NULL)
ys_free(yspec);

View file

@ -211,7 +211,7 @@ main(int argc,
char *stream_path;
int finish = 0;
char *str;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
uint32_t id = 0;
cvec *nsctx_global = NULL; /* Global namespace context */
size_t cligen_buflen;
@ -362,6 +362,10 @@ main(int argc,
/* Treat unknown XML as anydata */
if (clicon_option_bool(h, "CLICON_YANG_UNKNOWN_ANYDATA") == 1)
xml_bind_yang_unknown_anydata(1);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Load restconf plugins before yangs are loaded (eg extension callbacks) */
if ((dir = clicon_restconf_dir(h)) != NULL)
@ -372,7 +376,7 @@ main(int argc,
*/
if (clixon_pseudo_plugin(h, "pseudo restconf", &cp) < 0)
goto done;
cp->cp_api.ca_extension = restconf_main_extension_cb;
clixon_plugin_api_get(cp)->ca_extension = restconf_main_extension_cb;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
@ -427,6 +431,9 @@ main(int argc,
if (dbg)
clicon_option_dump(h, dbg);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Call start function in all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
goto done;

View file

@ -1544,7 +1544,7 @@ restconf_clixon_init(clicon_handle h,
size_t cligen_buflen;
size_t cligen_bufthreshold;
yang_stmt *yspec = NULL;
clixon_plugin *cp = NULL;
clixon_plugin_t *cp = NULL;
char *str;
cvec *nsctx_global = NULL; /* Global namespace context */
cxobj *xrestconf;
@ -1581,7 +1581,7 @@ restconf_clixon_init(clicon_handle h,
*/
if (clixon_pseudo_plugin(h, "pseudo restconf", &cp) < 0)
goto done;
cp->cp_api.ca_extension = restconf_main_extension_cb;
clixon_plugin_api_get(cp)->ca_extension = restconf_main_extension_cb;
/* Load Yang modules
* 1. Load a yang module as a specific absolute filename */
@ -1614,7 +1614,6 @@ restconf_clixon_init(clicon_handle h,
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)
goto done;
/* Add system modules */
if (clicon_option_bool(h, "CLICON_STREAM_DISCOVERY_RFC8040") &&
yang_spec_parse_module(h, "ietf-restconf-monitoring", NULL, yspec)< 0)
@ -1847,6 +1846,9 @@ main(int argc,
if (dbg)
clicon_option_dump(h, dbg);
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;
/* Call start function in all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
goto done;