### Check Compilation of Simple Examples (Commented Out) Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt These are commented-out examples demonstrating how to compile simple zenohc and zenohpico examples. They show specific file paths and library linking for testing basic functionality. ```cmake # check compilation of simple examples #add_examples("${CMAKE_CURRENT_SOURCE_DIR}/simple/universal/z_simple.cxx" zenohpico zenohcxx::zenohpico) #add_examples("${CMAKE_CURRENT_SOURCE_DIR}/simple/universal/z_simple.cxx" zenohc zenohcxx::zenohc::lib) #add_examples("${CMAKE_CURRENT_SOURCE_DIR}/simple/zenohpico/zp_simple.cxx" zenohpico zenohcxx::zenohpico) #add_examples("${CMAKE_CURRENT_SOURCE_DIR}/simple/zenohc/zc_simple.cxx" zenohc zenohcxx::zenohc::lib) ``` -------------------------------- ### Build Zenoh-C++ Tests and Examples Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/CLAUDE.md Configures and builds the Zenoh-C++ project, including tests and examples, using CMake. Requires zenoh-c and zenoh-pico to be installed. ```bash mkdir build cd build cmake .. -DZENOHCXX_ZENOHC=ON -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/local -DCMAKE_BUILD_TYPE=Debug cmake --build . --target tests cmake --build . --target examples ``` -------------------------------- ### Build Zenoh-CPP Examples with CMake Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Configure and build Zenoh-CPP examples using CMake. Specify the backend (zenoh-c, zenoh-pico, or both) using CMake variables. ```bash cmake .. -DCMAKE_INSTALL_PREFIX=~/.local # to build examples only for zenoh-c backend ``` ```bash cmake .. -DZENOHCXX_ZENOHC=OFF -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/.local # to build examples only for zenoh-pico backend ``` ```bash cmake .. -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/.local # to build examples for both backends ``` ```bash cmake --build . --target examples ``` -------------------------------- ### Install Python Documentation Tools Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/README.md Installs Sphinx and its themes using pip. These tools are required for building the documentation. ```bash pip3 install sphinx pip3 install breathe pip3 install sphinx-rtd-theme ``` -------------------------------- ### Get Zenoh Session Information Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Runs the `z_info` example to retrieve information about the current Zenoh session. This is useful for debugging and understanding the session state. ```bash z_info ``` -------------------------------- ### Compile Zenohpico Examples Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt This section compiles C++ examples using the zenohpico backend. It calls the 'add_examples' function to process C++ source files from the 'universal' directory, linking against the 'zenohcxx::zenohpico' library. ```cmake if(ZENOHCXX_ZENOHPICO) # zenohcxx examples compiled with C++ compiler with zenohpico add_examples("${CMAKE_CURRENT_SOURCE_DIR}/universal/*.cxx" zenohpico zenohcxx::zenohpico) endif() ``` -------------------------------- ### Install Doxygen on Ubuntu Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/README.md Installs Doxygen using apt on Ubuntu systems. Ensure you have the necessary permissions. ```bash sudo apt install doxygen ``` -------------------------------- ### Configure Zenoh Pico C++ Example Build Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/simple/zenohpico/CMakeLists.txt This CMakeLists.txt file sets up the build environment for a Zenoh Pico C++ example. It finds the necessary Zenoh Pico and Zenoh C++ packages, defines an executable target, links it against the Zenoh Pico library, and sets C++ standard to 17. ```cmake cmake_minimum_required(VERSION 3.16) project(zenohcxx_examples LANGUAGES C CXX) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH}) include(helpers) if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Release) endif() find_package(zenohpico REQUIRED) find_package(zenohcxx REQUIRED) add_executable(zp_simple zp_simple.cxx) target_link_libraries(zp_simple PRIVATE zenohcxx::zenohpico) set_property(TARGET zp_simple PROPERTY LANGUAGE CXX) set_property(TARGET zp_simple PROPERTY CXX_STANDARD 17) copy_dlls(zp_simple) ``` -------------------------------- ### Install Zenoh-C and Zenoh-Pico Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/CLAUDE.md Installs zenoh-c and zenoh-pico from git into a specified local directory. Enables unstable APIs and shared memory in the debug variant. ```bash ./scripts/install_from_git.sh ~/local TRUE TRUE TRUE Debug ``` -------------------------------- ### Compile Zenohc Examples Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt This section compiles C++ examples using the zenohc backend. It calls the 'add_examples' function to process C++ source files from the 'zenohc' and 'universal' directories, linking against the 'zenohcxx::zenohc' library. ```cmake if(ZENOHCXX_ZENOHC) # zenohcxx examples compiled with C++ compiler with zenohc add_examples("${CMAKE_CURRENT_SOURCE_DIR}/zenohc/*.cxx" zenohc zenohcxx::zenohc) add_examples("${CMAKE_CURRENT_SOURCE_DIR}/universal/*.cxx" zenohc zenohcxx::zenohc) endif() ``` -------------------------------- ### Define Custom Target for Examples Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt This defines a custom target named 'examples' to group all example builds. It conditionally adds sub-targets for 'zenohc' and 'zenohpico' backends if their respective features are enabled. ```cmake add_custom_target(examples) if(ZENOHCXX_ZENOHC) add_custom_target(examples_zenohc) add_dependencies(examples examples_zenohc) endif() if(ZENOHCXX_ZENOHPICO) add_custom_target(examples_zenohpico) add_dependencies(examples examples_zenohpico) endif() ``` -------------------------------- ### Install Zenoh C++ Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md After configuring the build with CMake, use this command to install the Zenoh C++ library. ```bash cmake --install . ``` -------------------------------- ### Add Multiple Examples from Glob Pattern Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt This function finds all C++ files matching a glob pattern and adds them as examples using the 'add_example' function. It includes conditional logic to skip certain examples based on the build mode (zenohc, zenohpico) and feature flags. ```cmake function(add_examples glob mode lib) file(GLOB files ${glob}) foreach(file ${files}) if("${mode}" STREQUAL "zenohc") # Exclude SHM examples if SHM feature is disabled if((${file} MATCHES ".*_shm.*$") AND NOT(ZENOHC_BUILD_WITH_SHARED_MEMORY AND (ZENOHC_BUILD_WITH_UNSTABLE_API))) continue() endif() if(((${file} MATCHES ".*advanced_sub.*$") OR (${file} MATCHES ".*advanced_pub.*$")) AND NOT(ZENOHC_BUILD_WITH_UNSTABLE_API)) continue() endif() endif() if("${mode}" STREQUAL "zenohpico") if ((${file} MATCHES ".*advanced_pub.*$") AND NOT(ZENOHPICO_FEATURE_ADVANCED_PUBLICATION)) continue() elseif ((${file} MATCHES ".*advanced_sub.*$") AND NOT(ZENOHPICO_FEATURE_ADVANCED_SUBSCRIPTION)) continue() elseif (((${file} MATCHES ".*pub.*$") OR (${file} MATCHES ".*delete.*$") OR (${file} MATCHES ".*put.*$") OR (${file} MATCHES ".*ping.*$") OR (${file} MATCHES ".*pong.*$")) AND NOT(ZENOHPICO_FEATURE_PUBLICATION) ) continue() elseif (((${file} MATCHES ".*sub.*$") OR (${file} MATCHES ".*ping.*$") OR (${file} MATCHES ".*pong.*$")) AND NOT(ZENOHPICO_FEATURE_SUBSCRIPTION) ) continue() elseif ((${file} MATCHES ".*get.*$") AND NOT(ZENOHPICO_FEATURE_QUERY)) continue() elseif ((${file} MATCHES ".*queryable.*$") AND NOT(ZENOHPICO_FEATURE_QUERYABLE)) continue() elseif ((${file} MATCHES ".*liveliness.*$") AND NOT(ZENOHPICO_FEATURE_LIVELINESS)) continue() elseif ((${file} MATCHES ".*querier.*$") AND NOT(ZENOHPICO_FEATURE_QUERY)) continue() endif() endif() add_example(${file} ${mode} ${lib}) endforeach() endfunction() ``` -------------------------------- ### Zenoh ZBytes Serialization Example Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Demonstrates serializing various message types into ZBytes and deserializing them back. ```bash z_bytes ``` -------------------------------- ### Install Doxygen on MacOS Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/README.md Installs Doxygen using Homebrew on MacOS systems. Make sure Homebrew is installed and updated. ```bash brew install doxygen ``` -------------------------------- ### Clone and Run Zenoh Router Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md This command sequence clones the Zenoh repository and runs the Zenoh router, which is required for `zenohpico` examples. ```bash git clone https://github.com/eclipse-zenoh/zenoh cd zenoh cargo run ``` -------------------------------- ### Configure Zenoh C++ Build with CMake Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Configure the build using CMake, specifying installation prefix and backend options (zenoh-c, zenoh-pico, or none). ```bash mkdir build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=~/.local # to configure only for zenoh-c backend cmake .. -DZENOHCXX_ZENOHC=OFF -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/.local # to configure only for zenoh-pico backend cmake .. -DZENOHCXX_ZENOHC=OFF -DZENOHCXX_ZENOHPICO=OFF -DCMAKE_INSTALL_PREFIX=~/.local # to configure for none of the backends cmake .. -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/.local # to configure for both backends ``` -------------------------------- ### Add Protobuf Support for Examples Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt This function conditionally adds Protobuf support to an example target. It finds the Protobuf package, generates C++ source and header files from a .proto definition, and links the generated library to the target. ```cmake function(add_protobuf target mode) if(ZENOHCXX_EXAMPLES_PROTOBUF) find_package(Protobuf) if(Protobuf_FOUND) message(STATUS "Found Protobuf ${protobuf_VERSION}, will build Protobuf example!") protobuf_generate_cpp(pb_src pb_hdr ${CMAKE_CURRENT_LIST_DIR}/universal/proto/entity.proto) add_library(example_message_${mode} ${pb_hdr} ${pb_src}) target_include_directories(example_message_${mode} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(example_message_${mode} PUBLIC protobuf::libprotobuf) target_link_libraries(${target} PRIVATE example_message_${mode}) target_compile_definitions(${target} PRIVATE -DZENOH_CPP_EXAMPLE_WITH_PROTOBUF) else() message("Protobuf not found, will build without Protobuf example!") endif() endif() endfunction() ``` -------------------------------- ### Build Zenoh C++ Tests with CMake Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Configure the build to include tests, specifying the installation prefix and backend options. ```bash mkdir build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=~/.local # to build tests only for zenoh-c backend cmake .. -DZENOHCXX_ZENOHC=OFF -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/.local # to build tests only for zenoh-pico backend cmake .. -DZENOHCXX_ZENOHPICO=ON -DCMAKE_INSTALL_PREFIX=~/.local # to build tests for both backends ``` -------------------------------- ### Subscribing to Messages with Zenoh C++ (Callback) Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/pubsub.md Shows how to subscribe to messages using a callback function. The subscriber will print received messages to the console. This example blocks until a key press to keep the subscriber active. ```c++ #include "zenoh.hxx" #include using namespace zenoh; int main(int argc, char **argv) { Config config = Config::create_default(); auto session = Session::open(std::move(config)); auto subscriber = session.declare_subscriber( KeyExpr("demo/example/simple"), [](const Sample& sample) { std::cout << "Received: " << sample.get_payload().as_string() << std::endl; }, closures::none ); // Wait for a key press to exit char c = getchar(); } ``` -------------------------------- ### Scout Zenoh Peers and Routers Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Executes the `z_scout` example to discover Zenoh peers and routers on the network. No specific arguments are required for basic usage. ```bash z_scout ``` -------------------------------- ### Add Individual Example Executable Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/CMakeLists.txt This function compiles a single C++ source file into an executable. It sets output properties, adds dependencies, links libraries, and conditionally includes Protobuf support for specific targets like 'z_bytes_*'. ```cmake function(add_example file mode lib) get_filename_component(filename ${file} NAME_WE) set(target ${filename}_${mode}) add_executable(${target} EXCLUDE_FROM_ALL ${file}) set_target_properties(${target} PROPERTIES OUTPUT_NAME ${filename} RUNTIME_OUTPUT_DIRECTORY ${mode}) add_dependencies(examples_${mode} ${target}) add_dependencies(${target} ${lib}) target_link_libraries(${target} PUBLIC ${lib}) if("${target}" MATCHES "z_bytes_*") add_protobuf(${target} ${mode}) endif() copy_dlls(${target}) endfunction() ``` -------------------------------- ### Send a Query with Callbacks in C++ Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/queryable.md Send a query using the asynchronous get interface and handle replies and completion through callbacks. The client must not exit immediately to allow asynchronous processing. ```c++ #include "zenoh.hxx" using namespace zenoh; int main(int argc, char **argv) { Config config = Config::create_default(); auto session = Session::open(std::move(config)); auto on_reply = [](const Reply& reply) { if (reply.is_ok()) { auto&& sample = reply.get_ok(); std::cout << "Received ('" << sample.get_keyexpr().as_string_view() << "' : '" << sample.get_payload().deserialize() << "')\n"; } else { auto&& err = reply.get_err(); std::cout << "Received an error :" << error.get_payload().deserialzie() << "\n"; } }; auto on_done = []() { std::cout << "No more replies" << std::endl; }; // Send a query and pass two callbacks: one for processing the reply // and one for handle the end of replies session.get(KeyExpr("demo/example/simple"), "", on_reply, on_done); // Do not exit immediately, give time to process replies // Better to wait on a mutex signalled by the on_done callback c = getchar(); } ``` -------------------------------- ### Get Data with Query Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Sends a query message for a selector to retrieve data. Use `-s` to specify the selector. This is used with queryables like `z_queryable` or `z_storage`. ```bash z_get ``` ```bash z_get -s 'demo/**' ``` -------------------------------- ### Configure Zenoh C++ Executables Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/simple/universal/CMakeLists.txt Defines CMake build for Zenoh C++ examples. It sets the minimum CMake version, project name, module path, and finds necessary Zenoh packages. It then defines two executables, 'zp_simple' and 'zc_simple', linking them against the appropriate Zenoh libraries and setting the C++ standard to 17. ```cmake cmake_minimum_required(VERSION 3.16) project(zenohcxx_examples LANGUAGES C CXX) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH}) include(helpers) if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE Release) endif() find_package(zenohpico REQUIRED) find_package(zenohc REQUIRED) find_package(zenohcxx REQUIRED) add_executable(zp_simple z_simple.cxx) target_link_libraries(zp_simple PRIVATE zenohcxx::zenohpico) set_property(TARGET zp_simple PROPERTY LANGUAGE CXX) set_property(TARGET zp_simple PROPERTY CXX_STANDARD 17) copy_dlls(zp_simple) add_executable(zc_simple z_simple.cxx) target_link_libraries(zc_simple PRIVATE zenohcxx::zenohc) set_property(TARGET zc_simple PROPERTY LANGUAGE CXX) set_property(TARGET zc_simple PROPERTY CXX_STANDARD 17) copy_dlls(zc_simple) ``` -------------------------------- ### Zenoh Pong for Roundtrip Time Test Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_pong` to reply to ping operations by writing received data to a second key expression. This must be started before `z_ping`. ```bash z_pong ``` -------------------------------- ### Publish using Shared Memory Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Publishes data using Zenoh's shared-memory feature. The corresponding subscriber uses the standard `z_sub` example. ```bash z_pub_shm ``` -------------------------------- ### Subscribing to Messages with Zenoh C++ (Non-blocking Stream) Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/pubsub.md Implements a non-blocking subscriber using a FIFO channel. This example continuously attempts to receive messages, sleeping when no data is available, allowing for other work to be performed. It breaks the loop if the channel is closed. ```c++ #include "zenoh.hxx" #include #include #include using namespace zenoh; using namespace std::chrono_literals; int main(int argc, char **argv) { Config config = Config::create_default(); auto session = Session::open(std::move(config)); auto subscriber = session.declare_subscriber( KeyExpr("demo/example/simple"), channels::FifoChannel(16) // use FIFO buffer to store unprocessed messages ); while (true) { auto res = subscriber.handler().try_recv(); if (std::holds_alternative(res)) { std::cout << "Received: " << std::get(res).get_payload().as_string() << std::endl; } else if (std::get(res) == channels::RecvError::Z_NODATA) { std::this_thread::sleep_for(1s); // do some other work } else { break; // channel is closed } } } ``` -------------------------------- ### Declare a Queryable Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Declares a queryable function associated with a specific path. This function is triggered by `get` calls matching the path and returns a value. Use `-k` for the path and `-v` for the return value. ```bash z_queryable ``` ```bash z_queryable -k demo/example/queryable -v 'This is the result' ``` -------------------------------- ### Zenoh Liveliness Change Subscription Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_sub_liveliness` to subscribe to liveliness changes (tokens becoming alive or dropped) matching a key expression. It can accept a custom key expression using the `-k` flag. It does not report tokens that were already alive before its start. ```bash z_sub_liveliness ``` ```bash z_sub_liveliness -k 'group1/**' ``` -------------------------------- ### Zenoh Liveliness Token Declaration Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_liveliness` to declare a liveliness token on a key expression. The token remains alive until explicitly dropped or the example terminates. It can accept a custom key expression using the `-k` flag. ```bash z_liveliness ``` ```bash z_liveliness -k 'group1/member1' ``` -------------------------------- ### Create Zenoh Session and Publish Data Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/session_ex.md Use `zenoh::Session::open()` with a configuration to create a session. Then, use the `put()` method to publish a string to a specified key expression. Includes basic error handling for Zenoh exceptions. ```c++ #include "zenoh.hxx" using namespace zenoh; int main(int argc, char **argv) { try { Config config = Config::create_default(); auto session = Session::open(std::move(config)); session.put(KeyExpr("demo/example/simple"), "Simple!"); } catch (ZException e) { std::cout << "Received an error :" << e.what() << "\n"; } } ``` -------------------------------- ### Clone Zenoh-CPP and Configure Build Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/README.md Clones the Zenoh-CPP repository and sets up the build directory using CMake. This prepares the project for building the documentation. ```bash git clone https://github.com/eclipse-zenoh/zenoh-cpp.git mkdir build cmake -Szenoh-cpp -Bbuild ``` -------------------------------- ### Publishing Messages with Zenoh C++ Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/pubsub.md Demonstrates publishing messages using both session.put for direct publishing and a declared Publisher object. Ensure Zenoh is properly configured and opened before publishing. ```c++ #include "zenoh.hxx" using namespace zenoh; int main(int argc, char **argv) { Config config = Config::create_default(); auto session = Session::open(std::move(config)); // Publish without creating a Publisher object session.put(KeyExpr("demo/example/simple"), Bytes("Simple from session.put!")); // Publish from a Publisher object auto publisher = session.declare_publisher(KeyExpr("demo/example/simple")); publisher.put("Simple from publisher.put!"); } ``` -------------------------------- ### Build and Run Zenoh C++ Tests Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Build the tests using CMake and then run them using 'ctest'. ```bash cmake --build . --target tests ctest ``` -------------------------------- ### Build Zenoh-CPP Documentation Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/README.md Builds the documentation using the CMake build system after configuration. This command generates the final documentation files. ```bash cmake --build build --target docs ``` -------------------------------- ### Put Data into Zenoh Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Demonstrates publishing a key-value pair to Zenoh. This data can be received by subscribers like `z_sub` or `z_storage`. Use `-k` for key and `-v` for value. ```bash z_put ``` ```bash z_put -k demo/example/test -v 'Hello World' ``` -------------------------------- ### Implement In-Memory Storage Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Implements a simple in-memory storage by declaring a subscriber and a queryable on the same selector. The subscriber stores data, and the queryable answers queries with stored data. Use `-k` for the selector. ```bash z_storage ``` ```bash z_storage -k 'demo/**' ``` -------------------------------- ### Publish Data Periodically Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Declares a key expression and publisher, then periodically writes values to it. Use `-k` for key expression and `-v` for value. ```bash z_pub ``` ```bash z_pub -k demo/example/test -v 'Hello World' ``` -------------------------------- ### Zenoh Pub/Sub Throughput Test Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_pub_thr` to perform throughput measurements as a publisher. It accepts an optional argument for message size. ```bash z_pub_thr 1024 ``` -------------------------------- ### Clone Zenoh C++ Repository Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Use this command to clone the Zenoh C++ source code from GitHub. ```bash git clone https://github.com/eclipse-zenoh/zenoh-cpp.git ``` -------------------------------- ### Declare a Queryable in C++ Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/queryable.md Implement a queryable endpoint that listens for queries on a specific key expression and replies with serialized data. Ensure the session remains open to receive queries. ```c++ #include "zenoh.hxx" #include using namespace zenoh; int main(int argc, char **argv) { auto queryable_keyexpr = KeyExpr("demo/example/simple"); Config config = Config::create_default(); auto session = Session::open(std::move(config)); auto queryable = session.declare_queryable( queryable_keyexpr, [&queryable_expr](const Query& query) { std::cout << "Received Query '" << query.get_keyexpr().as_string_view() << "?" << query.get_parameters() << std::endl; query.reply(queryable_expr, Bytes::serialize("42")); }, closures::none ); // Wait for a key press to exit c = getchar(); } ``` -------------------------------- ### Zenoh Publisher for Shared Memory Throughput Test Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_pub_shm_thr` to perform throughput measurements as a publisher utilizing the shared-memory feature. ```bash z_pub_shm_thr ``` -------------------------------- ### Include Zenoh Header in C++ Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Include the main Zenoh header file and use the zenoh namespace for accessing its functionality. ```cpp #include "zenoh.hxx" using namespace zenoh; ``` -------------------------------- ### Include Zenoh-CPP in CMake Project Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/README.md Steps to integrate Zenoh-CPP into your CMake project. Ensure backend libraries are included before Zenoh-CPP. ```cmake find_package(zenohc) #if using zenoh-c backend find_package(zenohpico) #if using zenoh-pico backend find_package(zenohcxx) ``` ```cmake target_link_libraries(yourproject PUBLIC zenohcxx::zenohc) #if using zenoh-c backend target_link_libraries(yourproject PUBLIC zenohcxx::zenohpico) #if using zenoh-pico backend ``` -------------------------------- ### Subscribe to Zenoh Data Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Declares a key expression and subscriber to receive notifications for `put` or `delete` operations matching the expression. Use `-k` to specify the key expression. ```bash z_sub ``` ```bash z_sub -k 'demo/**' ``` -------------------------------- ### Continuously Query Zenoh Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Continuously sends query messages for a selector. Use `-s` to specify the selector. This is useful for monitoring services that implement queryables. ```bash z_querier ``` ```bash z_querier -s 'demo/**' ``` -------------------------------- ### Zenoh Pub/Sub Roundtrip Time Test Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_ping` to measure roundtrip time by performing a put operation and waiting for a reply. It accepts an optional argument for message size. ```bash z_ping 1024 ``` -------------------------------- ### Zenoh Liveliness Token Query Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_get_liveliness` to query all currently alive liveliness tokens matching a key expression. It can accept a custom key expression using the `-k` flag. ```bash z_get_liveliness ``` ```bash z_get_liveliness -k 'group1/**' ``` -------------------------------- ### Send a Query using Blocking Stream in C++ Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/docs/queryable.md Retrieve query replies using a blocking stream interface with a FIFO channel. This method allows synchronous processing of replies until no more are available or an error occurs. ```c++ #include "zenoh.hxx" using namespace zenoh; int main(int argc, char **argv) { Config config = Config::create_default(); auto session = Session::open(std::move(config)); // Send a query and receive a stream providing replies. // We will receive a FIFO buffer to store unprocessed replies (with size of 16). auto replies = session.get(KeyExpr("demo/example/simple"), "", channels::FifoChannel(16)); while (true) { auto res = replies.recv(); Reply* reply = std::get_if(&res); if (reply == nullptr) break; if (reply->is_ok()) { const Sample& sample = reply->get_ok(); std::cout << "Received ('" << sample.get_keyexpr().as_string_view() << "' : '" << sample.get_payload().as_string() << "')\n"; } else { const ReplyError& error = reply->get_err(); std::cout << "Received an error :" << error.get_payload().as_string() << "\n"; } } std::cout << "No more replies" << std::endl; } ``` -------------------------------- ### Zenoh Subscriber for Throughput Test Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Use `z_sub_thr` to receive notifications from a publisher performing put operations for throughput measurements. This is also used for shared-memory throughput tests. ```bash z_sub_thr ``` -------------------------------- ### Pull Data from Zenoh Source: https://github.com/eclipse-zenoh/zenoh-cpp/blob/main/examples/README.md Declares a pull subscriber to receive notifications of the last N `put` or `delete` operations matching a key expression. Use `-k` for the key expression and `--size` for the number of notifications. ```bash z_pull ``` ```bash z_pull -k demo/** --size 3 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.