From 6d5c9b6ddec8a8405fd0a2074962686dff8a4874 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Aug 2012 14:28:56 -0700 Subject: [PATCH] Refactor creation of client to NOT require plugin. --- libguac/include/client.h | 28 +++++++++++++++------------- libguac/src/client.c | 22 ++++++++-------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/libguac/include/client.h b/libguac/include/client.h index 1ceafe9c..028a89d0 100644 --- a/libguac/include/client.h +++ b/libguac/include/client.h @@ -470,23 +470,25 @@ guac_client_plugin* guac_client_plugin_open(const char* protocol); int guac_client_plugin_close(guac_client_plugin* plugin); /** - * Initialize and return a new guac_client. The pluggable client will be - * initialized using the arguments provided. + * Initializes the given guac_client using the initialization routing provided + * by the given guac_client_plugin. * - * @param plugin The client plugin to use to create the new client. - * @param socket The guac_socket the client should use for communication. + * @param client The guac_client to initialize. + * @param plugin The client plugin to use to initialize the new client. * @param argc The number of arguments being passed to the client. * @param argv All arguments to be passed to the client. - * @param log_info_handler Info logging handler to provide to the client before - * initializing. - * @param log_error_handler Error logging handler to provide to the client - * before initializing. - * @return A pointer to the newly initialized client. + * @return Zero if initialization was successful, non-zero otherwise. */ -guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin, - guac_socket* socket, int argc, char** argv, - guac_client_log_handler* log_info_handler, - guac_client_log_handler* log_error_handler); +int guac_client_init(guac_client* client, + guac_client_plugin* plugin, int argc, char** argv); + +/** + * Returns a new, barebones guac_client. This new guac_client has no handlers + * set, but is otherwise usable. + * + * @return A pointer to the new client. + */ +guac_client* guac_client_alloc(); /** * Free all resources associated with the given client. diff --git a/libguac/src/client.c b/libguac/src/client.c index 90491b50..25e41428 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -237,10 +237,14 @@ int guac_client_plugin_close(guac_client_plugin* plugin) { } -guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin, - guac_socket* socket, int argc, char** argv, - guac_client_log_handler* log_info_handler, - guac_client_log_handler* log_error_handler) { +int guac_client_init(guac_client* client, + guac_client_plugin* plugin, int argc, char** argv) { + + return plugin->init_handler(client, argc, argv); + +} + +guac_client* guac_client_alloc() { /* Allocate new client */ guac_client* client = malloc(sizeof(guac_client)); @@ -253,7 +257,6 @@ guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin, /* Init new client */ memset(client, 0, sizeof(guac_client)); - client->socket = socket; client->last_received_timestamp = client->last_sent_timestamp = guac_protocol_get_timestamp(); @@ -266,15 +269,6 @@ guac_client* guac_client_plugin_get_client(guac_client_plugin* plugin, client->__next_buffer_index = -1; client->__next_layer_index = 1; - /* Set up logging in client */ - client->log_info_handler = log_info_handler; - client->log_error_handler = log_error_handler; - - if (plugin->init_handler(client, argc, argv) != 0) { - free(client); - return NULL; - } - return client; }