From f769c46b3607660cbf579e2685664e10a2aca79d Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Tue, 7 Nov 2017 16:35:26 +0900 Subject: [PATCH] add remove functions for attributes notify Change-Id: I59493283b84428424b7776f56bc19dd3dbb93741 --- inc/connectivity.h | 2 ++ src/connectivity.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/inc/connectivity.h b/inc/connectivity.h index 5bb4ba3..9adfcb6 100644 --- a/inc/connectivity.h +++ b/inc/connectivity.h @@ -95,5 +95,7 @@ extern int connectivity_attributes_add_int(connectivity_resource_s *resource_inf extern int connectivity_attributes_add_double(connectivity_resource_s *resource_info, const char *key, double value); extern int connectivity_attributes_add_string(connectivity_resource_s *resource_info, const char *key, const char *value); extern int connectivity_attributes_notify_all(connectivity_resource_s *resource_info); +extern int connectivity_attributes_remove_value_by_key(connectivity_resource_s *resource_info, const char *key); +extern int connectivity_attributes_remove_all(connectivity_resource_s *resource_info); #endif /* __POSITION_FINDER_CONNECTIVITY_H__ */ diff --git a/src/connectivity.c b/src/connectivity.c index 9cf3059..a9c695b 100644 --- a/src/connectivity.c +++ b/src/connectivity.c @@ -905,6 +905,29 @@ int connectivity_attributes_add_string(connectivity_resource_s *resource_info, c return __add_value_to_hash(resource_info, key, data_value); } +int connectivity_attributes_remove_value_by_key(connectivity_resource_s *resource_info, const char *key) +{ + retv_if(!resource_info, -1); + retv_if(!key, -1); + + if (resource_info->value_hash) + g_hash_table_remove(resource_info->value_hash, key); + + return 0; +} + +int connectivity_attributes_remove_all(connectivity_resource_s *resource_info) +{ + retv_if(!resource_info, -1); + + if (resource_info->value_hash) { + g_hash_table_destroy(resource_info->value_hash); + resource_info->value_hash = NULL; + } + + return 0; +} + static void __json_add_data_iter_cb(gpointer key, gpointer value, gpointer user_data) { char *name = key; @@ -1013,7 +1036,12 @@ int connectivity_attributes_notify_all(connectivity_resource_s *resource_info) int ret = 0; retv_if(!resource_info, -1); - retv_if(!resource_info->value_hash, -1); + + if (resource_info->value_hash == NULL) { + _W("You have nothing to notify now"); + return 0; + } + switch (resource_info->protocol_type) { case CONNECTIVITY_PROTOCOL_IOTIVITY: @@ -1062,7 +1090,6 @@ int connectivity_attributes_notify_all(connectivity_resource_s *resource_info) } break; case CONNECTIVITY_PROTOCOL_HTTP: - /* TODO */ ret = web_util_json_init(); retv_if(ret, -1); -- 2.7.4