Skip to content

Commit c945974

Browse files
authored
Introduce bindings for MessageDispatcher (#588)
* sort files in CMakeLists.txt * Introduce bindings for MessageDispatcher * Add `num_handlers` binding to MessageDispatcher and rename `clearHandlers` to `clear_handlers` * change naming convention
1 parent e277515 commit c945974

3 files changed

Lines changed: 81 additions & 4 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#include <SofaPython3/Sofa/Helper/Binding_MessageDispatcher.h>
21+
#include <sofa/helper/logging/MessageDispatcher.h>
22+
23+
namespace py { using namespace pybind11; }
24+
25+
void sofapython3::moduleAddMessageDispatcher(pybind11::module &m)
26+
{
27+
py::module messageDispatcherModule = m.def_submodule("MessageDispatcher");
28+
29+
messageDispatcherModule.doc() = R"doc(
30+
MessageDispatcher
31+
-----------------------
32+
33+
Configuration of the message dispatcher.
34+
)doc";
35+
36+
messageDispatcherModule.def("clearHandlers",
37+
[](){
38+
sofa::helper::logging::MessageDispatcher::clearHandlers();
39+
}, "Removes all registered message handlers.");
40+
41+
messageDispatcherModule.def("numHandlers",
42+
[](){
43+
return sofa::helper::logging::MessageDispatcher::getHandlers().size();
44+
}, "Returns the number of registered message handlers.");
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/******************************************************************************
2+
* SofaPython3 plugin *
3+
* (c) 2021 CNRS, University of Lille, INRIA *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify it *
6+
* under the terms of the GNU Lesser General Public License as published by *
7+
* the Free Software Foundation; either version 2.1 of the License, or (at *
8+
* your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, but WITHOUT *
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13+
* for more details. *
14+
* *
15+
* You should have received a copy of the GNU Lesser General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
*******************************************************************************
18+
* Contact information: contact@sofa-framework.org *
19+
******************************************************************************/
20+
#pragma once
21+
22+
#include <pybind11/pybind11.h>
23+
24+
namespace sofapython3
25+
{
26+
27+
void moduleAddMessageDispatcher(pybind11::module &m);
28+
29+
} /// namespace sofapython3
30+

bindings/Sofa/src/SofaPython3/Sofa/Helper/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
project(Bindings.Sofa.Helper)
22

33
set(HEADER_FILES
4+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageDispatcher.h
5+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h
46
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.h
57
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.h
68
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Version.h
7-
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h
8-
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.h
99
${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.h
10+
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.h
1011
)
1112

1213
set(SOURCE_FILES
13-
${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Helper.cpp
14+
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageDispatcher.cpp
1415
${CMAKE_CURRENT_SOURCE_DIR}/Binding_MessageHandler.cpp
1516
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Utils.cpp
1617
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Vector.cpp
1718
${CMAKE_CURRENT_SOURCE_DIR}/Binding_Version.cpp
18-
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp
19+
${CMAKE_CURRENT_SOURCE_DIR}/Submodule_Helper.cpp
1920
${CMAKE_CURRENT_SOURCE_DIR}/System/Binding_FileRepository.cpp
21+
${CMAKE_CURRENT_SOURCE_DIR}/System/Submodule_System.cpp
2022
)
2123

2224
sofa_find_package(Sofa.Core REQUIRED)

0 commit comments

Comments
 (0)