sysrepo  2.0.1
YANG-basedsystemrepositoryforall-aroundconfigurationmanagement.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Subscription API

Functions

int sr_get_event_pipe (sr_subscription_ctx_t *subscription, int *event_pipe)
 Get the event pipe of a subscription. Do not call unless SR_SUBSCR_NO_THREAD flag was used when subscribing! Event pipe can be used in select(), poll(), or similar functions to listen for new events. It will then be ready for reading. More...
 
int sr_process_events (sr_subscription_ctx_t *subscription, sr_session_ctx_t *session, time_t *stop_time_in)
 Process any pending new events on a subscription. Should not be called unless SR_SUBSCR_NO_THREAD flag was used when subscribing! Usually called after this subscription's event pipe is ready for reading but can also be called periodically. More...
 
uint32_t sr_subscription_get_last_sub_id (const sr_subscription_ctx_t *subscription)
 Get the subscription ID of the last created subscription. More...
 
int sr_subscription_get_suspended (sr_subscription_ctx_t *subscription, uint32_t sub_id, int *suspended)
 Learn the suspend state of a specific subscription. More...
 
int sr_subscription_resume (sr_subscription_ctx_t *subscription, uint32_t sub_id)
 Resume a previously suspended subscription. Special SR_EV_NOTIF_RESUMED notification is delivered for resumed notification subscriptions. More...
 
int sr_subscription_suspend (sr_subscription_ctx_t *subscription, uint32_t sub_id)
 Suspend a specific subscription. Special SR_EV_NOTIF_SUSPENDED notification is delivered for suspended notification subscriptions. More...
 
int sr_unsubscribe (sr_subscription_ctx_t *subscription)
 Unsubscribe all the subscriptions in a subscription structure and free it. More...
 
int sr_unsubscribe_sub (sr_subscription_ctx_t *subscription, uint32_t sub_id)
 Unsubscribe a specific or all the subscriptions in a subscription structure. More...
 
enum  sr_subscr_flag_t {
  SR_SUBSCR_DEFAULT = 0, SR_SUBSCR_CTX_REUSE = 1, SR_SUBSCR_NO_THREAD = 2, SR_SUBSCR_PASSIVE = 4,
  SR_SUBSCR_DONE_ONLY = 8, SR_SUBSCR_ENABLED = 16, SR_SUBSCR_UPDATE = 32, SR_SUBSCR_OPER_MERGE = 64
}
 Flags used to override default handling of subscriptions. More...
 
typedef struct
sr_subscription_ctx_s 
sr_subscription_ctx_t
 Sysrepo subscription context returned from sr_*_subscribe calls, it is supposed to be released by the caller using sr_unsubscribe call. More...
 
typedef uint32_t sr_subscr_options_t
 Options overriding default behavior of subscriptions, it is supposed to be a bitwise OR-ed value of any sr_subscr_flag_t flags. More...
 

Detailed Description

Typedef Documentation

typedef uint32_t sr_subscr_options_t

Options overriding default behavior of subscriptions, it is supposed to be a bitwise OR-ed value of any sr_subscr_flag_t flags.

Definition at line 395 of file sysrepo_types.h.

typedef struct sr_subscription_ctx_s sr_subscription_ctx_t

Sysrepo subscription context returned from sr_*_subscribe calls, it is supposed to be released by the caller using sr_unsubscribe call.

Definition at line 389 of file sysrepo_types.h.

Enumeration Type Documentation

Flags used to override default handling of subscriptions.

Enumerator
SR_SUBSCR_DEFAULT 

Default behavior of the subscription. In case of sr_module_change_subscribe call it means that:

SR_SUBSCR_CTX_REUSE 

This option enables the application to re-use an already existing subscription context previously returned from any sr_*_subscribe call instead of requesting the creation of a new one. In that case a single sr_unsubscribe call unsubscribes from all subscriptions filed within the context.

SR_SUBSCR_NO_THREAD 

There will be no thread created for handling this subscription meaning no event will be processed! Use this flag when the application has its own event loop and it will listen for and process events manually (see sr_get_event_pipe and sr_process_events).

SR_SUBSCR_PASSIVE 

The subscriber is not the "owner" of the subscribed data tree, just a passive watcher for changes. When this option is passed in to sr_module_change_subscribe, the subscription will have no effect on the presence of the subtree in the operational datastore.

SR_SUBSCR_DONE_ONLY 

The subscriber does not support verification of the changes and wants to be notified only after the changes has been applied in the datastore, without the possibility to deny them (it will not receive SR_EV_CHANGE nor SR_EV_ABORT but only SR_EV_DONE events).

SR_SUBSCR_ENABLED 

