Skip to content

Commit

Permalink
Add dummy InitLogger function
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Feb 3, 2025
1 parent 1024488 commit ab57505
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 8 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
55 changes: 55 additions & 0 deletions wasm/include/rtc/global.hpp
Original file line number Diff line number Diff line change
@@ -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 <future>
#include <iostream>

namespace rtc {

enum class LogLevel {
None = 0,
Fatal = 1,
Error = 2,
Warning = 3,
Info = 4,
Debug = 5,
Verbose = 6
};

typedef std::function<void(LogLevel level, string message)> LogCallback;

// Dummy function for compatibility with libdatachannel
void InitLogger(LogLevel level, LogCallback callback = nullptr);
void Preload();
std::shared_future<void> Cleanup();

std::ostream &operator<<(std::ostream &out, LogLevel level);

} // namespace rtc

#endif

9 changes: 1 addition & 8 deletions wasm/include/rtc/rtc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 69 additions & 0 deletions wasm/src/global.cpp
Original file line number Diff line number Diff line change
@@ -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<void> Cleanup() {
// Dummy
std::promise<void> 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

0 comments on commit ab57505

Please sign in to comment.