Loading...
Searching...
No Matches
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.
void | sr_free_change_iter (sr_change_iter_t *iter)
| Frees sr_change_iter_t iterator and all memory allocated within it.
const 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 operation_id, void *private_data)
| Callback to be called on the event of changing datastore content of the specified module.

## Detailed Description

## Typedef Documentation

## sr_change_iter_t

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 539 of file sysrepo_types.h.

## sr_module_change_cb

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 operation_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] | session | Implicit session (do not stop) with information about the changed data (retrieved by sr_get_changes_iter) and the event originator session IDs.
  [in] | sub_id | Subscription ID.
  [in] | module_name | Name of the module where the change has occurred.
  [in] | xpath | XPath used when subscribing, NULL if the whole module was subscribed to.
  [in] | event | Type of the callback event that has occurred.
  [in] | operation_id | Operation ID of the current operation used for all the callbacks and events.
  [in] | private_data | Private context opaque to sysrepo, as passed to sr_module_change_subscribe call.

Returns
  User error code (SR_ERR_OK on success).

Definition at line 556 of file sysrepo_types.h.

## Enumeration Type Documentation

## sr_change_oper_t

enum sr_change_oper_t

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 529 of file sysrepo_types.h.

## sr_event_t

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 502 of file sysrepo_types.h.

## Function Documentation

## sr_dup_changes_iter()

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] | session | Implicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
  [in] | xpath | XPath 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] | iter | Iterator 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).

## sr_free_change_iter()

void sr_free_change_iter | ( | sr_change_iter_t * | iter | ) |

Frees sr_change_iter_t iterator and all memory allocated within it.

Parameters

  [in] | iter | Iterator to be freed.

## sr_get_change_diff()

const 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] | session | Implicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.

Returns
  Const diff data tree, must not be modified.

## sr_get_change_next()

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] | session | Implicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
  [in,out] | iter | Iterator acquired with sr_get_changes_iter call.
  [out] | operation | Type of the operation made on the returned item.
  [out] | old_value | Old 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_value | New (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).

## sr_get_change_tree_next()

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] | session | Implicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
  [in,out] | iter | Iterator acquired with sr_get_changes_iter call.
  [out] | operation | Type of the operation made on the returned item.
  [out] | node | Affected data node always with all parents, depends on the operation.
  [out] | prev_value | Previous value, depends on the operation, may be NULL.
  [out] | prev_list | Previous list keys predicate ([key1="val1"][key2="val2"]...), depends on the operation, may be NULL.
  [out] | prev_dflt | Previous 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).

## sr_get_changes_iter()

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] | session | Implicit session provided in the callbacks (sr_module_change_cb). Will not work with other sessions.
  [in] | xpath | XPath 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] | iter | Iterator 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).

## sr_module_change_get_order()

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] | conn | Connection to use.
  [in] | module_name | Name of the module whose order to get.
  [in] | ds | Affected datastore.
  [out] | priority | Priority of the module.

Returns
  Error code (SR_ERR_OK on success).

## sr_module_change_set_order()

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] | conn | Connection to use.
  [in] | module_name | Name of the module whose order to change.
  [in] | ds | Affected datastore.
  [in] | priority | New priority of the module, higher first.

Returns
  Error code (SR_ERR_OK on success).

## sr_module_change_sub_get_info()

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] | subscription | Subscription structure to use.
  [in] | sub_id | Subscription ID of the specific subscription.
  [out] | module_name | Optional name of the module whose changes were subscribed.
  [out] | ds | Optional datastore of the subscription.
  [out] | xpath | Optional XPath filter of the subscription.
  [out] | filtered_out | Optional number of filtered-out change events of the subscription.

Returns
  Error code (SR_ERR_OK on success).

## sr_module_change_sub_modify_xpath()

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] | subscription | Subscription structure to use.
  [in] | sub_id | Subscription ID of the specific subscription to modify.
  [in] | xpath | New XPath filter to use by the subscription.

Returns
  Error code (SR_ERR_OK on success).

## sr_module_change_subscribe()

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] | session | Session (DS-specific) to use.
  [in] | module_name | Name of the module of interest for change notifications.
  [in] | xpath | Optional XPath further filtering the changes that will be handled by this subscription.
  [in] | callback | Callback to be called when the change in the datastore occurs.
  [in] | private_data | Private context passed to the callback function, opaque to sysrepo.
  [in] | priority | Specifies the order in which the callbacks (within module) will be called, higher first.
  [in] | opts | Options 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] | subscription | Subscription context, zeroed for first subscription, freed by sr_unsubscribe.

Returns
  Error code (SR_ERR_OK on success).