libyang-Context

libyang的上下文允许用户在不同的YANG模块集合环境中工作。首先通过ly_ctx_new()创建一个新的上下文。一旦开始处理数据,不应改变上下文及其内容。可以使用ly_ctx_destroy()移除上下文。可以设置选项来改变处理YANG模块时的行为,例如搜索目录、模块导入回调等。libyang提供了多种函数用于添加、获取和管理YANG模块及子模块。此外,还讨论了如何处理模块的最新修订版和实现状态。
摘要由CSDN通过智能技术生成

The context concept allows callers to work in environments with different sets of YANG modules.

The first step with libyang is to create a new context using ly_ctx_new(). It returns a handler used in the following work. Note that the context is supposed to provide a stable environment for work with the data. Therefore the caller should prepare a complete context and after starting working with the data, the context and its content should not change. If it does, in most cases it leads to the context being recompiled and any parsed data invalid. Despite the API not enforcing this approach, it may change in future versions in the form of a locking mechanism which would allow further optimization of data manipulation. Also note that modules cannot be removed from their context. If you need to change the set of the schema modules in the context, the recommended way is to create a new context. To remove the context, there is ly_ctx_destroy() function.

The context has several options changing behavior when processing YANG modules being inserted. The specific behavior is mentioned below. All the options can be set as a parameter when the context is being created or later with ly_ctx_set_options().

When creating a new context, another optional parameter is search_dir It provide directory where libyang will automatically search for YANG modules being imported or included. There is actually a set of search paths which can be later modified using ly_ctx_set_searchdir(), ly_ctx_unset_searchdir() and ly_ctx_unset_searchdir_last() functions. Before the values in the set are used, also the current working directory is (non-recursively) searched. For the case of the explicitly set search directories, they are searched recursively - all their subdirectories (and symlinks) are taken into account. Searching in the current working directory can be avoided with the context's

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值