sysrepo  1.4.70
YANG datastore
Session.hpp
Go to the documentation of this file.
1 
23 #ifndef SESSION_H
24 #define SESSION_H
25 
26 #include <iostream>
27 #include <memory>
28 #include <map>
29 #include <vector>
30 
31 #include <libyang/Tree_Data.hpp>
32 
33 #include "Sysrepo.hpp"
34 #include "Internal.hpp"
35 #include "Struct.hpp"
36 #include "Connection.hpp"
37 #include "Session.hpp"
38 
39 #include "sysrepo.h"
40 
41 namespace sysrepo {
42 
52 class Session
53 {
54 
55 public:
57  Session(S_Connection conn, sr_datastore_t datastore = (sr_datastore_t)DS_RUNNING);
59  Session(sr_session_ctx_t *sess, S_Deleter deleter = nullptr);
61  void session_stop();
71  void set_error(const char *message, const char *path);
73  uint32_t get_id();
75  void set_nc_id(uint32_t nc_id);
77  uint32_t get_nc_id();
79  void set_user(const char *user);
81  const char *get_user();
83  libyang::S_Context get_context();
84 
86  S_Val get_item(const char *path, uint32_t timeout_ms = 0);
88  S_Vals get_items(const char *xpath, uint32_t timeout_ms = 0, const sr_get_oper_options_t opts = OPER_DEFAULT);
90  libyang::S_Data_Node get_subtree(const char *path, uint32_t timeout_ms = 0);
92  libyang::S_Data_Node get_data(const char *xpath, uint32_t max_depth = 0, uint32_t timeout_ms = 0, \
93  const sr_get_oper_options_t opts = OPER_DEFAULT);
94 
96  void set_item(const char *path, S_Val value = nullptr, const sr_edit_options_t opts = EDIT_DEFAULT);
98  void set_item_str(const char *path, const char *value, const char *origin = nullptr, \
99  const sr_edit_options_t opts = EDIT_DEFAULT);
101  void delete_item(const char *path, const sr_edit_options_t opts = EDIT_DEFAULT);
103  void move_item(const char *path, const sr_move_position_t position, const char *list_keys = nullptr, \
104  const char *leaflist_value = nullptr, const char *origin = nullptr, const sr_edit_options_t opts = EDIT_DEFAULT);
106  void edit_batch(const libyang::S_Data_Node edit, const char *default_operation);
108  void validate(const char *module_name = nullptr, uint32_t timeout_ms = 0);
110  void apply_changes(uint32_t timeout_ms = 0, int wait = 0);
114  void replace_config(const libyang::S_Data_Node src_config, const char *module_name = nullptr, uint32_t timeout_ms = 0, \
115  int wait = 0);
117  void copy_config(sr_datastore_t src_datastore, const char *module_name = nullptr, uint32_t timeout_ms = 0, int wait = 0);
118 
120  void lock(const char *module_name = nullptr);
122  void unlock(const char *module_name = nullptr);
123 
125  S_Iter_Change get_changes_iter(const char *xpath);
127  S_Iter_Change dup_changes_iter(const char *xpath);
133 
135  S_Vals rpc_send(const char *path, S_Vals input, uint32_t timeout_ms = 0);
137  libyang::S_Data_Node rpc_send(libyang::S_Data_Node input, uint32_t timeout_ms = 0);
138 
140  void event_notif_send(const char *path, S_Vals values);
142  void event_notif_send(libyang::S_Data_Node notif);
143 
144  friend class Subscribe;
145 
146 private:
147  sr_session_ctx_t *_sess;
148  S_Connection _conn;
149  S_Deleter _deleter;
150 };
151 
156 class Callback
157 {
158 public:
160  virtual ~Callback();
161 
163  virtual int module_change(S_Session session, const char *module_name, const char *xpath, sr_event_t event, \
164  uint32_t request_id, void *private_data) {return SR_ERR_OK;};
166  virtual int rpc(S_Session session, const char *op_path, const S_Vals input, sr_event_t event, uint32_t request_id, \
167  S_Vals_Holder output, void *private_data) {return SR_ERR_OK;};
169  virtual int rpc_tree(S_Session session, const char *op_path, const libyang::S_Data_Node input, sr_event_t event, \
170  uint32_t request_id, libyang::S_Data_Node output, void *private_data) {return SR_ERR_OK;};
172  virtual void event_notif(S_Session session, const sr_ev_notif_type_t notif_type, const char *path, const S_Vals vals, \
173  time_t timestamp, void *private_data) {return;};
175  virtual void event_notif_tree(S_Session session, const sr_ev_notif_type_t notif_type, const libyang::S_Data_Node notif, \
176  time_t timestamp, void *private_data) {return;};
178  virtual int oper_get_items(S_Session session, const char *module_name, const char *path, const char *request_xpath, \
179  uint32_t request_id, libyang::S_Data_Node &parent, void *private_data) {return SR_ERR_OK;};
180  Callback *get() {return this;};
181 
182  std::map<const char *, void *> private_data;
183 };
184 
190 {
191 
192 public:
195 
197  void module_change_subscribe(const char *module_name, S_Callback callback, const char *xpath = nullptr, \
198  void *private_data = nullptr, uint32_t priority = 0, sr_subscr_options_t opts = SUBSCR_DEFAULT);
200  void rpc_subscribe(const char *xpath, S_Callback callback, void *private_data = nullptr, uint32_t priority = 0, \
201  sr_subscr_options_t opts = SUBSCR_DEFAULT);
203  void rpc_subscribe_tree(const char *xpath, S_Callback callback, void *private_data = nullptr, uint32_t priority = 0, \
204  sr_subscr_options_t opts = SUBSCR_DEFAULT);
206  void event_notif_subscribe(const char *module_name, S_Callback callback, const char *xpath = nullptr, \
207  time_t start_time = 0, time_t stop_time = 0, void *private_data = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT);
209  void event_notif_subscribe_tree(const char *module_name, S_Callback callback, const char *xpath = nullptr, \
210  time_t start_time = 0, time_t stop_time = 0, void *private_data = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT);
212  void oper_get_items_subscribe(const char *module_name, const char *path, S_Callback callback, \
213  void *private_data = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT);
214  std::vector<S_Callback > cb_list;
215 
219  time_t process_events(S_Session sess = nullptr);
221  void unsubscribe();
223 
225  sr_subscription_ctx_t **swig_sub() { return &_sub;};
227  sr_session_ctx_t *swig_sess() {return _sess->_sess;};
229  std::vector<void*> wrap_cb_l;
231  void additional_cleanup(void *private_data) {return;};
232 
233 private:
234  sr_subscription_ctx_t *_sub;
235  S_Session _sess;
236  S_Deleter sess_deleter;
237 };
238 
240 }
241 #endif
sysrepo::S_Deleter
std::shared_ptr< Deleter > S_Deleter
Definition: Sysrepo.hpp:73
sysrepo.h
public API sysrepo header
Internal.hpp
Sysrepo class header for internal C++ classes.
sysrepo::S_Tree_Change
std::shared_ptr< Tree_Change > S_Tree_Change
Definition: Sysrepo.hpp:71
sysrepo::Session::event_notif_send
void event_notif_send(const char *path, S_Vals values)
sysrepo::Callback
Helper class for calling C callbacks, C++ only.
Definition: Session.hpp:157
sysrepo::Session::get_id
uint32_t get_id()
sysrepo::Session::copy_config
void copy_config(sr_datastore_t src_datastore, const char *module_name=nullptr, uint32_t timeout_ms=0, int wait=0)
sysrepo::Subscribe::oper_get_items_subscribe
void oper_get_items_subscribe(const char *module_name, const char *path, S_Callback callback, void *private_data=nullptr, sr_subscr_options_t opts=SUBSCR_DEFAULT)
sysrepo
Definition: Connection.hpp:35
sysrepo::Callback::Callback
Callback()
sysrepo::Subscribe::cb_list
std::vector< S_Callback > cb_list
Definition: Session.hpp:214
sysrepo::Session::lock
void lock(const char *module_name=nullptr)
sysrepo::Callback::~Callback
virtual ~Callback()
sysrepo::Session::set_item_str
void set_item_str(const char *path, const char *value, const char *origin=nullptr, const sr_edit_options_t opts=EDIT_DEFAULT)
sysrepo::Session::get_subtree
libyang::S_Data_Node get_subtree(const char *path, uint32_t timeout_ms=0)
sysrepo::Session::get_change_next
S_Change get_change_next(S_Iter_Change iter)
sysrepo::Subscribe::process_events
time_t process_events(S_Session sess=nullptr)
sysrepo::Subscribe::Subscribe
Subscribe(S_Session sess)
sr_datastore_t
enum sr_datastore_e sr_datastore_t
Datastores that sysrepo supports. To change which datastore a session operates on,...
sysrepo::Session
Class for wrapping sr_session_ctx_t.
Definition: Session.hpp:53
sysrepo::Subscribe::additional_cleanup
void additional_cleanup(void *private_data)
Definition: Session.hpp:231
sysrepo::S_Vals_Holder
std::shared_ptr< Vals_Holder > S_Vals_Holder
Definition: Sysrepo.hpp:66
sysrepo::Session::session_get_ds
sr_datastore_t session_get_ds()
sr_subscr_options_t
uint32_t sr_subscr_options_t
Options overriding default behavior of subscriptions, it is supposed to be a bitwise OR-ed value of a...
Definition: sysrepo.h:1206
sysrepo::S_Errors
std::shared_ptr< Errors > S_Errors
Definition: Sysrepo.hpp:63
sysrepo::S_Iter_Change
std::shared_ptr< Iter_Change > S_Iter_Change
Definition: Sysrepo.hpp:58
sysrepo::Session::get_context
libyang::S_Context get_context()
sysrepo::Session::set_nc_id
void set_nc_id(uint32_t nc_id)
sysrepo::Session::delete_item
void delete_item(const char *path, const sr_edit_options_t opts=EDIT_DEFAULT)
sysrepo::S_Session
std::shared_ptr< Session > S_Session
Definition: Sysrepo.hpp:59
sysrepo::S_Change
std::shared_ptr< Change > S_Change
Definition: Sysrepo.hpp:70
Sysrepo.hpp
Sysrepo Sysrepo class header.
sr_move_position_t
enum sr_move_position_e sr_move_position_t
Options for specifying move direction of sr_move_item call.
sysrepo::Subscribe::unsubscribe
void unsubscribe()
sysrepo::Callback::event_notif_tree
virtual void event_notif_tree(S_Session session, const sr_ev_notif_type_t notif_type, const libyang::S_Data_Node notif, time_t timestamp, void *private_data)
Definition: Session.hpp:175
sysrepo::S_Val
std::shared_ptr< Val > S_Val
Definition: Sysrepo.hpp:65
sysrepo::Subscribe::event_notif_subscribe
void event_notif_subscribe(const char *module_name, S_Callback callback, const char *xpath=nullptr, time_t start_time=0, time_t stop_time=0, void *private_data=nullptr, sr_subscr_options_t opts=SUBSCR_DEFAULT)
sysrepo::Session::get_error
S_Errors get_error()
sysrepo::Session::move_item
void move_item(const char *path, const sr_move_position_t position, const char *list_keys=nullptr, const char *leaflist_value=nullptr, const char *origin=nullptr, const sr_edit_options_t opts=EDIT_DEFAULT)
sysrepo::Session::get_changes_iter
S_Iter_Change get_changes_iter(const char *xpath)
sysrepo::Session::get_nc_id
uint32_t get_nc_id()
sr_subscription_ctx_t
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...
Definition: sysrepo.h:1200
sysrepo::Subscribe::rpc_subscribe_tree
void rpc_subscribe_tree(const char *xpath, S_Callback callback, void *private_data=nullptr, uint32_t priority=0, sr_subscr_options_t opts=SUBSCR_DEFAULT)
sysrepo::Session::get_item
S_Val get_item(const char *path, uint32_t timeout_ms=0)
sysrepo::Session::get_items
S_Vals get_items(const char *xpath, uint32_t timeout_ms=0, const sr_get_oper_options_t opts=OPER_DEFAULT)
sysrepo::S_Callback
std::shared_ptr< Callback > S_Callback
Definition: Sysrepo.hpp:72
sysrepo::Session::replace_config
void replace_config(const libyang::S_Data_Node src_config, const char *module_name=nullptr, uint32_t timeout_ms=0, int wait=0)
sysrepo::Session::rpc_send
S_Vals rpc_send(const char *path, S_Vals input, uint32_t timeout_ms=0)
sysrepo::Subscribe::swig_sub
sr_subscription_ctx_t ** swig_sub()
Definition: Session.hpp:225
sysrepo::Subscribe::wrap_cb_l
std::vector< void * > wrap_cb_l
Definition: Session.hpp:227
sr_session_ctx_t
struct sr_session_ctx_s sr_session_ctx_t
Sysrepo session on a connection.
Definition: sysrepo.h:173
sysrepo::Session::session_switch_ds
void session_switch_ds(sr_datastore_t ds)
sysrepo::Callback::module_change
virtual int module_change(S_Session session, const char *module_name, const char *xpath, sr_event_t event, uint32_t request_id, void *private_data)
Definition: Session.hpp:163
sysrepo::Callback::private_data
std::map< const char *, void * > private_data
Definition: Session.hpp:180
sysrepo::Session::get_user
const char * get_user()
sysrepo::Session::Session
Session(S_Connection conn, sr_datastore_t datastore=(sr_datastore_t) DS_RUNNING)
sr_ev_notif_type_t
enum sr_ev_notif_type_e sr_ev_notif_type_t
Type of the notification passed to the sr_event_notif_cb and sr_event_notif_tree_cb callbacks.
sysrepo::Callback::rpc
virtual int rpc(S_Session session, const char *op_path, const S_Vals input, sr_event_t event, uint32_t request_id, S_Vals_Holder output, void *private_data)
Definition: Session.hpp:166
sysrepo::Session::edit_batch
void edit_batch(const libyang::S_Data_Node edit, const char *default_operation)
Connection.hpp
Sysrepo Connection class header.
sysrepo::Session::~Session
~Session()
sysrepo::Session::get_data
libyang::S_Data_Node get_data(const char *xpath, uint32_t max_depth=0, uint32_t timeout_ms=0, const sr_get_oper_options_t opts=OPER_DEFAULT)
sysrepo::Session::session_stop
void session_stop()
sysrepo::Subscribe::swig_sess
sr_session_ctx_t * swig_sess()
Definition: Session.hpp:227
sysrepo::S_Vals
std::shared_ptr< Vals > S_Vals
Definition: Sysrepo.hpp:67
sysrepo::Callback::event_notif
virtual void event_notif(S_Session session, const sr_ev_notif_type_t notif_type, const char *path, const S_Vals vals, time_t timestamp, void *private_data)
Definition: Session.hpp:172
sysrepo::Subscribe::event_notif_subscribe_tree
void event_notif_subscribe_tree(const char *module_name, S_Callback callback, const char *xpath=nullptr, time_t start_time=0, time_t stop_time=0, void *private_data=nullptr, sr_subscr_options_t opts=SUBSCR_DEFAULT)
sr_get_oper_options_t
uint32_t sr_get_oper_options_t
Options overriding default get handling by sr_get_data call, it is supposed to be bitwise OR-ed value...
Definition: sysrepo.h:711
sysrepo::Session::unlock
void unlock(const char *module_name=nullptr)
Session.hpp
Sysrepo Session class header.
sysrepo::Session::session_notif_buffer
void session_notif_buffer()
sysrepo::Session::dup_changes_iter
S_Iter_Change dup_changes_iter(const char *xpath)
sysrepo::Session::rpc_send
libyang::S_Data_Node rpc_send(libyang::S_Data_Node input, uint32_t timeout_ms=0)
sysrepo::Session::discard_changes
void discard_changes()
sysrepo::Subscribe::get_event_pipe
int get_event_pipe()
sysrepo::Subscribe::rpc_subscribe
void rpc_subscribe(const char *xpath, S_Callback callback, void *private_data=nullptr, uint32_t priority=0, sr_subscr_options_t opts=SUBSCR_DEFAULT)
sysrepo::S_Connection
std::shared_ptr< Connection > S_Connection
Definition: Sysrepo.hpp:61
sysrepo::Session::get_change_tree_next
S_Tree_Change get_change_tree_next(S_Iter_Change iter)
SR_ERR_OK
@ SR_ERR_OK
Definition: sysrepo.h:52
sysrepo::Callback::get
Callback * get()
Definition: Session.hpp:180
sysrepo::Session::event_notif_send
void event_notif_send(libyang::S_Data_Node notif)
sr_edit_options_t
uint32_t sr_edit_options_t
Options overriding default behavior of data manipulation calls, it is supposed to be bitwise OR-ed va...
Definition: sysrepo.h:849
sysrepo::Session::set_user
void set_user(const char *user)
sr_event_t
enum sr_event_e sr_event_t
Type of the event that has occurred (passed to application callbacks).
sysrepo::Subscribe::module_change_subscribe
void module_change_subscribe(const char *module_name, S_Callback callback, const char *xpath=nullptr, void *private_data=nullptr, uint32_t priority=0, sr_subscr_options_t opts=SUBSCR_DEFAULT)
Struct.hpp
Sysrepo class header for C struts.
sysrepo::Subscribe::~Subscribe
~Subscribe()
sysrepo::Callback::oper_get_items
virtual int oper_get_items(S_Session session, const char *module_name, const char *path, const char *request_xpath, uint32_t request_id, libyang::S_Data_Node &parent, void *private_data)
Definition: Session.hpp:178
sysrepo::Session::set_error
void set_error(const char *message, const char *path)
sysrepo::Session::set_item
void set_item(const char *path, S_Val value=nullptr, const sr_edit_options_t opts=EDIT_DEFAULT)
sysrepo::Callback::rpc_tree
virtual int rpc_tree(S_Session session, const char *op_path, const libyang::S_Data_Node input, sr_event_t event, uint32_t request_id, libyang::S_Data_Node output, void *private_data)
Definition: Session.hpp:169
sysrepo::Session::validate
void validate(const char *module_name=nullptr, uint32_t timeout_ms=0)
sysrepo::Session::Session
Session(sr_session_ctx_t *sess, S_Deleter deleter=nullptr)
sysrepo::Session::apply_changes
void apply_changes(uint32_t timeout_ms=0, int wait=0)
sysrepo::Subscribe
Class for wrapping sr_subscription_ctx_t.
Definition: Session.hpp:190