CLI plugin API restructuring completed. Now all plugin APIs have the generic form

documented in README and FAQ.
This commit is contained in:
Olof hagsand 2018-04-08 11:32:43 +02:00
parent afb6aa31db
commit 2e00411621
19 changed files with 317 additions and 551 deletions

View file

@ -38,10 +38,16 @@
#ifndef _CLIXON_PLUGIN_H_
#define _CLIXON_PLUGIN_H_
/*
* Constants
*/
/* Hardcoded plugin symbol. Must exist in all plugins to kickstart */
#define CLIXON_PLUGIN_INIT "clixon_plugin_init"
/*
* Types
*/
/* The dynamicically loadable plugin object handle */
/* Dynamicically loadable plugin object handle. @see return value of dlopen(3) */
typedef void *plghndl_t;
/* Registered RPC callback function */
@ -62,22 +68,13 @@ typedef int (*clicon_rpc_cb)(
* Backend see config_plugin.c
*/
/*! Called when plugin loaded. Only mandadory callback. All others optional
* @see plginit_t
*/
#define PLUGIN_INIT "plugin_init"
typedef void * (plginit_t)(clicon_handle); /* Clixon plugin Init */
/* Called when backend started with cmd-line arguments from daemon call.
* @see plgstart_t
*/
#define PLUGIN_START "plugin_start"
typedef int (plgstart_t)(clicon_handle, int, char **); /* Plugin start */
/* Called just before plugin unloaded.
*/
#define PLUGIN_EXIT "plugin_exit"
typedef int (plgexit_t)(clicon_handle); /* Plugin exit */
/*! Called by restconf to check credentials and return username
@ -99,6 +96,14 @@ typedef void *transaction_data;
/* Transaction callbacks */
typedef int (trans_cb_t)(clicon_handle h, transaction_data td);
/* Hook to override default prompt with explicit function
* Format prompt before each getline
* @param[in] h Clicon handle
* @param[in] mode Cligen syntax mode
* @retval prompt Prompt to prepend all CLigen command lines
*/
typedef char *(cli_prompthook_t)(clicon_handle, char *mode);
/* plugin init struct for the api
* Note: Implicit init function
*/
@ -106,14 +111,20 @@ struct clixon_plugin_api;
typedef struct clixon_plugin_api* (plginit2_t)(clicon_handle); /* Clixon plugin Init */
struct clixon_plugin_api{
/*--- Common fields. ---*/
char ca_name[PATH_MAX]; /* Name of plugin (given by plugin) */
plginit2_t *ca_init; /* Clixon plugin Init (implicit) */
plgstart_t *ca_start; /* Plugin start */
plgexit_t *ca_exit; /* Plugin exit */
plgauth_t *ca_auth; /* Auth credentials */
/*--Above here common fields w clixon_backend_api ----------*/
plgreset_t *ca_reset; /* Reset system status (backend only) */
/*--- CLI plugin-only ---*/
cli_prompthook_t *ca_prompt; /* Prompt hook */
cligen_susp_cb_t *ca_suspend; /* Ctrl-Z hook, see cligen getline */
cligen_interrupt_cb_t *ca_interrupt; /* Ctrl-C, see cligen getline */
/*--- Backend plugin only ---*/
plgreset_t *ca_reset; /* Reset system status (backend only) */
plgstatedata_t *ca_statedata; /* Get state data from plugin (backend only) */
trans_cb_t *ca_trans_begin; /* Transaction start */
trans_cb_t *ca_trans_validate; /* Transaction validation */
@ -124,46 +135,34 @@ struct clixon_plugin_api{
};
typedef struct clixon_plugin_api clixon_plugin_api;
/*! Called when plugin loaded. Only mandadory callback. All others optional
* @see plginit_t
*/
/* Internal plugin structure with dlopen() handle and plugin_api
*/
struct clixon_plugin{
char cp_name[PATH_MAX]; /* Plugin filename. Note api ca_name is given by plugin itself */
plghndl_t cp_handle; /* Handle to plugin using dlopen(3) */
struct clixon_plugin_api cp_api;
char cp_name[PATH_MAX]; /* Plugin filename. Note api ca_name is given by plugin itself */
plghndl_t cp_handle; /* Handle to plugin using dlopen(3) */
clixon_plugin_api cp_api;
};
typedef struct clixon_plugin clixon_plugin;
/*
* Pseudo-Prototypes
* User-defineed plugins, not in library code
*/
#define CLIXON_PLUGIN_INIT "clixon_plugin_init" /* Nextgen */
/*! Plugin initialization
* @param[in] h Clixon handle
* @retval NULL Error with clicon_err set
* @retval api Pointer to API struct
*/
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
/*
* Prototypes
*/
clixon_plugin *plugin_each(clixon_plugin *cpprev);
clixon_plugin *plugin_each_revert(clixon_plugin *cpprev, int nr);
/*! Plugin initialization function. Must appear in all plugins
* @param[in] h Clixon handle
* @retval api Pointer to API struct
* @see CLIXON_PLUGIN_INIT default symbol
*/
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
clixon_plugin *plugin_each(clicon_handle h, clixon_plugin *cpprev);
clixon_plugin *plugin_each_revert(clicon_handle h, clixon_plugin *cpprev, int nr);
clixon_plugin *plugin_find(clicon_handle h, char *name);
int clixon_plugins_load(clicon_handle h, char *function, char *dir);
/* obsolete */
plghndl_t plugin_load (clicon_handle h, char *file, int dlflags);
/* obsolete */
int plugin_unload(clicon_handle h, plghndl_t *handle);
int clixon_plugin_start(clicon_handle h, int argc, char **argv);
int clixon_plugin_exit(clicon_handle h);