mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-17 17:05:50 +00:00
Add support for using a callback for writing debug messages
This commit is contained in:
parent
7fb3ef3f79
commit
058ad2df23
@ -4,7 +4,9 @@
|
||||
static int stage = STAGE_NONE;
|
||||
static CONNECTION_LISTENER_CALLBACKS listenerCallbacks;
|
||||
static CONNECTION_LISTENER_CALLBACKS originalCallbacks;
|
||||
static PLATFORM_CALLBACKS platformCallbacks;
|
||||
|
||||
// This is used for debug prints so it's not declared static
|
||||
PLATFORM_CALLBACKS platformCallbacks;
|
||||
|
||||
static int alreadyTerminated;
|
||||
|
||||
@ -161,13 +163,13 @@ int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONN
|
||||
|
||||
Limelog("Initializing platform...");
|
||||
listenerCallbacks.stageStarting(STAGE_PLATFORM_INIT);
|
||||
err = initializePlatformSockets(&platformCallbacks);
|
||||
err = initializePlatformSockets();
|
||||
if (err != 0) {
|
||||
Limelog("failed: %d\n", err);
|
||||
listenerCallbacks.stageFailed(STAGE_PLATFORM_INIT, err);
|
||||
goto Cleanup;
|
||||
}
|
||||
err = initializePlatformThreads(&platformCallbacks);
|
||||
err = initializePlatformThreads();
|
||||
if (err != 0) {
|
||||
Limelog("failed: %d\n", err);
|
||||
listenerCallbacks.stageFailed(STAGE_PLATFORM_INIT, err);
|
||||
|
@ -91,9 +91,11 @@ typedef struct _CONNECTION_LISTENER_CALLBACKS {
|
||||
} CONNECTION_LISTENER_CALLBACKS, *PCONNECTION_LISTENER_CALLBACKS;
|
||||
|
||||
typedef void(*PlatformThreadStart)(void);
|
||||
typedef void(*PlatformDebugPrint)(char* string);
|
||||
|
||||
typedef struct _PLATFORM_CALLBACKS {
|
||||
PlatformThreadStart threadStart;
|
||||
PlatformDebugPrint debugPrint;
|
||||
} PLATFORM_CALLBACKS, *PPLATFORM_CALLBACKS;
|
||||
|
||||
int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
||||
|
@ -27,11 +27,13 @@
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "Limelight.h"
|
||||
#if defined(LC_WINDOWS_PHONE) || defined(LC_WINDOWS)
|
||||
extern WCHAR DbgBuf[512];
|
||||
extern char DbgBuf[512];
|
||||
extern PLATFORM_CALLBACKS platformCallbacks;
|
||||
#define Limelog(s, ...) \
|
||||
swprintf(DbgBuf, sizeof(DbgBuf) / sizeof(WCHAR), L ## s, ##__VA_ARGS__); \
|
||||
OutputDebugStringW(DbgBuf)
|
||||
sprintf(DbgBuf, s, ##__VA_ARGS__); \
|
||||
platformCallbacks.debugPrint(DbgBuf)
|
||||
#else
|
||||
#define Limelog printf
|
||||
#endif
|
||||
|
@ -80,7 +80,7 @@ int enableNoDelay(SOCKET s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int initializePlatformSockets(PPLATFORM_CALLBACKS plCallbacks) {
|
||||
int initializePlatformSockets(void) {
|
||||
#if defined(LC_WINDOWS) || defined(LC_WINDOWS_PHONE)
|
||||
WSADATA data;
|
||||
return WSAStartup(MAKEWORD(2, 0), &data);
|
||||
|
@ -33,5 +33,5 @@ typedef ssize_t SOCK_RET;
|
||||
SOCKET connectTcpSocket(IP_ADDRESS dstaddr, unsigned short port);
|
||||
SOCKET bindUdpSocket(void);
|
||||
int enableNoDelay(SOCKET s);
|
||||
int initializePlatformSockets(PPLATFORM_CALLBACKS plCallbacks);
|
||||
int initializePlatformSockets(void);
|
||||
void cleanupPlatformSockets(void);
|
@ -2,14 +2,13 @@
|
||||
#include "Platform.h"
|
||||
|
||||
#if defined(LC_WINDOWS_PHONE) || defined(LC_WINDOWS)
|
||||
WCHAR DbgBuf[512];
|
||||
CHAR DbgBuf[512];
|
||||
#endif
|
||||
|
||||
#if defined(LC_WINDOWS) || defined(LC_WINDOWS_PHONE)
|
||||
PLT_MUTEX thread_list_lock;
|
||||
PLT_THREAD *pending_thread_head;
|
||||
PLT_THREAD *thread_head;
|
||||
PPLATFORM_CALLBACKS platformCallbacks;
|
||||
static PLT_MUTEX thread_list_lock;
|
||||
static PLT_THREAD *pending_thread_head;
|
||||
static PLT_THREAD *thread_head;
|
||||
#else
|
||||
void* ThreadProc(void* context) {
|
||||
struct thread_context *ctx = (struct thread_context *)context;
|
||||
@ -208,7 +207,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
|
||||
PltUnlockMutex(&thread_list_lock);
|
||||
|
||||
// Make a callback to managed code to ask for a thread to grab this
|
||||
platformCallbacks->threadStart();
|
||||
platformCallbacks.threadStart();
|
||||
|
||||
err = 0;
|
||||
}
|
||||
@ -308,14 +307,8 @@ int PltWaitForEvent(PLT_EVENT *event) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int initializePlatformThreads(PPLATFORM_CALLBACKS plCallbacks) {
|
||||
int initializePlatformThreads(void) {
|
||||
#if defined(LC_WINDOWS) || defined(LC_WINDOWS_PHONE)
|
||||
pending_thread_head = thread_head = NULL;
|
||||
|
||||
// This data is stored in static memory in Connection.c, so we don't
|
||||
// bother making our own copy
|
||||
platformCallbacks = plCallbacks;
|
||||
|
||||
return PltCreateMutex(&thread_list_lock);
|
||||
#else
|
||||
return 0;
|
||||
@ -324,6 +317,9 @@ int initializePlatformThreads(PPLATFORM_CALLBACKS plCallbacks) {
|
||||
|
||||
void cleanupPlatformThreads(void) {
|
||||
#if defined(LC_WINDOWS) || defined(LC_WINDOWS_PHONE)
|
||||
LC_ASSERT(pending_thread_head == NULL);
|
||||
LC_ASSERT(thread_head == NULL);
|
||||
|
||||
PltDeleteMutex(&thread_list_lock);
|
||||
#else
|
||||
#endif
|
||||
|
@ -35,7 +35,7 @@ typedef struct _PLT_EVENT {
|
||||
#error Unsupported platform
|
||||
#endif
|
||||
|
||||
int initializePlatformThreads(PPLATFORM_CALLBACKS plCallbacks);
|
||||
int initializePlatformThreads(void);
|
||||
void cleanupPlatformThreads(void);
|
||||
|
||||
int PltCreateMutex(PLT_MUTEX *mutex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user