sysrepo  3.0.0
YANG-based system repository for all-around configuration management.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Change Data Subscription API

Functions

int sr_dup_changes_iter (sr_session_ctx_t *session, const char *xpath, sr_change_iter_t **iter)
 Create an iterator for retrieving the changes (list of newly added / removed / modified nodes) in module-change callbacks. It can be used even outside the callback. More...
 
void sr_free_change_iter (sr_change_iter_t *iter)
 Frees sr_change_iter_t iterator and all memory allocated within it. More...
 
struct lyd_node * sr_get_change_diff (sr_session_ctx_t *session)
 Get the changes directly in the form of a diff in module-change callbacks. It cannot be used outside the callback. More...
 
int sr_get_change_next (sr_session_ctx_t *session, sr_change_iter_t *iter, sr_change_oper_t *operation, sr_val_t **old_value, sr_val_t **new_value)
 Return the next change from the provided iterator created by sr_get_changes_iter call. Data are represented as sr_val_t structures. More...
 
int sr_get_change_tree_next (sr_session_ctx_t *session, sr_change_iter_t *iter, sr_change_oper_t *operation, const struct lyd_node **node, const char **prev_value, const char **prev_list, int *prev_dflt)
 Returns the next change from the provided iterator created by sr_get_changes_iter call. Data are represented as libyang subtrees. More...
 
int sr_get_changes_iter (sr_session_ctx_t *session, const char *xpath, sr_change_iter_t **iter)
 Create an iterator for retrieving the changes (list of newly added / removed / modified nodes) in module-change callbacks. It cannot be used outside the callback. More...
 
int sr_module_change_get_order (sr_conn_ctx_t *conn, const char *module_name, sr_datastore_t ds, uint32_t *priority)
 Get the current global priority of change subscriptions of a module. More...
 
int sr_module_change_set_order (sr_conn_ctx_t *conn, const char *module_name, sr_datastore_t ds, uint32_t priority)
 Change the global priority of modules being notified about their changes. The default priority of every module is 0 and modules with the same priority have their callbacks notified simultaneously. More...
 
int sr_module_change_sub_get_info (sr_subscription_ctx_t *subscription, uint32_t sub_id, const char **module_name, sr_datastore_t *ds, const char **xpath, uint32_t *filtered_out)
 Get information about an existing change subscription. More...
 
int sr_module_change_sub_modify_xpath (sr_subscription_ctx_t *subscription, uint32_t sub_id, const char *xpath)
 Modify an existing change subscription by changing its XPath filter. More...
 
int sr_module_change_subscribe (sr_session_ctx_t *session, const char *module_name, const char *xpath, sr_module_change_cb callback, void *private_data, uint32_t priority, sr_subscr_options_t opts, sr_subscription_ctx_t **subscription)
 Subscribe for changes made in the specified module. More...
 
enum  sr_event_t {
  SR_EV_UPDATE, SR_EV_CHANGE, SR_EV_DONE, SR_EV_ABORT,
  SR_EV_ENABLED, SR_EV_RPC
}
 Type of the event that has occurred (passed to application callbacks). More...
 
enum  sr_change_oper_t { SR_OP_CREATED, SR_OP_MODIFIED, SR_OP_DELETED, SR_OP_MOVED }
 Type of the operation made on an item, used by changeset retrieval in sr_get_change_next. More...
 
typedef struct sr_change_iter_s sr_change_iter_t
 Iterator used for retrieval of a changeset using sr_get_changes_iter call. More...
 
typedef int(* sr_module_change_cb )(sr_session_ctx_t *session, uint32_t sub_id, const char *module_name, const char *xpath, sr_event_t event, uint32_t request_id, void *private_data)
 Callback to be called on the event of changing datastore content of the specified module. More...
 

Detailed Description

Typedef Documentation

typedef struct sr_change_iter_s sr_change_iter_t

Iterator used for retrieval of a changeset using sr_get_changes_iter call.

Definition at line 532 of file sysrepo_types.h.

typedef int(* sr_module_change_cb)(sr_session_ctx_t *session, uint32_t sub_id, const char *module_name, const char *xpath, sr_event_t event, uint32_t request_id, void *private_data)

Callback to be called on the event of changing datastore content of the specified module.

Note
Callback must not modify the same module and datastore change subscriptions, it would result in a deadlock.
Parameters
[in]sessionImplicit session (do not stop) with information about the changed data (retrieved by sr_get_changes_iter) and the event originator session IDs.
[in]sub_idSubscription ID.
[in]module_nameName of the module where the change has occurred.
[in]xpathXPath used when subscribing, NULL if the whole module was subscribed to.
[in]eventType of the callback event that has occurred.
[in]request_idRequest ID unique for the specific module_name. Connected events for one request (SR_EV_CHANGE and SR_EV_DONE, for example) have the same request ID.
[in]private_dataPrivate context opaque to sysrepo, as passed to sr_module_change_subscribe call.
Returns
User error code (SR_ERR_OK on success).

Definition at line 550 of file sysrepo_types.h.

Enumeration Type Documentation

Type of the operation made on an item, used by changeset retrieval in sr_get_change_next.

Enumerator
SR_OP_CREATED 

The item has been created by the change.

SR_OP_MODIFIED 

The value of the item has been modified by the change.

SR_OP_DELETED 

The item has been deleted by the change.

SR_OP_MOVED 

The item has been moved in the subtree by the change (applicable for leaf-lists and user-ordered lists).

Definition at line 522 of file sysrepo_types.h.

enum sr_event_t

Type of the event that has occurred (passed to application callbacks).

Note
Each change is normally announced twice: first as SR_EV_CHANGE event and then as SR_EV_DONE or SR_EV_ABORT event. If the subscriber does not support verification, it can subscribe only to SR_EV_DONE event by providing SR_SUBSCR_DONE_ONLY subscription flag. The general rule is that in case the operation fails, only if the subscriber has successfully processed the first event (SR_EV_CHANGE/SR_EV_RPC), it will get the second SR_EV_ABORT event.
Enumerator
SR_EV_UPDATE 

Occurs before any other events and the subscriber can update the apply-changes diff. It is performed by calling sr_*_item() or sr_edit_batch() on the callback session without calling sr_apply_changes() or any other function.

SR_EV_CHANGE 

Occurs just before the changes are committed to the datastore, the subscriber is supposed to verify that the changes are valid and can be applied and prepare all resources required for the changes. The subscriber can still deny the changes in this phase by returning an error from the callback.

SR_EV_DONE 

Occurs just after the changes have been successfully committed to the datastore, the subscriber can apply the changes now, but it cannot deny the changes in this phase anymore (any returned errors are just logged and ignored).

SR_EV_ABORT 

Occurs in case that the commit transaction has failed because one of the verifiers has denied the change (returned an error). The subscriber is supposed to return the managed application to the state before the commit. Any returned errors are just logged and ignored. This event is also generated for RPC subscriptions when a later callback has failed and this one has already successfully processed SR_EV_RPC. The callback that failed will never get this event!

SR_EV_ENABLED 

Occurs for subscriptions with the flag SR_SUBSCR_ENABLED and is normally followed by SR_EV_DONE. It can fail and will also be triggered even when there is no startup configuration (which is different from the SR_EV_CHANGE event). Also note that the callback on this event cannot return SR_ERR_CALLBACK_SHELVE.

SR_EV_RPC 

Occurs for a standard RPC execution. If a later callback fails, SR_EV_ABORT is generated.

Definition at line 495 of file sysrepo_types.h.

Function Documentation

int sr_dup_changes_iter ( sr_session_ctx_t session,
const char *  xpath,
sr_change_iter_t **  iter 
)

Create an iterator for retrieving the changes (list of newly added / removed / modified nodes) in module-change callbacks. It can be used even outside the callback.

See Also
sr_get_change_next for iterating over the changeset using this iterator.
Parameters
[in]sessionImplicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
[in]xpathXPath selecting the changes. Note that you must select all the changes specifically, not just subtrees (to get a full change subtree //. can be appended to the XPath)! Also note that if you use an XPath that selects more changes than subscribed to, you may actually get them because all the changes of a module are available in every callback!
[out]iterIterator context that can be used to retrieve individual changes using sr_get_change_next calls. Allocated by the function, should be freed with sr_free_change_iter.
Returns
Error code (SR_ERR_OK on success).
void sr_free_change_iter ( sr_change_iter_t iter)

Frees sr_change_iter_t iterator and all memory allocated within it.

Parameters
[in]iterIterator to be freed.
struct lyd_node* sr_get_change_diff ( sr_session_ctx_t session)

Get the changes directly in the form of a diff in module-change callbacks. It cannot be used outside the callback.

Parameters
[in]sessionImplicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
Returns
Const diff data tree, must not be modified.
int sr_get_change_next ( sr_session_ctx_t session,
sr_change_iter_t iter,
sr_change_oper_t operation,
sr_val_t **  old_value,
sr_val_t **  new_value 
)

Return the next change from the provided iterator created by sr_get_changes_iter call. Data are represented as sr_val_t structures.

Note
If the operation is SR_OP_MOVED the meaning of new_value and old value argument is as follows - the value pointed by new_value was moved after the old_value. If the old value is NULL it was moved to the first position. The same applies for operation SR_OP_CREATED if the created instance was a user-ordered (leaf-)list.
Parameters
[in]sessionImplicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
[in,out]iterIterator acquired with sr_get_changes_iter call.
[out]operationType of the operation made on the returned item.
[out]old_valueOld value of the item (the value before the change). NULL in case that the item has been just created (operation SR_OP_CREATED).
[out]new_valueNew (modified) value of the the item. NULL in case that the item has been just deleted (operation SR_OP_DELETED).
Returns
Error code (SR_ERR_OK on success, SR_ERR_NOT_FOUND on no more changes).
int sr_get_change_tree_next ( sr_session_ctx_t session,
sr_change_iter_t iter,
sr_change_oper_t operation,
const struct lyd_node **  node,
const char **  prev_value,
const char **  prev_list,
int *  prev_dflt 
)

Returns the next change from the provided iterator created by sr_get_changes_iter call. Data are represented as libyang subtrees.

Note
Meaning of output parameters varies based on the operation: SR_OP_CREATED - node is the created node, for user-ordered lists either prev_value or prev_list is always set with meaning similar to SR_OP_MOVED. SR_OP_MODIFIED - node is the modified node, prev_value is set to the previous value of the leaf, prev_dflt is set if the previous leaf value was the default. SR_OP_DELETED - node is the deleted node. SR_OP_MOVED - node is the moved (leaf-)list instance, for user-ordered lists either prev_value (leaf-list) or prev_list (list) is set to the preceding instance unless the node is the first, when they are set to "" (empty string).
Parameters
[in]sessionImplicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
[in,out]iterIterator acquired with sr_get_changes_iter call.
[out]operationType of the operation made on the returned item.
[out]nodeAffected data node always with all parents, depends on the operation.
[out]prev_valuePrevious value, depends on the operation, may be NULL.
[out]prev_listPrevious list keys predicate ([key1="val1"][key2="val2"]...), depends on the operation, may be NULL.
[out]prev_dfltPrevious value default flag, depends on the operation, may be NULL.
Returns
Error code (SR_ERR_OK on success, SR_ERR_NOT_FOUND on no more changes).
int sr_get_changes_iter ( sr_session_ctx_t session,
const char *  xpath,
sr_change_iter_t **  iter 
)

Create an iterator for retrieving the changes (list of newly added / removed / modified nodes) in module-change callbacks. It cannot be used outside the callback.

See Also
sr_get_change_next for iterating over the changeset using this iterator.
Parameters
[in]sessionImplicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
[in]xpathXPath selecting the changes. Note that you must select all the changes specifically, not just subtrees (to get a full change subtree //. can be appended to the XPath)! Also note that if you use an XPath that selects more changes than subscribed to, you may actually get them because all the changes of a module are available in every callback!
[out]iterIterator context that can be used to retrieve individual changes using sr_get_change_next calls. Allocated by the function, should be freed with sr_free_change_iter.
Returns
Error code (SR_ERR_OK on success).
int sr_module_change_get_order ( sr_conn_ctx_t conn,
const char *  module_name,
sr_datastore_t  ds,
uint32_t *  priority 
)

Get the current global priority of change subscriptions of a module.

Required READ access.

Parameters
[in]connConnection to use.
[in]module_nameName of the module whose order to get.
[in]dsAffected datastore.
[out]priorityPriority of the module.
Returns
Error code (SR_ERR_OK on success).
int sr_module_change_set_order ( sr_conn_ctx_t conn,
const char *  module_name,
sr_datastore_t  ds,
uint32_t  priority 
)

Change the global priority of modules being notified about their changes. The default priority of every module is 0 and modules with the same priority have their callbacks notified simultaneously.

Example callback order for modules A, B, C with A having callbacks with priority 10, 5, and 0, module B with callbacks 5, 4, and 3, and module C with 1, and 0. Simultaneously notified: ``` A10, B5, C1; A5, B4, C0; A0, B3; ``` As soon as a callback fails, its batch of callbacks is the last to be notified. Also note that the callbacks may not actually be executed concurrently in case they are handled by a single subscription (thread).

This order (of running datastore) is also used when initializing and copying data from startup to running on SHM creation.

Required WRITE access.

Parameters
[in]connConnection to use.
[in]module_nameName of the module whose order to change.
[in]dsAffected datastore.
[in]priorityNew priority of the module, higher first.
Returns
Error code (SR_ERR_OK on success).
int sr_module_change_sub_get_info ( sr_subscription_ctx_t subscription,
uint32_t  sub_id,
const char **  module_name,
sr_datastore_t ds,
const char **  xpath,
uint32_t *  filtered_out 
)

Get information about an existing change subscription.

Parameters
[in]subscriptionSubscription structure to use.
[in]sub_idSubscription ID of the specific subscription.
[out]module_nameOptional name of the module whose changes were subscribed.
[out]dsOptional datastore of the subscription.
[out]xpathOptional XPath filter of the subscription.
[out]filtered_outOptional number of filtered-out change events of the subscription.
Returns
Error code (SR_ERR_OK on success).
int sr_module_change_sub_modify_xpath ( sr_subscription_ctx_t subscription,
uint32_t  sub_id,
const char *  xpath 
)

Modify an existing change subscription by changing its XPath filter.

Parameters
[in]subscriptionSubscription structure to use.
[in]sub_idSubscription ID of the specific subscription to modify.
[in]xpathNew XPath filter to use by the subscription.
Returns
Error code (SR_ERR_OK on success).
int sr_module_change_subscribe ( sr_session_ctx_t session,
const char *  module_name,
const char *  xpath,
sr_module_change_cb  callback,
void *  private_data,
uint32_t  priority,
sr_subscr_options_t  opts,
sr_subscription_ctx_t **  subscription 
)

Subscribe for changes made in the specified module.

The order of callbacks of a single module is determined by their priority. The order of modules being notified is determined by their priority which can be adjusted by sr_module_change_set_order().

Required WRITE access. If SR_SUBSCR_PASSIVE is set, required READ access.

Parameters
[in]sessionSession (DS-specific) to use.
[in]module_nameName of the module of interest for change notifications.
[in]xpathOptional XPath further filtering the changes that will be handled by this subscription.
[in]callbackCallback to be called when the change in the datastore occurs.
[in]private_dataPrivate context passed to the callback function, opaque to sysrepo.
[in]prioritySpecifies the order in which the callbacks (within module) will be called, higher first.
[in]optsOptions overriding default behavior of the subscription, it is supposed to be a bitwise OR-ed value of any sr_subscr_flag_t flags.
[in,out]subscriptionSubscription context, zeroed for first subscription, freed by sr_unsubscribe.
Returns
Error code (SR_ERR_OK on success).