Skip to content

Commit

Permalink
Add some debugging.....
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuehlner committed Oct 3, 2023
1 parent 2a0fe85 commit 2335632
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/common/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <stdlib.h>
#include <string.h>

#include <stdio.h>

/**
* Synchronizes all surfaces within the given linked list to the given socket.
* If the provided pointer to the linked list is NULL, this function has no
Expand Down Expand Up @@ -167,23 +169,39 @@ void guac_common_display_dup(
guac_common_display* display, guac_client* client,
guac_socket* socket) {

fprintf(stderr, "guac_common_display_dup start\n");

pthread_mutex_lock(&display->_lock);

fprintf(stderr, "pthread_mutex_lock(&display->_lock); done\n");

/* Sunchronize shared cursor */
guac_common_cursor_dup(display->cursor, client, socket);

fprintf(stderr, "guac_common_cursor_dup(display->cursor, client, socket); done\n");

/* Synchronize default surface */
guac_common_surface_dup(display->default_surface, client, socket);

fprintf(stderr, "guac_common_surface_dup(display->default_surface, client, socket); done\n");

/* Synchronize all layers and buffers */
guac_common_display_dup_layers(display->layers, client, socket);

fprintf(stderr, "guac_common_display_dup_layers(display->layers, client, socket); done\n");
guac_common_display_dup_layers(display->buffers, client, socket);

fprintf(stderr, "guac_common_display_dup_layers(display->buffers, client, socket); done\n");

/* Sends a sync instruction to mark the boundary of the first frame */
guac_protocol_send_sync(socket, client->last_sent_timestamp, 1);

fprintf(stderr, "guac_protocol_send_sync(socket, client->last_sent_timestamp, 1); done\n");

pthread_mutex_unlock(&display->_lock);

fprintf(stderr, "guac_common_display_dup end\n");

}

