21 #include "Internal.hpp"
40 ctx = ly_ctx_new(search_dir, options);
42 check_libyang_error(
nullptr);
44 deleter = std::make_shared<Deleter>(ctx);
47 ctx = ly_ctx_new_ylpath(search_dir, path, format, options);
49 check_libyang_error(
nullptr);
51 deleter = std::make_shared<Deleter>(ctx);
54 ctx = ly_ctx_new_ylmem(search_dir, data, format, options);
56 check_libyang_error(
nullptr);
58 deleter = std::make_shared<Deleter>(ctx);
62 int ret = ly_ctx_set_searchdir(ctx, search_dir);
64 check_libyang_error(ctx);
69 struct lyd_node *new_node = ly_ctx_info(ctx);
71 check_libyang_error(ctx);
75 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
76 return std::make_shared<Data_Node>(new_node, new_deleter);
79 const struct lys_module *module = ly_ctx_get_module(
ctx, name, revision, implemented);
80 return module ? std::make_shared<Module>((
lys_module *) module, deleter) :
nullptr;
83 const struct lys_module *new_module = ly_ctx_get_module_older(
ctx, module->module);
84 return new_module ? std::make_shared<Module>((
lys_module *) new_module, deleter) :
nullptr;
87 const struct lys_module *module = ly_ctx_load_module(
ctx, name, revision);
89 check_libyang_error(
ctx);
91 return module ? std::make_shared<Module>((
lys_module *) module, deleter) :
nullptr;
94 const struct lys_module *module = ly_ctx_get_module_by_ns(
ctx, ns, revision, implemented);
95 return module ? std::make_shared<Module>((
lys_module *) module, deleter) :
nullptr;
101 std::vector<S_Module> s_vector;
103 while ((mod = ly_ctx_get_module_iter(
ctx, &i))) {
104 if (mod ==
nullptr) {
107 s_vector.push_back(std::make_shared<Module>((
lys_module *) mod, deleter));
116 std::vector<S_Module> s_vector;
118 while ((mod = ly_ctx_get_disabled_module_iter(
ctx, &i))) {
119 if (mod ==
nullptr) {
122 s_vector.push_back(std::make_shared<Module>((
lys_module *) mod, deleter));
128 return ly_ctx_clean(
ctx,
nullptr);
131 std::vector<std::string> s_vector;
132 const char *
const *
data = ly_ctx_get_searchdirs(
ctx);
139 if (data[size] ==
nullptr) {
142 s_vector.push_back(std::string(data[size]));
148 S_Submodule
Context::get_submodule(
const char *module,
const char *revision,
const char *submodule,
const char *sub_revision) {
151 tmp_submodule = ly_ctx_get_submodule(
ctx, module, revision, submodule, sub_revision);
153 return tmp_submodule ? std::make_shared<Submodule>((
struct lys_submodule *) tmp_submodule, deleter) :
nullptr;
158 tmp_submodule = ly_ctx_get_submodule2(main_module->module, submodule);
160 return tmp_submodule ? std::make_shared<Submodule>((
struct lys_submodule *) tmp_submodule, deleter) :
nullptr;
163 const struct lys_node *node =
nullptr;
165 node = ly_ctx_get_node(ctx, start ? start->node : NULL, data_path, output);
167 return node ? std::make_shared<Schema_Node>((
struct lys_node *) node, deleter) :
nullptr;
170 struct ly_set *set = ly_ctx_find_path(ctx, schema_path);
175 S_Deleter new_deleter = std::make_shared<Deleter>(set, deleter);
176 return std::make_shared<Set>(set, new_deleter);
179 std::vector<S_Schema_Node> s_vector;
183 for (i = 0; i < ctx->models.used; i++) {
184 while ((iter = (
struct lys_node *)
lys_getnext(iter, NULL, ctx->models.list[i], options))) {
185 s_vector.push_back(std::make_shared<Schema_Node>(iter, deleter));
192 struct lyd_node *new_node =
nullptr;
196 check_libyang_error(ctx);
200 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
201 return std::make_shared<Data_Node>(new_node, new_deleter);
204 struct lyd_node *new_node =
nullptr;
206 new_node =
lyd_parse_fd(ctx, fd, format, options, NULL);
208 check_libyang_error(ctx);
212 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
213 return std::make_shared<Data_Node>(new_node, new_deleter);
221 check_libyang_error(
ctx);
225 S_Deleter new_deleter = std::make_shared<Deleter>(module, deleter);
226 return std::make_shared<Module>(module, new_deleter);
233 check_libyang_error(
ctx);
237 S_Deleter new_deleter = std::make_shared<Deleter>(module, deleter);
238 return std::make_shared<Module>(module, new_deleter);
245 check_libyang_error(
ctx);
249 S_Deleter new_deleter = std::make_shared<Deleter>(module, deleter);
250 return std::make_shared<Module>(module, new_deleter);
253 struct lyd_node *new_node =
nullptr;
257 check_libyang_error(ctx);
261 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
262 return std::make_shared<Data_Node>(new_node, new_deleter);
265 struct lyd_node *new_node =
nullptr;
268 throw std::invalid_argument(
"Elem can not be empty");
273 check_libyang_error(ctx);
277 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
278 return std::make_shared<Data_Node>(new_node, new_deleter);
286 mod_missing_cb.emplace_back(std::move(callback), std::move(deleter));
289 const char*
Context::cpp_mod_missing_cb(
const char *mod_name,
const char *mod_rev,
const char *submod_name,
const char *sub_rev,
void *user_data,
LYS_INFORMAT *format,
void (**free_module_data)(
void*,
void*))
293 const auto &cb = x.first;
294 auto ret = cb(mod_name, mod_rev, submod_name, sub_rev);
296 *format = ret.format;
303 if (ly_errno != LY_SUCCESS) {
325 std::vector<S_Error> s_vector;
330 struct ly_err_item *first_eitem = ly_err_first(context->ctx);
335 struct ly_err_item *eitem = first_eitem;
337 s_vector.push_back(std::make_shared<Error>(eitem));
346 return ly_log_options(options);
351 return ly_verb(level);
355 struct ly_set *set_new = ly_set_new();
357 check_libyang_error(
nullptr);
361 deleter = std::make_shared<Deleter>(set_new);
369 std::vector<S_Data_Node> s_vector;
372 for (i = 0; i < set->number; i++){
373 s_vector.push_back(std::make_shared<Data_Node>(set->set.d[i], deleter));
379 std::vector<S_Schema_Node> s_vector;
382 for (i = 0; i < set->number; i++){
383 s_vector.push_back(std::make_shared<Schema_Node>(set->set.s[i], deleter));
389 ly_set *new_set = ly_set_dup(set);
394 auto deleter = std::make_shared<Deleter>(new_set);
395 return std::make_shared<Set>(new_set, deleter);
399 throw std::invalid_argument(
"Node can not be empty");
401 return ly_set_add(set, (
void *) node->node, options);
405 throw std::invalid_argument(
"Node can not be empty");
407 return ly_set_add(set, (
void *) node->node, options);
413 return ly_set_contains(set, (
void *) node->node);
419 return ly_set_contains(set, (
void *) node->node);
422 return ly_set_clean(set);
426 throw std::invalid_argument(
"Node can not be empty");
428 return ly_set_rm(set, (
void *) node->node);
432 throw std::invalid_argument(
"Node can not be empty");
434 return ly_set_rm(set, (
void *) node->node);
437 return ly_set_rm_index(set, index);
442 return new_ctx ? std::make_shared<Context>(new_ctx,
nullptr) :
nullptr;
struct lyd_node * lyd_parse_fd(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options,...)
Read (and validate) data from the given file descriptor.
Common structure representing single YANG data statement describing.
LY_LOG_LEVEL set_log_verbosity(LY_LOG_LEVEL level)
S_Module get_module_by_ns(const char *ns, const char *revision=nullptr, int implemented=0)
Error(struct ly_err_item *eitem)
std::vector< const mod_missing_deleter_t * > mod_missing_deleter
Submodule schema node structure that can be included into a YANG module.
S_Module load_module(const char *name, const char *revision=nullptr)
S_Set find_path(const char *schema_path)
Class implementation for libyang C header xml.h.
libyang representation of data model trees.
std::vector< S_Module > get_disabled_module_iter()
struct lyd_node * lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem **root, int options,...)
Parse (and validate) XML tree.
std::vector< std::pair< mod_missing_cb_t, mod_missing_deleter_t > > mod_missing_cb
S_Data_Node parse_data_xml(S_Xml_Elem elem, int options=0)
class for wrapping ly_ctx.
S_Data_Node parse_data_path(const char *path, LYD_FORMAT format, int options=0)
static void cpp_mod_missing_deleter(void *data, void *user_data)
S_Data_Node parse_data_fd(int fd, LYD_FORMAT format, int options=0)
S_Module parse_module_path(const char *path, LYS_INFORMAT format)
libyang representation of data trees.
S_Submodule get_submodule2(S_Module main_module, const char *submodule=nullptr)
Class implementation for libyang C header tree_schema.h.
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
void add_missing_module_callback(const mod_missing_cb_t &callback, const mod_missing_deleter_t &deleter=mod_missing_deleter_t())
Add a missing include or import module callback.
S_Data_Node parse_data_mem(const char *data, LYD_FORMAT format, int options=0)
struct lys_node * lys_getnext(const struct lys_node *last, const struct lys_node *parent, const struct lys_module *module, int options)
Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can be from an augment.
struct lyd_node * lyd_parse_path(struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options,...)
Read (and validate) data from the given file path.
std::vector< std::string > get_searchdirs()
S_Module get_module(const char *name, const char *revision=nullptr, int implemented=0)
std::function< mod_missing_cb_return(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev)> mod_missing_cb_t
int add(S_Data_Node node, int options=0)
std::vector< S_Schema_Node > schema()
std::vector< S_Error > get_ly_errors(S_Context context)
int contains(S_Data_Node node)
LYS_INFORMAT
Schema input formats accepted by libyang parser functions.
std::function< void(void *)> mod_missing_deleter_t
int set_log_options(int options)
std::vector< S_Schema_Node > data_instantiables(int options)
Context(struct ly_ctx *ctx, S_Deleter deleter)
Main schema node structure representing YANG module.
struct lys_module * lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format)
Load a schema into the specified context.
S_Module get_module_older(S_Module module)
Class implementation for libyang C header libyang.h.
S_Module parse_module_mem(const char *data, LYS_INFORMAT format)
std::vector< S_Data_Node > data()
S_Module parse_module_fd(int fd, LYS_INFORMAT format)
std::vector< S_Module > get_module_iter()
Class implementation for libyang C header tree_data.h.
Generic structure for a data node, directly applicable to the data nodes defined as LYS_CONTAINER...
struct lyd_node * lyd_parse_mem(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options,...)
Parse (and validate) data from memory.
int set_searchdir(const char *search_dir)
S_Schema_Node get_node(S_Schema_Node start, const char *data_path, int output=0)
struct lys_module * lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format)
Load a schema into the specified context from a file.
S_Submodule get_submodule(const char *module, const char *revision=nullptr, const char *submodule=nullptr, const char *sub_revision=nullptr)
S_Context create_new_Context(struct ly_ctx *ctx)
int rm_index(unsigned int index)
struct lys_module * lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format)
Read a schema from file descriptor into the specified context.
static const char * cpp_mod_missing_cb(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data, LYS_INFORMAT *format, void(**free_module_data)(void *model_data, void *user_data))