From f4635b0d572a5d39da0ac919a3b13eb8ad18d01a Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Fri, 19 Jan 2024 11:25:42 +0100 Subject: [PATCH 1/2] Moved operator<< to rtc namespace --- include/rtc/candidate.hpp | 10 +++++----- include/rtc/description.hpp | 11 +++++------ include/rtc/global.hpp | 4 ++-- include/rtc/peerconnection.hpp | 12 +++++------- src/candidate.cpp | 30 +++++++++++++++--------------- src/description.cpp | 28 ++++++++++++++-------------- src/global.cpp | 18 +++++++++--------- src/peerconnection.cpp | 20 ++++++++++---------- 8 files changed, 65 insertions(+), 68 deletions(-) diff --git a/include/rtc/candidate.hpp b/include/rtc/candidate.hpp index 88524851a..00ca20d84 100644 --- a/include/rtc/candidate.hpp +++ b/include/rtc/candidate.hpp @@ -67,11 +67,11 @@ class RTC_CPP_EXPORT Candidate { uint16_t mPort; }; -} // namespace rtc - -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Candidate::Type &type); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const Candidate &candidate); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const Candidate::Type &type); RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, - const rtc::Candidate::TransportType &transportType); + const Candidate::TransportType &transportType); + +} // namespace rtc #endif diff --git a/include/rtc/description.hpp b/include/rtc/description.hpp index 32c7f529a..0d0c58b5f 100644 --- a/include/rtc/description.hpp +++ b/include/rtc/description.hpp @@ -314,12 +314,11 @@ class RTC_CPP_EXPORT Description { bool mEnded = false; }; -} // namespace rtc +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const Description &description); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, Description::Type type); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, Description::Role role); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const Description::Direction &direction); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const rtc::Description &description); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::Description::Type type); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::Description::Role role); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, - const rtc::Description::Direction &direction); +} // namespace rtc #endif diff --git a/include/rtc/global.hpp b/include/rtc/global.hpp index a2038ed09..84317f4dd 100644 --- a/include/rtc/global.hpp +++ b/include/rtc/global.hpp @@ -52,8 +52,8 @@ struct SctpSettings { RTC_CPP_EXPORT void SetSctpSettings(SctpSettings s); -} // namespace rtc +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, LogLevel level); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::LogLevel level); +} // namespace rtc #endif diff --git a/include/rtc/peerconnection.hpp b/include/rtc/peerconnection.hpp index 0afc2ad56..86ea410cd 100644 --- a/include/rtc/peerconnection.hpp +++ b/include/rtc/peerconnection.hpp @@ -120,13 +120,11 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat { optional rtt(); }; -} // namespace rtc +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, PeerConnection::State state); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, PeerConnection::IceState state); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, PeerConnection::GatheringState state); +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, PeerConnection::SignalingState state); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::State state); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::IceState state); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, - rtc::PeerConnection::GatheringState state); -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, - rtc::PeerConnection::SignalingState state); +} // namespace rtc #endif diff --git a/src/candidate.cpp b/src/candidate.cpp index cd88b0e10..13ee90029 100644 --- a/src/candidate.cpp +++ b/src/candidate.cpp @@ -248,40 +248,40 @@ optional Candidate::port() const { return isResolved() ? std::make_optional(mPort) : nullopt; } -} // namespace rtc - -std::ostream &operator<<(std::ostream &out, const rtc::Candidate &candidate) { - return out << std::string(candidate); +std::ostream &operator<<(std::ostream &out, const Candidate &candidate) { + return out << string(candidate); } -std::ostream &operator<<(std::ostream &out, const rtc::Candidate::Type &type) { +std::ostream &operator<<(std::ostream &out, const Candidate::Type &type) { switch (type) { - case rtc::Candidate::Type::Host: + case Candidate::Type::Host: return out << "host"; - case rtc::Candidate::Type::PeerReflexive: + case Candidate::Type::PeerReflexive: return out << "prflx"; - case rtc::Candidate::Type::ServerReflexive: + case Candidate::Type::ServerReflexive: return out << "srflx"; - case rtc::Candidate::Type::Relayed: + case Candidate::Type::Relayed: return out << "relay"; default: return out << "unknown"; } } -std::ostream &operator<<(std::ostream &out, const rtc::Candidate::TransportType &transportType) { +std::ostream &operator<<(std::ostream &out, const Candidate::TransportType &transportType) { switch (transportType) { - case rtc::Candidate::TransportType::Udp: + case Candidate::TransportType::Udp: return out << "UDP"; - case rtc::Candidate::TransportType::TcpActive: + case Candidate::TransportType::TcpActive: return out << "TCP_active"; - case rtc::Candidate::TransportType::TcpPassive: + case Candidate::TransportType::TcpPassive: return out << "TCP_passive"; - case rtc::Candidate::TransportType::TcpSo: + case Candidate::TransportType::TcpSo: return out << "TCP_so"; - case rtc::Candidate::TransportType::TcpUnknown: + case Candidate::TransportType::TcpUnknown: return out << "TCP_unknown"; default: return out << "unknown"; } } + +} // namespace rtc diff --git a/src/description.cpp b/src/description.cpp index 84eecc0ea..b2165a895 100644 --- a/src/description.cpp +++ b/src/description.cpp @@ -1347,18 +1347,16 @@ bool CertificateFingerprint::isValid() const { return true; } -} // namespace rtc - -std::ostream &operator<<(std::ostream &out, const rtc::Description &description) { - return out << std::string(description); +std::ostream &operator<<(std::ostream &out, const Description &description) { + return out << string(description); } -std::ostream &operator<<(std::ostream &out, rtc::Description::Type type) { - return out << rtc::Description::typeToString(type); +std::ostream &operator<<(std::ostream &out, Description::Type type) { + return out << Description::typeToString(type); } -std::ostream &operator<<(std::ostream &out, rtc::Description::Role role) { - using Role = rtc::Description::Role; +std::ostream &operator<<(std::ostream &out, Description::Role role) { + using Role = Description::Role; // Used for SDP generation, do not change switch (role) { case Role::Active: @@ -1374,25 +1372,27 @@ std::ostream &operator<<(std::ostream &out, rtc::Description::Role role) { return out; } -std::ostream &operator<<(std::ostream &out, const rtc::Description::Direction &direction) { +std::ostream &operator<<(std::ostream &out, const Description::Direction &direction) { // Used for SDP generation, do not change switch (direction) { - case rtc::Description::Direction::RecvOnly: + case Description::Direction::RecvOnly: out << "recvonly"; break; - case rtc::Description::Direction::SendOnly: + case Description::Direction::SendOnly: out << "sendonly"; break; - case rtc::Description::Direction::SendRecv: + case Description::Direction::SendRecv: out << "sendrecv"; break; - case rtc::Description::Direction::Inactive: + case Description::Direction::Inactive: out << "inactive"; break; - case rtc::Description::Direction::Unknown: + case Description::Direction::Unknown: default: out << "unknown"; break; } return out; } + +} // namespace rtc diff --git a/src/global.cpp b/src/global.cpp index e7a5896d2..959053749 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -88,26 +88,24 @@ std::shared_future Cleanup() { return impl::Init::Instance().cleanup(); } void SetSctpSettings(SctpSettings s) { impl::Init::Instance().setSctpSettings(std::move(s)); } -} // namespace rtc - -RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::LogLevel level) { +RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, LogLevel level) { switch (level) { - case rtc::LogLevel::Fatal: + case LogLevel::Fatal: out << "fatal"; break; - case rtc::LogLevel::Error: + case LogLevel::Error: out << "error"; break; - case rtc::LogLevel::Warning: + case LogLevel::Warning: out << "warning"; break; - case rtc::LogLevel::Info: + case LogLevel::Info: out << "info"; break; - case rtc::LogLevel::Debug: + case LogLevel::Debug: out << "debug"; break; - case rtc::LogLevel::Verbose: + case LogLevel::Verbose: out << "verbose"; break; default: @@ -116,3 +114,5 @@ RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::LogLevel level) } return out; } + +} // namespace rtc diff --git a/src/peerconnection.cpp b/src/peerconnection.cpp index 11d585b87..dd1ec7c82 100644 --- a/src/peerconnection.cpp +++ b/src/peerconnection.cpp @@ -354,10 +354,8 @@ optional PeerConnection::rtt() { return sctpTransport ? sctpTransport->rtt() : nullopt; } -} // namespace rtc - -std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::State state) { - using State = rtc::PeerConnection::State; +std::ostream &operator<<(std::ostream &out, PeerConnection::State state) { + using State = PeerConnection::State; const char *str; switch (state) { case State::New: @@ -385,8 +383,8 @@ std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::State state) { return out << str; } -std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::IceState state) { - using IceState = rtc::PeerConnection::IceState; +std::ostream &operator<<(std::ostream &out, PeerConnection::IceState state) { + using IceState = PeerConnection::IceState; const char *str; switch (state) { case IceState::New: @@ -417,8 +415,8 @@ std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::IceState state) return out << str; } -std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::GatheringState state) { - using GatheringState = rtc::PeerConnection::GatheringState; +std::ostream &operator<<(std::ostream &out, PeerConnection::GatheringState state) { + using GatheringState = PeerConnection::GatheringState; const char *str; switch (state) { case GatheringState::New: @@ -437,8 +435,8 @@ std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::GatheringState return out << str; } -std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::SignalingState state) { - using SignalingState = rtc::PeerConnection::SignalingState; +std::ostream &operator<<(std::ostream &out, PeerConnection::SignalingState state) { + using SignalingState = PeerConnection::SignalingState; const char *str; switch (state) { case SignalingState::Stable: @@ -462,3 +460,5 @@ std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::SignalingState } return out << str; } + +} // namespace rtc From 26216800e1de56983cbc9cc792976e39e1cfef9c Mon Sep 17 00:00:00 2001 From: Paul-Louis Ageneau Date: Fri, 19 Jan 2024 11:29:09 +0100 Subject: [PATCH 2/2] Added operator<< for WebSocket::State --- include/rtc/websocket.hpp | 2 ++ src/websocket.cpp | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/rtc/websocket.hpp b/include/rtc/websocket.hpp index d8a7c64f9..0b20faef2 100644 --- a/include/rtc/websocket.hpp +++ b/include/rtc/websocket.hpp @@ -58,6 +58,8 @@ class RTC_CPP_EXPORT WebSocket final : private CheshireCat, pub using CheshireCat::impl; }; +std::ostream &operator<<(std::ostream &out, WebSocket::State state); + } // namespace rtc #endif diff --git a/src/websocket.cpp b/src/websocket.cpp index 53db483ea..70368192c 100644 --- a/src/websocket.cpp +++ b/src/websocket.cpp @@ -68,6 +68,29 @@ optional WebSocket::path() const { return state != State::Connecting && handshake ? make_optional(handshake->path()) : nullopt; } +std::ostream &operator<<(std::ostream &out, WebSocket::State state) { + using State = WebSocket::State; + const char *str; + switch (state) { + case State::Connecting: + str = "connecting"; + break; + case State::Open: + str = "open"; + break; + case State::Closing: + str = "closing"; + break; + case State::Closed: + str = "closed"; + break; + default: + str = "unknown"; + break; + } + return out << str; +} + } // namespace rtc #endif