From 323cd576e2477ff49c4fa765cac2d28c913d9bc2 Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Date: Thu, 4 Jun 2026 12:40:04 +0200 Subject: [PATCH 1/5] Change default log verbosity to Error Signed-off-by: Raul Sanchez-Mateos --- ddsenabler_yaml/src/cpp/EnablerConfiguration.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ddsenabler_yaml/src/cpp/EnablerConfiguration.cpp b/ddsenabler_yaml/src/cpp/EnablerConfiguration.cpp index 33af68ee..928286ab 100644 --- a/ddsenabler_yaml/src/cpp/EnablerConfiguration.cpp +++ b/ddsenabler_yaml/src/cpp/EnablerConfiguration.cpp @@ -179,6 +179,12 @@ void EnablerConfiguration::load_ddsenabler_configuration_( enabler_configuration->id = "EnablerEnablerParticipant"; enabler_configuration->app_id = "DDS_ENABLER"; + ///// + // Set the DDS Enabler default log verbosity to ERROR, so that INFO and WARNING traces + // (from both the Enabler and the underlying DDS Pipe) are silenced unless the user + // explicitly raises the verbosity through the logging configuration. + ddspipe_configuration.log_configuration.verbosity.set_value(utils::VerbosityKind::Error); + ///// // Get optional Enabler configuration options if (YamlReader::is_tag_present(yml, ENABLER_ENABLER_TAG)) From 20ec08f6eb03d8b0e640bb97e8e4c7f9c186d17b Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Date: Thu, 4 Jun 2026 12:40:30 +0200 Subject: [PATCH 2/5] Add new example for topic, services and actions discovery Signed-off-by: Raul Sanchez-Mateos --- ddsenabler/examples/CMakeLists.txt | 1 + ddsenabler/examples/discovery/CMakeLists.txt | 39 +++++++ ddsenabler/examples/discovery/README.md | 32 ++++++ ddsenabler/examples/discovery/config.yml | 2 + ddsenabler/examples/discovery/main.cpp | 113 +++++++++++++++++++ 5 files changed, 187 insertions(+) create mode 100644 ddsenabler/examples/discovery/CMakeLists.txt create mode 100644 ddsenabler/examples/discovery/README.md create mode 100644 ddsenabler/examples/discovery/config.yml create mode 100644 ddsenabler/examples/discovery/main.cpp diff --git a/ddsenabler/examples/CMakeLists.txt b/ddsenabler/examples/CMakeLists.txt index 8d8fa754..9760d5e4 100644 --- a/ddsenabler/examples/CMakeLists.txt +++ b/ddsenabler/examples/CMakeLists.txt @@ -20,6 +20,7 @@ install( # Add subdirectories for examples add_subdirectory(utils) +add_subdirectory(discovery) add_subdirectory(publish) add_subdirectory(service) add_subdirectory(action) diff --git a/ddsenabler/examples/discovery/CMakeLists.txt b/ddsenabler/examples/discovery/CMakeLists.txt new file mode 100644 index 00000000..42fba486 --- /dev/null +++ b/ddsenabler/examples/discovery/CMakeLists.txt @@ -0,0 +1,39 @@ +# Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.20) +project(ddsenabler_example_discovery LANGUAGES CXX) + +# When built standalone (not as a subdirectory of the DDS Enabler project), the +# 'ddsenabler' target does not exist yet, so locate the installed library. The +# imported 'ddsenabler' target links transitively against the packages below, so +# they must be found as well for the standalone build to configure and link. +if(NOT TARGET ddsenabler) + find_package(cpp_utils REQUIRED) + find_package(ddspipe_core REQUIRED) + find_package(ddspipe_participants REQUIRED) + find_package(ddspipe_yaml REQUIRED) + find_package(ddsenabler_participants REQUIRED) + find_package(ddsenabler_yaml REQUIRED) + find_package(ddsenabler REQUIRED) +endif() + +add_executable(ddsenabler_example_discovery main.cpp) + +target_link_libraries(ddsenabler_example_discovery PRIVATE ddsenabler) + +# Install rule +install(TARGETS ddsenabler_example_discovery + RUNTIME DESTINATION examples/discovery +) diff --git a/ddsenabler/examples/discovery/README.md b/ddsenabler/examples/discovery/README.md new file mode 100644 index 00000000..99d55056 --- /dev/null +++ b/ddsenabler/examples/discovery/README.md @@ -0,0 +1,32 @@ +# Discovery Example Readme + +This is the simplest DDS Enabler example and a good starting point. +It launches a DDS Enabler that listens to the DDS network and prints the **name** of every topic, service and action it discovers — nothing else (no types, no QoS, no data). + +The application keeps running until it is stopped with `Ctrl+C`. + +It registers only the three discovery notification callbacks of the `CallbackSet`: + +- `dds.topic_notification` → prints discovered topic names. +- `service.service_notification` → prints discovered service names. +- `action.action_notification` → prints discovered action names. + +## Example Command + +```bash +./ddsenabler_example_discovery config.yml +``` + +Run it and then start any DDS / ROS 2 application (for instance the ROS 2 `talker`, or another DDS Enabler example such as `publish`, `service` or `action`). +Each newly discovered topic, service or action prints a line like: + +``` +[Discovery] Topic discovered: rt/chatter +[Discovery] Service discovered: /add_two_ints +[Discovery] Action discovered: /fibonacci +``` + +Press `Ctrl+C` to stop the application cleanly. + +An optional YAML configuration file may be passed as the first argument to customize the DDS behavior (domain, allow/deny topic lists, etc.). +Without it, the Enabler uses its default configuration (DDS domain 0). diff --git a/ddsenabler/examples/discovery/config.yml b/ddsenabler/examples/discovery/config.yml new file mode 100644 index 00000000..2983a009 --- /dev/null +++ b/ddsenabler/examples/discovery/config.yml @@ -0,0 +1,2 @@ +dds: + domain: 0 \ No newline at end of file diff --git a/ddsenabler/examples/discovery/main.cpp b/ddsenabler/examples/discovery/main.cpp new file mode 100644 index 00000000..7be7b83d --- /dev/null +++ b/ddsenabler/examples/discovery/main.cpp @@ -0,0 +1,113 @@ +// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @file main.cpp + * + * Minimal DDS Enabler example: print the name of every topic, service and action + * the Enabler discovers, and keep running until the user presses Ctrl+C. + */ + +#include +#include +#include +#include +#include + +#include "ddsenabler/dds_enabler_runner.hpp" +#include "ddsenabler/DDSEnabler.hpp" + +// Synchronization used to keep the application alive until a stop signal arrives. +std::mutex app_mutex; +std::condition_variable app_cv; +bool stop_app = false; + +// Called by the Enabler every time a new DDS topic is discovered. +void on_topic_discovered( + const char* topic_name, + const eprosima::ddsenabler::participants::TopicInfo& /* topic_info */) +{ + std::cout << "[Discovery] Topic discovered: " << topic_name << std::endl; +} + +// Called by the Enabler every time a new ROS 2 / DDS service is discovered. +void on_service_discovered( + const char* service_name, + const eprosima::ddsenabler::participants::ServiceInfo& /* service_info */) +{ + std::cout << "[Discovery] Service discovered: " << service_name << std::endl; +} + +// Called by the Enabler every time a new ROS 2 / DDS action is discovered. +void on_action_discovered( + const char* action_name, + const eprosima::ddsenabler::participants::ActionInfo& /* action_info */) +{ + std::cout << "[Discovery] Action discovered: " << action_name << std::endl; +} + +// Stops the application cleanly when Ctrl+C (or another termination signal) is received. +void signal_handler( + int /* signum */) +{ + { + std::lock_guard lock(app_mutex); + stop_app = true; + } + app_cv.notify_all(); +} + +int main( + int argc, + char** argv) +{ + using namespace eprosima::ddsenabler; + + // Register only the discovery notification callbacks; everything else is left unset. + CallbackSet callbacks{}; + callbacks.dds.topic_notification = on_topic_discovered; + callbacks.service.service_notification = on_service_discovered; + callbacks.action.action_notification = on_action_discovered; + + // Create the Enabler. An optional YAML configuration file may be passed as the first argument. + std::shared_ptr enabler; + bool enabler_created = (argc > 1) + ? create_dds_enabler(argv[1], callbacks, enabler) + : create_dds_enabler(yaml::EnablerConfiguration(""), callbacks, enabler); + + if (!enabler_created) + { + std::cerr << "Failed to create DDSEnabler instance." << std::endl; + return EXIT_FAILURE; + } + + // Install signal handlers for a clean shutdown. + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); + + std::cout << "DDS Enabler running. Listening for topics, services and actions. " + << "Press Ctrl+C to stop." << std::endl; + + // Block until a stop signal is received. + { + std::unique_lock lock(app_mutex); + app_cv.wait(lock, [] + { + return stop_app; + }); + } + + std::cout << "Stopping DDS Enabler..." << std::endl; + return EXIT_SUCCESS; +} From c65d22050d705a4d5636843b2aedfe784d6426d8 Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Date: Thu, 4 Jun 2026 12:48:13 +0200 Subject: [PATCH 3/5] Add compilation instructions for the new example Signed-off-by: Raul Sanchez-Mateos --- ddsenabler/examples/discovery/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ddsenabler/examples/discovery/README.md b/ddsenabler/examples/discovery/README.md index 99d55056..9c150b00 100644 --- a/ddsenabler/examples/discovery/README.md +++ b/ddsenabler/examples/discovery/README.md @@ -11,6 +11,28 @@ It registers only the three discovery notification callbacks of the `CallbackSet - `service.service_notification` → prints discovered service names. - `action.action_notification` → prints discovered action names. +## Compilation + +The example is compiled together with the DDS Enabler when the project is built with the `-DCOMPILE_EXAMPLES=ON` CMake option. +It can also be compiled standalone against an already installed DDS Enabler. + +First, source the environment where the DDS Enabler is installed. + +```bash +source /install/setup.bash +``` + +Then configure and build the example from its own directory. + +```bash +mkdir build +cd build +cmake .. +cmake --build . +``` + +The `ddsenabler_example_discovery` executable is generated inside the `build` directory. + ## Example Command ```bash From d23f949671b4023ff684efdd732fc8c1edf07350 Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Lizano Date: Thu, 4 Jun 2026 16:45:46 +0200 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: DannyP39 <98972125+Danipiza@users.noreply.github.com> Signed-off-by: Raul Sanchez-Mateos Lizano --- ddsenabler/examples/discovery/CMakeLists.txt | 2 +- ddsenabler/examples/discovery/README.md | 6 +++--- ddsenabler/examples/discovery/config.yml | 3 ++- ddsenabler/examples/discovery/main.cpp | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ddsenabler/examples/discovery/CMakeLists.txt b/ddsenabler/examples/discovery/CMakeLists.txt index 42fba486..5d43d57a 100644 --- a/ddsenabler/examples/discovery/CMakeLists.txt +++ b/ddsenabler/examples/discovery/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima). # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/ddsenabler/examples/discovery/README.md b/ddsenabler/examples/discovery/README.md index 9c150b00..f6805992 100644 --- a/ddsenabler/examples/discovery/README.md +++ b/ddsenabler/examples/discovery/README.md @@ -1,7 +1,7 @@ -# Discovery Example Readme +# Discovery Example README This is the simplest DDS Enabler example and a good starting point. -It launches a DDS Enabler that listens to the DDS network and prints the **name** of every topic, service and action it discovers — nothing else (no types, no QoS, no data). +It launches a DDS Enabler that listens to the DDS network and prints the **name** of every topic, service and action it discovers - nothing else (no types, no QoS, no data). The application keeps running until it is stopped with `Ctrl+C`. @@ -40,7 +40,7 @@ The `ddsenabler_example_discovery` executable is generated inside the `build` di ``` Run it and then start any DDS / ROS 2 application (for instance the ROS 2 `talker`, or another DDS Enabler example such as `publish`, `service` or `action`). -Each newly discovered topic, service or action prints a line like: +When a topic, service, or action is discovered, the application prints a line like: ``` [Discovery] Topic discovered: rt/chatter diff --git a/ddsenabler/examples/discovery/config.yml b/ddsenabler/examples/discovery/config.yml index 2983a009..27b3774b 100644 --- a/ddsenabler/examples/discovery/config.yml +++ b/ddsenabler/examples/discovery/config.yml @@ -1,2 +1,3 @@ dds: - domain: 0 \ No newline at end of file + domain: 0 + \ No newline at end of file diff --git a/ddsenabler/examples/discovery/main.cpp b/ddsenabler/examples/discovery/main.cpp index 7be7b83d..8d992e52 100644 --- a/ddsenabler/examples/discovery/main.cpp +++ b/ddsenabler/examples/discovery/main.cpp @@ -1,4 +1,4 @@ -// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// Copyright 2026 Proyectos y Sistemas de Mantenimiento SL (eProsima). // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 032f77c7a2dbde6151f91299ac33b0c3af6a3c07 Mon Sep 17 00:00:00 2001 From: Raul Sanchez-Mateos Date: Thu, 4 Jun 2026 16:48:06 +0200 Subject: [PATCH 5/5] Install config file in the example Signed-off-by: Raul Sanchez-Mateos --- ddsenabler/examples/discovery/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ddsenabler/examples/discovery/CMakeLists.txt b/ddsenabler/examples/discovery/CMakeLists.txt index 5d43d57a..89521061 100644 --- a/ddsenabler/examples/discovery/CMakeLists.txt +++ b/ddsenabler/examples/discovery/CMakeLists.txt @@ -37,3 +37,8 @@ target_link_libraries(ddsenabler_example_discovery PRIVATE ddsenabler) install(TARGETS ddsenabler_example_discovery RUNTIME DESTINATION examples/discovery ) + +# Install the example configuration file +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.yml + DESTINATION examples/discovery +)