RetroArch
Classes | Macros | Functions | Variables
discord_rpc.cpp File Reference
#include "discord_rpc.h"
#include "backoff.h"
#include "discord_register.h"
#include "msg_queue.h"
#include "rpc_connection.h"
#include "serialization.h"
#include <atomic>
#include <chrono>
#include <mutex>
#include <condition_variable>
#include <thread>
Include dependency graph for discord_rpc.cpp:

Classes

struct  QueuedMessage
 
struct  User
 
class  IoThreadHolder
 

Macros

#define HANDLE_EVENT_REGISTRATION(handler_name, event)
 

Functions

static void Discord_UpdateConnection (void)
 
static void UpdateReconnectTime ()
 
static void SignalIOActivity ()
 
static bool RegisterForEvent (const char *evtName)
 
static bool DeregisterForEvent (const char *evtName)
 
DISCORD_EXPORT void Discord_Initialize (const char *applicationId, DiscordEventHandlers *handlers, int autoRegister, const char *optionalSteamId)
 
DISCORD_EXPORT void Discord_Shutdown (void)
 
DISCORD_EXPORT void Discord_UpdatePresence (const DiscordRichPresence *presence)
 
DISCORD_EXPORT void Discord_ClearPresence (void)
 
DISCORD_EXPORT void Discord_Respond (const char *userId, int reply)
 
DISCORD_EXPORT void Discord_RunCallbacks (void)
 
DISCORD_EXPORT void Discord_UpdateHandlers (DiscordEventHandlers *newHandlers)
 

Variables

constexpr size_t MaxMessageSize {16 * 1024}
 
constexpr size_t MessageQueueSize {8}
 
constexpr size_t JoinQueueSize {8}
 
static RpcConnectionConnection {nullptr}
 
static DiscordEventHandlers QueuedHandlers {}
 
static DiscordEventHandlers Handlers {}
 
static std::atomic_bool WasJustConnected {false}
 
static std::atomic_bool WasJustDisconnected {false}
 
static std::atomic_bool GotErrorMessage {false}
 
static std::atomic_bool WasJoinGame {false}
 
static std::atomic_bool WasSpectateGame {false}
 
static char JoinGameSecret [256]
 
static char SpectateGameSecret [256]
 
static int LastErrorCode {0}
 
static char LastErrorMessage [256]
 
static int LastDisconnectErrorCode {0}
 
static char LastDisconnectErrorMessage [256]
 
static std::mutex PresenceMutex
 
static std::mutex HandlerMutex
 
static QueuedMessage QueuedPresence {}
 
static MsgQueue< QueuedMessage, MessageQueueSizeSendQueue
 
static MsgQueue< User, JoinQueueSizeJoinAskQueue
 
static User connectedUser
 
static Backoff ReconnectTimeMs (500, 60 *1000)
 
static auto NextConnect = std::chrono::system_clock::now()
 
static int Pid {0}
 
static int Nonce {1}
 
static IoThreadHolderIoThread {nullptr}
 

Macro Definition Documentation

◆ HANDLE_EVENT_REGISTRATION

#define HANDLE_EVENT_REGISTRATION (   handler_name,
  event 
)
Value:
if (!Handlers.handler_name && newHandlers->handler_name) { \
RegisterForEvent(event); \
} \
else if (Handlers.handler_name && !newHandlers->handler_name) { \
DeregisterForEvent(event); \
}
static DiscordEventHandlers Handlers
Definition: discord_rpc.cpp:51
struct _cl_event * event
Definition: glext.h:8406

Function Documentation

◆ DeregisterForEvent()

static bool DeregisterForEvent ( const char *  evtName)
static
Here is the call graph for this function:

◆ Discord_ClearPresence()

DISCORD_EXPORT void Discord_ClearPresence ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Discord_Initialize()

DISCORD_EXPORT void Discord_Initialize ( const char *  applicationId,
DiscordEventHandlers handlers,
int  autoRegister,
const char *  optionalSteamId 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Discord_Respond()

DISCORD_EXPORT void Discord_Respond ( const char *  userId,
int  reply 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Discord_RunCallbacks()

DISCORD_EXPORT void Discord_RunCallbacks ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Discord_Shutdown()

DISCORD_EXPORT void Discord_Shutdown ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Discord_UpdateConnection()

static void Discord_UpdateConnection ( void  )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Discord_UpdateHandlers()

DISCORD_EXPORT void Discord_UpdateHandlers ( DiscordEventHandlers newHandlers)
Here is the caller graph for this function:

◆ Discord_UpdatePresence()

DISCORD_EXPORT void Discord_UpdatePresence ( const DiscordRichPresence presence)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterForEvent()

static bool RegisterForEvent ( const char *  evtName)
static
Here is the call graph for this function:

◆ SignalIOActivity()

static void SignalIOActivity ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateReconnectTime()

static void UpdateReconnectTime ( )
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ connectedUser

User connectedUser
static

◆ Connection

RpcConnection* Connection {nullptr}
static

◆ GotErrorMessage

std::atomic_bool GotErrorMessage {false}
static

◆ HandlerMutex

std::mutex HandlerMutex
static

◆ Handlers

DiscordEventHandlers Handlers {}
static

◆ IoThread

IoThreadHolder* IoThread {nullptr}
static

◆ JoinAskQueue

MsgQueue<User, JoinQueueSize> JoinAskQueue
static

◆ JoinGameSecret

char JoinGameSecret[256]
static

◆ JoinQueueSize

constexpr size_t JoinQueueSize {8}

◆ LastDisconnectErrorCode

int LastDisconnectErrorCode {0}
static

◆ LastDisconnectErrorMessage

char LastDisconnectErrorMessage[256]
static

◆ LastErrorCode

int LastErrorCode {0}
static

◆ LastErrorMessage

char LastErrorMessage[256]
static

◆ MaxMessageSize

constexpr size_t MaxMessageSize {16 * 1024}

◆ MessageQueueSize

constexpr size_t MessageQueueSize {8}

◆ NextConnect

auto NextConnect = std::chrono::system_clock::now()
static

◆ Nonce

int Nonce {1}
static

◆ Pid

int Pid {0}
static

◆ PresenceMutex

std::mutex PresenceMutex
static

◆ QueuedHandlers

DiscordEventHandlers QueuedHandlers {}
static

◆ QueuedPresence

QueuedMessage QueuedPresence {}
static

◆ ReconnectTimeMs

Backoff ReconnectTimeMs(500, 60 *1000)
static

◆ SendQueue

◆ SpectateGameSecret

char SpectateGameSecret[256]
static

◆ WasJoinGame

std::atomic_bool WasJoinGame {false}
static

◆ WasJustConnected

std::atomic_bool WasJustConnected {false}
static

◆ WasJustDisconnected

std::atomic_bool WasJustDisconnected {false}
static

◆ WasSpectateGame

std::atomic_bool WasSpectateGame {false}
static