diff options
author | James Prestwood <james.prestwood@intel.com> | 2017-03-15 11:45:19 -0700 |
---|---|---|
committer | Geoff Gustafson <geoff@linux.intel.com> | 2017-03-15 11:45:19 -0700 |
commit | 556ac3404ded8217f890cc5e61aff5811b81a840 (patch) | |
tree | 69a6024ce52141723267fb840d774cf1943107e8 /src/zjs_ocf_client.c | |
parent | 60455e99b3d937864ae2520f07754d632658439e (diff) |
[ocf] register resource correctly (#800)
Signed-off-by: James Prestwood <james.prestwood@intel.com>
Diffstat (limited to 'src/zjs_ocf_client.c')
-rw-r--r-- | src/zjs_ocf_client.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/zjs_ocf_client.c b/src/zjs_ocf_client.c index b6a822f..2add8c2 100644 --- a/src/zjs_ocf_client.c +++ b/src/zjs_ocf_client.c @@ -49,7 +49,7 @@ struct ocf_handler { struct client_resource* res; }; -struct client_resource* resources = NULL; +static struct client_resource* resource_list = NULL; #define MAX_URI_LENGTH (30) @@ -216,7 +216,7 @@ static void print_props_data(oc_client_response_t *data) static struct client_resource* find_resource_by_id(const char* device_id) { if (device_id) { - struct client_resource* cur = resources; + struct client_resource* cur = resource_list; while (cur) { if (cur->state != RES_STATE_SEARCHING) { if (strcmp(cur->device_id, device_id) == 0) { @@ -236,7 +236,7 @@ static struct client_resource* find_resource_by_id(const char* device_id) static struct client_resource* find_resource_by_path(const char* path) { if (path) { - struct client_resource* cur = resources; + struct client_resource* cur = resource_list; while (cur) { if (cur->state != RES_STATE_SEARCHING) { if (strcmp(cur->resource_path, path) == 0) { @@ -273,7 +273,7 @@ static void free_client(const uintptr_t native_p) { struct client_resource* client = (struct client_resource*)native_p; if (client) { - struct client_resource* cur = resources; + struct client_resource* cur = resource_list; while (cur->next) { if (cur->next == client) { cur->next = client->next; @@ -295,7 +295,7 @@ static void free_client(const uintptr_t native_p) } /* - * Add a discovered resource to the list of resources + * Add a discovered resource to the list of resource_list */ static void add_resource(char* id, char* type, char* path, jerry_value_t client, jerry_value_t listener) { @@ -328,8 +328,8 @@ static void add_resource(char* id, char* type, char* path, jerry_value_t client, zjs_add_event_listener(new->client, "resourcefound", listener); } - new->next = resources; - resources = new; + new->next = resource_list; + resource_list = new; } static void post_ocf_promise(void* handle) @@ -377,7 +377,7 @@ static oc_discovery_flags_t discovery(const char *di, for (i = 0; i < oc_string_array_get_allocated_size(types); i++) { char *t = oc_string_array_get_item(types, i); - struct client_resource* cur = resources; + struct client_resource* cur = resource_list; while (cur) { if (cur->state == RES_STATE_SEARCHING) { // check if resource has any filter constraints @@ -1080,4 +1080,23 @@ jerry_value_t zjs_ocf_client_init() return ocf_client; } +void zjs_ocf_client_cleanup() +{ + if (resource_list) { + struct client_resource *cur = resource_list; + while (cur) { + if (cur->resource_type) { + zjs_free(cur->resource_type); + } + if (cur->resource_path) { + zjs_free(cur->resource_path); + } + jerry_release_value(cur->client); + resource_list = resource_list->next; + zjs_free(cur); + cur = resource_list; + } + } +} + #endif // BUILD_MODULE_OCF |