The subscriber wants to be notified about the current configuration at the moment of subscribing. It will receive SR_EV_ENABLED event, whose applying can fail causing the whole subscription to fail. On success this event will be followed by SR_EV_DONE. Be careful, SR_EV_ENABLED will be triggered even if there are no data so there will not be any changes!

SR_SUBSCR_UPDATE 

The subscriber will be called before any other subscribers for the particular module with an additional SR_EV_UPDATE event and is then allowed to modify the new module data. It can add new changes by calling standard set functions (such as sr_set_item_str) on the implicit callback session and returning. Note that you cannot subscribe more callbacks with this flag on one module with the same priority.

SR_SUBSCR_OPER_MERGE 

Instead of removing any previous existing matching data before getting them from an operational subscription callback, keep them. Then the returned data are merged into the existing data. Accepted only for operational subscriptions.

Definition at line 319 of file sysrepo_types.h.

Function Documentation

int sr_get_event_pipe ( sr_subscription_ctx_t subscription,
int *  event_pipe 
)

Get the event pipe of a subscription. Do not call unless SR_SUBSCR_NO_THREAD flag was used when subscribing! Event pipe can be used in select(), poll(), or similar functions to listen for new events. It will then be ready for reading.

Parameters
[in]subscriptionSubscription without a listening thread.
[out]event_pipeEvent pipe of the subscription, do not close! It will be closed when the subscription is unsubscribed.
Returns
Error code (SR_ERR_OK on success).
int sr_process_events ( sr_subscription_ctx_t subscription,
sr_session_ctx_t session,
time_t *  stop_time_in 
)

Process any pending new events on a subscription. Should not be called unless SR_SUBSCR_NO_THREAD flag was used when subscribing! Usually called after this subscription's event pipe is ready for reading but can also be called periodically.

Parameters
[in]subscriptionSubscription without a listening thread with some new events.
[in]sessionOptional session for storing errors.
[out]stop_time_inOptional seconds until the nearest notification subscription stop time is elapsed and this function should be called. If there are no subscriptions with stop time in future, it is set to 0.
Returns
Error code (SR_ERR_OK on success).
uint32_t sr_subscription_get_last_sub_id ( const sr_subscription_ctx_t subscription)

Get the subscription ID of the last created subscription.

Parameters
[in]subscriptionSubscription context to read from.
Returns
Unique subscription ID.
int sr_subscription_get_suspended ( sr_subscription_ctx_t subscription,
uint32_t  sub_id,
int *  suspended 
)

Learn the suspend state of a specific subscription.

Parameters
[in]subscriptionSubscription context to use.
[in]sub_idSubscription ID of the subscription to check.
[out]suspendedWhether the subscription is suspended or not.
Returns
Error code (SR_ERR_OK on success).
int sr_subscription_resume ( sr_subscription_ctx_t subscription,
uint32_t  sub_id 
)

Resume a previously suspended subscription. Special SR_EV_NOTIF_RESUMED notification is delivered for resumed notification subscriptions.

Parameters
[in]subscriptionSubscription context to use.
[in]sub_idSubscription ID of the specific subscription to resume.
Returns
Error code (SR_ERR_OK on success).
int sr_subscription_suspend ( sr_subscription_ctx_t subscription,
uint32_t  sub_id 
)

Suspend a specific subscription. Special SR_EV_NOTIF_SUSPENDED notification is delivered for suspended notification subscriptions.

Parameters
[in]subscriptionSubscription context to use.
[in]sub_idSubscription ID of the specific subscription to suspend.
Returns
Error code (SR_ERR_OK on success).
int sr_unsubscribe ( sr_subscription_ctx_t subscription)

Unsubscribe all the subscriptions in a subscription structure and free it.

Note
Even on error, all the possible tasks are still performed and the subscripton(s) are unsubscribed and freed. So it cannot be used anymore after calling this function.
Parameters
[in]subscriptionSubscription context to use.
Returns
Error code (SR_ERR_OK on success).
int sr_unsubscribe_sub ( sr_subscription_ctx_t subscription,
uint32_t  sub_id 
)

Unsubscribe a specific or all the subscriptions in a subscription structure.

If all subscriptions are being unsubscribed, the subscription structure can still be used normally until sr_unsubscribe() is called, even if there are no actual subscriptions left in it. This is useful for preventing dead locks if using the subscription in a custom event loop.

Note
Even on error, all the possible tasks are still performed and the subscripton(s) are unsubscribed.
Parameters
[in]subscriptionSubscription context to use.
[in]sub_idSubscription ID of the subscription to unsubscribe, 0 for all the subscriptions.
Returns
Error code (SR_ERR_OK on success).