From ea9d5e291f95b2e58f8d719db6b044d09585967d Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 26 Feb 2026 21:29:48 +0100 Subject: [PATCH 1/3] sort files in CMakeLists.txt --- .../SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp | 0 .../SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h | 0 bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt | 8 ++++---- 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp create mode 100644 bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h new file mode 100644 index 000000000..e69de29bb diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt b/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt index b65f18044..4dfb1fc67 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt @@ -1,20 +1,20 @@ project(Bindings.Sofa.Helper) set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.h - ${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h - ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h ${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.h + ${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h ) set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Helper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp ) sofa_find_package(Sofa.Core REQUIRED) From 734f0186ccc9433c22a38d4139e034f805a2fd52 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 26 Feb 2026 21:46:41 +0100 Subject: [PATCH 2/3] Introduce bindings for MessageDispatcher --- .../Sofa/Helper/Binding_MessageDispatcher.cpp | 40 +++++++++++++++++++ .../Sofa/Helper/Binding_MessageDispatcher.h | 30 ++++++++++++++ .../SofaPython3/Sofa/Helper/CMakeLists.txt | 2 + 3 files changed, 72 insertions(+) diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp index e69de29bb..9af91f48d 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp @@ -0,0 +1,40 @@ +/****************************************************************************** +* SofaPython3 plugin * +* (c) 2021 CNRS, University of Lille, INRIA * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#include +#include + +namespace py { using namespace pybind11; } + +void sofapython3::moduleAddMessageDispatcher(pybind11::module &m) +{ + py::module messageDispatcherModule = m.def_submodule("MessageDispatcher"); + + messageDispatcherModule.doc() = R"doc( + MessageDispatcher + ----------------------- + + Configuration of the message dispatcher. + )doc"; + + messageDispatcherModule.def("clearHandlers", + [](){ + sofa::helper::logging::MessageDispatcher::clearHandlers(); + }, "Removes all registered message handlers."); +} diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h index e69de29bb..90f219bb4 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h @@ -0,0 +1,30 @@ +/****************************************************************************** +* SofaPython3 plugin * +* (c) 2021 CNRS, University of Lille, INRIA * +* * +* This program is free software; you can redistribute it and/or modify it * +* under the terms of the GNU Lesser General Public License as published by * +* the Free Software Foundation; either version 2.1 of the License, or (at * +* your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, but WITHOUT * +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * +* for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with this program. If not, see . * +******************************************************************************* +* Contact information: contact@sofa-framework.org * +******************************************************************************/ +#pragma once + +#include + +namespace sofapython3 +{ + +void moduleAddMessageDispatcher(pybind11::module &m); + +} /// namespace sofapython3 + diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt b/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt index 4dfb1fc67..f51d2a634 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt @@ -1,6 +1,7 @@ project(Bindings.Sofa.Helper) set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageDispatcher.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.h ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.h @@ -9,6 +10,7 @@ set(HEADER_FILES ) set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageDispatcher.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.cpp From 836b7f5ead918e31b3867d4762eb3832fe6c8b39 Mon Sep 17 00:00:00 2001 From: Alex Bilger Date: Thu, 26 Feb 2026 21:54:03 +0100 Subject: [PATCH 3/3] Add `num_handlers` binding to MessageDispatcher and rename `clearHandlers` to `clear_handlers` --- .../SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp index 9af91f48d..cd8fb4d00 100644 --- a/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp +++ b/bindings/Sofa/src/SofaPython3/Sofa/Helper/Binding_MessageDispatcher.cpp @@ -33,8 +33,13 @@ void sofapython3::moduleAddMessageDispatcher(pybind11::module &m) Configuration of the message dispatcher. )doc"; - messageDispatcherModule.def("clearHandlers", + messageDispatcherModule.def("clear_handlers", [](){ sofa::helper::logging::MessageDispatcher::clearHandlers(); }, "Removes all registered message handlers."); + + messageDispatcherModule.def("num_handlers", + [](){ + return sofa::helper::logging::MessageDispatcher::getHandlers().size(); + }, "Returns the number of registered message handlers."); }