Skip to content

Commit

Permalink
Add missing headers for correct wrapping
Browse files Browse the repository at this point in the history
Add additional logging sample.
  • Loading branch information
KerstinKeller committed Feb 17, 2025
1 parent 1d681a7 commit 83de9a6
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include <core/config/py_configuration.h>
#include <ecal/config/configuration.h>

// Nanobind includes to map stl types to python types
#include <nanobind/stl/string.h>

namespace nb = nanobind;

void AddConfigConfiguration(nanobind::module_& module)
Expand Down
4 changes: 4 additions & 0 deletions lang/python/nanobind_core/src/core/pubsub/py_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <core/pubsub/py_publisher.h>
#include <ecal/pubsub/publisher.h>

// Nanobind includes to map stl types to python types
#include <nanobind/stl/function.h>
#include <nanobind/stl/string.h>

namespace nb = nanobind;
using namespace eCAL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <ecal/pubsub/subscriber.h>

#include <nanobind/stl/function.h>
#include <nanobind/stl/string.h>

#include <exception>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <core/types/py_custom_data_types.h>
#include <ecal/types/custom_data_types.h>

#include <nanobind/stl/string.h>

namespace nb = nanobind;
using namespace eCAL;

Expand Down
1 change: 1 addition & 0 deletions lang/python/nanobind_core/src/core/types/py_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <ecal/types/logging.h>

#include <nanobind/stl/list.h>
#include <nanobind/stl/string.h>

namespace nb = nanobind;
using namespace eCAL::Logging;
Expand Down
44 changes: 24 additions & 20 deletions lang/python/nanobind_core/src/nanobind_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,34 @@
#include <core/types/py_logging.h>
#include <core/types/py_monitoring.h>

namespace nb = nanobind;

NB_MODULE(nanobind_core, m) {
AddConfig(m);
AddCore(m);
AddInit(m);
AddLog(m);
AddLogLevel(m);
NB_MODULE(nanobind_core, core) {
auto init = core.def_submodule("init", "Initialization related functions and classes");

AddTypes(m);
AddCore(core);

AddConfigApplication(m);
AddConfigConfiguration(m);
AddConfigLogging(m);
AddConfigPublisher(m);
AddConfigRegistration(m);
AddConfigSubscriber(m);
AddConfigTime(m);
AddConfigTransportLayer(m);
AddInit(init);
AddLog(core);
AddLogLevel(core);

AddPubsubPublisher(m);
AddPubsubSubscriber(m);
AddPubsubTypes(m);
AddTypes(core);

AddConfigApplication(core);
AddConfigLogging(core);
AddConfigPublisher(core);
AddConfigRegistration(core);
AddConfigSubscriber(core);
AddConfigTime(core);
AddConfigTransportLayer(core);
AddConfigConfiguration(core); // need to add last, so the others are available.
AddConfig(core);

AddTypesCustomDataTypes(m);
AddTypesLogging(m);
AddPubsubPublisher(core);
AddPubsubSubscriber(core);
AddPubsubTypes(core);


AddTypesCustomDataTypes(core);
AddTypesLogging(core);
}
1 change: 1 addition & 0 deletions lang/python/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(python_samples_nanobind_core
nanobind_core/pubsub/nb_binary_snd.py
nanobind_core/service/nb_minimal_service_client.py
nanobind_core/service/nb_minimal_service_server.py
nanobind_core/nb_logging.py
)

function(add_sample_to_solution python_filenname)
Expand Down
43 changes: 43 additions & 0 deletions lang/python/samples/nanobind_core/nb_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2025 Continental Corporation
#
# 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.
#
# ========================= eCAL LICENSE =================================
import ecal.nanobind_core as ecal_core
help(ecal_core)

def main():

# For pure logging, it's not necessary to modify the configuration.
# However, in order to also receive logging information it's necessary to be turned on
config = ecal_core.init.get_configuration()
config.logging.receiver.enable = True
ecal_core.initialize(config, 'logging', ecal_core.init.ALL)

ecal_core.log(ecal_core.LogLevel.INFO, "Hello Hello")
ecal_core.log(ecal_core.LogLevel.WARNING, "Help")


all_logging = ecal_core.get_logging()

for log in all_logging.log_messages:
print(log)

ecal_core.finalize()



if __name__ == "__main__":
main()

0 comments on commit 83de9a6

Please sign in to comment.