*/
static bool transaction_in_progress;
+static int nb_callback_pre_validate(const struct nb_node *nb_node,
+ const struct lyd_node *dnode);
static int nb_callback_configuration(const enum nb_event event,
struct nb_config_change *change);
-static void nb_log_callback(const enum nb_event event,
- enum nb_operation operation, const char *xpath,
- const char *value);
static struct nb_transaction *nb_transaction_new(struct nb_config *config,
struct nb_config_cbs *changes,
enum nb_client client,
if (!nb_node->cbs.pre_validate)
goto next;
- if (DEBUG_MODE_CHECK(&nb_dbg_cbs_config,
- DEBUG_MODE_ALL)) {
- char xpath[XPATH_MAXLEN];
-
- yang_dnode_get_path(child, xpath,
- sizeof(xpath));
- nb_log_callback(NB_EV_VALIDATE,
- NB_OP_PRE_VALIDATE, xpath,
- NULL);
- }
-
- ret = (*nb_node->cbs.pre_validate)(child);
+ ret = nb_callback_pre_validate(nb_node, child);
if (ret != NB_OK)
return NB_ERR_VALIDATION;
return ret;
}
-static void nb_log_callback(const enum nb_event event,
- enum nb_operation operation, const char *xpath,
- const char *value)
+static void nb_log_config_callback(const enum nb_event event,
+ enum nb_operation operation,
+ const struct lyd_node *dnode)
{
+ const char *value;
+ char xpath[XPATH_MAXLEN];
+
+ if (!DEBUG_MODE_CHECK(&nb_dbg_cbs_config, DEBUG_MODE_ALL))
+ return;
+
+ yang_dnode_get_path(dnode, xpath, sizeof(xpath));
+ if (yang_snode_is_typeless_data(dnode->schema))
+ value = "(none)";
+ else
+ value = yang_dnode_get_string(dnode, NULL);
+
zlog_debug(
"northbound callback: event [%s] op [%s] xpath [%s] value [%s]",
nb_event_name(event), nb_operation_name(operation), xpath,
- value ? value : "(NULL)");
+ value);
+}
+
+static int nb_callback_create(const struct nb_node *nb_node,
+ enum nb_event event, const struct lyd_node *dnode,
+ union nb_resource *resource)
+{
+ nb_log_config_callback(event, NB_OP_CREATE, dnode);
+
+ return nb_node->cbs.create(event, dnode, resource);
+}
+
+static int nb_callback_modify(const struct nb_node *nb_node,
+ enum nb_event event, const struct lyd_node *dnode,
+ union nb_resource *resource)
+{
+ nb_log_config_callback(event, NB_OP_MODIFY, dnode);
+
+ return nb_node->cbs.modify(event, dnode, resource);
+}
+
+static int nb_callback_destroy(const struct nb_node *nb_node,
+ enum nb_event event,
+ const struct lyd_node *dnode)
+{
+ nb_log_config_callback(event, NB_OP_DESTROY, dnode);
+
+ return nb_node->cbs.destroy(event, dnode);
+}
+
+static int nb_callback_move(const struct nb_node *nb_node, enum nb_event event,
+ const struct lyd_node *dnode)
+{
+ nb_log_config_callback(event, NB_OP_MOVE, dnode);
+
+ return nb_node->cbs.move(event, dnode);
+}
+
+static int nb_callback_pre_validate(const struct nb_node *nb_node,
+ const struct lyd_node *dnode)
+{
+ nb_log_config_callback(NB_EV_VALIDATE, NB_OP_PRE_VALIDATE, dnode);
+
+ return nb_node->cbs.pre_validate(dnode);
+}
+
+static void nb_callback_apply_finish(const struct nb_node *nb_node,
+ const struct lyd_node *dnode)
+{
+ nb_log_config_callback(NB_EV_APPLY, NB_OP_APPLY_FINISH, dnode);
+
+ nb_node->cbs.apply_finish(dnode);
+}
+
+struct yang_data *nb_callback_get_elem(const struct nb_node *nb_node,
+ const char *xpath,
+ const void *list_entry)
+{
+ DEBUGD(&nb_dbg_cbs_state,
+ "northbound callback (get_elem): xpath [%s] list_entry [%p]",
+ xpath, list_entry);
+
+ return nb_node->cbs.get_elem(xpath, list_entry);
+}
+
+const void *nb_callback_get_next(const struct nb_node *nb_node,
+ const void *parent_list_entry,
+ const void *list_entry)
+{
+ DEBUGD(&nb_dbg_cbs_state,
+ "northbound callback (get_next): node [%s] parent_list_entry [%p] list_entry [%p]",
+ nb_node->xpath, parent_list_entry, list_entry);
+
+ return nb_node->cbs.get_next(parent_list_entry, list_entry);
+}
+
+int nb_callback_get_keys(const struct nb_node *nb_node, const void *list_entry,
+ struct yang_list_keys *keys)
+{
+ DEBUGD(&nb_dbg_cbs_state,
+ "northbound callback (get_keys): node [%s] list_entry [%p]",
+ nb_node->xpath, list_entry);
+
+ return nb_node->cbs.get_keys(list_entry, keys);
+}
+
+const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
+ const void *parent_list_entry,
+ const struct yang_list_keys *keys)
+{
+ DEBUGD(&nb_dbg_cbs_state,
+ "northbound callback (lookup_entry): node [%s] parent_list_entry [%p]",
+ nb_node->xpath, parent_list_entry);
+
+ return nb_node->cbs.lookup_entry(parent_list_entry, keys);
+}
+
+int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
+ const struct list *input, struct list *output)
+{
+ DEBUGD(&nb_dbg_cbs_rpc, "northbound RPC: %s", xpath);
+
+ return nb_node->cbs.rpc(xpath, input, output);
}
/*
union nb_resource *resource;
int ret = NB_ERR;
- if (DEBUG_MODE_CHECK(&nb_dbg_cbs_config, DEBUG_MODE_ALL)) {
- const char *value = "(none)";
-
- if (dnode && !yang_snode_is_typeless_data(dnode->schema))
- value = yang_dnode_get_string(dnode, NULL);
-
- yang_dnode_get_path(dnode, xpath, sizeof(xpath));
- nb_log_callback(event, operation, xpath, value);
- }
if (event == NB_EV_VALIDATE)
resource = NULL;
switch (operation) {
case NB_OP_CREATE:
- ret = (*nb_node->cbs.create)(event, dnode, resource);
+ ret = nb_callback_create(nb_node, event, dnode, resource);
break;
case NB_OP_MODIFY:
- ret = (*nb_node->cbs.modify)(event, dnode, resource);
+ ret = nb_callback_modify(nb_node, event, dnode, resource);
break;
case NB_OP_DESTROY:
- ret = (*nb_node->cbs.destroy)(event, dnode);
+ ret = nb_callback_destroy(nb_node, event, dnode);
break;
case NB_OP_MOVE:
- ret = (*nb_node->cbs.move)(event, dnode);
+ ret = nb_callback_move(nb_node, event, dnode);
break;
default:
yang_dnode_get_path(dnode, xpath, sizeof(xpath));
return ret;
}
-struct yang_data *nb_callback_get_elem(const struct nb_node *nb_node,
- const char *xpath,
- const void *list_entry)
-{
- DEBUGD(&nb_dbg_cbs_state,
- "northbound callback (get_elem): xpath [%s] list_entry [%p]",
- xpath, list_entry);
-
- return nb_node->cbs.get_elem(xpath, list_entry);
-}
-
-const void *nb_callback_get_next(const struct nb_node *nb_node,
- const void *parent_list_entry,
- const void *list_entry)
-{
- DEBUGD(&nb_dbg_cbs_state,
- "northbound callback (get_next): node [%s] parent_list_entry [%p] list_entry [%p]",
- nb_node->xpath, parent_list_entry, list_entry);
-
- return nb_node->cbs.get_next(parent_list_entry, list_entry);
-}
-
-int nb_callback_get_keys(const struct nb_node *nb_node, const void *list_entry,
- struct yang_list_keys *keys)
-{
- DEBUGD(&nb_dbg_cbs_state,
- "northbound callback (get_keys): node [%s] list_entry [%p]",
- nb_node->xpath, list_entry);
-
- return nb_node->cbs.get_keys(list_entry, keys);
-}
-
-const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
- const void *parent_list_entry,
- const struct yang_list_keys *keys)
-{
- DEBUGD(&nb_dbg_cbs_state,
- "northbound callback (lookup_entry): node [%s] parent_list_entry [%p]",
- nb_node->xpath, parent_list_entry);
-
- return nb_node->cbs.lookup_entry(parent_list_entry, keys);
-}
-
-int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
- const struct list *input, struct list *output)
-{
- DEBUGD(&nb_dbg_cbs_rpc, "northbound RPC: %s", xpath);
-
- return nb_node->cbs.rpc(xpath, input, output);
-}
-
static struct nb_transaction *
nb_transaction_new(struct nb_config *config, struct nb_config_cbs *changes,
enum nb_client client, const void *user, const char *comment)
{
struct nb_config_cbs cbs;
struct nb_config_cb *cb;
- char xpath[XPATH_MAXLEN];
/* Initialize tree of 'apply_finish' callbacks. */
RB_INIT(nb_config_cbs, &cbs);
* be called though).
*/
if (change->cb.operation == NB_OP_DESTROY) {
+ char xpath[XPATH_MAXLEN];
+
dnode = dnode->parent;
if (!dnode)
break;
}
/* Call the 'apply_finish' callbacks, sorted by their priorities. */
- RB_FOREACH (cb, nb_config_cbs, &cbs) {
- if (DEBUG_MODE_CHECK(&nb_dbg_cbs_config, DEBUG_MODE_ALL)) {
- yang_dnode_get_path(cb->dnode, xpath, sizeof(xpath));
- nb_log_callback(NB_EV_APPLY, NB_OP_APPLY_FINISH, xpath,
- NULL);
- }
-
- (*cb->nb_node->cbs.apply_finish)(cb->dnode);
- }
+ RB_FOREACH (cb, nb_config_cbs, &cbs)
+ nb_callback_apply_finish(cb->nb_node, cb->dnode);
/* Release memory. */
while (!RB_EMPTY(nb_config_cbs, &cbs)) {