Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move operator<< to rtc namespace #1096

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions include/rtc/candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions include/rtc/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions include/rtc/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 5 additions & 7 deletions include/rtc/peerconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,11 @@ class RTC_CPP_EXPORT PeerConnection final : CheshireCat<impl::PeerConnection> {
optional<std::chrono::milliseconds> 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
2 changes: 2 additions & 0 deletions include/rtc/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class RTC_CPP_EXPORT WebSocket final : private CheshireCat<impl::WebSocket>, pub
using CheshireCat<impl::WebSocket>::impl;
};

std::ostream &operator<<(std::ostream &out, WebSocket::State state);

} // namespace rtc

#endif
Expand Down
30 changes: 15 additions & 15 deletions src/candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,40 +248,40 @@ optional<uint16_t> 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
28 changes: 14 additions & 14 deletions src/description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
18 changes: 9 additions & 9 deletions src/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,24 @@ std::shared_future<void> 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:
Expand All @@ -116,3 +114,5 @@ RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, rtc::LogLevel level)
}
return out;
}

} // namespace rtc
20 changes: 10 additions & 10 deletions src/peerconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,8 @@ optional<std::chrono::milliseconds> 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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -462,3 +460,5 @@ std::ostream &operator<<(std::ostream &out, rtc::PeerConnection::SignalingState
}
return out << str;
}

} // namespace rtc
23 changes: 23 additions & 0 deletions src/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ optional<string> 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
Loading