diff options
Diffstat (limited to 'test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo')
11 files changed, 2145 insertions, 0 deletions
diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Connection.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Connection.hpp new file mode 100644 index 000000000..eb944f72c --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Connection.hpp @@ -0,0 +1,63 @@ +/** + * @file Connection.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo Connection class header. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * Modifications Copyright (C) 2019 Nokia. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CONNECTION_H +#define CONNECTION_H + +#include <iostream> + +#include "Sysrepo.hpp" +#include "Internal.hpp" + +extern "C" { +#include "../sysrepo.h" +} + +namespace sysrepo { + +/** + * @defgroup classes C++/Python + * @{ + */ + +/** + * @brief Class for wrapping sr_conn_ctx_t. + * @class Connection + */ +class Connection +{ +public: + /** Wrapper for [sr_connect](@ref sr_connect) */ + Connection(const char *app_name, const sr_conn_options_t opts = CONN_DEFAULT); + ~Connection(); + + sr_conn_ctx_t *_conn; + friend class Session; + +private: + sr_conn_options_t _opts; +}; + +/**@} */ +} + +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Internal.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Internal.hpp new file mode 100644 index 000000000..aec62f9f1 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Internal.hpp @@ -0,0 +1,80 @@ +/** + * @file Internal.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo class header for internal C++ classes. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERNAL_H +#define INTERNAL_H + +#include <iostream> +#include <memory> + +extern "C" { +#include "../sysrepo.h" +#include "../sysrepo/trees.h" +} + +namespace sysrepo { + +enum class Free_Type { + VAL, + VALS, + VALS_POINTER, + TREE, + TREES, + TREES_POINTER, + SCHEMAS, + SESSION, +}; + +typedef union value_e { + sr_val_t *_val; + sr_val_t **p_vals; + sr_node_t *_tree; + sr_node_t **p_trees; + sr_schema_t *_sch; + sr_session_ctx_t *_sess; +} value_t; + +typedef union count_e { + size_t _cnt; + size_t *p_cnt; +} count_t; + +class Deleter +{ +public: + Deleter(sr_val_t *val); + Deleter(sr_val_t *vals, size_t cnt); + Deleter(sr_val_t **vals, size_t *cnt); + Deleter(sr_node_t *tree); + Deleter(sr_node_t *trees, size_t cnt); + Deleter(sr_node_t **trees, size_t *cnt); + Deleter(sr_schema_t *sch, size_t cnt); + Deleter(sr_session_ctx_t *sess); + ~Deleter(); + +private: + count_t c; + value_t v; + Free_Type _t; +}; + +} +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Session.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Session.hpp new file mode 100644 index 000000000..02d03ed38 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Session.hpp @@ -0,0 +1,245 @@ +/** + * @file Session.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo Session class header. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SESSION_H +#define SESSION_H + +#include <iostream> +#include <memory> +#include <map> +#include <vector> + +#include "Sysrepo.hpp" +#include "Internal.hpp" +#include "Struct.hpp" +#include "Tree.hpp" +#include "Connection.hpp" +#include "Session.hpp" + +extern "C" { +#include "../sysrepo.h" +} + +namespace sysrepo { + +/** + * @defgroup classes C++/Python + * @{ + */ + +/** + * @brief Class for wrapping sr_session_ctx_t. + * @class Session + */ +class Session +{ + +public: + /** Wrapper for [sr_session_start](@ref sr_session_start) and [sr_session_start_user](@ref sr_session_start_user) + * if user_name is set.*/ + Session(S_Connection conn, sr_datastore_t datastore = (sr_datastore_t) DS_RUNNING, \ + const sr_sess_options_t opts = SESS_DEFAULT, const char *user_name = nullptr); + /** Wrapper for [sr_session_ctx_t](@ref sr_session_ctx_t), for internal use only.*/ + Session(sr_session_ctx_t *sess, sr_sess_options_t opts = SESS_DEFAULT, S_Deleter deleter = nullptr); + /** Wrapper for [sr_session_stop](@ref sr_session_stop) */ + void session_stop(); + /** Wrapper for [sr_session_switch_ds](@ref sr_session_switch_ds) */ + void session_switch_ds(sr_datastore_t ds); + /** Wrapper for [sr_get_last_error](@ref sr_get_last_error) */ + S_Error get_last_error(); + /** Wrapper for [sr_get_last_errors](@ref sr_get_last_errors) */ + S_Errors get_last_errors(); + /** Wrapper for [sr_list_schemas](@ref sr_list_schemas) */ + S_Yang_Schemas list_schemas(); + /** Wrapper for [sr_get_schema](@ref sr_get_schema) */ + std::string get_schema(const char *module_name, const char *revision, + const char *submodule_name, sr_schema_format_t format); + /** Wrapper for [sr_get_item](@ref sr_get_item) */ + S_Val get_item(const char *xpath); + /** Wrapper for [sr_get_items](@ref sr_get_items) */ + S_Vals get_items(const char *xpath); + /** Wrapper for [sr_get_items_iter](@ref sr_get_items_iter) */ + S_Iter_Value get_items_iter(const char *xpath); + /** Wrapper for [sr_get_item_next](@ref sr_get_item_next) */ + S_Val get_item_next(S_Iter_Value iter); + /** Wrapper for [sr_get_subtree](@ref sr_get_subtree) */ + S_Tree get_subtree(const char *xpath, sr_get_subtree_options_t opts = GET_SUBTREE_DEFAULT); + /** Wrapper for [sr_get_subtrees](@ref sr_get_subtrees) */ + S_Trees get_subtrees(const char *xpath, sr_get_subtree_options_t opts = GET_SUBTREE_DEFAULT); + + /** Wrapper for [sr_node_get_child](@ref sr_node_get_child) */ + S_Tree get_child(S_Tree in_tree); + /** Wrapper for [sr_node_get_next_sibling](@ref sr_node_get_next_sibling) */ + S_Tree get_next_sibling(S_Tree in_tree); + /** Wrapper for [sr_node_get_parent](@ref sr_node_get_parent) */ + S_Tree get_parent(S_Tree in_tree); + + /** Wrapper for [sr_set_item](@ref sr_set_item) */ + void set_item(const char *xpath, S_Val value = nullptr, const sr_edit_options_t opts = EDIT_DEFAULT); + /** Wrapper for [sr_set_item_str](@ref sr_set_item_str) */ + void set_item_str(const char *xpath, const char *value, const sr_edit_options_t opts = EDIT_DEFAULT); + /** Wrapper for [sr_delete_item](@ref sr_delete_item) */ + void delete_item(const char *xpath, const sr_edit_options_t opts = EDIT_DEFAULT); + /** Wrapper for [sr_move_item](@ref sr_move_item) */ + void move_item(const char *xpath, const sr_move_position_t position, const char *relative_item = nullptr); + /** Wrapper for [sr_session_refresh](@ref sr_session_refresh) */ + void refresh(); + /** Wrapper for [sr_validate](@ref sr_validate) */ + void validate(); + /** Wrapper for [sr_commit](@ref sr_commit) */ + void commit(); + /** Wrapper for [sr_lock_datastore](@ref sr_lock_datastore) */ + void lock_datastore(); + /** Wrapper for [sr_unlock_datastore](@ref sr_unlock_datastore) */ + void unlock_datastore(); + /** Wrapper for [sr_lock_module](@ref sr_lock_module) */ + void lock_module(const char *module_name); + /** Wrapper for [sr_unlock_module](@ref sr_unlock_module) */ + void unlock_module(const char *module_name); + /** Wrapper for [sr_discard_changes](@ref sr_discard_changes) */ + void discard_changes(); + /** Wrapper for [sr_copy_config](@ref sr_copy_config) */ + void copy_config(const char *module_name, sr_datastore_t src_datastore, sr_datastore_t dst_datastore); + /** Wrapper for [sr_session_set_options](@ref sr_session_set_options) */ + void set_options(const sr_sess_options_t opts); + /** Wrapper for [sr_get_changes_iter](@ref sr_get_changes_iter) */ + S_Iter_Change get_changes_iter(const char *xpath); + /** Wrapper for [sr_get_change_next](@ref sr_get_change_next) */ + S_Change get_change_next(S_Iter_Change iter); + ~Session(); + + /** Wrapper for [sr_rpc_send](@ref sr_rpc_send) */ + S_Vals rpc_send(const char *xpath, S_Vals input); + /** Wrapper for [sr_rpc_send_tree](@ref sr_rpc_send_tree) */ + S_Trees rpc_send(const char *xpath, S_Trees input); + /** Wrapper for [sr_action_send](@ref sr_action_send) */ + S_Vals action_send(const char *xpath, S_Vals input); + /** Wrapper for [sr_action_send_tree](@ref sr_action_send_tree) */ + S_Trees action_send(const char *xpath, S_Trees input); + /** Wrapper for [sr_event_notif_send](@ref sr_event_notif_send) */ + void event_notif_send(const char *xpath, S_Vals values, const sr_ev_notif_flag_t options = SR_EV_NOTIF_DEFAULT); + /** Wrapper for [sr_event_notif_send_tree](@ref sr_event_notif_send_tree) */ + void event_notif_send(const char *xpath, S_Trees trees, const sr_ev_notif_flag_t options = SR_EV_NOTIF_DEFAULT); + + friend class Subscribe; + +private: + sr_session_ctx_t *_sess; + sr_datastore_t _datastore; + sr_sess_options_t _opts; + S_Connection _conn; + S_Deleter _deleter; +}; + +/** + * @brief Helper class for calling C callbacks, C++ only. + * @class Callback + */ +class Callback +{ +public: + Callback(); + virtual ~Callback(); + + /** Wrapper for [sr_module_change_cb](@ref sr_module_change_cb) callback.*/ + virtual int module_change(S_Session session, const char *module_name, sr_notif_event_t event, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_subtree_change_cb](@ref sr_subtree_change_cb) callback.*/ + virtual int subtree_change(S_Session session, const char *xpath, sr_notif_event_t event, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_module_install_cb](@ref sr_module_install_cb) callback.*/ + virtual void module_install(const char *module_name, const char *revision, sr_module_state_t state, void *private_ctx) {return;}; + /** Wrapper for [sr_feature_enable_cb](@ref sr_feature_enable_cb) callback.*/ + virtual void feature_enable(const char *module_name, const char *feature_name, bool enabled, void *private_ctx) {return;}; + /** Wrapper for [sr_rpc_cb](@ref sr_rpc_cb) callback.*/ + virtual int rpc(const char *xpath, const S_Vals input, S_Vals_Holder output, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_action_cb](@ref sr_action_cb) callback.*/ + virtual int action(const char *xpath, const S_Vals input, S_Vals_Holder output, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_rpc_tree_cb](@ref sr_rpc_tree_cb) callback.*/ + virtual int rpc_tree(const char *xpath, const S_Trees input, S_Trees_Holder output, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_action_tree_cb](@ref sr_action_tree_cb) callback.*/ + virtual int action_tree(const char *xpath, const S_Trees input, S_Trees_Holder output, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_dp_get_items_cb](@ref sr_dp_get_items_cb) callback.*/ + virtual int dp_get_items(const char *xpath, S_Vals_Holder vals, uint64_t request_id, void *private_ctx) {return SR_ERR_OK;}; + /** Wrapper for [sr_event_notif_cb](@ref sr_event_notif_cb) callback.*/ + virtual void event_notif(const sr_ev_notif_type_t notif_type, const char *xpath, S_Vals vals, time_t timestamp, void *private_ctx) {return;}; + /** Wrapper for [sr_event_notif_tree_cb](@ref sr_event_notif_tree_cb) callback.*/ + virtual void event_notif_tree(const sr_ev_notif_type_t notif_type, const char *xpath, S_Trees trees, time_t timestamp, void *private_ctx) {return;}; + Callback *get() {return this;}; + + std::map<const char *, void*> private_ctx; +}; + +/** + * @brief Class for wrapping sr_subscription_ctx_t. + * @class Subscribe + */ +class Subscribe +{ + +public: + /** Wrapper for [sr_subscription_ctx_t](@ref sr_subscription_ctx_t), for internal use only.*/ + Subscribe(S_Session sess); + + /** Wrapper for [sr_module_change_subscribe](@ref sr_module_change_subscribe) */ + void module_change_subscribe(const char *module_name, S_Callback callback, void *private_ctx = nullptr, uint32_t priority = 0, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_subtree_change_subscribe](@ref sr_subtree_change_subscribe) */ + void subtree_change_subscribe(const char *xpath, S_Callback callback, void *private_ctx = nullptr, uint32_t priority = 0, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_module_install_subscribe](@ref sr_module_install_subscribe) */ + void module_install_subscribe(S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_feature_enable_subscribe](@ref sr_feature_enable_subscribe) */ + void feature_enable_subscribe(S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_rpc_subscribe](@ref sr_rpc_subscribe) */ + void rpc_subscribe(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_action_subscribe](@ref sr_action_subscribe) */ + void action_subscribe(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_event_notif_subscribe_tree](@ref sr_event_notif_subscribe_tree) */ + void event_notif_subscribe_tree(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_event_notif_subscribe](@ref sr_event_notif_subscribe) */ + void event_notif_subscribe(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_rpc_subscribe_tree](@ref sr_rpc_subscribe_tree) */ + void rpc_subscribe_tree(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_action_subscribe_tree](@ref sr_action_subscribe_tree) */ + void action_subscribe_tree(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + /** Wrapper for [sr_dp_get_items_subscribe](@ref sr_dp_get_items_subscribe) */ + void dp_get_items_subscribe(const char *xpath, S_Callback callback, void *private_ctx = nullptr, sr_subscr_options_t opts = SUBSCR_DEFAULT); + std::vector<S_Callback > cb_list; + + /** Wrapper for [sr_unsubscribe](@ref sr_unsubscribe) */ + void unsubscribe(); + ~Subscribe(); + + /** SWIG specific, internal use only.*/ + sr_subscription_ctx_t **swig_sub() { return &_sub;}; + /** SWIG specific, internal use only.*/ + sr_session_ctx_t *swig_sess() {return _sess->_sess;}; + /** SWIG specific, internal use only.*/ + std::vector<void*> wrap_cb_l; + /** SWIG specific, internal use only.*/ + void additional_cleanup(void *private_ctx) {return;}; + +private: + sr_subscription_ctx_t *_sub; + S_Session _sess; + S_Deleter sess_deleter; +}; + +/**@} */ +} +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Struct.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Struct.hpp new file mode 100644 index 000000000..7f48d562d --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Struct.hpp @@ -0,0 +1,514 @@ +/** + * @file Struct.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo class header for C struts. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef STRUCT_H +#define STRUCT_H + +#include <iostream> +#include <memory> + +#include "Sysrepo.hpp" +#include "Internal.hpp" + +extern "C" { +#include "../sysrepo.h" +} + +namespace sysrepo { + +/** + * @defgroup classes C++/Python + * @{ + */ + +/** + * @brief Class for wrapping sr_data_t. + * @class Data + */ +class Data +{ +public: + /** Wrapper for [sr_data_t](@ref sr_data_t), for internal use only.*/ + Data(sr_data_t data, sr_type_t type, S_Deleter deleter); + ~Data(); + /** Getter for binary data.*/ + char *get_binary() const; + /** Getter for bits.*/ + char *get_bits() const; + /** Getter for bool.*/ + bool get_bool() const; + /** Getter for decimal64.*/ + double get_decimal64() const; + /** Getter for enum.*/ + char *get_enum() const; + /** Getter for identityref.*/ + char *get_identityref() const; + /** Getter for instanceid.*/ + char *get_instanceid() const; + /** Getter for int8.*/ + int8_t get_int8() const; + /** Getter for int16.*/ + int16_t get_int16() const; + /** Getter for int32.*/ + int32_t get_int32() const; + /** Getter for int64.*/ + int64_t get_int64() const; + /** Getter for string.*/ + char *get_string() const; + /** Getter for uint8.*/ + uint8_t get_uint8() const; + /** Getter for uint16.*/ + uint16_t get_uint16() const; + /** Getter for uint32.*/ + uint32_t get_uint32() const; + /** Getter for uint64.*/ + uint64_t get_uint64() const; + +private: + sr_data_t _d; + sr_type_t _t; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_val_t. + * @class Val + */ +class Val +{ +public: + /** Constructor for an empty value.*/ + Val(); + /** Wrapper for [sr_val_t](@ref sr_val_t).*/ + Val(sr_val_t *val, S_Deleter deleter); + /** Constructor for string value, type can be SR_STRING_T, SR_BINARY_T, SR_BITS_T, SR_ENUM_T, + * SR_IDENTITYREF_T and SR_INSTANCEID_T.*/ + Val(const char *val, sr_type_t type = SR_STRING_T); + /** Constructor for bool value.*/ + Val(bool bool_val, sr_type_t type = SR_BOOL_T); + /** Constructor for decimal64 value.*/ + Val(double decimal64_val); + /** Constructor for int8 value, C++ only.*/ + Val(int8_t int8_val, sr_type_t type); + /** Constructor for int16 value, C++ only.*/ + Val(int16_t int16_val, sr_type_t type); + /** Constructor for int32 value, C++ only.*/ + Val(int32_t int32_val, sr_type_t type); + /** Constructor for int64 value, type can be SR_INT8_T, SR_INT16_T, SR_INT32_T, + * SR_INT64_T, SR_UINT8_T, SR_UINT16_T and SR_UINT32_T,*/ + Val(int64_t int64_val, sr_type_t type); + /** Constructor for uint8 value, C++ only.*/ + Val(uint8_t uint8_val, sr_type_t type); + /** Constructor for uint16 value, C++ only.*/ + Val(uint16_t uint16_val, sr_type_t type); + /** Constructor for uint32 value, C++ only.*/ + Val(uint32_t uint32_val, sr_type_t type); + /** Constructor for uint64 value, C++ only.*/ + Val(uint64_t uint64_val, sr_type_t type); + ~Val(); + /** Setter for string value, type can be SR_STRING_T, SR_BINARY_T, SR_BITS_T, SR_ENUM_T, + * SR_IDENTITYREF_T and SR_INSTANCEID_T.*/ + void set(const char *xpath, const char *val, sr_type_t type = SR_STRING_T); + /** Setter for bool value.*/ + void set(const char *xpath, bool bool_val, sr_type_t type = SR_BOOL_T); + /** Setter for decimal64 value.*/ + void set(const char *xpath, double decimal64_val); + /** Setter for int8 value, C++ only.*/ + void set(const char *xpath, int8_t int8_val, sr_type_t type); + /** Setter for int16 value, C++ only.*/ + void set(const char *xpath, int16_t int16_val, sr_type_t type); + /** Setter for int32 value, C++ only.*/ + void set(const char *xpath, int32_t int32_val, sr_type_t type); + /** Setter for int64 value, type can be SR_INT8_T, SR_INT16_T, SR_INT32_T, + * SR_INT64_T, SR_UINT8_T, SR_UINT16_T and SR_UINT32_T,*/ + void set(const char *xpath, int64_t int64_val, sr_type_t type); + /** Setter for uint8 value, C++ only.*/ + void set(const char *xpath, uint8_t uint8_val, sr_type_t type); + /** Setter for uint16 value, C++ only.*/ + void set(const char *xpath, uint16_t uint16_val, sr_type_t type); + /** Setter for uint32 value, C++ only.*/ + void set(const char *xpath, uint32_t uint32_val, sr_type_t type); + /** Setter for uint64 value, C++ only.*/ + void set(const char *xpath, uint64_t uint64_val, sr_type_t type); + /** Getter for xpath.*/ + char *xpath() {return _val->xpath;}; + /** Setter for xpath.*/ + void xpath_set(char *xpath); + /** Getter for type.*/ + sr_type_t type() {return _val->type;}; + /** Getter for dflt.*/ + bool dflt() {return _val->dflt;}; + /** Setter for dflt.*/ + void dflt_set(bool data) {_val->dflt = data;}; + /** Getter for data.*/ + S_Data data() {S_Data data(new Data(_val->data, _val->type, _deleter)); return data;}; + /** Wrapper for [sr_print_val_mem](@ref sr_print_val_mem) */ + std::string to_string(); + /** Wrapper for [sr_val_to_string](@ref sr_val_to_string) */ + std::string val_to_string(); + /** Wrapper for [sr_dup_val](@ref sr_dup_val) */ + S_Val dup(); + + friend class Session; + friend class Subscribe; + +private: + sr_val_t *_val; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_val_t array. + * @class Vals + */ +class Vals +{ +public: + /** Wrapper for [sr_val_t](@ref sr_val_t) array, internal use only.*/ + Vals(const sr_val_t *vals, const size_t cnt, S_Deleter deleter = nullptr); + /** Wrapper for [sr_val_t](@ref sr_val_t) array, internal use only.*/ + Vals(sr_val_t **vals, size_t *cnt, S_Deleter deleter = nullptr); + /** Wrapper for [sr_val_t](@ref sr_val_t) array, create n-array.*/ + Vals(size_t cnt); + /** Constructor for an empty [sr_val_t](@ref sr_val_t) array.*/ + Vals(); + ~Vals(); + /** Getter for [sr_val_t](@ref sr_val_t), get the n-th element in array.*/ + S_Val val(size_t n); + /** Getter for array size */ + size_t val_cnt() {return _cnt;}; + /** Wrapper for [sr_dup_values](@ref sr_dup_values) */ + S_Vals dup(); + + friend class Session; + friend class Subscribe; + +private: + size_t _cnt; + sr_val_t *_vals; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_val_t in callbacks. + * @class Vals_holder + */ +class Vals_Holder +{ +public: + /** Wrapper for [sr_val_t](@ref sr_val_t) array, used only in callbacks.*/ + Vals_Holder(sr_val_t **vals, size_t *cnt); + /** Create [sr_val_t](@ref sr_val_t) array of n size.*/ + S_Vals allocate(size_t n); + ~Vals_Holder(); + +private: + size_t *p_cnt; + sr_val_t **p_vals; + bool _allocate; +}; + +/** + * @brief Class for wrapping sr_val_iter_t. + * @class Val_Iter + */ +class Val_Iter +{ +public: + /** Wrapper for [sr_val_iter_t](@ref sr_val_iter_t).*/ + Val_Iter(sr_val_iter_t *iter = nullptr); + ~Val_Iter(); + /** Getter for [sr_val_iter_t](@ref sr_val_iter_t).*/ + sr_val_iter_t *iter() {return _iter;}; + +private: + sr_val_iter_t *_iter; +}; + +/** + * @brief Class for wrapping sr_change_iter_t. + * @class Change_Iter + */ +class Change_Iter +{ +public: + /** Wrapper for [sr_change_iter_t](@ref sr_change_iter_t).*/ + Change_Iter(sr_change_iter_t *iter = nullptr); + ~Change_Iter(); + /** Getter for [sr_change_iter_t](@ref sr_change_iter_t).*/ + sr_change_iter_t *iter() {return _iter;}; + +private: + sr_change_iter_t *_iter; +}; + +/** + * @brief Class for wrapping sr_error_info_t. + * @class Error + */ +class Error +{ +public: + /** Constructor for an empty [sr_error_info_t](@ref sr_error_info_t).*/ + Error(); + /** Wrapper for [sr_error_info_t](@ref sr_error_info_t).*/ + Error(const sr_error_info_t *info); + ~Error(); + /** Getter for message.*/ + const char *message() const {if (_info) return _info->message; else return nullptr;}; + /** Getter for xpath.*/ + const char *xpath() const {if (_info) return _info->xpath; else return nullptr;}; + + friend class Session; + +private: + const sr_error_info_t *_info; +}; + +/** + * @brief Class for wrapping sr_error_info_t array. + * @class Errors + */ +class Errors +{ +public: + /** Constructor for an empty [sr_error_info_t](@ref sr_error_info_t) array.*/ + Errors(); + ~Errors(); + /** Getter for [sr_error_info_t](@ref sr_error_info_t), get the n-th element in array.*/ + S_Error error(size_t n); + /** Getter for array size.*/ + size_t error_cnt() {return _cnt;}; + + friend class Session; + +private: + size_t _cnt; + const sr_error_info_t *_info; +}; + +/** + * @brief Class for wrapping sr_sch_revision_t array. + * @class Schema_Revision + */ +class Schema_Revision +{ +public: + /** Wrapper for [sr_sch_revision_t](@ref sr_sch_revision_t).*/ + Schema_Revision(sr_sch_revision_t rev); + ~Schema_Revision(); + /** Getter for revision.*/ + const char *revision() const {return _rev.revision;}; + /** Getter for file_path_yang.*/ + const char *file_path_yang() const {return _rev.file_path_yang;}; + /** Getter for file_path_yin.*/ + const char *file_path_yin() const {return _rev.file_path_yin;}; + +private: + sr_sch_revision_t _rev; +}; + +/** + * @brief Class for wrapping sr_sch_submodule_t. + * @class Schema_Submodule + */ +class Schema_Submodule +{ +public: + /** Wrapper for [sr_sch_submodule_t](@ref sr_sch_submodule_t).*/ + Schema_Submodule(sr_sch_submodule_t sub, S_Deleter deleter); + ~Schema_Submodule(); + /** Getter for submodule_name.*/ + const char *submodule_name() const {return _sub.submodule_name;}; + /** Getter for revision.*/ + S_Schema_Revision revision(); + +private: + sr_sch_submodule_t _sub; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_schema_t. + * @class Yang_Schema + */ +class Yang_Schema +{ +public: + /** Wrapper for [sr_schema_t](@ref sr_schema_t).*/ + Yang_Schema(sr_schema_t *sch, S_Deleter deleter); + ~Yang_Schema(); + /** Getter for module_name.*/ + const char *module_name() const {return _sch->module_name;}; + /** Getter for ns.*/ + const char *ns() const {return _sch->ns;}; + /** Getter for prefix.*/ + const char *prefix() const {return _sch->prefix;}; + /** Getter for implemented.*/ + bool implemented() const {return _sch->implemented;}; + /** Getter for revision.*/ + S_Schema_Revision revision(); + /** Getter for submodule.*/ + S_Schema_Submodule submodule(size_t n); + /** Getter for submodule_cnt.*/ + size_t submodule_cnt() const {return _sch->submodule_count;}; + /** Getter for enabled_features.*/ + char *enabled_features(size_t n); + /** Getter for enabled_features_cnt.*/ + size_t enabled_feature_cnt() const {return _sch->enabled_feature_cnt;}; + + friend class Session; + +private: + sr_schema_t *_sch; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_schema_t array. + * @class Yang_Schemas + */ +class Yang_Schemas +{ +public: + /** Constructor for an empty [sr_schema_t](@ref sr_schema_t) array.*/ + Yang_Schemas(); + ~Yang_Schemas(); + /** Getter for [sr_schema_t](@ref sr_schema_t) array, get the n-th element in array.*/ + S_Yang_Schema schema(size_t n); + /** Getter for array size.*/ + size_t schema_cnt() const {return _cnt;}; + + friend class Session; + +private: + size_t _cnt; + sr_schema_t *_sch; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_fd_change_t. + * @class Fd_Change + */ +class Fd_Change +{ +public: + /** Wrapper for [sr_fd_change_t](@ref sr_fd_change_t).*/ + Fd_Change(sr_fd_change_t *ch); + ~Fd_Change(); + /** Getter for fd.*/ + int fd() const {return _ch->fd;}; + /** Getter for events.*/ + int events() const {return _ch->events;}; + /** Getter for action.*/ + sr_fd_action_t action() const {return _ch->action;}; + +private: + sr_fd_change_t *_ch; +}; + +/** + * @brief Class for wrapping sr_fd_change_t array. + * @class Fd_Changes + */ +class Fd_Changes +{ +public: + /** Wrapper for [sr_fd_change_t](@ref sr_fd_change_t) array.*/ + Fd_Changes(sr_fd_change_t *ch, size_t cnt); + ~Fd_Changes(); + /** Getter for [sr_fd_change_t](@ref sr_fd_change_t) array, get the n-th element in array.*/ + S_Fd_Change fd_change(size_t n); + +private: + sr_fd_change_t *_ch; + size_t _cnt; +}; + +/** + * @brief Class for wrapping sr_val_iter_t. + * @class Fd_Changes + */ +class Iter_Value +{ + +public: + /** Wrapper for [sr_val_iter_t](@ref sr_val_iter_t).*/ + Iter_Value(sr_val_iter_t *iter = nullptr); + ~Iter_Value(); + /** Setter for [sr_val_iter_t](@ref sr_val_iter_t).*/ + void Set(sr_val_iter_t *iter); + + friend class Session; + +private: + sr_val_iter_t *_iter; +}; + +/** + * @brief Class for wrapping sr_change_iter_t. + * @class Iter_Change + */ +class Iter_Change +{ + +public: + /** Wrapper for [sr_change_iter_t](@ref sr_change_iter_t).*/ + Iter_Change(sr_change_iter_t *iter = nullptr); + ~Iter_Change(); + + friend class Session; + +private: + sr_change_iter_t *_iter; +}; + +/** + * @brief Class for wrapping sr_change_oper_t. + * @class Change + */ +class Change +{ +public: + /** Constructor for an empty [sr_change_oper_t](@ref sr_change_oper_t).*/ + Change(); + ~Change(); + /** Getter for sr_change_oper_t.*/ + sr_change_oper_t oper() {return _oper;}; + /** Getter for new sr_val_t.*/ + S_Val new_val(); + /** Getter for old sr_val_t.*/ + S_Val old_val(); + + friend class Session; + +private: + sr_change_oper_t _oper; + sr_val_t *_new; + sr_val_t *_old; + S_Deleter _deleter_new; + S_Deleter _deleter_old; +}; + +/**@} */ +} +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Sysrepo.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Sysrepo.hpp new file mode 100644 index 000000000..d3b76483f --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Sysrepo.hpp @@ -0,0 +1,177 @@ +/** + * @file Sysrepo.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo Sysrepo class header. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSREPO_H +#define SYSREPO_H + +#include <iostream> +#include <memory> +#include <stdexcept> + +#include "Internal.hpp" + +extern "C" { +#include "../sysrepo.h" +} + +namespace sysrepo { + +/** + * @defgroup classes C++/Python + * @{ + */ + +class Iter_Value; +class Iter_Change; +class Session; +class Subscribe; +class Connection; +class Operation; +class Schema_Content; +class Error; +class Errors; +class Data; +class Schema_Revision; +class Schema_Submodule; +class Yang_Schema; +class Yang_Schemas; +class Fd_Change; +class Fd_Changes; +class Val; +class Vals_Holder; +class Vals; +class Tree; +class Trees; +class Trees_Holder; +class Xpath_Ctx; +class Logs; +class Change; +class Counter; +class Callback; +class Deleter; + +#ifdef SWIGLUA +using S_Iter_Value = Iter_Value*; +using S_Iter_Change = Iter_Change*; +using S_Session = Session*; +using S_Subscribe = Subscribe*; +using S_Connection = Connection*; +using S_Operation = Operation*; +using S_Schema_Content = Schema_Content*; +using S_Error = Error*; +using S_Errors = Errors*; +using S_Data = Data*; +using S_Schema_Revision = Schema_Revision*; +using S_Schema_Submodule = Schema_Submodule*; +using S_Yang_Schema = Yang_Schema*; +using S_Yang_Schemas = Yang_Schemas*; +using S_Fd_Change = Fd_Change*; +using S_Fd_Changes = Fd_Changes*; +using S_Val = Val*; +using S_Vals_Holder = Vals_Holder*; +using S_Vals = Vals*; +using S_Tree = Tree*; +using S_Trees = Trees*; +using S_Trees_Holder = Trees_Holder*; +using S_Xpath_Ctx = Xpath_Ctx*; +using S_Logs = Logs*; +using S_Change = Change*; +using S_Counter = Counter*; +using S_Callback = Callback*; +#else +using S_Iter_Value = std::shared_ptr<Iter_Value>; +using S_Iter_Change = std::shared_ptr<Iter_Change>; +using S_Session = std::shared_ptr<Session>; +using S_Subscribe = std::shared_ptr<Subscribe>; +using S_Connection = std::shared_ptr<Connection>; +using S_Operation = std::shared_ptr<Operation>; +using S_Schema_Content = std::shared_ptr<Schema_Content>; +using S_Error = std::shared_ptr<Error>; +using S_Errors = std::shared_ptr<Errors>; +using S_Data = std::shared_ptr<Data>; +using S_Schema_Revision = std::shared_ptr<Schema_Revision>; +using S_Schema_Submodule = std::shared_ptr<Schema_Submodule>; +using S_Yang_Schema = std::shared_ptr<Yang_Schema>; +using S_Yang_Schemas = std::shared_ptr<Yang_Schemas>; +using S_Fd_Change = std::shared_ptr<Fd_Change>; +using S_Fd_Changes = std::shared_ptr<Fd_Changes>; +using S_Val = std::shared_ptr<Val>; +using S_Vals_Holder = std::shared_ptr<Vals_Holder>; +using S_Vals = std::shared_ptr<Vals>; +using S_Tree = std::shared_ptr<Tree>; +using S_Trees = std::shared_ptr<Trees>; +using S_Trees_Holder = std::shared_ptr<Trees_Holder>; +using S_Xpath_Ctx = std::shared_ptr<Xpath_Ctx>; +using S_Logs = std::shared_ptr<Logs>; +using S_Change = std::shared_ptr<Change>; +using S_Counter = std::shared_ptr<Counter>; +using S_Callback = std::shared_ptr<Callback>; +using S_Deleter = std::shared_ptr<Deleter>; +#endif + +/* this is a workaround for python not recognizing + * enum's in function default values */ +static const int SESS_DEFAULT = SR_SESS_DEFAULT; +static const int DS_RUNNING = SR_DS_RUNNING; +static const int EDIT_DEFAULT = SR_EDIT_DEFAULT; +static const int CONN_DEFAULT = SR_CONN_DEFAULT; +static const int GET_SUBTREE_DEFAULT = SR_GET_SUBTREE_DEFAULT; +static const int SUBSCR_DEFAULT = SR_SUBSCR_DEFAULT; + +#ifdef SWIG +// https://github.com/swig/swig/issues/1158 +void throw_exception (int error); +#else +void throw_exception [[noreturn]] (int error); +#endif + +/** + * @brief Class for wrapping sr_error_t. + * @class sysrepo_exception + */ +class sysrepo_exception : public std::runtime_error +{ +public: + explicit sysrepo_exception(const sr_error_t error_code); + virtual ~sysrepo_exception() override; + sr_error_t error_code() const; +private: + sr_error_t m_error_code; +}; + +/** + * @brief Class for wrapping ref sr_log_level_t. + * @class Logs + */ +class Logs +{ +public: + Logs(); + ~Logs(); + /** Wrapper for [sr_log_stderr](@ref sr_log_stderr) */ + void set_stderr(sr_log_level_t log_level); + /** Wrapper for [sr_log_syslog](@ref sr_log_syslog) */ + void set_syslog(sr_log_level_t log_level); +}; + +/**@} */ +} +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Tree.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Tree.hpp new file mode 100644 index 000000000..31f3abd47 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Tree.hpp @@ -0,0 +1,176 @@ +/** + * @file Trees.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo class header for C header trees.h. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TREE_H +#define TREE_H + +#include "Sysrepo.hpp" +#include "Struct.hpp" + +extern "C" { +#include "../sysrepo.h" +#include "../sysrepo/trees.h" +} + +namespace sysrepo { + +/** + * @defgroup classes C++/Python + * @{ + */ + +/** + * @brief Class for wrapping sr_node_t. + * @class Tree + */ +class Tree +{ +public: + /** Constructor for an empty [sr_node_t](@ref sr_node_t).*/ + Tree(); + /** Wrapper for [sr_new_tree](@ref sr_new_tree).*/ + Tree(const char *root_name, const char *root_module_name); + /** Wrapper for [sr_node_t](@ref sr_node_t).*/ + Tree(sr_node_t *tree, S_Deleter deleter); + /** Wrapper for [sr_dup_tree](@ref sr_dup_tree).*/ + S_Tree dup(); + /** Get the node value.*/ + S_Tree node(); + /** Getter for name.*/ + char *name() {return _node->name;}; + /** Getter for type.*/ + sr_type_t type() {return _node->type;}; + /** Getter for dflt.*/ + bool dflt() {return _node->dflt;}; + /** Getter for data.*/ + S_Data data() {S_Data data(new Data(_node->data, _node->type, _deleter)); return data;}; + /** Getter for module_name.*/ + char *module_name() {return _node->module_name;}; + /** Getter for parent.*/ + S_Tree parent(); + /** Getter for next.*/ + S_Tree next(); + /** Getter for prev.*/ + S_Tree prev(); + /** Getter for first_child.*/ + S_Tree first_child(); + /** Getter for last_child.*/ + S_Tree last_child(); + /** Wrapper for [sr_print_tree_mem](@ref sr_print_tree_mem).*/ + std::string to_string(int depth_limit); + /** Wrapper for [sr_print_val_mem](@ref sr_print_val_mem).*/ + std::string value_to_string(); + /** Wrapper for [sr_node_set_name](@ref sr_node_set_name).*/ + void set_name(const char *name); + /** Wrapper for [sr_node_set_module](@ref sr_node_set_module).*/ + void set_module(const char *module_name); + /** Wrapper for [sr_node_set_str_data](@ref sr_node_set_str_data).*/ + void set_str_data(sr_type_t type, const char *string_val); + /** Wrapper for [sr_node_add_child](@ref sr_node_add_child).*/ + void add_child(const char *child_name, const char *child_module_name, S_Tree child); + /** Setter for string value, type can be SR_STRING_T, SR_BINARY_T, SR_BITS_T, SR_ENUM_T, + * SR_IDENTITYREF_T and SR_INSTANCEID_T.*/ + void set(const char *val, sr_type_t type = SR_STRING_T); + /** Setter for bool value.*/ + void set(bool bool_val, sr_type_t type = SR_BOOL_T); + /** Setter for decimal64 value.*/ + void set(double decimal64_val); + /** Setter for int8 value, C++ only.*/ + void set(int8_t int8_val, sr_type_t type); + /** Setter for int16 value, C++ only.*/ + void set(int16_t int16_val, sr_type_t type); + /** Setter for int32 value, C++ only.*/ + void set(int32_t int32_val, sr_type_t type); + /** Setter for int64 value, type can be SR_INT8_T, SR_INT16_T, SR_INT32_T, + * SR_INT64_T, SR_UINT8_T, SR_UINT16_T and SR_UINT32_T,*/ + void set(int64_t int64_val, sr_type_t type); + /** Setter for uint8 value, C++ only.*/ + void set(uint8_t uint8_val, sr_type_t type); + /** Setter for uint16 value, C++ only.*/ + void set(uint16_t uint16_val, sr_type_t type); + /** Setter for uint32 value, C++ only.*/ + void set(uint32_t uint32_val, sr_type_t type); + /** Setter for uint64 value, C++ only.*/ + void set(uint64_t uint64_val, sr_type_t type); + ~Tree(); + + friend class Session; + friend class Subscribe; + +private: + sr_node_t *_node; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_node_t array. + * @class Trees + */ +class Trees +{ +public: + /** Constructor for an empty [sr_node_t](@ref sr_node_t) array.*/ + Trees(); + /** Wrapper for [sr_node_t](@ref sr_node_t) array, create n-array.*/ + Trees(size_t n); + /** Wrapper for [sr_node_t](@ref sr_node_t) array, internal use only.*/ + Trees(sr_node_t **trees, size_t *cnt, S_Deleter deleter = nullptr); + /** Wrapper for [sr_node_t](@ref sr_node_t) array, internal use only.*/ + Trees(const sr_node_t *trees, const size_t n, S_Deleter deleter = nullptr); + /** Getter for [sr_node_t](@ref sr_node_t), get the n-th element in array.*/ + S_Tree tree(size_t n); + /** Wrapper for [sr_dup_trees](@ref sr_dup_trees) */ + S_Trees dup(); + /** Getter for array size */ + size_t tree_cnt() {return _cnt;}; + ~Trees(); + + friend class Session; + friend class Subscribe; + +private: + size_t _cnt; + sr_node_t *_trees; + S_Deleter _deleter; +}; + +/** + * @brief Class for wrapping sr_node_t in callbacks. + * @class Trees_Holder + */ +class Trees_Holder +{ +public: + /** Wrapper for [sr_node_t](@ref sr_node_t) array, used only in callbacks.*/ + Trees_Holder(sr_node_t **trees, size_t *cnt); + /** Create [sr_node_t](@ref sr_node_t) array of n size.*/ + S_Trees allocate(size_t n); + ~Trees_Holder(); + +private: + size_t *p_cnt; + sr_node_t **p_trees; + bool _allocate; +}; + +/**@} */ +} +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Xpath.hpp b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Xpath.hpp new file mode 100644 index 000000000..4406134da --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Xpath.hpp @@ -0,0 +1,97 @@ +/** + * @file Xpath.h + * @author Mislav Novakovic <mislav.novakovic@sartura.hr> + * @brief Sysrepo class header for C header xpath_utils.h. + * + * @copyright + * Copyright 2016 Deutsche Telekom AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef XPATH_H +#define XPATH_H + +#include <iostream> + +extern "C" { +#include "../sysrepo/xpath.h" +} + +namespace sysrepo { + +/** + * @defgroup classes C++/Python + * @{ + */ + +/** + * @brief Class for wrapping sr_xpath_ctx_t. + * @class Xpath_Ctx + */ +class Xpath_Ctx +{ +public: + /** Constructor for an empty [sr_xpath_ctx_t](@ref sr_xpath_ctx_t).*/ + Xpath_Ctx(); + /** Getter for begining.*/ + char *begining() {if (_state != nullptr) return _state->begining; return nullptr;}; + /** Getter for current_node.*/ + char *current_node() {if (_state != nullptr) return _state->current_node; return nullptr;}; + /** Getter for replaced_position.*/ + char *replaced_position() {if (_state != nullptr) return _state->replaced_position; return nullptr;}; + /** Getter for replaced_char.*/ + char replaced_char() {if (_state != nullptr) return _state->replaced_char; return (char) 0;}; + ~Xpath_Ctx(); + /** Wrapper for [sr_xpath_next_node](@ref sr_xpath_next_node).*/ + char *next_node(char *xpath) {return sr_xpath_next_node(xpath, _state);}; + /** Wrapper for [sr_xpath_next_node_with_ns](@ref sr_xpath_next_node_with_ns).*/ + char *next_node_with_ns(char *xpath) {return sr_xpath_next_node_with_ns(xpath, _state);}; + /** Wrapper for [sr_xpath_next_key_name](@ref sr_xpath_next_key_name).*/ + char *next_key_name(char *xpath) {return sr_xpath_next_key_name(xpath, _state);}; + /** Wrapper for [sr_xpath_next_key_value](@ref sr_xpath_next_key_value).*/ + char *next_key_value(char *xpath) {return sr_xpath_next_key_value(xpath, _state);}; + /** Wrapper for [sr_xpath_node](@ref sr_xpath_node).*/ + char *node(char *xpath, const char *node_name) {return sr_xpath_node(xpath, node_name, _state);}; + /** Wrapper for [sr_xpath_node_rel](@ref sr_xpath_node_rel).*/ + char *node_rel(char *xpath, const char *node_name) {return sr_xpath_node_rel(xpath, node_name, _state);}; + /** Wrapper for [sr_xpath_node_idx](@ref sr_xpath_node_idx).*/ + char *node_idx(char *xpath, size_t index) {return sr_xpath_node_idx(xpath, index, _state);}; + /** Wrapper for [sr_xpath_node_idx_rel](@ref sr_xpath_node_idx_rel).*/ + char *node_idx_rel(char *xpath, size_t index) {return sr_xpath_node_idx_rel(xpath, index, _state);}; + /** Wrapper for [sr_xpath_node_key_value](@ref sr_xpath_node_key_value).*/ + char *node_key_value(char *xpath, const char *key) {return sr_xpath_node_key_value(xpath, key, _state);}; + /** Wrapper for [sr_xpath_node_key_value_idx](@ref sr_xpath_node_key_value_idx).*/ + char *node_key_value_idx(char *xpath, size_t index) {return sr_xpath_node_key_value_idx(xpath, index, _state);}; + /** Wrapper for [sr_xpath_key_value](@ref sr_xpath_key_value).*/ + char *key_value(char *xpath, const char *node_name, const char *key_name) { + return sr_xpath_key_value(xpath, node_name, key_name, _state);}; + /** Wrapper for [sr_xpath_key_value_idx](@ref sr_xpath_key_value_idx).*/ + char *key_value_idx(char *xpath, size_t node_index, size_t key_index) { + return sr_xpath_key_value_idx(xpath, node_index, key_index, _state);}; + /** Wrapper for [sr_xpath_last_node](@ref sr_xpath_last_node).*/ + char *last_node(char *xpath) {return sr_xpath_last_node(xpath, _state);}; + /** Wrapper for [sr_xpath_node_name](@ref sr_xpath_node_name).*/ + char *node_name(const char *xpath) {return sr_xpath_node_name(xpath);}; + /** Wrapper for [sr_xpath_node_name_eq](@ref sr_xpath_node_name_eq).*/ + bool node_name_eq(const char *xpath, const char *node_str) {return sr_xpath_node_name_eq(xpath, node_str);}; + /** Wrapper for [sr_xpath_recover](@ref sr_xpath_recover).*/ + void recover() {return sr_xpath_recover(_state);}; + +private: + sr_xpath_ctx_t *_state; +}; + +/**@} */ +} +#endif diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/plugins.h b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/plugins.h new file mode 100644 index 000000000..3c4efc9a9 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/plugins.h @@ -0,0 +1,139 @@ +/** + * @file plugins.h + * @author Rastislav Szabo <raszabo@cisco.com>, Lukas Macko <lmacko@cisco.com> + * @brief Sysrepo helpers for plugin integrations. + * + * @copyright + * Copyright 2016 Cisco Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSREPO_PLUGINS_H_ +#define SYSREPO_PLUGINS_H_ + +#include <stdio.h> +#include <stdint.h> +#include <errno.h> +#include <string.h> +#include <syslog.h> + +#include <sysrepo.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup plugin_utils Plugin Utilities + * @{ + * + * @brief Utilities that expand sysrepo API aimed for sysrepo plugins. + * + * The provided features are: logging macros. + */ + +/** Prints an error message (with format specifiers). */ +#define SRP_LOG_ERR(MSG, ...) SRP_LOG__INTERNAL(SR_LL_ERR, MSG, __VA_ARGS__) +/** Prints an error message. */ +#define SRP_LOG_ERR_MSG(MSG) SRP_LOG__INTERNAL(SR_LL_ERR, MSG "%s", "") + +/** Prints a warning message (with format specifiers). */ +#define SRP_LOG_WRN(MSG, ...) SRP_LOG__INTERNAL(SR_LL_WRN, MSG, __VA_ARGS__) +/** Prints a warning message. */ +#define SRP_LOG_WRN_MSG(MSG) SRP_LOG__INTERNAL(SR_LL_WRN, MSG "%s", "") + +/** Prints an informational message (with format specifiers). */ +#define SRP_LOG_INF(MSG, ...) SRP_LOG__INTERNAL(SR_LL_INF, MSG, __VA_ARGS__) +/** Prints an informational message. */ +#define SRP_LOG_INF_MSG(MSG) SRP_LOG__INTERNAL(SR_LL_INF, MSG "%s", "") + +/** Prints a development debug message (with format specifiers). */ +#define SRP_LOG_DBG(MSG, ...) SRP_LOG__INTERNAL(SR_LL_DBG, MSG, __VA_ARGS__) +/** Prints a development debug message. */ +#define SRP_LOG_DBG_MSG(MSG) SRP_LOG__INTERNAL(SR_LL_DBG, MSG "%s", "") + +/**@} plugin_utils */ + + +//////////////////////////////////////////////////////////////////////////////// +// Internal macros (not intended to be used directly) +//////////////////////////////////////////////////////////////////////////////// + +#ifdef NDEBUG + #define SRP_LOG_PRINT_FUNCTION_NAMES (0) /**< Do not print function names in messages */ +#else + #define SRP_LOG_PRINT_FUNCTION_NAMES (1) /**< Every message will include the function that generated the output */ +#endif + +extern volatile uint8_t sr_ll_stderr; /**< Holds current level of stderr debugs. */ +extern volatile uint8_t sr_ll_syslog; /**< Holds current level of syslog debugs. */ + +/** + * @brief Matching log level to message beginning + */ +#define SRP_LOG__LL_STR(LL) \ + ((SR_LL_DBG == LL) ? "DBG" : \ + (SR_LL_INF == LL) ? "INF" : \ + (SR_LL_WRN == LL) ? "WRN" : \ + "ERR") + +/** + * @brief Matching log level to message macros + */ +#define SRP_LOG__LL_FACILITY(LL) \ + ((SR_LL_DBG == LL) ? LOG_DEBUG : \ + (SR_LL_INF == LL) ? LOG_INFO : \ + (SR_LL_WRN == LL) ? LOG_WARNING : \ + LOG_ERR) + +#if SRP_LOG_PRINT_FUNCTION_NAMES +/** + * @brief Syslog output macro with function names. + */ +#define SRP_LOG__SYSLOG(LL, MSG, ...) \ + syslog(SRP_LOG__LL_FACILITY(LL), "[%s] (%s:%d) " MSG, SRP_LOG__LL_STR(LL), __func__, __LINE__, __VA_ARGS__); +/** + * @brief Stderr output macro with function names. + */ +#define SRP_LOG__STDERR(LL, MSG, ...) \ + fprintf(stderr, "[%s] (%s:%d) " MSG "\n", SRP_LOG__LL_STR(LL), __func__, __LINE__, __VA_ARGS__); +#else +/** + * @brief Syslog output macro without function names. + */ +#define SRP_LOG__SYSLOG(LL, MSG, ...) \ + syslog(SRP_LOG__LL_FACILITY(LL), "[%s] " MSG, SRP_LOG__LL_STR(LL), __VA_ARGS__); +/** + * @brief Stderr output macro without function names. + */ +#define SRP_LOG__STDERR(LL, MSG, ...) \ + fprintf(stderr, "[%s] " MSG "\n", SRP_LOG__LL_STR(LL), __VA_ARGS__); +#endif + +/** + * @brief Internal outptu macro. + */ +#define SRP_LOG__INTERNAL(LL, MSG, ...) \ + do { \ + if (sr_ll_stderr >= LL) \ + SRP_LOG__STDERR(LL, MSG, __VA_ARGS__) \ + if (sr_ll_syslog >= LL) \ + SRP_LOG__SYSLOG(LL, MSG, __VA_ARGS__) \ + } while(0) + +#ifdef __cplusplus +} +#endif + +#endif /* SYSREPO_PLUGINS_H_ */ diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/trees.h b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/trees.h new file mode 100644 index 000000000..8db1602e6 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/trees.h @@ -0,0 +1,226 @@ +/** + * @file trees.h + * @author Rastislav Szabo <raszabo@cisco.com>, Lukas Macko <lmacko@cisco.com>, + * Milan Lenco <milan.lenco@pantheon.tech> + * @brief Functions for simplified manipulation with Sysrepo trees. + * + * @copyright + * Copyright 2016 Cisco Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSREPO_TREES_H_ +#define SYSREPO_TREES_H_ + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup trees Tree Manipulation Utilities + * @{ + * + * @brief Set of functions facilitating simplified manipulation and traversal + * of Sysrepo trees. As there are many connections between the tree nodes + * and also some internal attributes associated with each node, it is actually + * recommended to use these function rather than to allocate and initialize trees + * manually, which is very likely to lead to time-wasting and hard-to-debug programming + * errors. + * Iterative tree loading (@see SR_GET_SUBTREE_ITERATIVE) even requires to use + * designated functions for tree traversal -- ::sr_node_get_child and ::sr_node_get_next_sibling. + * + * Another added benefit of using these function is that the trees created using + * ::sr_new_tree and ::sr_new_trees will be allocated using the Sysrepo's own memory management + * (if enabled) which was proven to be more efficient for larger data sets + * (far less copying, quicker conversion to/from google protocol buffer messages, + * stable memory footprint, etc.). + */ + +/** + * @brief Allocate an instance of Sysrepo tree. The newly allocated tree has only + * one node -- the tree root -- and can be expanded to its full desired size + * through a repeated use of the function ::sr_node_add_child. + * + * @param [in] root_name Name for the newly allocated tree root. Can be NULL. + * @param [in] root_module_name Name of the module that defines scheme of the tree root. + * Can be NULL. + * @param [out] tree Returned newly allocated Sysrepo tree. + */ +int sr_new_tree(const char *root_name, const char *root_module_name, sr_node_t **tree); + +/** + * @brief Allocate an array of sysrepo trees (uninitialized tree roots). + * + * @param [in] tree_cnt Length of the array to allocate. + * @param [out] trees Returned newly allocated array of trees. + */ +int sr_new_trees(size_t tree_cnt, sr_node_t **trees); + +/** + * @brief Reallocate an array of sysrepo trees (uninitialized tree roots). + * + * @param [in] old_tree_cnt Current length of the tree array. + * @param [in] new_tree_cnt Desired length of the tree array. + * @param [in,out] trees Returned newly allocated/enlarged array of trees. + */ +int sr_realloc_trees(size_t old_tree_cnt, size_t new_tree_cnt, sr_node_t **trees); + +/** + * @brief Set/change name of a Sysrepo node. + * + * @param [in] node Sysrepo node to change the name of. + * @param [in] name Name to set. + */ +int sr_node_set_name(sr_node_t *node, const char *name); + +/** + * @brief Set/change module of a Sysrepo node. + * + * @param [in] node Sysrepo node to change the module of. + * @param [in] module_name Module name to set. + */ +int sr_node_set_module(sr_node_t *node, const char *module_name); + +/** + * @brief Store data of string type into the Sysrepo node data. + * + * @param [in] node Sysrepo node to edit. + * @param [in] type Exact type of the data. + * @param [in] string_val String value to set. + */ +int sr_node_set_str_data(sr_node_t *node, sr_type_t type, const char *string_val); + +/** + * @brief Store data of string type into the Sysrepo node data. The actual data + * will be built from the a format string and a variable arguments list. + * + * @param [in] node Sysrepo node to edit. + * @param [in] type Exact type of the data. + * @param [in] format Format string used to build the data. + */ +int sr_node_build_str_data(sr_node_t *node, sr_type_t type, const char *format, ...); + +/** + * @brief Create a new child for a given Sysrepo node. + * + * @param [in] parent Sysrepo node that should be parent of the newly created node. + * @param [in] child_name Name of the newly created child node. Can be NULL. + * @param [in] child_module_name Name of the module that defines scheme of the newly created + * child node. Can be NULL. + * @param [out] child Returned newly allocated child node. + */ +int sr_node_add_child(sr_node_t *parent, const char *child_name, const char *child_module_name, + sr_node_t **child); + +/** + * @brief Duplicate node and all its descendants (with or without Sysrepo memory context) + * into a new instance of Sysrepo tree with memory context. + * + * @param [in] tree Sysrepo tree to duplicate. + * @param [out] tree_dup Returned duplicate of the input tree. + */ +int sr_dup_tree(const sr_node_t *tree, sr_node_t **tree_dup); + +/** + * @brief Duplicate an array of trees (with or without Sysrepo memory context) into a new + * array of trees with memory context. + * + * @param [in] trees Array of sysrepo trees to duplicate. + * @param [in] count Size of the array to duplicate. + * @param [out] trees_dup Returned duplicate of the input array. + */ +int sr_dup_trees(const sr_node_t *trees, size_t count, sr_node_t **trees_dup); + +/** + * @brief Print sysrepo tree to STDOUT. + * + * @param [in] tree Sysrepo tree to print. + * @param [in] depth_limit Maximum number of tree levels to print. + */ +int sr_print_tree(const sr_node_t *tree, int depth_limit); + +/** + * @brief Print sysrepo tree to the specified file descriptor. + * + * @param [in] fd File descriptor to print the tree into. + * @param [in] tree Sysrepo tree to print. + * @param [in] depth_limit Maximum number of tree levels to print. + */ +int sr_print_tree_fd(int fd, const sr_node_t *tree, int depth_limit); + +/** + * @brief Print sysrepo tree to the specified output file stream. + * + * @param [in] stream Output file stream to print the tree into. + * @param [in] tree Sysrepo tree to print. + * @param [in] depth_limit Maximum number of tree levels to print. + */ +int sr_print_tree_stream(FILE *stream, const sr_node_t *tree, int depth_limit); + +/** + * @brief Print sysrepo tree into a newly allocated memory buffer. + * The caller is expected to eventually free the returned string. + * + * @param [in] mem_p Pointer to store the resulting dump. + * @param [in] tree Sysrepo tree to print. + * @param [in] depth_limit Maximum number of tree levels to print. + */ +int sr_print_tree_mem(char **mem_p, const sr_node_t *tree, int depth_limit); + +/** + * @brief Returns pointer to the first child (based on the schema) of a given node. + * For a fully loaded tree it is equivalent to "node->first_child". For a partially + * loaded tree (@see SR_GET_SUBTREE_ITERATIVE) it may internally issue a sysrepo + * get-subtree-chunk request in order to obtain the data of the child + * (and the data of some surrounding nodes with it for efficiency). + * + * @param[in] session Session context acquired with ::sr_session_start call. + * @param[in] node Node to get the child of. + * @return Pointer to a child node. NULL if there is none or an error occured. + */ +sr_node_t *sr_node_get_child(sr_session_ctx_t *session, sr_node_t *node); + +/** + * @brief Returns pointer to the next sibling (based on the schema) of a given node. + * For a fully loaded tree it is equivalent to "node->next". For a partially + * loaded tree (@see SR_GET_SUBTREE_ITERATIVE) it may internally issue a sysrepo + * get-subtree-chunk request in order to obtain the data of the next sibling + * (and the data of some surrounding nodes with it for efficiency). + * + * @param[in] session Session context acquired with ::sr_session_start call. + * @param[in] node Node to get the next sibling of. + * @return Pointer to the next sibling. NULL if this is the last sibling or an error occured. + */ +sr_node_t *sr_node_get_next_sibling(sr_session_ctx_t *session, sr_node_t *node); + +/** + * @brief Get the parent of a given node. It is equivalent to "node->parent", but for + * a partially loaded tree it is preferred to use this function rather than to access + * the pointer directly just for the sake of code cleanliness. + * + * @param[in] session Session context acquired with ::sr_session_start call. + * @param[in] node Node to get the parent of. + * @return Pointer to the node's parent or NULL if the node is a root of a (sub)tree. + */ +sr_node_t *sr_node_get_parent(sr_session_ctx_t *session, sr_node_t *node); + +/**@} trees */ + +#ifdef __cplusplus +} +#endif + +#endif /* SYSREPO_TREES_H_ */ diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/values.h b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/values.h new file mode 100644 index 000000000..049c82f19 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/values.h @@ -0,0 +1,196 @@ +/** + * @file values.h + * @author Rastislav Szabo <raszabo@cisco.com>, Lukas Macko <lmacko@cisco.com>, + * Milan Lenco <milan.lenco@pantheon.tech> + * @brief Functions for simplified manipulation with Sysrepo values. + * + * @copyright + * Copyright 2016 Cisco Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSREPO_VALUES_H_ +#define SYSREPO_VALUES_H_ + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup values Value Manipulation Utilities + * @{ + * + * @brief Set of functions facilitating simplified manipulation with sysrepo + * values. It is not necessary to use these functions in any scenario, values + * can be allocated and initialized manually (just remember to set all uninitialized + * members to zero!). + * + * Using these utilities, however, has several benefits. Firstly, all the memory + * allocations associated with creating values and setting their attributes get + * hidden behind these functions. The "old-way" was (and still is) to set xpath + * and string values using strdup, which may repeat in applications communicating + * with sysrepo very often and becomes very annoying to write. + * Secondly, the programmer may actually forget to copy or give-up on the ownership + * of a string passed to sysrepo value which will then get unexpectedly deallocated + * in ::sr_free_val or ::sr_free_values. + * The third benefit is that the values created using ::sr_new_val + * and ::sr_new_values will be allocated using the Sysrepo's own memory management + * (if enabled) which was proven to be more efficient for larger data sets + * (far less copying, quicker conversion to/from google protocol buffer messages, + * stable memory footprint, etc.). + */ + +/** + * @brief Allocate an instance of Sysrepo value. + * + * @param [in] xpath Xpath to set for the newly allocated value. Can be NULL. + * @param [out] value Returned newly allocated value. + */ +int sr_new_val(const char *xpath, sr_val_t **value); + +/** + * @brief Allocate an array of sysrepo values. + * + * @param [in] value_cnt Length of the array to allocate. + * @param [out] values Returned newly allocated array of values. + */ +int sr_new_values(size_t value_cnt, sr_val_t **values); + +/** + * @brief Reallocate an array of sysrepo values. + * + * @param [in] old_value_cnt Current length of the value array. + * @param [in] new_value_cnt Desired length of the value array. + * @param [in,out] values Returned newly allocated/enlarged array of values. + */ +int sr_realloc_values(size_t old_value_cnt, size_t new_value_cnt, sr_val_t **values); + +/** + * @brief Set/change xpath of a Sysrepo value. + * + * @param [in] value Sysrepo value to change the xpath of. + * @param [in] xpath XPath to set. + */ +int sr_val_set_xpath(sr_val_t *value, const char *xpath); + +/** + * @brief Set/change xpath of a Sysrepo value to a new one, built from + * a format string and a variable arguments list. + * + * @param [in] value Sysrepo value to change the xpath of. + * @param [in] format Format string used to build XPath. + */ +int sr_val_build_xpath(sr_val_t *value, const char *format, ...); + +/** + * @brief Store data of string type into the Sysrepo value data. + * + * @param [in] value Sysrepo value to edit. + * @param [in] type Exact type of the data. + * @param [in] string_val String value to set. + */ +int sr_val_set_str_data(sr_val_t *value, sr_type_t type, const char *string_val); + +/** + * @brief Store data of string type into the Sysrepo value data. The actual data + * will be built from the a format string and a variable arguments list. + * + * @param [in] value Sysrepo value to edit. + * @param [in] type Exact type of the data. + * @param [in] format Format string used to build the data. + */ +int sr_val_build_str_data(sr_val_t *value, sr_type_t type, const char *format, ...); + +/** + * @brief Duplicate value (with or without Sysrepo memory context) into a new + * instance with memory context. + * + * @param [in] value Sysrepo value to duplicate + * @param [out] value_dup Returned duplicate of the input value. + */ +int sr_dup_val(const sr_val_t *value, sr_val_t **value_dup); + +/** + * @brief Duplicate values (with or without Sysrepo memory context) into a new + * array with memory context. + * + * @param [in] values Array of sysrepo values to duplicate + * @param [in] count Size of the array to duplicate. + * @param [out] values_dup Returned duplicate of the input array. + */ +int sr_dup_values(const sr_val_t *values, size_t count, sr_val_t **values_dup); + +/** + * @brief Print sysrepo value to STDOUT. + * + * @param [in] value Sysrepo value to print. + */ +int sr_print_val(const sr_val_t *value); + +/** + * @brief Print sysrepo value to the specified file descriptor. + * + * @param [in] fd File descriptor to print the value into. + * @param [in] value Sysrepo value to print. + */ +int sr_print_val_fd(int fd, const sr_val_t *value); + +/** + * @brief Print sysrepo value to the specified output file stream. + * + * @param [in] stream Output file stream to print the value into. + * @param [in] value Sysrepo value to print. + */ +int sr_print_val_stream(FILE *stream, const sr_val_t *value); + +/** + * @brief Print sysrepo value into a newly allocated memory buffer. + * The caller is expected to eventually free the returned string. + * + * @param [in] mem_p Pointer to store the resulting dump. + * @param [in] value Sysrepo value to print. + */ +int sr_print_val_mem(char **mem_p, const sr_val_t *value); + +/** + * @brief Converts value to string representation + * @param [in] value + * @return allocated string representation of value (must be freed by caller), NULL in case of error + * @note In case of SR_DECIMAL64_T type, number of fraction digits doesn't have to + * correspond to schema. + */ +char *sr_val_to_str(const sr_val_t *value); + +/** + * @brief Converts value to string and prints it to the provided buffer including + * terminating NULL byte + * @param [in] value + * @param [in] buffer - buffer provided by caller where the data will be printed + * @param [in] size - the size of the buffer + * @return number of characters that was written in case of success, otherwise number of characters which would have been + * written if enough space had been available (excluding terminating NULL byte) + * @note In case of SR_DECIMAL64_T type, number of fraction digits doesn't have to + * correspond to schema. + */ +int sr_val_to_buff(const sr_val_t *value, char buffer[], size_t size); + +/**@} values */ + +#ifdef __cplusplus +} +#endif + +#endif /* SYSREPO_VALUES_H_ */ diff --git a/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/xpath.h b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/xpath.h new file mode 100644 index 000000000..7eca41e57 --- /dev/null +++ b/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/xpath.h @@ -0,0 +1,232 @@ +/** + * @file xpath.h + * @author Rastislav Szabo <raszabo@cisco.com>, Lukas Macko <lmacko@cisco.com> + * @brief Sysrepo helpers for node's address manipulation. + * + * @copyright + * Copyright 2015 Cisco Systems, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSREPO_XPATH_H_ +#define SYSREPO_XPATH_H_ + +#include <stdbool.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @defgroup xpath_utils XPath Processing Utilities + * @{ + * + * @brief Set of helpers working on a subset of xpath expressions used of node identification + * Functions modify inputs arguments by placing termination zero at appropriate places to save up + * string duplication. The state of processing is stored in ::sr_xpath_ctx_t opaque for user. + * It allows to continue in processing where the processing stopped or recover processed input. + * + * Similarly to strtok function in all subsequent calls that is supposed to work with the same + * input xpath must be NULL. + */ + +/** + * @brief State of xpath parsing. User must not modify nor rely on the content + * of the structure. + */ +typedef struct sr_xpath_ctx_s { + char *begining; /**< Pointer to the begining of the processed string */ + char *current_node; /**< Pointer to the currently processed node, used as a context for key search */ + char *replaced_position; /**< Pointer to the posistion where the last terminating 0 by was written */ + char replaced_char; /**< Character that was overwritten by the last termination 0 */ +} sr_xpath_ctx_t; + +/** + * @brief The function returns a pointer to the following node. If xpath is + * not NULL returns the first node name, otherwise returns the subsequent node + * according to the state. + * + * The state is modified upon function successful return from function, so the subsequent + * calls can continue in processing or xpath can be recovered by calling ::sr_xpath_recover. + * + * @note It writes terminating zero at the and of the node name. + * + * @note Skips the namespace if it is present to get node name qualified by namespace use ::sr_xpath_next_node_with_ns + * + * @param [in] xpath - xpath to be processed, can be NULL + * @param [in] state + * @return Pointer to the node name, NULL if there are no more node names + */ +char *sr_xpath_next_node(char *xpath, sr_xpath_ctx_t *state); + +/** + * @brief Returns pointer to the last node. + * @param [in] xpath + * @param [in] state + * @return Pointer to the last node + */ +char *sr_xpath_last_node(char *xpath, sr_xpath_ctx_t *state); + +/** + * @brief Same as ::sr_xpath_next_node with the difference that namespace is included in result if present in xpath + * + * @param [in] xpath - xpath to be processed, can be NULL if the user wants to continue in processing of previous input + * @param [in] state + * @return Pointer to the node name including namespace, NULL if there are no more node names + */ +char *sr_xpath_next_node_with_ns(char *xpath, sr_xpath_ctx_t *state); + +/** + * @brief Returns the name of the next key at the current level in processed xpath. + * + * @param [in] xpath + * @param [in] state + * @return Pointer to the key name, NULL if there are no more keys at the current level + */ +char *sr_xpath_next_key_name(char *xpath, sr_xpath_ctx_t *state); + +/** + * @brief Returns the value of the next key at the current level in processed xpath. + * + * @param [in] xpath + * @param [in] state + * @return Pointer to the key value, NULL if there are no more keys at the current level + */ +char *sr_xpath_next_key_value(char *xpath, sr_xpath_ctx_t *state); + +/** + * @brief Returns a pointer to the node specified by name. It searches from the beginning of the xpath, returns first match. + * Can be used to jump at the desired node xpath and subsequent analysis of key values. + * + * @param [in] xpath + * @param [in] node_name + * @param [in] state + * @return Pointer to the node, NULL if the node with the specified name is not found + */ +char *sr_xpath_node(char *xpath, const char *node_name, sr_xpath_ctx_t *state); + +/** + * @brief Similar to ::sr_xpath_node. The difference is that search start at current node + * according to the state. + * + * @param [in] xpath + * @param [in] node_name + * @param [in] state + * @return Pointer to the node, NULL if the node with the specified name is not found + */ +char *sr_xpath_node_rel(char *xpath, const char *node_name, sr_xpath_ctx_t *state); + +/** + * @brief Returns node specified by index starting at the begin of expression. + * First node has index 0. + * + * @param [in] xpath + * @param [in] index + * @param [in] state + * @return Pointer to the specified node, NULL if the index is out of bounds + */ +char *sr_xpath_node_idx(char *xpath, size_t index, sr_xpath_ctx_t *state); + +/** + * @brief Return node specified by index. Following node has index zero. + * + * @param [in] xpath + * @param [in] index + * @param [in] state + * @return Pointer to the specified node, NULL if the index is out of bounds + */ +char *sr_xpath_node_idx_rel(char *xpath, size_t index, sr_xpath_ctx_t *state); + +/** + * @brief Looks up the value for the key at the current level in xpath. + * + * @param [in] xpath + * @param [in] key - key name to be looked up + * @param [in] state + * @return Key value, NULL if the key with the specified name is not found + */ +char *sr_xpath_node_key_value(char *xpath, const char *key, sr_xpath_ctx_t *state); + +/** + * @brief Looks up the value for the key at the current level in xpath specified by index. + * First key has index zero. + * + * @param [in] xpath + * @param [in] index + * @param [in] state + * @return Key value, NULL if the index is out of bound + */ +char *sr_xpath_node_key_value_idx(char *xpath, size_t index, sr_xpath_ctx_t *state); + +/** + * @brief Looks up the value of the key in a node specified by name. + * + * @param [in] xpath + * @param [in] node_name + * @param [in] key_name + * @param [in] state + * @return Pointer to the key value, NULL if not found + */ +char *sr_xpath_key_value(char *xpath, const char *node_name, const char *key_name, sr_xpath_ctx_t *state); + +/** + * @brief Looks up the value of the key in a node specified by index. First node has index zero. + * + * @param [in] xpath + * @param [in] node_index + * @param [in] key_index + * @param [in] state + * @return Pointer to the key value, NULL if not found or index out of bound + */ +char *sr_xpath_key_value_idx(char *xpath, size_t node_index, size_t key_index, sr_xpath_ctx_t *state); + +/** + * @brief Returns pointer to the string after the last slash in xpath (node name). + * + * @note The returned string can also contain namespace and/or key values + * if they were specified for the last node in xpath. + * + * @param [in] xpath + * @return Result, NULL in case of the slash was not found + */ +char *sr_xpath_node_name(const char *xpath); + +/** + * @brief Compares string after the last slash in xpath (node name) with provided string. + * + * @note The returned string can also contain namespace and/or key values + * if they were specified for the last node in xpath. + * + * @param [in] xpath + * @param [in] node_str String to test for equality. + * @return true in case that the Node names are equal, false otherwise + */ +bool sr_xpath_node_name_eq(const char *xpath, const char *node_str); + +/** + * @brief Recovers the xpath string to the original state (puts back the character + * that was replaced by termination zero). + * + * @param [in] state + */ +void sr_xpath_recover(sr_xpath_ctx_t *state); + +/**@} xpath_utils */ + +#ifdef __cplusplus +} +#endif + +#endif /* SYSREPO_XPATH_H_ */ + |