Closed ayou0057 closed 1 year ago
Right now there's no API for querying that information from sysrepo, but you can get that info from the associated libyang::Context
-- either use getModule(name, revision)
, or iterate over libyang::Context::modules()
.
Your code looks fishy, there's no c_str()
method on a return value from sysrepo::Session::getData()
. Since Session::getData()
returns std::optional<libyang::DataNode>
, the code should always check whether the optional
is empty (indicating no matching data) or not. Note that a call returning no data does not mean that a module is not installed, and it's quite possible that a module is installed, but there are simply no data, and std::nullopt
is returned.
Right now there's no API for querying that information from sysrepo, but you can get that info from the associated
libyang::Context
-- either usegetModule(name, revision)
, or iterate overlibyang::Context::modules()
.Your code looks fishy, there's no
c_str()
method on a return value fromsysrepo::Session::getData()
. SinceSession::getData()
returnsstd::optional<libyang::DataNode>
, the code should always check whether theoptional
is empty (indicating no matching data) or not. Note that a call returning no data does not mean that a module is not installed, and it's quite possible that a module is installed, but there are simply no data, andstd::nullopt
is returned.
I am using the same as the example provided. https://github.com/sysrepo/sysrepo-cpp/blob/master/examples/module_change_example.cpp#L63
Thank you for all the information.
I am using the same as the example provided. https://github.com/sysrepo/sysrepo-cpp/blob/master/examples/module_change_example.cpp#L63
Sorry, I misread the parentheses, that's indeed correct. How exactly does that crash for you?
I am using the same as the example provided. https://github.com/sysrepo/sysrepo-cpp/blob/master/examples/module_change_example.cpp#L63
Sorry, I misread the parentheses, that's indeed correct. How exactly does that crash for you?
No worries I started using libyang::Context::modules() as per your suggestion and it's working fine, please ignore the crash :). you can close the ticket. Thanks again.
std::string moduleName = "examples"; I call
auto data = session.getData("/" + moduleName+":*//.").c_str());
and when the module is not installed my application is crashing.Let say I installed example.yang and I want to check in my c++ code if this module is installed and then based on that I log it.