From a11469885469e321c9891a40367ac18323def1ad Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 6 Sep 2012 20:08:15 -0700 Subject: [PATCH] Implement alloc/free for guac_resource. --- libguac/src/client.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/libguac/src/client.c b/libguac/src/client.c index 9dfe835e..db228f12 100644 --- a/libguac/src/client.c +++ b/libguac/src/client.c @@ -56,6 +56,29 @@ guac_layer __GUAC_DEFAULT_LAYER = { const guac_layer* GUAC_DEFAULT_LAYER = &__GUAC_DEFAULT_LAYER; +guac_resource* guac_client_alloc_resource(guac_client* client) { + + /* Init new layer */ + guac_resource* resource = malloc(sizeof(guac_resource)); + resource->index = guac_pool_next_int(client->__resource_pool); + resource->accept_handler = NULL; + resource->reject_handler = NULL; + resource->data = NULL; + + /* Resize resource map if necessary */ + if (resource->index >= client->__available_resource_slots) { + client->__available_resource_slots = resource->index * 2; + client->__resource_map = realloc(client->__resource_map, + sizeof(guac_resource*) * client->__available_resource_slots); + } + + /* Store resource in map */ + client->__resource_map[resource->index] = resource; + + return resource; + +} + guac_layer* guac_client_alloc_layer(guac_client* client) { /* Init new layer */ @@ -80,6 +103,16 @@ guac_layer* guac_client_alloc_buffer(guac_client* client) { } +void guac_client_free_resource(guac_client* client, guac_resource* resource) { + + /* Release index to pool */ + guac_pool_free_int(client->__resource_pool, resource->index); + + /* Free resource */ + free(resource); + +} + void guac_client_free_buffer(guac_client* client, guac_layer* layer) { /* Release index to pool */