- 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:
parent
7ebb538ebf
commit
b88722fa25
29 changed files with 557 additions and 345 deletions
|
|
@ -41,7 +41,7 @@ CFLAGS = @CFLAGS@
|
|||
LINKAGE = @LINKAGE@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
ifeq ($(LINKAGE),dynamic)
|
||||
CPPFLAGS += -fPIC
|
||||
CPPFLAGS += -fPIC
|
||||
endif
|
||||
SH_SUFFIX = @SH_SUFFIX@
|
||||
INSTALLFLAGS = @INSTALLFLAGS@
|
||||
|
|
@ -66,10 +66,10 @@ CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@
|
|||
CLIXON_MINOR = @CLIXON_VERSION_MINOR@
|
||||
|
||||
# Use this clixon lib for linking
|
||||
ifeq ($(LINKAGE),dynamic)
|
||||
CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR)
|
||||
else
|
||||
ifeq ($(LINKAGE),static)
|
||||
CLIXON_LIB = libclixon.a
|
||||
else
|
||||
CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR)
|
||||
endif
|
||||
|
||||
# For dependency. A little strange that we rely on it being built in the src dir
|
||||
|
|
@ -78,7 +78,6 @@ LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB)
|
|||
|
||||
LIBS = -L$(top_srcdir)/lib/src $(top_srcdir)/lib/src/$(CLIXON_LIB) @LIBS@
|
||||
|
||||
|
||||
INCLUDES = -I. -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@
|
||||
|
||||
# Name of application
|
||||
|
|
@ -118,6 +117,7 @@ $(top_srcdir)/lib/src/$(CLIXON_LIB):
|
|||
|
||||
clean:
|
||||
rm -f $(LIBOBJ) $(APPOBJ) *.core $(APPL) $(MYLIB) $(MYLIBSO) $(MYLIBLINK) test test.c
|
||||
rm -f *.gcda *.gcno *.gcov # coverage
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile *~ .depend
|
||||
|
|
|
|||
|
|
@ -178,7 +178,11 @@ cli_terminate(clicon_handle h)
|
|||
xml_free(x);
|
||||
clicon_data_cvec_del(h, "cli-edit-cvv");;
|
||||
xpath_optimize_exit();
|
||||
cli_plugin_finish(h);
|
||||
/* Delete all plugins, and RPC callbacks */
|
||||
clixon_plugin_module_exit(h);
|
||||
/* Delete CLI syntax et al */
|
||||
cli_plugin_finish(h);
|
||||
|
||||
cli_history_save(h);
|
||||
cli_handle_exit(h);
|
||||
clixon_err_exit();
|
||||
|
|
@ -615,6 +619,10 @@ main(int argc,
|
|||
*/
|
||||
cv_exclude_keys(clicon_cli_varonly(h));
|
||||
|
||||
/* Initialize plugin module by creating a handle holding plugin and callback lists */
|
||||
if (clixon_plugin_module_init(h) < 0)
|
||||
goto done;
|
||||
|
||||
/* Load cli plugins before yangs are loaded (eg extension callbacks) */
|
||||
if ((dir = clicon_cli_dir(h)) != NULL &&
|
||||
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
|
|
@ -625,7 +633,6 @@ main(int argc,
|
|||
*/
|
||||
if (netconf_module_features(h) < 0)
|
||||
goto done;
|
||||
|
||||
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
|
||||
xml_nsctx_namespace_netconf_default(h);
|
||||
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ cli_load_syntax_file(clicon_handle h,
|
|||
char **vec = NULL;
|
||||
int i, nvec;
|
||||
char *plgnam;
|
||||
clixon_plugin *cp;
|
||||
clixon_plugin_t *cp;
|
||||
|
||||
if ((pt = pt_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "pt_new");
|
||||
|
|
@ -313,7 +313,7 @@ cli_load_syntax_file(clicon_handle h,
|
|||
|
||||
if (plgnam != NULL) { /* Find plugin for callback resolving */
|
||||
if ((cp = clixon_plugin_find(h, plgnam)) != NULL)
|
||||
handle = cp->cp_handle;
|
||||
handle = clixon_plugin_handle_get(cp);
|
||||
if (handle == NULL){
|
||||
clicon_err(OE_PLUGIN, 0, "CLICON_PLUGIN set to '%s' in %s but plugin %s.so not found in %s",
|
||||
plgnam, filename, plgnam,
|
||||
|
|
@ -393,7 +393,7 @@ cli_syntax_load(clicon_handle h)
|
|||
cli_syntaxmode_t *m;
|
||||
cligen_susp_cb_t *fns = NULL;
|
||||
cligen_interrupt_cb_t *fni = NULL;
|
||||
clixon_plugin *cp;
|
||||
clixon_plugin_t *cp;
|
||||
parse_tree *ptall = NULL; /* Universal CLIgen parse tree all modes */
|
||||
|
||||
/* Syntax already loaded. XXX should we re-load?? */
|
||||
|
|
@ -457,10 +457,10 @@ cli_syntax_load(clicon_handle h)
|
|||
/* Set susp and interrupt callbacks into CLIgen */
|
||||
cp = NULL;
|
||||
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
if (fns==NULL && (fns = cp->cp_api.ca_suspend) != NULL)
|
||||
if (fns==NULL && (fns = clixon_plugin_api_get(cp)->ca_suspend) != NULL)
|
||||
if (cli_susp_hook(h, fns) < 0)
|
||||
goto done;
|
||||
if (fni==NULL && (fni = cp->cp_api.ca_interrupt) != NULL)
|
||||
if (fni==NULL && (fni = clixon_plugin_api_get(cp)->ca_interrupt) != NULL)
|
||||
if (cli_interrupt_hook(h, fni) < 0)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -469,7 +469,6 @@ cli_syntax_load(clicon_handle h)
|
|||
retval = 0;
|
||||
done:
|
||||
if (retval != 0) {
|
||||
clixon_plugin_exit_all(h);
|
||||
cli_syntax_unload(h);
|
||||
cli_syntax_set(h, NULL);
|
||||
}
|
||||
|
|
@ -485,8 +484,6 @@ done:
|
|||
int
|
||||
cli_plugin_finish(clicon_handle h)
|
||||
{
|
||||
/* Remove all CLI plugins */
|
||||
clixon_plugin_exit_all(h);
|
||||
/* Remove all cligen syntax modes */
|
||||
cli_syntax_unload(h);
|
||||
cli_syntax_set(h, NULL);
|
||||
|
|
@ -744,7 +741,7 @@ clicon_cliread(clicon_handle h,
|
|||
cli_syntaxmode_t *mode;
|
||||
cli_syntax_t *stx;
|
||||
cli_prompthook_t *fn;
|
||||
clixon_plugin *cp;
|
||||
clixon_plugin_t *cp;
|
||||
char *promptstr;
|
||||
|
||||
stx = cli_syntax(h);
|
||||
|
|
@ -752,7 +749,7 @@ clicon_cliread(clicon_handle h,
|
|||
/* Get prompt from plugin callback? */
|
||||
cp = NULL;
|
||||
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
|
||||
if ((fn = cp->cp_api.ca_prompt) == NULL)
|
||||
if ((fn = clixon_plugin_api_get(cp)->ca_prompt) == NULL)
|
||||
continue;
|
||||
pfmt = fn(h, mode->csm_name);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue