From 2fa3040eaef653b19f20e84cef7f33b0a0350bbe Mon Sep 17 00:00:00 2001 From: Franco Cipollone Date: Fri, 17 Nov 2023 17:40:53 -0300 Subject: [PATCH] Use a zenoh session to run the router. This eliminates the need for zenohd_vendor, which we also remove here. Signed-off-by: Franco Cipollone --- rmw_zenoh_cpp/CMakeLists.txt | 1 + rmw_zenoh_cpp/apps/init_rmw_zenoh_router.cpp | 34 +++++++++++--------- rmw_zenoh_cpp/package.xml | 1 - zenohd_vendor/CMakeLists.txt | 33 ------------------- zenohd_vendor/package.xml | 17 ---------- 5 files changed, 20 insertions(+), 66 deletions(-) delete mode 100644 zenohd_vendor/CMakeLists.txt delete mode 100644 zenohd_vendor/package.xml diff --git a/rmw_zenoh_cpp/CMakeLists.txt b/rmw_zenoh_cpp/CMakeLists.txt index 24b70723..a625bd84 100644 --- a/rmw_zenoh_cpp/CMakeLists.txt +++ b/rmw_zenoh_cpp/CMakeLists.txt @@ -98,6 +98,7 @@ add_executable(init_rmw_zenoh_router apps/init_rmw_zenoh_router.cpp) target_link_libraries(init_rmw_zenoh_router PRIVATE ament_index_cpp::ament_index_cpp + zenohc::lib ) install( diff --git a/rmw_zenoh_cpp/apps/init_rmw_zenoh_router.cpp b/rmw_zenoh_cpp/apps/init_rmw_zenoh_router.cpp index b664e423..672a8e80 100644 --- a/rmw_zenoh_cpp/apps/init_rmw_zenoh_router.cpp +++ b/rmw_zenoh_cpp/apps/init_rmw_zenoh_router.cpp @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include - -#include +#include +#include #include +#include + +#include #include @@ -31,19 +32,22 @@ int Main(int, char **) ament_index_cpp::get_package_share_directory(RMW_ZENOH_IDENTIFIER) + "/config/" + std::string(ZENOH_ROUTER_CONFIG_NAME); - // Execute zenohd command - const std::string zenohd_cmd = "zenohd -c " + zenoh_router_config_path; - const int ret = system(zenohd_cmd.c_str()); - if (ret < 0) { - std::cerr << "Error running zenoh router via command: " << zenohd_cmd << std::endl; - return ret; - } else { - if (WIFEXITED(ret)) { - std::cout << "Zenoh router exited normally." << std::endl; - } else { - std::cout << "Zenoh router exited abnormally with error code [" << ret << "]" << std::endl; + z_owned_config_t config = zc_config_from_file(zenoh_router_config_path.c_str()); + z_owned_session_t s = z_open(z_move(config)); + if (!z_check(s)) { + printf("Unable to open router session!\n"); + return 1; + } + + printf("Enter 'q' to quit...\n"); + char c = 0; + while (c != 'q') { + c = getchar(); + if (c == -1) { + std::this_thread::sleep_for(std::chrono::seconds(1)); } } + z_close(z_move(s)); return 0; } diff --git a/rmw_zenoh_cpp/package.xml b/rmw_zenoh_cpp/package.xml index 02abec46..a53ba6cc 100644 --- a/rmw_zenoh_cpp/package.xml +++ b/rmw_zenoh_cpp/package.xml @@ -10,7 +10,6 @@ ament_cmake zenoh_c_vendor - zenohd_vendor ament_index_cpp fastcdr diff --git a/zenohd_vendor/CMakeLists.txt b/zenohd_vendor/CMakeLists.txt deleted file mode 100644 index c748c7ab..00000000 --- a/zenohd_vendor/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(zenohd_vendor) - -# Default to C++17 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() - -find_package(ament_cmake REQUIRED) - -include(ExternalProject) - -ExternalProject_Add( - zenoh - PREFIX ${CMAKE_BINARY_DIR}/_cargo_deps - GIT_REPOSITORY https://github.com/eclipse-zenoh/zenoh.git - GIT_TAG 0.10.1-rc - BUILD_COMMAND cargo build --package zenohd --release - CONFIGURE_COMMAND "" # Disable the configure step - INSTALL_COMMAND "" - BUILD_IN_SOURCE 1 -) - -# Install the zenohd executable from the rust crate -install( - PROGRAMS ${CMAKE_BINARY_DIR}/_cargo_deps/src/zenoh/target/release/zenohd - DESTINATION bin -) - -# TODO(francocipollone): Install zenoh router plugins - -ament_package() diff --git a/zenohd_vendor/package.xml b/zenohd_vendor/package.xml deleted file mode 100644 index 8a4b1966..00000000 --- a/zenohd_vendor/package.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - zenohd_vendor - 0.0.1 - Vendor pkg to install zenoh router - FrancoCipollone - Apache License 2.0 - - ament_cmake - - - - - ament_cmake - -