mirror of
https://github.com/ValveSoftware/Proton.git
synced 2025-03-04 17:45:31 +03:00
81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
|
#include "unix_private.h"
|
||
|
|
||
|
#include <pthread.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
|
||
|
|
||
|
struct callback_entry
|
||
|
{
|
||
|
struct list entry;
|
||
|
struct callback callback;
|
||
|
};
|
||
|
|
||
|
static struct list callbacks = LIST_INIT( callbacks );
|
||
|
static pthread_mutex_t callbacks_lock = PTHREAD_MUTEX_INITIALIZER;
|
||
|
|
||
|
void queue_sockets_debug_output( void (*W_STDCALL pfnFunc)( uint32_t, const char * ), uint32_t type, const char *msg )
|
||
|
{
|
||
|
uint32_t msg_size = strlen( msg ) + 1, size = msg_size;
|
||
|
struct callback_entry *entry;
|
||
|
|
||
|
size += sizeof(struct callback_entry);
|
||
|
if (!(entry = (struct callback_entry *)malloc( size ))) return;
|
||
|
|
||
|
entry->callback.type = SOCKETS_DEBUG_OUTPUT;
|
||
|
size -= offsetof( struct callback_entry, callback );
|
||
|
entry->callback.size = size;
|
||
|
|
||
|
entry->callback.sockets_debug_output.pfnFunc = pfnFunc;
|
||
|
entry->callback.sockets_debug_output.type = type;
|
||
|
memcpy( (char *)entry->callback.sockets_debug_output.msg, msg, msg_size );
|
||
|
|
||
|
pthread_mutex_lock( &callbacks_lock );
|
||
|
list_add_tail( &callbacks, &entry->entry );
|
||
|
pthread_mutex_unlock( &callbacks_lock );
|
||
|
}
|
||
|
|
||
|
void queue_warning_message_hook( void (*W_CDECL pFunction)( int32_t, const char * ), int32_t severity, const char *msg )
|
||
|
{
|
||
|
uint32_t msg_size = strlen( msg ) + 1, size = msg_size;
|
||
|
struct callback_entry *entry;
|
||
|
|
||
|
size += sizeof(struct callback_entry);
|
||
|
if (!(entry = (struct callback_entry *)malloc( size ))) return;
|
||
|
|
||
|
entry->callback.type = WARNING_MESSAGE_HOOK;
|
||
|
size -= offsetof( struct callback_entry, callback );
|
||
|
entry->callback.size = size;
|
||
|
|
||
|
entry->callback.warning_message_hook.pFunction = pFunction;
|
||
|
entry->callback.warning_message_hook.severity = severity;
|
||
|
memcpy( (char *)entry->callback.warning_message_hook.msg, msg, msg_size );
|
||
|
|
||
|
pthread_mutex_lock( &callbacks_lock );
|
||
|
list_add_tail( &callbacks, &entry->entry );
|
||
|
pthread_mutex_unlock( &callbacks_lock );
|
||
|
}
|
||
|
|
||
|
bool unix_steamclient_next_callback( struct callback *callback, uint32_t *size )
|
||
|
{
|
||
|
struct list *ptr;
|
||
|
|
||
|
pthread_mutex_lock( &callbacks_lock );
|
||
|
if ((ptr = list_head( &callbacks )))
|
||
|
{
|
||
|
struct callback_entry *entry = LIST_ENTRY( ptr, struct callback_entry, entry );
|
||
|
|
||
|
if (entry->callback.size <= *size)
|
||
|
{
|
||
|
memcpy( callback, &entry->callback, entry->callback.size );
|
||
|
list_remove( &entry->entry );
|
||
|
free( entry );
|
||
|
}
|
||
|
|
||
|
*size = entry->callback.size;
|
||
|
}
|
||
|
pthread_mutex_unlock( &callbacks_lock );
|
||
|
|
||
|
return !!ptr;
|
||
|
}
|