From cd1798a3d31b965cac5a1ef396290b680966c5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Tue, 28 Dec 2021 14:15:30 +0100 Subject: [PATCH] Fix static function warning --- libraries/networking/src/SockAddr.cpp | 8 ++++---- libraries/networking/src/SocketType.h | 18 ++++++++++-------- libraries/networking/src/udt/Socket.cpp | 6 +++--- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libraries/networking/src/SockAddr.cpp b/libraries/networking/src/SockAddr.cpp index e8eb6c4b86..8dbbf39ec4 100644 --- a/libraries/networking/src/SockAddr.cpp +++ b/libraries/networking/src/SockAddr.cpp @@ -113,7 +113,7 @@ void SockAddr::handleLookupResult(const QHostInfo& hostInfo) { } QString SockAddr::toString() const { - return socketTypeToString(_socketType) + " " + _address.toString() + ":" + QString::number(_port); + return SocketTypeToString::socketTypeToString(_socketType) + " " + _address.toString() + ":" + QString::number(_port); } QString SockAddr::toShortString() const { @@ -133,9 +133,9 @@ bool SockAddr::hasPrivateAddress() const { } QDebug operator<<(QDebug debug, const SockAddr& sockAddr) { - debug.nospace() - << (sockAddr._socketType != SocketType::Unknown - ? (socketTypeToString(sockAddr._socketType) + " ").toLocal8Bit().constData() : "") + debug.nospace() + << (sockAddr._socketType != SocketType::Unknown + ? (SocketTypeToString::socketTypeToString(sockAddr._socketType) + " ").toLocal8Bit().constData() : "") << sockAddr._address.toString().toLocal8Bit().constData() << ":" << sockAddr._port; return debug.space(); } diff --git a/libraries/networking/src/SocketType.h b/libraries/networking/src/SocketType.h index d9b613a7e1..c689f51422 100644 --- a/libraries/networking/src/SocketType.h +++ b/libraries/networking/src/SocketType.h @@ -25,14 +25,16 @@ enum class SocketType : uint8_t { WebRTC ///< WebRTC socket. A WebRTC data channel presented as a UDP-style socket. }; -/// @brief Returns the name of a SocketType value, e.g., "WebRTC". -/// @param socketType The SocketType value. -/// @return The name of the SocketType value. -static QString socketTypeToString(SocketType socketType) { - static QStringList SOCKET_TYPE_STRINGS { "Unknown", "UDP", "WebRTC" }; - return SOCKET_TYPE_STRINGS[(int)socketType]; -} - +class SocketTypeToString { +public: + /// @brief Returns the name of a SocketType value, e.g., "WebRTC". + /// @param socketType The SocketType value. + /// @return The name of the SocketType value. + static QString socketTypeToString (SocketType socketType) { + static QStringList SOCKET_TYPE_STRINGS { "Unknown", "UDP", "WebRTC" }; + return SOCKET_TYPE_STRINGS[(int)socketType]; + } +}; /// @} diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 7beeedb1eb..eeed277875 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -559,8 +559,8 @@ void Socket::handleSocketError(SocketType socketType, QAbstractSocket::SocketErr #endif int pending = _networkSocket.bytesToWrite(socketType); QString errorString; - QDebug(&errorString) << "udt::Socket (" << socketTypeToString(socketType) << _networkSocket.state(socketType) - << ") error - " << wsaError << socketError << "(" << _networkSocket.errorString(socketType) << ")" + QDebug(&errorString) << "udt::Socket (" << SocketTypeToString::socketTypeToString(socketType) << _networkSocket.state(socketType) + << ") error - " << wsaError << socketError << "(" << _networkSocket.errorString(socketType) << ")" << (pending ? "pending bytes:" : "pending:") << pending; if (previousWsaError.exchange(wsaError) != wsaError) { @@ -576,7 +576,7 @@ void Socket::handleSocketError(SocketType socketType, QAbstractSocket::SocketErr void Socket::handleStateChanged(SocketType socketType, QAbstractSocket::SocketState socketState) { if (socketState != QAbstractSocket::BoundState) { - qCDebug(networking) << socketTypeToString(socketType) << "socket state changed - state is now" << socketState; + qCDebug(networking) << SocketTypeToString::socketTypeToString(socketType) << "socket state changed - state is now" << socketState; } }