Skip to content

Commit

Permalink
xml changelog next iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Mar 26, 2019
1 parent 1991c38 commit 8624be0
Show file tree
Hide file tree
Showing 9 changed files with 512 additions and 333 deletions.
365 changes: 174 additions & 191 deletions apps/backend/backend_commit.c

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions example/example_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ example_statedata(clicon_handle h,
/*! Registered Upgrade callback function
* @param[in] h Clicon handle
* @param[in] xn XML tree to be updated
* @param[in] modname Name of module
* @param[in] modns Namespace of module (for info)
* @param[in] ns Namespace of module (for info)
* @param[in] from From revision on the form YYYYMMDD
* @param[in] to To revision on the form YYYYMMDD (0 not in system)
* @param[in] arg User argument given at rpc_callback_register()
Expand Down Expand Up @@ -466,11 +465,9 @@ clixon_plugin_init(clicon_handle h)
) < 0)
goto done;
/* General purpose upgrade callback */
if (upgrade_callback_register(h, 0?upgrade_all:xml_changelog_upgrade,
NULL, 0, 0, NULL) < 0)
if (upgrade_callback_register(h, xml_changelog_upgrade, NULL, 0, 0, NULL) < 0)
goto done;


/* Return plugin API */
return &api;
done:
Expand Down
7 changes: 6 additions & 1 deletion lib/clixon/clixon_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ struct clixon_plugin_api{
#define ca_trans_end u.cau_backend.cb_trans_end
#define ca_trans_abort u.cau_backend.cb_trans_abort

/*
* Macros
*/
#define upgrade_callback_register(h, cb, namespace, from, to, arg) upgrade_callback_reg_fn((h), (cb), #cb, (namespace), (from), (to), (arg))

typedef struct clixon_plugin_api clixon_plugin_api;

/* Internal plugin structure with dlopen() handle and plugin_api
Expand Down Expand Up @@ -244,7 +249,7 @@ int rpc_callback_delete_all(void);
int rpc_callback_call(clicon_handle h, cxobj *xe, cbuf *cbret, void *arg);

/* upgrade callback API */
int upgrade_callback_register(clicon_handle h, clicon_upgrade_cb cb, char *namespace, uint32_t from, uint32_t to, void *arg);
int upgrade_callback_reg_fn(clicon_handle h, clicon_upgrade_cb cb, const char *strfn, char *namespace, uint32_t from, uint32_t to, void *arg);
int upgrade_callback_delete_all(void);
int upgrade_callback_call(clicon_handle h, cxobj *xt, char *namespace, uint32_t from, uint32_t to, cbuf *cbret);

Expand Down
26 changes: 18 additions & 8 deletions lib/src/clixon_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ rpc_callback_call(clicon_handle h,
typedef struct {
qelem_t uc_qelem; /* List header */
clicon_upgrade_cb uc_callback; /* RPC Callback */
const char *uc_fnstr; /* Stringified fn name for debug */
void *uc_arg; /* Application specific argument to cb */
char *uc_namespace; /* Module namespace */
uint32_t uc_rev; /* Module revision (to) in YYYYMMDD format or 0 */
Expand All @@ -555,6 +556,7 @@ static upgrade_callback_t *upgrade_cb_list = NULL;
*
* @param[in] h clicon handle
* @param[in] cb Callback called
* @param[in] fnstr Stringified function for debug
* @param[in] arg Domain-specific argument to send to callback
* @param[in] namespace Module namespace (if NULL all modules)
* @param[in] rev To module revision (0 means module obsoleted)
Expand All @@ -564,12 +566,13 @@ static upgrade_callback_t *upgrade_cb_list = NULL;
* @see upgrade_callback_call which makes the actual callback
*/
int
upgrade_callback_register(clicon_handle h,
clicon_upgrade_cb cb,
char *namespace,
uint32_t revision,
uint32_t from,
void *arg)
upgrade_callback_reg_fn(clicon_handle h,
clicon_upgrade_cb cb,
const char *fnstr,
char *namespace,
uint32_t revision,
uint32_t from,
void *arg)
{
upgrade_callback_t *uc;

Expand All @@ -579,6 +582,7 @@ upgrade_callback_register(clicon_handle h,
}
memset(uc, 0, sizeof(*uc));
uc->uc_callback = cb;
uc->uc_fnstr = fnstr;
uc->uc_arg = arg;
if (namespace)
uc->uc_namespace = strdup(namespace);
Expand Down Expand Up @@ -623,7 +627,7 @@ upgrade_callback_delete_all(void)
* @retval -1 Error
* @retval 0 Invalid - cbret contains reason as netconf
* @retval 1 OK
* @see upgrade_callback_register which registers the callbacks
* @see upgrade_callback_reg_fn which registers the callbacks
*/
int
upgrade_callback_call(clicon_handle h,
Expand Down Expand Up @@ -657,8 +661,14 @@ upgrade_callback_call(clicon_handle h,
clicon_debug(1, "%s Error in: %s", __FUNCTION__, uc->uc_namespace);
goto done;
}
if (ret == 0)
if (ret == 0){
if (cbuf_len(cbret)==0){
clicon_err(OE_CFG, 0, "Validation fail %s(%s): cbret not set",
uc->uc_fnstr, namespace);
goto done;
}
goto fail;
}
nr++;
}
uc = NEXTQ(upgrade_callback_t *, uc);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/clixon_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ xml_addsub(cxobj *xp,
* @param[in] tag Name of new xml child
* @retval xc Return the new child (xc)
* @see xml_addsub
* The name of the function is somewhat misleading
* The name of the function is somewhat misleading, should be called "wrap"
*/
cxobj *
xml_insert(cxobj *xp,
Expand Down
Loading

0 comments on commit 8624be0

Please sign in to comment.