Plugin RPC callback interface have been unified between backend, netconf and restconf.
* Backend RPC register callback function (Netconf RPC or restconf operation POST) has been changed from: `backend_rpc_cb_register()` to `rpc_callback_register()`
* Backend RPC callback signature has been changed from: `int cb(clicon_handle h, cxobj *xe, struct client_entry *ce, cbuf *cbret, void *arg)` has been changed to : `int cb(clicon_handle h, cxobj *xe, struct client_entry *ce, cbuf *cbret, void *arg)`
* Frontend netconf and restconf plugins can register callbacks as well with same API as backends.
This commit is contained in:
parent
7a4371e76f
commit
d541c49c6f
20 changed files with 323 additions and 229 deletions
|
|
@ -25,4 +25,20 @@ module example {
|
|||
type string;
|
||||
}
|
||||
}
|
||||
rpc client-rpc {
|
||||
description "Example local client-side RPC that is processed by the
|
||||
the netconf/restconf and not sent to the backend.
|
||||
This is a clixon implementation detail: some rpc:s
|
||||
are better processed by the client for API or perf reasons";
|
||||
input {
|
||||
leaf request {
|
||||
type string;
|
||||
}
|
||||
}
|
||||
output {
|
||||
leaf result{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,9 +125,9 @@ notification_timer_setup(clicon_handle h)
|
|||
static int
|
||||
fib_route(clicon_handle h, /* Clicon handle */
|
||||
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><route>"
|
||||
"<address-family>ipv4</address-family>"
|
||||
|
|
@ -139,10 +139,10 @@ fib_route(clicon_handle h, /* Clicon handle */
|
|||
/*! Smallest possible RPC declaration for test */
|
||||
static int
|
||||
empty(clicon_handle h, /* Clicon handle */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
struct client_entry *ce, /* Client session */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg) /* Argument given at register */
|
||||
cxobj *xe, /* Request: <rpc><xn></rpc> */
|
||||
cbuf *cbret, /* Reply eg <rpc-reply>... */
|
||||
void *arg, /* client_entry */
|
||||
void *regarg) /* Argument given at register */
|
||||
{
|
||||
cprintf(cbret, "<rpc-reply/>");
|
||||
return 0;
|
||||
|
|
@ -152,9 +152,9 @@ empty(clicon_handle h, /* Clicon handle */
|
|||
static int
|
||||
route_count(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,
|
||||
void *regarg) /* Argument given at register */
|
||||
{
|
||||
cprintf(cbret, "<rpc-reply><ok/></rpc-reply>");
|
||||
return 0;
|
||||
|
|
@ -278,20 +278,20 @@ clixon_plugin_init(clicon_handle h)
|
|||
if (notification_timer_setup(h) < 0)
|
||||
goto done;
|
||||
/* Register callback for routing rpc calls */
|
||||
if (backend_rpc_cb_register(h, fib_route,
|
||||
NULL,
|
||||
"fib-route"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
if (rpc_callback_register(h, fib_route,
|
||||
NULL,
|
||||
"fib-route"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
if (backend_rpc_cb_register(h, route_count,
|
||||
NULL,
|
||||
"route-count"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
if (rpc_callback_register(h, route_count,
|
||||
NULL,
|
||||
"route-count"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
if (backend_rpc_cb_register(h, empty,
|
||||
NULL,
|
||||
"empty"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
if (rpc_callback_register(h, empty,
|
||||
NULL,
|
||||
"empty"/* Xml tag when callback is made */
|
||||
) < 0)
|
||||
goto done;
|
||||
return &api;
|
||||
done:
|
||||
|
|
|
|||
|
|
@ -62,6 +62,19 @@ plugin_exit(clicon_handle h)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Local example netconf rpc callback
|
||||
*/
|
||||
int netconf_client_rpc(clicon_handle h,
|
||||
cxobj *xn,
|
||||
cbuf *cbret,
|
||||
void *arg,
|
||||
void *regarg)
|
||||
{
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
cprintf(cbret, "<rpc-reply><result>ok</result></rpc-reply>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static struct clixon_plugin_api api = {
|
||||
|
|
@ -81,6 +94,9 @@ clixon_plugin_api *
|
|||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
/* Register local netconf rpc client (note not backend rpc client) */
|
||||
if (rpc_callback_register(h, netconf_client_rpc, NULL, "client-rpc") < 0)
|
||||
return NULL;
|
||||
return &api;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -266,6 +266,21 @@ plugin_credentials(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
|
||||
/*! Local example restconf rpc callback
|
||||
*/
|
||||
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__);
|
||||
cprintf(cbret, "<rpc-reply><result>ok</result></rpc-reply>");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
clixon_plugin_api * clixon_plugin_init(clicon_handle h);
|
||||
|
||||
static clixon_plugin_api api = {
|
||||
|
|
@ -285,5 +300,8 @@ clixon_plugin_api *
|
|||
clixon_plugin_init(clicon_handle h)
|
||||
{
|
||||
clicon_debug(1, "%s restconf", __FUNCTION__);
|
||||
/* Register local netconf rpc client (note not backend rpc client) */
|
||||
if (rpc_callback_register(h, restconf_client_rpc, NULL, "client-rpc") < 0)
|
||||
return NULL;
|
||||
return &api;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue