sysrepo  1.4.168
YANG datastore
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Change Data Subscription API

Typedefs

typedef enum sr_event_e sr_event_t
 Type of the event that has occurred (passed to application callbacks). More...
 
typedef enum sr_change_oper_e sr_change_oper_t
 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, 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...
 

Enumerations

enum  sr_event_e {
  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_e { 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...
 

Functions

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. If there are changes made in several modules, the module order is determined by the order in the changes (it is kept). 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_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...
 
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, bool *prev_dflt)
 Returns the next change from the provided iterator created by sr_get_changes_iter call. Data are represented as libyang subtrees. More...
 
void sr_free_change_iter (sr_change_iter_t *iter)
 Frees sr_change_iter_t iterator and all memory allocated within it. More...
 

Detailed Description

Typedef Documentation

typedef enum sr_event_e 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.

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

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 1319 of file sysrepo.h.

typedef int(* sr_module_change_cb)(sr_session_ctx_t *session, 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]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 1336 of file sysrepo.h.

Enumeration Type Documentation

enum sr_event_e

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 1282 of file sysrepo.h.

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 1309 of file sysrepo.h.

Function Documentation

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. If there are changes made in several modules, the module order is determined by the order in the changes (it is kept).

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.
[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 that is supposed to be released by sr_unsubscribe.
Note
An existing context may be passed in case that SR_SUBSCR_CTX_REUSE option is specified.
Returns
Error code (SR_ERR_OK on success).
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_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).
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,
bool *  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.
[out]prev_listPrevious list keys predicate ([key1="val1"][key2="val2"]...), depends on the operation.
[out]prev_dfltPrevious value default flag, depends on the operation.
Returns
Error code (SR_ERR_OK on success, SR_ERR_NOT_FOUND on no more changes).
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.