|
Packit Service |
311553 |
/**
|
|
Packit Service |
311553 |
* @file Libyang.hpp
|
|
Packit Service |
311553 |
* @author Mislav Novakovic <mislav.novakovic@sartura.hr>
|
|
Packit Service |
311553 |
* @brief Class implementation for libyang C header libyang.h.
|
|
Packit Service |
311553 |
*
|
|
Packit Service |
311553 |
* Copyright (c) 2017 Deutsche Telekom AG.
|
|
Packit Service |
311553 |
*
|
|
Packit Service |
311553 |
* This source code is licensed under BSD 3-Clause License (the "License").
|
|
Packit Service |
311553 |
* You may not use this file except in compliance with the License.
|
|
Packit Service |
311553 |
* You may obtain a copy of the License at
|
|
Packit Service |
311553 |
*
|
|
Packit Service |
311553 |
* https://opensource.org/licenses/BSD-3-Clause
|
|
Packit Service |
311553 |
*/
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
#ifndef LIBYANG_CPP_H
|
|
Packit Service |
311553 |
#define LIBYANG_CPP_H
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
#include <iostream>
|
|
Packit Service |
311553 |
#include <memory>
|
|
Packit Service |
311553 |
#include <exception>
|
|
Packit Service |
311553 |
#include <functional>
|
|
Packit Service |
311553 |
#include <vector>
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
#include "Internal.hpp"
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
extern "C" {
|
|
Packit Service |
311553 |
#include "libyang.h"
|
|
Packit Service |
311553 |
}
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
namespace libyang {
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/**
|
|
Packit Service |
311553 |
* @defgroup classes C++/Python
|
|
Packit Service |
311553 |
* @{
|
|
Packit Service |
311553 |
*
|
|
Packit Service |
311553 |
* Class wrappers for data structures and functions to manipulate and access instance data tree.
|
|
Packit Service |
311553 |
*/
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/**
|
|
Packit Service |
311553 |
* @brief class for wrapping ly_ctx.
|
|
Packit Service |
311553 |
* @class Context
|
|
Packit Service |
311553 |
*/
|
|
Packit Service |
311553 |
class Context
|
|
Packit Service |
311553 |
{
|
|
Packit Service |
311553 |
public:
|
|
Packit Service |
311553 |
/** wrapper for struct ly_ctx, for internal use only */
|
|
Packit Service |
311553 |
Context(struct ly_ctx *ctx, S_Deleter deleter);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_new](@ref ly_ctx_new) */
|
|
Packit Service |
311553 |
explicit Context(const char *search_dir = nullptr, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_new_ylpath](@ref ly_ctx_new_ylpath) */
|
|
Packit Service |
311553 |
Context(const char *search_dir, const char *path, LYD_FORMAT format, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_new_ylmem](@ref ly_ctx_new_ylmem) */
|
|
Packit Service |
311553 |
Context(const char *search_dir, LYD_FORMAT format, const char *data, int options = 0);
|
|
Packit Service |
311553 |
~Context();
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_set_searchdir](@ref ly_ctx_set_searchdir) */
|
|
Packit Service |
311553 |
int set_searchdir(const char *search_dir);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_unset_searchdirs](@ref ly_ctx_unset_searchdirs) */
|
|
Packit Service |
311553 |
void unset_searchdirs(int idx) {return ly_ctx_unset_searchdirs(ctx, idx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_searchdirs](@ref ly_ctx_get_searchdirs) */
|
|
Packit Service |
311553 |
std::vector<std::string> get_searchdirs();
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_set_allimplemented](@ref ly_ctx_set_allimplemented) */
|
|
Packit Service |
311553 |
void set_allimplemented() {return ly_ctx_set_allimplemented(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_unset_allimplemented](@ref ly_ctx_unset_allimplemented) */
|
|
Packit Service |
311553 |
void unset_allimplemented() {return ly_ctx_unset_allimplemented(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_set_disable_searchdirs](@ref ly_ctx_set_disable_searchdirs) */
|
|
Packit Service |
311553 |
void set_disable_searchdirs() {return ly_ctx_set_disable_searchdirs(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_unset_disable_searchdirs](@ref ly_ctx_unset_disable_searchdirs) */
|
|
Packit Service |
311553 |
void unset_disable_searchdirs() {return ly_ctx_unset_disable_searchdirs(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_set_disable_searchdir_cwd](@ref ly_ctx_set_disable_searchdir_cwd) */
|
|
Packit Service |
311553 |
void set_disable_searchdir_cwd() {return ly_ctx_set_disable_searchdir_cwd(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_unset_disable_searchdir_cwd](@ref ly_ctx_unset_disable_searchdir_cwd) */
|
|
Packit Service |
311553 |
void unset_disable_searchdir_cwd() {return ly_ctx_unset_disable_searchdir_cwd(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_set_prefer_searchdirs](@ref ly_ctx_set_disable_searchdirs) */
|
|
Packit Service |
311553 |
void set_prefer_searchdirs() {return ly_ctx_set_prefer_searchdirs(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_unset_prefer_searchdirs](@ref ly_ctx_unset_prefer_searchdirs) */
|
|
Packit Service |
311553 |
void unset_prefer_searchdirs() {return ly_ctx_unset_prefer_searchdirs(ctx);};
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_info](@ref ly_ctx_info) */
|
|
Packit Service |
311553 |
S_Data_Node info();
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_module_iter](@ref ly_ctx_get_module_iter) */
|
|
Packit Service |
311553 |
std::vector<S_Module> get_module_iter();
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_disabled_module_iter](@ref ly_ctx_get_disabled_module_iter) */
|
|
Packit Service |
311553 |
std::vector<S_Module> get_disabled_module_iter();
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_module](@ref ly_ctx_get_module) */
|
|
Packit Service |
311553 |
S_Module get_module(const char *name, const char *revision = nullptr, int implemented = 0);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_module_older](@ref ly_ctx_get_module_older) */
|
|
Packit Service |
311553 |
S_Module get_module_older(S_Module module);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_load_module](@ref ly_ctx_load_module) */
|
|
Packit Service |
311553 |
S_Module load_module(const char *name, const char *revision = nullptr);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_module_by_ns](@ref ly_ctx_get_module_by_ns) */
|
|
Packit Service |
311553 |
S_Module get_module_by_ns(const char *ns, const char *revision = nullptr, int implemented = 0);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_submodule](@ref ly_ctx_get_submodule) */
|
|
Packit Service |
311553 |
S_Submodule get_submodule(const char *module, const char *revision = nullptr, const char *submodule = nullptr, const char *sub_revision = nullptr);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_submodule2](@ref ly_ctx_get_submodule2) */
|
|
Packit Service |
311553 |
S_Submodule get_submodule2(S_Module main_module, const char *submodule = nullptr);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_get_node](@ref ly_ctx_get_node) */
|
|
Packit Service |
311553 |
S_Schema_Node get_node(S_Schema_Node start, const char *data_path, int output = 0);
|
|
Packit Service |
311553 |
/** wrapper for [lys_getnext](@ref lys_getnext) */
|
|
Packit Service |
311553 |
std::vector<S_Schema_Node> data_instantiables(int options);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_find_path](@ref ly_ctx_find_path) */
|
|
Packit Service |
311553 |
S_Set find_path(const char *schema_path);
|
|
Packit Service |
311553 |
/** wrapper for [ly_ctx_clean](@ref ly_ctx_clean) */
|
|
Packit Service |
311553 |
void clean();
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
struct mod_missing_cb_return {
|
|
Packit Service |
311553 |
LYS_INFORMAT format;
|
|
Packit Service |
311553 |
const char *data;
|
|
Packit Service |
311553 |
};
|
|
Packit Service |
311553 |
using mod_missing_cb_t = std::function<mod_missing_cb_return(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev)>;
|
|
Packit Service |
311553 |
using mod_missing_deleter_t = std::function<void(void *)>;
|
|
Packit Service |
311553 |
/** @short Add a missing include or import module callback
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
When libyang hits a missing module, the @arg callback will be called. If it can accommodate this request, it should return an
|
|
Packit Service |
311553 |
appropriate mod_missing_cb_return struct. If it is needed to free the actual module "source code", then @arg deleter should be
|
|
Packit Service |
311553 |
provided; it is then responsible for deallocation of the resulting mod_missing_cb_return::data.
|
|
Packit Service |
311553 |
*/
|
|
Packit Service |
311553 |
void add_missing_module_callback(const mod_missing_cb_t &callback, const mod_missing_deleter_t &deleter = mod_missing_deleter_t());
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/* functions */
|
|
Packit Service |
311553 |
/** wrapper for [lyd_parse_mem](@ref lyd_parse_mem) */
|
|
Packit Service |
311553 |
S_Data_Node parse_data_mem(const char *data, LYD_FORMAT format, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [lyd_parse_fd](@ref lyd_parse_fd) */
|
|
Packit Service |
311553 |
S_Data_Node parse_data_fd(int fd, LYD_FORMAT format, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [lyd_parse_path](@ref lyd_parse_path) */
|
|
Packit Service |
311553 |
S_Data_Node parse_data_path(const char *path, LYD_FORMAT format, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [lyd_parse_xml](@ref lyd_parse_xml) */
|
|
Packit Service |
311553 |
S_Data_Node parse_data_xml(S_Xml_Elem elem, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [lys_parse_mem](@ref lys_parse_mem) */
|
|
Packit Service |
311553 |
S_Module parse_module_mem(const char *data, LYS_INFORMAT format);
|
|
Packit Service |
311553 |
/** wrapper for [lys_parse_fd](@ref lys_parse_fd) */
|
|
Packit Service |
311553 |
S_Module parse_module_fd(int fd, LYS_INFORMAT format);
|
|
Packit Service |
311553 |
/** wrapper for [lys_parse_path](@ref lys_parse_path) */
|
|
Packit Service |
311553 |
S_Module parse_module_path(const char *path, LYS_INFORMAT format);
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
friend std::vector<S_Error> get_ly_errors(S_Context context);
|
|
Packit Service |
311553 |
friend Data_Node;
|
|
Packit Service |
311553 |
friend Deleter;
|
|
Packit Service |
311553 |
friend Error;
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
std::vector<std::pair<mod_missing_cb_t, mod_missing_deleter_t>> mod_missing_cb;
|
|
Packit Service |
311553 |
std::vector<const mod_missing_deleter_t *> mod_missing_deleter;
|
|
Packit Service |
311553 |
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));
|
|
Packit Service |
311553 |
static void cpp_mod_missing_deleter(void *data, void *user_data);
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/* SWIG specific */
|
|
Packit Service |
311553 |
struct ly_ctx *swig_ctx() {return ctx;};
|
|
Packit Service |
311553 |
std::vector<void*> wrap_cb_l;
|
|
Packit Service |
311553 |
private:
|
|
Packit Service |
311553 |
struct ly_ctx *ctx;
|
|
Packit Service |
311553 |
S_Deleter deleter;
|
|
Packit Service |
311553 |
};
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
S_Context create_new_Context(struct ly_ctx *ctx);
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/**
|
|
Packit Service |
311553 |
* @brief class for wrapping [ly_err_item](@ref ly_err_item).
|
|
Packit Service |
311553 |
* @class Error
|
|
Packit Service |
311553 |
*/
|
|
Packit Service |
311553 |
class Error
|
|
Packit Service |
311553 |
{
|
|
Packit Service |
311553 |
public:
|
|
Packit Service |
311553 |
/** wrapper for [ly_err_item](@ref ly_err_item) */
|
|
Packit Service |
311553 |
Error(struct ly_err_item *eitem);
|
|
Packit Service |
311553 |
~Error() {};
|
|
Packit Service |
311553 |
/** get no variable from [ly_err_item](@ref ly_err_item) */
|
|
Packit Service |
311553 |
LY_ERR err() throw() {return eitem->no;};
|
|
Packit Service |
311553 |
/** get vecode variable from [ly_err_item](@ref ly_err_item)*/
|
|
Packit Service |
311553 |
LY_VECODE vecode() throw() {return eitem->vecode;};
|
|
Packit Service |
311553 |
/** get errmsg variable from [ly_err_item](@ref ly_err_item)*/
|
|
Packit Service |
311553 |
const char *errmsg() const throw() {return eitem->msg ? eitem->msg : "";};
|
|
Packit Service |
311553 |
/** get errpath variable from [ly_err_item](@ref ly_err_item)*/
|
|
Packit Service |
311553 |
const char *errpath() const throw() {return eitem->path ? eitem->path : "";};
|
|
Packit Service |
311553 |
/** get errapptag variable from [ly_err_item](@ref ly_err_item)*/
|
|
Packit Service |
311553 |
const char *errapptag() const throw() {return eitem->apptag ? eitem->path : "";};
|
|
Packit Service |
311553 |
private:
|
|
Packit Service |
311553 |
struct ly_err_item *eitem;
|
|
Packit Service |
311553 |
};
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
std::vector<S_Error> get_ly_errors(S_Context context);
|
|
Packit Service |
311553 |
int set_log_options(int options);
|
|
Packit Service |
311553 |
LY_LOG_LEVEL set_log_verbosity(LY_LOG_LEVEL level);
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/**
|
|
Packit Service |
311553 |
* @brief class for wrapping [ly_set](@ref ly_set).
|
|
Packit Service |
311553 |
* @class Set
|
|
Packit Service |
311553 |
*/
|
|
Packit Service |
311553 |
class Set
|
|
Packit Service |
311553 |
{
|
|
Packit Service |
311553 |
public:
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_new](@ref ly_set_new) */
|
|
Packit Service |
311553 |
Set(struct ly_set *set, S_Deleter);
|
|
Packit Service |
311553 |
Set();
|
|
Packit Service |
311553 |
~Set();
|
|
Packit Service |
311553 |
/** get size variable from [ly_set](@ref ly_set)*/
|
|
Packit Service |
311553 |
unsigned int size() {return set->size;};
|
|
Packit Service |
311553 |
/** get number variable from [ly_set](@ref ly_set)*/
|
|
Packit Service |
311553 |
unsigned int number() {return set->number;};
|
|
Packit Service |
311553 |
/** get d variable from [ly_set_set](@ref ly_set_set)*/
|
|
Packit Service |
311553 |
std::vector<S_Data_Node> data();
|
|
Packit Service |
311553 |
/** get s variable from [ly_set_set](@ref ly_set_set)*/
|
|
Packit Service |
311553 |
std::vector<S_Schema_Node> schema();
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/* functions */
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_dup](@ref ly_set_dup) */
|
|
Packit Service |
311553 |
S_Set dup();
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_add](@ref ly_set_add) */
|
|
Packit Service |
311553 |
int add(S_Data_Node node, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_add](@ref ly_set_add) */
|
|
Packit Service |
311553 |
int add(S_Schema_Node node, int options = 0);
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_contains](@ref ly_set_contains) */
|
|
Packit Service |
311553 |
int contains(S_Data_Node node);
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_contains](@ref ly_set_contains) */
|
|
Packit Service |
311553 |
int contains(S_Schema_Node node);
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_clean](@ref ly_set_clean) */
|
|
Packit Service |
311553 |
int clean();
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_rm](@ref ly_set_rm) */
|
|
Packit Service |
311553 |
int rm(S_Data_Node node);
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_rm](@ref ly_set_rm) */
|
|
Packit Service |
311553 |
int rm(S_Schema_Node node);
|
|
Packit Service |
311553 |
/** wrapper for [ly_set_rm_index](@ref ly_set_rm_index) */
|
|
Packit Service |
311553 |
int rm_index(unsigned int index);
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
private:
|
|
Packit Service |
311553 |
struct ly_set *set;
|
|
Packit Service |
311553 |
S_Deleter deleter;
|
|
Packit Service |
311553 |
};
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
/**@} */
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
}
|
|
Packit Service |
311553 |
|
|
Packit Service |
311553 |
#endif
|