diff --git a/libguac/include/client.h b/libguac/include/client.h index b1b481ee..05d14172 100644 --- a/libguac/include/client.h +++ b/libguac/include/client.h @@ -134,6 +134,14 @@ typedef int guac_client_init_handler(guac_client* client, int argc, char** argv) */ #define GUAC_BUFFER_POOL_INITIAL_SIZE 1024 +/** + * The number of initial slots to allocate for resources within the client resource + * map. The client resource map maps resource indices to actual guac_resource instances. + * This map will need to be reallocated once the number of resources required exceeds + * the available number of slots. + */ +#define GUAC_RESOURCE_MAP_INITIAL_SIZE 1024 + /** * Possible current states of the Guacamole client. Currently, the only * two states are GUAC_CLIENT_RUNNING and GUAC_CLIENT_STOPPING. @@ -353,15 +361,33 @@ struct guac_client { guac_client_log_handler* log_error_handler; /** - * Pool of buffer indices. + * Pool of buffer indices. Buffers are simply layers with negative indices. Note that + * because guac_pool always gives non-negative indices starting at 0, the output of + * this guac_pool will be adjusted. */ guac_pool* __buffer_pool; /** - * Pool of layer indices. + * Pool of layer indices. Note that because guac_pool always gives non-negative indices + * starting at 0, the output of this guac_pool will be adjusted. */ guac_pool* __layer_pool; + /** + * Pool of server-side resource indices. + */ + guac_pool* __resource_pool; + + /** + * Array of all allocated resources. + */ + guac_resource** __resource_map; + + /** + * The number of elements in the __resource_map array. + */ + int __available_resource_slots; + }; /** diff --git a/libguac/src/client.c b/libguac/src/client.c index 0a771ffb..9dfe835e 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -118,9 +118,16 @@ guac_client* guac_client_alloc() { client->state = GUAC_CLIENT_RUNNING; + /* Allocate buffer and layer pools */ client->__buffer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE); client->__layer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE); + /* Allocate resource pool */ + client->__resource_pool = guac_pool_alloc(0); + client->__available_resource_slots = GUAC_RESOURCE_MAP_INITIAL_SIZE; + client->__resource_map = + malloc(sizeof(guac_resource*) * client->__available_resource_slots); + return client; }