Skip to content

Commit

Permalink
port to libnetconf2 v3
Browse files Browse the repository at this point in the history
This is really just a change of logging, nothing else. Unfortunately,
the new logging still affects a global state, it was really just a
change of the function signature, and the logger callback might well be
invoked with a NULL session. This means that mapping from the
nc_session* to a libnetconf::client::Session is not possible, so I
though that simply providing an opaque pointer is not a bad solution.

Change-Id: Iaa10855f4173fdd5e3046efa1827e4931cd05acb
Depends-on: https://gerrit.cesnet.cz/c/CzechLight/libyang-cpp/+/7049
Depends-on: CESNET/libnetconf2#477
Depends-on: CESNET/libnetconf2#478
  • Loading branch information
jktjkt committed Apr 10, 2024
1 parent b1fd592 commit b88db61
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .zuul.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
pre-run: ci/pre.yaml
required-projects:
- name: github/CESNET/libyang
override-checkout: cesnet/2024-03--v2-latest
override-checkout: devel
- name: github/CESNET/libnetconf2
override-checkout: cesnet/wip-libnetconf-v2
override-checkout: cesnet/2024-04-10--00
- name: github/onqtam/doctest
override-checkout: v2.4.8
- name: github/rollbear/trompeloeil
Expand All @@ -17,9 +17,9 @@
pre-run: ci/pre.yaml
required-projects: &projects
- name: github/CESNET/libyang
override-checkout: cesnet/2024-03--v2-latest
override-checkout: devel
- name: github/CESNET/libnetconf2
override-checkout: cesnet/wip-libnetconf-v2
override-checkout: cesnet/2024-04-10--00
- name: github/onqtam/doctest
override-checkout: v2.4.11
- name: github/rollbear/trompeloeil
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${D
option(BUILD_SHARED_LIBS "By default, shared libs are enabled. Turn off for a static build." ON)

find_package(PkgConfig)
pkg_check_modules(LIBYANG_CPP REQUIRED libyang-cpp>=1.1.0 IMPORTED_TARGET)
pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=2.1.40 libnetconf2<3 IMPORTED_TARGET)
set(LIBNETCONF2_CPP_PKG_VERSION "1.0.0")
pkg_check_modules(LIBYANG_CPP REQUIRED libyang-cpp>=2 IMPORTED_TARGET)
pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=3.0.17 IMPORTED_TARGET)
set(LIBNETCONF2_CPP_PKG_VERSION "2")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}/include)

Expand Down
6 changes: 6 additions & 0 deletions ci/pre.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
- name: install libssh-debuginfo
command: 'dnf debuginfo-install -y libssh'
become: true

- name: install curl
package:
name: libcurl-devel
state: present
become: true
2 changes: 1 addition & 1 deletion include/libnetconf2-cpp/netconf-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReportedError : public std::runtime_error {
~ReportedError() override;
};

using LogCb = std::function<void(LogLevel, const char*)>;
using LogCb = std::function<void(const nc_session*, LogLevel, const char*)>;

void setLogLevel(LogLevel level);
void setLogCallback(const LogCb& callback);
Expand Down
6 changes: 3 additions & 3 deletions src/netconf-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ namespace impl {

static client::LogCb logCallback;

static void logViaCallback(NC_VERB_LEVEL level, const char* message)
static void logViaCallback(const nc_session* session, NC_VERB_LEVEL level, const char* message)
{
logCallback(libnetconf::utils::toLogLevel(level), message);
logCallback(session, libnetconf::utils::toLogLevel(level), message);
}


Expand Down Expand Up @@ -165,7 +165,7 @@ void setLogLevel(LogLevel level)
void setLogCallback(const client::LogCb& callback)
{
impl::logCallback = callback;
nc_set_print_clb(callback ? impl::logViaCallback : NULL);
nc_set_print_clb_session(callback ? impl::logViaCallback : NULL);
}

libyang::Context Session::libyangContext()
Expand Down
2 changes: 1 addition & 1 deletion tests/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_CASE("client")
}
}
)";
logCb = [&logBuf, &logMtx](const auto, const auto msg) {
logCb = [&logBuf, &logMtx](const auto, const auto, const auto msg) {
std::unique_lock lck{logMtx};
logBuf += "\n";
logBuf += msg;
Expand Down

0 comments on commit b88db61

Please sign in to comment.