void guac_common_display_set_lossless(guac_common_display* display,
Expand Down
55 changes: 55 additions & 0 deletions src/libguac/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ static void guac_client_promote_pending_users(union sigval data) {

guac_client* guac_client_alloc() {

fprintf(stderr, "guac_client_alloc start\n");

int i;

/* Allocate new client */
Expand Down Expand Up @@ -308,12 +310,16 @@ guac_client* guac_client_alloc() {
client->socket = guac_socket_broadcast(client);
client->pending_socket = guac_socket_broadcast_pending(client);

fprintf(stderr, "guac_client_alloc end\n");

return client;

}

void guac_client_free(guac_client* client) {

fprintf(stderr, "guac_client_free start\n");

/* Acquire write locks before referencing user pointers */
guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_write_lock(&(client->__users_lock));
Expand Down Expand Up @@ -376,6 +382,8 @@ void guac_client_free(guac_client* client) {

free(client->connection_id);
free(client);

fprintf(stderr, "guac_client_free end\n");
}

void vguac_client_log(guac_client* client, guac_client_log_level level,
Expand Down Expand Up @@ -450,6 +458,8 @@ void guac_client_abort(guac_client* client, guac_protocol_status status,
static void guac_client_add_pending_user(
guac_client* client, guac_user* user) {

fprintf(stderr, "guac_client_add_pending_user start\n");

/* Acquire the lock for modifying the list of pending users */
guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));

Expand All @@ -467,6 +477,8 @@ static void guac_client_add_pending_user(
/* Release the lock */
guac_rwlock_release_lock(&(client->__pending_users_lock));

fprintf(stderr, "guac_client_add_pending_user end\n");

}

/**
Expand All @@ -484,6 +496,8 @@ static void guac_client_add_pending_user(
*/
static int guac_client_start_pending_users_timer(guac_client* client) {

fprintf(stderr, "guac_client_start_pending_users_timer start\n");

pthread_mutex_lock(&(client->__pending_users_timer_mutex));

/* Return success if the timer is already created and running */
Expand Down Expand Up @@ -526,12 +540,17 @@ static int guac_client_start_pending_users_timer(guac_client* client) {
client->__pending_users_timer_state = GUAC_CLIENT_PENDING_TIMER_REGISTERED;

pthread_mutex_unlock(&(client->__pending_users_timer_mutex));

fprintf(stderr, "guac_client_start_pending_users_timer end\n");

return 0;

}

int guac_client_add_user(guac_client* client, guac_user* user, int argc, char** argv) {

fprintf(stderr, "guac_client_add_user start\n");

/* Create and start the timer if it hasn't already been initialized */
if (guac_client_start_pending_users_timer(client)) {

Expand Down Expand Up @@ -569,12 +588,16 @@ int guac_client_add_user(guac_client* client, guac_user* user, int argc, char**
if (retval == 0 && !user->owner)
guac_client_owner_notify_join(client, user);

fprintf(stderr, "guac_client_add_user end\n");

return retval;

}

void guac_client_remove_user(guac_client* client, guac_user* user) {

fprintf(stderr, "guac_client_remove_user start\n");

guac_rwlock_acquire_write_lock(&(client->__pending_users_lock));
guac_rwlock_acquire_write_lock(&(client->__users_lock));

Expand Down Expand Up @@ -609,10 +632,14 @@ void guac_client_remove_user(guac_client* client, guac_user* user) {
else if (client->leave_handler)
client->leave_handler(user);

fprintf(stderr, "guac_client_remove_user end\n");

}

void guac_client_foreach_user(guac_client* client, guac_user_callback* callback, void* data) {

fprintf(stderr, "guac_client_foreach_user start\n");

guac_user* current;

guac_rwlock_acquire_read_lock(&(client->__users_lock));
Expand All @@ -626,11 +653,15 @@ void guac_client_foreach_user(guac_client* client, guac_user_callback* callback,

guac_rwlock_release_lock(&(client->__users_lock));

fprintf(stderr, "guac_client_foreach_user end\n");

}

void guac_client_foreach_pending_user(
guac_client* client, guac_user_callback* callback, void* data) {

fprintf(stderr, "guac_client_foreach_pending_user start\n");

guac_user* current;

guac_rwlock_acquire_read_lock(&(client->__pending_users_lock));
Expand All @@ -644,11 +675,15 @@ void guac_client_foreach_pending_user(

guac_rwlock_release_lock(&(client->__pending_users_lock));

fprintf(stderr, "guac_client_foreach_pending_user end\n");

}

void* guac_client_for_owner(guac_client* client, guac_user_callback* callback,
void* data) {

fprintf(stderr, "guac_client_for_owner start\n");

void* retval;

guac_rwlock_acquire_read_lock(&(client->__users_lock));
Expand All @@ -658,6 +693,8 @@ void* guac_client_for_owner(guac_client* client, guac_user_callback* callback,

guac_rwlock_release_lock(&(client->__users_lock));

fprintf(stderr, "guac_client_for_owner end\n");

/* Return value from callback */
return retval;

Expand All @@ -666,6 +703,8 @@ void* guac_client_for_owner(guac_client* client, guac_user_callback* callback,
void* guac_client_for_user(guac_client* client, guac_user* user,
guac_user_callback* callback, void* data) {

fprintf(stderr, "guac_client_for_user start\n");

guac_user* current;

int user_valid = 0;
Expand Down Expand Up @@ -695,6 +734,8 @@ void* guac_client_for_user(guac_client* client, guac_user* user,

guac_rwlock_release_lock(&(client->__users_lock));

fprintf(stderr, "guac_client_for_user end\n");

/* Return value from callback */
return retval;

Expand All @@ -706,19 +747,25 @@ int guac_client_end_frame(guac_client* client) {

int guac_client_end_multiple_frames(guac_client* client, int frames) {

fprintf(stderr, "guac_client_end_multiple_frames start\n");

/* Update and send timestamp */
client->last_sent_timestamp = guac_timestamp_current();

/* Log received timestamp and calculated lag (at TRACE level only) */
guac_client_log(client, GUAC_LOG_TRACE, "Server completed "
"frame %" PRIu64 "ms (%i logical frames)", client->last_sent_timestamp, frames);

fprintf(stderr, "guac_client_end_multiple_frames end\n");

return guac_protocol_send_sync(client->socket, client->last_sent_timestamp, frames);

}

int guac_client_load_plugin(guac_client* client, const char* protocol) {

fprintf(stderr, "guac_client_load_plugin start\n");

/* Reference to dlopen()'d plugin */
void* client_plugin_handle;

Expand Down Expand Up @@ -766,6 +813,8 @@ int guac_client_load_plugin(guac_client* client, const char* protocol) {
/* Init client */
client->__plugin_handle = client_plugin_handle;

fprintf(stderr, "guac_client_load_plugin end\n");

return alias.client_init(client);

}
Expand Down Expand Up @@ -1043,6 +1092,8 @@ int guac_client_owner_supports_required(guac_client* client) {
*/
static void* guac_client_owner_notify_join_callback(guac_user* user, void* data) {

fprintf(stderr, "guac_client_owner_notify_join_callback start\n");

const guac_user* joiner = (const guac_user *) data;

if (user == NULL)
Expand All @@ -1064,6 +1115,8 @@ static void* guac_client_owner_notify_join_callback(guac_user* user, void* data)

/* Send user joined notification to owner. */
const char* args[] = { (const char*)joiner->user_id, (const char*)send_joiner, NULL };

fprintf(stderr, "guac_client_owner_notify_join_callback end\n");
return (void*) ((intptr_t) guac_protocol_send_msg(user->socket, GUAC_MESSAGE_USER_JOINED, args));

}
Expand Down Expand Up @@ -1102,6 +1155,8 @@ int guac_client_owner_notify_join(guac_client* client, guac_user* joiner) {
*/
static void* guac_client_owner_notify_leave_callback(guac_user* user, void* data) {

fprintf(stderr, "guac_client_owner_notify_leave_callback start\n");

const guac_user* quitter = (const guac_user *) data;

if (user == NULL)
Expand Down
15 changes: 15 additions & 0 deletions src/protocols/vnc/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@
*/
static void* guac_vnc_sync_pending_user_audio(guac_user* user, void* data) {

fprintf(stderr, "guac_vnc_sync_pending_user_audio start\n");

/* Add the user to the stream */
guac_pa_stream* audio = (guac_pa_stream*) data;
guac_pa_stream_add_user(audio, user);

fprintf(stderr, "guac_vnc_sync_pending_user_audio end\n");

return NULL;

}
Expand All @@ -76,10 +80,14 @@ static void* guac_vnc_sync_pending_user_audio(guac_user* user, void* data) {
*/
static int guac_vnc_join_pending_handler(guac_client* client) {

fprintf(stderr, "guac_vnc_join_pending_handler start\n");

guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
guac_socket* broadcast_socket = client->pending_socket;

#ifdef ENABLE_PULSE

fprintf(stderr, "calling guac_vnc_sync_pending_user_audio()\n");
/* Synchronize any audio stream for each pending user */
if (vnc_client->audio)
guac_client_foreach_pending_user(
Expand All @@ -88,16 +96,21 @@ static int guac_vnc_join_pending_handler(guac_client* client) {

/* Synchronize with current display */
if (vnc_client->display != NULL) {
fprintf(stderr, "calling guac_common_display_dup()\n");
guac_common_display_dup(vnc_client->display, client, broadcast_socket);
guac_socket_flush(broadcast_socket);
}

fprintf(stderr, "guac_vnc_join_pending_handler end\n");

return 0;

}

int guac_client_init(guac_client* client) {

fprintf(stderr, "guac_client_init (VNC) start\n");

/* Set client args */
client->args = GUAC_VNC_CLIENT_ARGS;

Expand Down Expand Up @@ -211,6 +224,8 @@ int guac_vnc_client_free_handler(guac_client* client) {
/* Free generic data struct */
free(client->data);

fprintf(stderr, "guac_client_init (VNC) end\n");

return 0;
}

0 comments on commit 2335632

Please sign in to comment.