- Add remaining argument to state callback

This commit is contained in:
Olof hagsand 2021-09-06 12:31:34 +02:00
parent 6e316b519b
commit 60193cca0d
9 changed files with 76 additions and 83 deletions

View file

@ -258,7 +258,7 @@ get_client_statedata(clicon_handle h,
goto fail;
}
/* Use plugin state callbacks */
if ((ret = clixon_plugin_statedata_all(h, yspec, nsc, xpath, PAGING_NONE, 0, 0, xret)) < 0)
if ((ret = clixon_plugin_statedata_all(h, yspec, nsc, xpath, PAGING_NONE, 0, 0, NULL, xret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -470,13 +470,11 @@ get_list_pagination(clicon_handle h,
char *xpath2; /* With optional paging predicate */
int ret;
uint32_t iddb; /* DBs lock, if any */
enum paging_status pagingstatus;
paging_status_t pagingstatus;
cxobj *x1 = NULL;
#ifdef LIST_PAGINATION_REMAINING
cxobj *xcache = NULL;
uint32_t total = 0;
uint32_t remaining = 0;
#endif
/* Check if list/leaf-list */
if (yang_path_arg(yspec, xpath, &ylist) < 0)
@ -566,26 +564,6 @@ get_list_pagination(clicon_handle h,
cprintf(cbpath, "[position() < %u]", limit);
/* Append predicate to original xpath and replace it */
xpath2 = cbuf_get(cbpath);
#ifdef LIST_PAGINATION_REMAINING
/* Get total/remaining
* XXX: Works only for cache, and only if already populated
* XXX: Maybe together with get config / state data
*/
if (list_config){
if ((xcache = xmldb_cache_get(h, db)) != NULL){
if (xpath_count(xcache, nsc, xpath, &total) < 0)
goto done;
if (total >= (offset + limit))
remaining = total - (offset + limit);
}
}
else{
/* Remaining of state list. Two strategies:
* 1. New api where state callback is registered, lock, iterative, unlock
* 2. Read all here and count (fallback)
*/
}
#endif /* LIST_PAGINATION_REMAINING */
/* Read config */
switch (content){
case CONTENT_CONFIG: /* config data only */
@ -607,8 +585,19 @@ get_list_pagination(clicon_handle h,
goto done;
break;
}/* switch content */
if (!list_config){
/* Check if running locked (by this session) */
if (list_config){
/* Get total/remaining
* XXX: Works only for cache
*/
if ((xcache = xmldb_cache_get(h, db)) != NULL){
if (xpath_count(xcache, nsc, xpath, &total) < 0)
goto done;
if (total >= (offset + limit))
remaining = total - (offset + limit);
}
}
else {/* Check if running locked (by this session) */
if ((iddb = xmldb_islocked(h, "running")) != 0 &&
iddb == ce->ce_id)
pagingstatus = PAGING_LOCK;
@ -617,7 +606,7 @@ get_list_pagination(clicon_handle h,
/* Use plugin state callbacks */
if ((ret = clixon_plugin_statedata_all(h, yspec, nsc, xpath,
pagingstatus,
offset, limit, &xret)) < 0)
offset, limit, &remaining, &xret)) < 0)
goto done;
}
if (filter_xpath_again(h, yspec, xret, xpath, nsc, &x1) < 0)

View file

@ -242,6 +242,7 @@ clixon_plugin_daemon_all(clicon_handle h)
* @param[in] pagingstatus List pagination status
* @param[in] offset Offset, for list pagination
* @param[in] limit Limit, for list pagination
* @param[out] remaining Remaining elements (if limit is non-zero)
* @param[out] xp If retval=1, state tree created and returned: <config>...
* @retval -1 Fatal error
* @retval 0 Statedata callback failed. no XML tree returned
@ -252,9 +253,10 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
clicon_handle h,
cvec *nsc,
char *xpath,
enum paging_status pagingstatus,
paging_status_t pagingstatus,
uint32_t offset,
uint32_t limit,
uint32_t *remaining,
cxobj **xp)
{
int retval = -1;
@ -266,7 +268,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
if ((fn2 = clixon_plugin_api_get(cp)->ca_statedata2) != NULL){
if ((x = xml_new(DATASTORE_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn2(h, nsc, xpath, pagingstatus, offset, limit, x) < 0){
if (fn2(h, nsc, xpath, pagingstatus, offset, limit, remaining, x) < 0){
if (clicon_errno < 0)
clicon_log(LOG_WARNING, "%s: Internal error: State callback in plugin: %s returned -1 but did not make a clicon_err call",
__FUNCTION__, clixon_plugin_name_get(cp));
@ -303,6 +305,7 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
* @param[in] pagination List pagination
* @param[in] offset Offset, for list pagination
* @param[in] limit Limit, for list pagination
* @param[out] remaining Remaining elements (if limit is non-zero)
* @param[in,out] xret State XML tree is merged with existing tree.
* @retval -1 Error
* @retval 0 Statedata callback failed (xret set with netconf-error)
@ -310,14 +313,15 @@ clixon_plugin_statedata_one(clixon_plugin_t *cp,
* @note xret can be replaced in this function
*/
int
clixon_plugin_statedata_all(clicon_handle h,
yang_stmt *yspec,
cvec *nsc,
char *xpath,
enum paging_status pagingstatus,
uint32_t offset,
uint32_t limit,
cxobj **xret)
clixon_plugin_statedata_all(clicon_handle h,
yang_stmt *yspec,
cvec *nsc,
char *xpath,
paging_status_t pagingstatus,
uint32_t offset,
uint32_t limit,
uint32_t *remaining,
cxobj **xret)
{
int retval = -1;
int ret;
@ -329,7 +333,7 @@ clixon_plugin_statedata_all(clicon_handle h,
clicon_debug(1, "%s", __FUNCTION__);
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((ret = clixon_plugin_statedata_one(cp, h, nsc, xpath, pagingstatus,
offset, limit, &x)) < 0)
offset, limit, remaining, &x)) < 0)
goto done;
if (ret == 0){
if ((cberr = cbuf_new()) == NULL){

View file

@ -76,8 +76,9 @@ int clixon_plugin_pre_daemon_all(clicon_handle h);
int clixon_plugin_daemon_all(clicon_handle h);
int clixon_plugin_statedata_all(clicon_handle h, yang_stmt *yspec, cvec *nsc, char *xpath,
enum paging_status pagingstatus,
uint32_t offset, uint32_t limit, cxobj **xtop);
paging_status_t pagingstatus,
uint32_t offset, uint32_t limit, uint32_t *remaining,
cxobj **xtop);
int clixon_plugin_lockdb_all(clicon_handle h, char *db, int lock, int id);
transaction_data_t * transaction_new(void);