From ab575058fd7f873064d87c979704c44be6611320 Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Mon, 3 Feb 2025 09:22:38 +0100 Subject: [PATCH] Add dummy InitLogger function --- CMakeLists.txt | 1 + wasm/include/rtc/global.hpp | 55 +++++++++++++++++++++++++++++ wasm/include/rtc/rtc.hpp | 9 +---- wasm/src/global.cpp | 69 +++++++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 wasm/include/rtc/global.hpp create mode 100644 wasm/src/global.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 72ea68b..eb69902 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ set(DATACHANNELS_SRC ${WASM_SRC_DIR}/configuration.cpp ${WASM_SRC_DIR}/description.cpp ${WASM_SRC_DIR}/datachannel.cpp + ${WASM_SRC_DIR}/global.cpp ${WASM_SRC_DIR}/peerconnection.cpp ${WASM_SRC_DIR}/websocket.cpp) diff --git a/wasm/include/rtc/global.hpp b/wasm/include/rtc/global.hpp new file mode 100644 index 0000000..aba28c5 --- /dev/null +++ b/wasm/include/rtc/global.hpp @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2017-2024 Paul-Louis Ageneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef RTC_GLOBAL_H +#define RTC_GLOBAL_H + +#include "common.hpp" + +#include +#include + +namespace rtc { + +enum class LogLevel { + None = 0, + Fatal = 1, + Error = 2, + Warning = 3, + Info = 4, + Debug = 5, + Verbose = 6 +}; + +typedef std::function LogCallback; + +// Dummy function for compatibility with libdatachannel +void InitLogger(LogLevel level, LogCallback callback = nullptr); +void Preload(); +std::shared_future Cleanup(); + +std::ostream &operator<<(std::ostream &out, LogLevel level); + +} // namespace rtc + +#endif + diff --git a/wasm/include/rtc/rtc.hpp b/wasm/include/rtc/rtc.hpp index ee91bb6..b90dec8 100644 --- a/wasm/include/rtc/rtc.hpp +++ b/wasm/include/rtc/rtc.hpp @@ -24,17 +24,10 @@ #define RTC_H #include "common.hpp" +#include "global.hpp" #include "datachannel.hpp" #include "peerconnection.hpp" #include "websocket.hpp" -namespace rtc { - -// Dummy functions -inline void Preload() {} -inline void Cleanup() {} - -} // namespace rtc - #endif // RTC_H diff --git a/wasm/src/global.cpp b/wasm/src/global.cpp new file mode 100644 index 0000000..7b5f231 --- /dev/null +++ b/wasm/src/global.cpp @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2017-2024 Paul-Louis Ageneau + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "global.hpp" + +namespace rtc { + +void InitLogger([[maybe_unused]] LogLevel level, [[maybe_unused]] LogCallback callback) { + // Dummy +} + +void Preload() { + // Dummy +} + +std::shared_future Cleanup() { + // Dummy + std::promise p; + p.set_value(); + return p.get_future(); +} + +std::ostream &operator<<(std::ostream &out, LogLevel level) { + switch (level) { + case LogLevel::Fatal: + out << "fatal"; + break; + case LogLevel::Error: + out << "error"; + break; + case LogLevel::Warning: + out << "warning"; + break; + case LogLevel::Info: + out << "info"; + break; + case LogLevel::Debug: + out << "debug"; + break; + case LogLevel::Verbose: + out << "verbose"; + break; + default: + out << "none"; + break; + } + return out; +} + +} // namespace rtc