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

@ -89,6 +89,43 @@ Routing notification
...
```
## Initializing a plugin
The example includes a restonf, netconf, CLI and two backend plugins.
Each plugin is initiated with an API struct followed by a plugin init function.
The content of the API struct is different depending on what kind of plugin it is. Some fields are
meaningful only for some plugins.
The plugin init function may also include registering RPC functions.
```
static clixon_plugin_api api = {
"example", /* name */
clixon_plugin_init,
plugin_start,
plugin_exit,
NULL, /* cli prompt N/A for backend */
NULL, /* cli suspend N/A for backend */
NULL, /* cli interrupt N/A for backend */
NULL, /* auth N/A for backend */
plugin_reset,
plugin_statedata,
transaction_begin,
transaction_validate,
transaction_complete,
transaction_commit,
transaction_end,
transaction_abort
};
clixon_plugin_api *
clixon_plugin_init(clicon_handle h)
{
/* Optional callback registration for RPC calls */
rpc_callback_register(h, fib_route, NULL, "fib-route");
/* Return plugin API */
return &api; /* Return NULL on error */
}
```
## Operation data
Clixon implements Yang RPC operations by an extension mechanism. The
@ -119,18 +156,18 @@ In the backend, a callback is registered (fib_route()) which handles the RPC.
static int
fib_route(clicon_handle h,
cxobj *xe, /* Request: <rpc><xn></rpc> */
struct client_entry *ce, /* Client session */
cbuf *cbret, /* Reply eg <rpc-reply>... */
void *arg) /* Argument given at register */
void *arg, /* Client session */
void *regarg) /* Argument given at register */
{
cprintf(cbret, "<rpc-reply><ok/></rpc-reply>");
return 0;
}
int
plugin_init(clicon_handle h)
clixon_plugin_init(clicon_handle h)
{
...
backend_rpc_cb_register(h, fib_route, NULL, "fib-route");
rpc_callback_register(h, fib_route, NULL, "fib-route");
...
}
```

View file

@ -256,6 +256,9 @@ static clixon_plugin_api api = {
plugin_start, /* start */
NULL, /* exit */
NULL, /* auth */
NULL, /* cli prompt */
NULL, /* cli suspend */
NULL, /* cli interrupt */
plugin_reset, /* reset */
plugin_statedata, /* statedata */
NULL, /* trans begin */
@ -293,6 +296,7 @@ clixon_plugin_init(clicon_handle h)
"empty"/* Xml tag when callback is made */
) < 0)
goto done;
/* Return plugin API */
return &api;
done:
return NULL;

View file

@ -52,19 +52,6 @@
#include <clixon/clixon.h>
#include <clixon/clixon_cli.h>
/*
* Plugin initialization
*/
int
plugin_init(clicon_handle h)
{
struct timeval tv;
gettimeofday(&tv, NULL);
srandom(tv.tv_usec);
return 0;
}
/*! Example cli function */
int
@ -125,3 +112,29 @@ fib_route_rpc(clicon_handle h,
return retval;
}
static clixon_plugin_api api = {
"example", /* name */
clixon_plugin_init, /* init */
NULL, /* start */
NULL, /* exit */
NULL, /* auth */
NULL, /* cli_prompthook_t */
NULL, /* cligen_susp_cb_t */
NULL, /* cligen_interrupt_cb_t */
};
/*! CLI 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)
{
struct timeval tv;
gettimeofday(&tv, NULL);
srandom(tv.tv_usec);
return &api;
}

View file

@ -268,11 +268,12 @@ plugin_credentials(clicon_handle h,
/*! Local example restconf rpc callback
*/
int restconf_client_rpc(clicon_handle h,
cxobj *xn,
cbuf *cbret,
void *arg,
void *regarg)
int
restconf_client_rpc(clicon_handle h,
cxobj *xn,
cbuf *cbret,
void *arg,
void *regarg)
{
// FCGX_Request *r = (FCGX_Request *)arg;
clicon_debug(1, "%s", __FUNCTION__);