discord_rpc: Use anonymous namespace
This commit is contained in:
86
3rdparty/discord-rpc/discord_rpc.cpp
vendored
86
3rdparty/discord-rpc/discord_rpc.cpp
vendored
@@ -34,7 +34,11 @@
|
|||||||
#include "discord_rpc_connection.h"
|
#include "discord_rpc_connection.h"
|
||||||
#include "discord_serialization.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 MaxMessageSize { 16 * 1024 };
|
||||||
constexpr size_t MessageQueueSize { 8 };
|
constexpr size_t MessageQueueSize { 8 };
|
||||||
@@ -94,7 +98,6 @@ static auto NextConnect = std::chrono::system_clock::now();
|
|||||||
static int Pid { 0 };
|
static int Pid { 0 };
|
||||||
static int Nonce { 1 };
|
static int Nonce { 1 };
|
||||||
|
|
||||||
static void Discord_UpdateConnection(void);
|
|
||||||
class IoThreadHolder {
|
class IoThreadHolder {
|
||||||
private:
|
private:
|
||||||
std::atomic_bool keepRunning { true };
|
std::atomic_bool keepRunning { true };
|
||||||
@@ -128,6 +131,7 @@ class IoThreadHolder {
|
|||||||
|
|
||||||
~IoThreadHolder() { Stop(); }
|
~IoThreadHolder() { Stop(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static IoThreadHolder *IoThread { nullptr };
|
static IoThreadHolder *IoThread { nullptr };
|
||||||
|
|
||||||
static void UpdateReconnectTime() {
|
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() {
|
static void Discord_UpdateConnection() {
|
||||||
|
|
||||||
if (!Connection) {
|
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) {
|
extern "C" void Discord_Initialize(const char *applicationId, DiscordEventHandlers *handlers, const int autoRegister) {
|
||||||
|
|
||||||
IoThread = new (std::nothrow) IoThreadHolder();
|
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) {
|
if (!Connection) {
|
||||||
return;
|
return;
|
||||||
@@ -502,5 +508,3 @@ extern "C" void Discord_UpdateHandlers(DiscordEventHandlers *newHandlers) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
|
|||||||
4
3rdparty/discord-rpc/discord_rpc.h
vendored
4
3rdparty/discord-rpc/discord_rpc.h
vendored
@@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace discord_rpc {
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -92,6 +90,4 @@ void Discord_UpdateHandlers(DiscordEventHandlers *handlers);
|
|||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace discord_rpc
|
|
||||||
|
|
||||||
#endif // DISCORD_RPC_H
|
#endif // DISCORD_RPC_H
|
||||||
|
|||||||
3
3rdparty/discord-rpc/discord_serialization.h
vendored
3
3rdparty/discord-rpc/discord_serialization.h
vendored
@@ -28,6 +28,8 @@
|
|||||||
#include <rapidjson/stringbuffer.h>
|
#include <rapidjson/stringbuffer.h>
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
|
|
||||||
|
struct DiscordRichPresence;
|
||||||
|
|
||||||
namespace discord_rpc {
|
namespace discord_rpc {
|
||||||
|
|
||||||
// if only there was a standard library function for this
|
// 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);
|
size_t JsonWriteHandshakeObj(char *dest, size_t maxLen, int version, const char *applicationId);
|
||||||
|
|
||||||
// Commands
|
// Commands
|
||||||
struct DiscordRichPresence;
|
|
||||||
size_t JsonWriteRichPresenceObj(char *dest, const size_t maxLen, const int nonce, const int pid, const DiscordRichPresence *presence);
|
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);
|
size_t JsonWriteSubscribeCommand(char *dest, size_t maxLen, int nonce, const char *evtName);
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ constexpr char kStrawberryIconResourceName[] = "embedded_cover";
|
|||||||
constexpr char kStrawberryIconDescription[] = "Strawberry Music Player";
|
constexpr char kStrawberryIconDescription[] = "Strawberry Music Player";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
using namespace discord_rpc;
|
|
||||||
|
|
||||||
namespace discord {
|
namespace discord {
|
||||||
|
|
||||||
RichPresence::RichPresence(const SharedPtr<Player> player,
|
RichPresence::RichPresence(const SharedPtr<Player> player,
|
||||||
|
|||||||
Reference in New Issue
Block a user