static int event_notif_subscriber(sr_session_ctx_t *session) { sr_subscription_ctx_t *subscription = NULL; int rc = SR_ERR_OK; /* subscribe for the notification */ rc = sr_event_notif_subscribe(session, "/turing-machine:paused", event_notif_cb, NULL, SR_SUBSCR_DEFAULT, &subscription); if (SR_ERR_OK != rc) { fprintf(stderr, "Error by sr_event_notif_subscribe: %s\n", sr_strerror(rc)); goto cleanup; } printf("\n\n ========== SUBSCRIBED FOR EVENT NOTIFICATION ==========\n\n"); /* loop until ctrl-c is pressed / SIGINT is received */ signal(SIGINT, sigint_handler); signal(SIGPIPE, SIG_IGN); while (!exit_application) { sleep(1000); /* or do some more useful work... */ } printf("Application exit requested, exiting.\n"); cleanup: if (NULL != subscription) { sr_unsubscribe(session, subscription); } return rc; }
void Subscribe::event_notif_subscribe(const char *xpath, S_Callback callback, void *private_ctx, sr_subscr_options_t opts) { callback->private_ctx["event_notif"] = private_ctx; cb_list.push_back(callback); int ret = sr_event_notif_subscribe(_sess->_sess, xpath, event_notif_cb, callback->get(), opts, &_sub); if (SR_ERR_OK != ret) { throw_exception(ret); } }