From c5e38b71f7d894ff8bf1164ab714384a21591666 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 13 Apr 2025 21:34:40 +0200 Subject: [PATCH] discord_rpc: Use anonymous namespace --- 3rdparty/discord-rpc/discord_rpc.cpp | 86 ++++++++++---------- 3rdparty/discord-rpc/discord_rpc.h | 4 - 3rdparty/discord-rpc/discord_serialization.h | 3 +- src/discord/richpresence.cpp | 2 - 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/3rdparty/discord-rpc/discord_rpc.cpp b/3rdparty/discord-rpc/discord_rpc.cpp index a16db32c3..989acc8ff 100644 --- a/3rdparty/discord-rpc/discord_rpc.cpp +++ b/3rdparty/discord-rpc/discord_rpc.cpp @@ -34,7 +34,11 @@ #include "discord_rpc_connection.h" #include "discord_serialization.h" -namespace discord_rpc { +using namespace discord_rpc; + +static void Discord_UpdateConnection(); + +namespace { constexpr size_t MaxMessageSize { 16 * 1024 }; constexpr size_t MessageQueueSize { 8 }; @@ -94,7 +98,6 @@ static auto NextConnect = std::chrono::system_clock::now(); static int Pid { 0 }; static int Nonce { 1 }; -static void Discord_UpdateConnection(void); class IoThreadHolder { private: std::atomic_bool keepRunning { true }; @@ -128,6 +131,7 @@ class IoThreadHolder { ~IoThreadHolder() { Stop(); } }; + static IoThreadHolder *IoThread { nullptr }; static void UpdateReconnectTime() { @@ -136,6 +140,44 @@ static void UpdateReconnectTime() { } +static void SignalIOActivity() { + + if (IoThread != nullptr) { + IoThread->Notify(); + } + +} + +static bool RegisterForEvent(const char *evtName) { + + auto qmessage = SendQueue.GetNextAddMessage(); + if (qmessage) { + qmessage->length = JsonWriteSubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName); + SendQueue.CommitAdd(); + SignalIOActivity(); + return true; + } + + return false; + +} + +static bool DeregisterForEvent(const char *evtName) { + + auto qmessage = SendQueue.GetNextAddMessage(); + if (qmessage) { + qmessage->length = JsonWriteUnsubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName); + SendQueue.CommitAdd(); + SignalIOActivity(); + return true; + } + + return false; + +} + +} // namespace + static void Discord_UpdateConnection() { if (!Connection) { @@ -242,42 +284,6 @@ static void Discord_UpdateConnection() { } -static void SignalIOActivity() { - - if (IoThread != nullptr) { - IoThread->Notify(); - } - -} - -static bool RegisterForEvent(const char *evtName) { - - auto qmessage = SendQueue.GetNextAddMessage(); - if (qmessage) { - qmessage->length = JsonWriteSubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName); - SendQueue.CommitAdd(); - SignalIOActivity(); - return true; - } - - return false; - -} - -static bool DeregisterForEvent(const char *evtName) { - - auto qmessage = SendQueue.GetNextAddMessage(); - if (qmessage) { - qmessage->length = JsonWriteUnsubscribeCommand(qmessage->buffer, sizeof(qmessage->buffer), Nonce++, evtName); - SendQueue.CommitAdd(); - SignalIOActivity(); - return true; - } - - return false; - -} - extern "C" void Discord_Initialize(const char *applicationId, DiscordEventHandlers *handlers, const int autoRegister) { IoThread = new (std::nothrow) IoThreadHolder(); @@ -348,7 +354,7 @@ extern "C" void Discord_Initialize(const char *applicationId, DiscordEventHandle } -extern "C" void Discord_Shutdown(void) { +extern "C" void Discord_Shutdown() { if (!Connection) { return; @@ -502,5 +508,3 @@ extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) { } } - -} // namespace discord_rpc diff --git a/3rdparty/discord-rpc/discord_rpc.h b/3rdparty/discord-rpc/discord_rpc.h index 81382bfb4..8467dd729 100644 --- a/3rdparty/discord-rpc/discord_rpc.h +++ b/3rdparty/discord-rpc/discord_rpc.h @@ -26,8 +26,6 @@ #include -namespace discord_rpc { - #ifdef __cplusplus extern "C" { #endif @@ -92,6 +90,4 @@ void Discord_UpdateHandlers(DiscordEventHandlers *handlers); } /* extern "C" */ #endif -} // namespace discord_rpc - #endif // DISCORD_RPC_H diff --git a/3rdparty/discord-rpc/discord_serialization.h b/3rdparty/discord-rpc/discord_serialization.h index 65c6e05eb..2f68a6b77 100644 --- a/3rdparty/discord-rpc/discord_serialization.h +++ b/3rdparty/discord-rpc/discord_serialization.h @@ -28,6 +28,8 @@ #include #include +struct DiscordRichPresence; + namespace discord_rpc { // if only there was a standard library function for this @@ -48,7 +50,6 @@ inline size_t StringCopy(char (&dest)[Len], const char *src) { size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char *applicationId); // Commands -struct DiscordRichPresence; size_t JsonWriteRichPresenceObj(char *dest, const size_t maxLen, const int nonce, const int pid, const DiscordRichPresence *presence); size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName); diff --git a/src/discord/richpresence.cpp b/src/discord/richpresence.cpp index 97c4af10a..0b2e493cb 100644 --- a/src/discord/richpresence.cpp +++ b/src/discord/richpresence.cpp @@ -38,8 +38,6 @@ constexpr char kStrawberryIconResourceName[] = "embedded_cover"; constexpr char kStrawberryIconDescription[] = "Strawberry Music Player"; } // namespace -using namespace discord_rpc; - namespace discord { RichPresence::RichPresence(const SharedPtr player,