diff options
author | saerome.kim <saerome.kim@samsung.com> | 2019-10-31 15:06:01 +0900 |
---|---|---|
committer | saerome.kim <saerome.kim@samsung.com> | 2019-11-04 16:08:30 +0900 |
commit | 1d83298f440e2675c8d4818bc6c9b5c06435838e (patch) | |
tree | c4c60971ccaffdb77390063d3431fa57b144b6f1 | |
parent | b196432104569e5f6a874cd42b3a680a2286ce39 (diff) | |
download | user-awareness-1d83298f440e2675c8d4818bc6c9b5c06435838e.tar.gz user-awareness-1d83298f440e2675c8d4818bc6c9b5c06435838e.tar.bz2 user-awareness-1d83298f440e2675c8d4818bc6c9b5c06435838e.zip |
Remove useless handle checker
- Problem: can't clone any device.
- Cause: There is useleess handle comparison at ua_device_clone.
- Solution: Remove them.
Change-Id: Idee58777a86be96b51bf3896326a3be2a6d70644
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
-rw-r--r-- | include/user-awareness-log.h | 21 | ||||
-rw-r--r-- | include/user-awareness-private.h | 36 | ||||
-rw-r--r-- | src/user-awareness-device.c | 119 | ||||
-rwxr-xr-x[-rw-r--r--] | src/user-awareness-event-handler.c | 9 | ||||
-rwxr-xr-x[-rw-r--r--] | src/user-awareness-monitors.c | 0 | ||||
-rw-r--r-- | src/user-awareness-service.c | 82 | ||||
-rw-r--r-- | src/user-awareness-users.c | 63 |
7 files changed, 196 insertions, 134 deletions
diff --git a/include/user-awareness-log.h b/include/user-awareness-log.h index f5aae40..f1f3330 100644 --- a/include/user-awareness-log.h +++ b/include/user-awareness-log.h @@ -29,10 +29,23 @@ extern "C" { #endif #define LOG_TAG "UA_CAPI" -#define UA_DBG(fmt, args...) LOGD(fmt, ##args) -#define UA_INFO(fmt, args...) LOGI(fmt, ##args) -#define UA_WARN(fmt, args...) LOGW(fmt, ##args) -#define UA_ERR(fmt, args...) LOGE(fmt, ##args) +#define LOG_COLOR_RESET "\033[0m" +#define LOG_COLOR_RED "\033[31m" +#define LOG_COLOR_YELLOW "\033[33m" +#define LOG_COLOR_GREEN "\033[32m" +#define LOG_COLOR_BLUE "\033[36m" +#define LOG_COLOR_PURPLE "\033[35m" + +#define UA_DBG(fmt, args...) \ + SLOGD(fmt, ##args) +#define UA_INFO(fmt, args...) \ + SLOGI(fmt, ##args) +#define UAM_INFO_C(fmt, arg...) \ + SLOGI_IF(TRUE, LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg) +#define UA_WARN(fmt, arg...) \ + SLOGI_IF(TRUE, LOG_COLOR_YELLOW" "fmt" "LOG_COLOR_RESET, ##arg) +#define UA_ERR(fmt, arg...) \ + SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg) #define FUNC_ENTRY UA_DBG("+") #define FUNC_EXIT UA_DBG("-") diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index 31fca40..d67d3a9 100644 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -60,6 +60,17 @@ extern "C" { } /** + * @brief Returns error code if expr is NULL. + * @since_tizen 5.5 + */ +#define UA_IS_EXIST(arg) \ + if (arg == NULL) { \ + UA_ERR("UA_ERROR_NOT_FOUND(%s is NULL)", #arg); \ + return UA_ERROR_NOT_FOUND; \ + } + + +/** * @brief Prints arg. * @since_tizen 5.5 */ @@ -412,6 +423,18 @@ void _ua_monitor_handle_sensor_status_changed(uam_sensor_info_s *info); void _ua_free_ua_monitor_t(gpointer data); /** + * @brief Gets a user handle. + * @since_tizen 5.5 + * + * @param[in] account User account. + * + * @exception + * @pre + * @post + */ +ua_user_info_s *_ua_get_user_from_list(const char *account); + +/** * @brief Destroys a user handle. * @since_tizen 5.5 * @@ -517,6 +540,19 @@ ua_ble_payload_s* _ua_payload_clone(ua_ble_payload_s *org_payload); int _ua_device_add_info_to_list(ua_dev_info_s* dev_info); /** + * @brief Gets a device handle. + * @since_tizen 5.5 + * + * @param[in] account User account. + * + * @exception + * @pre + * @post + */ +ua_dev_info_s *_ua_get_device_from_list(const char *device_id, + const char *mac, ua_mac_type_e type); + +/** * @brief Destroys a device handle. * @since_tizen 5.5 * diff --git a/src/user-awareness-device.c b/src/user-awareness-device.c index ba42d3e..5d05a9c 100644 --- a/src/user-awareness-device.c +++ b/src/user-awareness-device.c @@ -24,34 +24,20 @@ extern GSList *ua_users_list; -GSList *ua_devices_list; -GSList *ua_devices_db_list; +GSList *ua_devices_list = NULL; +GSList *ua_devices_user_list = NULL; ua_callback_s user_callbacks[UA_USER_EVENT_MAX] = {{NULL, NULL},}; -static ua_dev_info_s *__ua_get_device_from_list(const char *device_id, - const char *mac, ua_mac_type_e type) +static void __ua_check_and_free_device_info_from_list(ua_dev_info_s *device) { - GSList *l; - ua_dev_info_s *dev; - - for (l = ua_devices_list; NULL != l; l = g_slist_next(l)) { - dev = (ua_dev_info_s *)l->data; - - if (type != dev->type) - continue; - - if (device_id && !g_strcmp0(device_id, dev->device_id)) { - UA_INFO("Device ID found, device id[%s]", dev->device_id); + int ret; + gboolean is_exist = FALSE; - if (mac && !g_strcmp0(mac, dev->mac)) { - UA_INFO("Device found, mac address[%s]", dev->mac); - return dev; - } - return dev; - } - } + ret = _ua_is_device_exist(device->device_id, device->mac, device->type, &is_exist); + if (UA_ERROR_NONE == ret && TRUE == is_exist) + ua_devices_list = g_slist_remove(ua_devices_list, device); - return NULL; + _ua_free_ua_device_info_t((gpointer)device); } static void __ua_remove_device_info_from_list(uam_device_info_s *uam_info) @@ -92,7 +78,7 @@ static ua_dev_info_s* __ua_add_device_info_to_list(uam_device_info_s *uam_info) ua_dev_info_s *dev; retv_if(NULL == uam_info, NULL); - dev = __ua_get_device_from_list(uam_info->device_id, + dev = _ua_get_device_from_list(uam_info->device_id, uam_info->mac, _to_ua_mac_type(uam_info->type)); if (dev) { /* Update device info */ @@ -122,6 +108,34 @@ static ua_dev_info_s* __ua_add_device_info_to_list(uam_device_info_s *uam_info) return dev; } +ua_dev_info_s *_ua_get_device_from_list(const char *device_id, + const char *mac, ua_mac_type_e type) +{ + GSList *l; + ua_dev_info_s *dev; + + for (l = ua_devices_list; NULL != l; l = g_slist_next(l)) { + dev = (ua_dev_info_s *)l->data; + + UA_INFO("dev->device id [%s] dev->mac [%s]", dev->device_id, dev->mac); + + if (type != dev->type) + continue; + + if (device_id && !g_strcmp0(device_id, dev->device_id)) { + UA_INFO("Device ID found, device id[%s]", dev->device_id); + + if (mac && !g_strcmp0(mac, dev->mac)) { + UA_INFO("Device found, mac address[%s]", dev->mac); + return dev; + } + return dev; + } + } + + return NULL; +} + ua_dev_info_s* _ua_get_device_info_from_uam(uam_device_info_s *uam_info) { ua_dev_info_s *dev = g_malloc0(sizeof(ua_dev_info_s)); @@ -343,8 +357,6 @@ int _ua_is_device_exist(char *device_id, char *mac, ua_mac_type_e type, return UA_ERROR_NONE; } - - int _ua_device_add_info_to_list(ua_dev_info_s* dev_info) { FUNC_ENTRY; @@ -352,13 +364,14 @@ int _ua_device_add_info_to_list(ua_dev_info_s* dev_info) ua_dev_info_s* device_info; UA_VALIDATE_INPUT_PARAMETER(dev_info); - if (NULL != __ua_get_device_from_list( + if (NULL != _ua_get_device_from_list( dev_info->device_id, dev_info->mac, dev_info->type)) return UA_ERROR_ALREADY_DONE; // LCOV_EXCL_LINE + ret = ua_device_clone((ua_device_h)&device_info, dev_info); if (UA_ERROR_NONE != ret) { - UA_ERR("_ua_device_add_info_to_list failed [%s]", _ua_get_error_string(ret)); + UA_ERR("ua_device_clone failed [%s]", _ua_get_error_string(ret)); return ret; } @@ -378,7 +391,7 @@ void _ua_handle_device_added(int result, uam_device_info_s *uam_info) if (NULL == uam_info) { UA_ERR("Add device failed [%s]", _ua_get_error_string(result)); } else { - dev = __ua_get_device_from_list(uam_info->device_id, + dev = _ua_get_device_from_list(uam_info->device_id, uam_info->mac, _to_ua_mac_type(uam_info->type)); if (NULL != dev) UA_ERR("Add device failed for Id:[%s] MAC type:[0x%4.4X]", @@ -447,7 +460,6 @@ int ua_device_create(ua_device_h *device_handle) *device_handle = (ua_device_h)device; device->handle = *device_handle; device->create_by_app = true; - ua_devices_list = g_slist_append(ua_devices_list, device); FUNC_EXIT; return UA_ERROR_NONE; @@ -456,13 +468,12 @@ int ua_device_create(ua_device_h *device_handle) int ua_device_destroy(ua_device_h device_handle) { FUNC_ENTRY; + ua_dev_info_s *device = (ua_dev_info_s *)device_handle; UA_VALIDATE_INPUT_PARAMETER(device_handle); - UA_VALIDATE_HANDLE(device_handle, ua_devices_list); - ua_devices_list = g_slist_remove(ua_devices_list, device); - _ua_free_ua_device_info_t((gpointer)device); + __ua_check_and_free_device_info_from_list(device); FUNC_EXIT; return UA_ERROR_NONE; @@ -511,7 +522,6 @@ int ua_device_set_mac_address( UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_INPUT_PARAMETER(mac_address); - UA_VALIDATE_HANDLE(handle, ua_devices_list); retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER); @@ -549,7 +559,6 @@ int ua_device_set_os_info( ua_dev_info_s *device = (ua_dev_info_s *)handle; UA_VALIDATE_INPUT_PARAMETER(handle); - UA_VALIDATE_HANDLE(handle, ua_devices_list); retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER); @@ -577,7 +586,6 @@ int ua_device_set_device_id( UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_INPUT_PARAMETER(device_id); - UA_VALIDATE_HANDLE(handle, ua_devices_list); retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER); /* This code will check if app try to add device id which is already set for same @@ -607,7 +615,6 @@ int ua_device_set_wifi_bssid( UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_INPUT_PARAMETER(bssid); - UA_VALIDATE_HANDLE(handle, ua_devices_list); retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER); retv_if((strlen(bssid) != (UA_MAC_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER); @@ -634,7 +641,6 @@ int ua_device_set_wifi_ipv4_address( UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_INPUT_PARAMETER(ipv4_address); - UA_VALIDATE_HANDLE(handle, ua_devices_list); retv_if(device->isadded, UA_ERROR_INVALID_PARAMETER); retv_if((strlen(ipv4_address) > (UA_IPV4_ADDRESS_STRING_LEN -1)), UA_ERROR_INVALID_PARAMETER); @@ -660,7 +666,6 @@ int ua_device_set_discriminant( ua_dev_info_s *device = (ua_dev_info_s *)device_handle; UA_VALIDATE_INPUT_PARAMETER(device_handle); - UA_VALIDATE_HANDLE(device_handle, ua_devices_list); device->discriminant = discriminant; @@ -683,7 +688,6 @@ int ua_device_set_payload_service_id( _ua_create_ua_ble_payload_s(&device->payload); if (!device->payload) { UA_ERR("_ua_create_ua_ble_payload_s() failed"); - _ua_free_ua_device_info_t((gpointer)device); return UA_ERROR_OUT_OF_MEMORY; } } @@ -709,7 +713,6 @@ int ua_device_set_payload_device_icon( _ua_create_ua_ble_payload_s(&device->payload); if (!device->payload) { UA_ERR("_ua_create_ua_ble_payload_s() failed"); - _ua_free_ua_device_info_t((gpointer)device); return UA_ERROR_OUT_OF_MEMORY; } } @@ -735,7 +738,6 @@ int ua_device_set_payload_purpose( _ua_create_ua_ble_payload_s(&device->payload); if (!device->payload) { UA_ERR("_ua_create_ua_ble_payload_s() failed"); - _ua_free_ua_device_info_t((gpointer)device); return UA_ERROR_OUT_OF_MEMORY; } } @@ -764,7 +766,6 @@ int ua_device_set_payload_duid( _ua_create_ua_ble_payload_s(&device->payload); if (!device->payload) { UA_ERR("_ua_create_ua_ble_payload_s() failed"); - _ua_free_ua_device_info_t((gpointer)device); return UA_ERROR_OUT_OF_MEMORY; } } @@ -775,7 +776,7 @@ int ua_device_set_payload_duid( device->payload->duid = g_malloc0(UA_BLE_PAYLOAD_DUID_LEN + 1); if (device->payload->duid == NULL) { UA_ERR("g_malloc0 failed"); - _ua_free_ua_device_info_t((gpointer)device); + _ua_free_ua_ble_payload_s((gpointer)device->payload); return UA_ERROR_OUT_OF_MEMORY; } @@ -1329,6 +1330,12 @@ int ua_device_clone(ua_device_h *cloned, UA_VALIDATE_INPUT_PARAMETER(cloned); UA_VALIDATE_INPUT_PARAMETER(origin); + UA_DBG("org_device->device_id [%s] org_device->mac [%s] org_device->type [%d]", + org_device->device_id, org_device->mac, org_device->type); + + UA_IS_EXIST(_ua_get_device_from_list( + org_device->device_id, org_device->mac, org_device->type)); + device = g_malloc0(sizeof(ua_dev_info_s)); if (!device) { UA_ERR("g_malloc0 failed"); @@ -1438,6 +1445,11 @@ int ua_device_foreach_added( return ret; } + if (ua_devices_list) { + g_slist_free_full(ua_devices_list, _ua_free_ua_device_info_t); + ua_devices_list = NULL; + } + for (i = 0; i < devices_list->len; i++) { /* LCOV_EXCL_START */ ptr = g_ptr_array_index(devices_list, i); @@ -1488,7 +1500,7 @@ int ua_device_foreach_added( device_info->os = ptr->operating_system; device_info->discriminant = ptr->discriminant; device_info->last_presence_timestamp = ptr->last_seen; - ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info); + ua_devices_list = g_slist_append(ua_devices_list, device_info); } else { UA_ERR("OPERATION_FAILED(0x%08x)", UA_ERROR_OPERATION_FAILED); @@ -1498,7 +1510,7 @@ int ua_device_foreach_added( /* LCOV_EXCL_STOP */ } - for (l = ua_devices_db_list; l; l = g_slist_next(l)) { + for (l = ua_devices_list; l; l = g_slist_next(l)) { /* LCOV_EXCL_START */ ua_dev_info_s *u = l->data; @@ -1511,9 +1523,6 @@ int ua_device_foreach_added( } done: - g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t); - ua_devices_db_list = NULL; - g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL); g_ptr_array_free(devices_list, TRUE); @@ -1549,6 +1558,11 @@ int ua_device_foreach_added_by_user( return ret; } + if (ua_devices_user_list) { + g_slist_free_full(ua_devices_user_list, _ua_free_ua_device_info_t); + ua_devices_user_list= NULL; + } + for (i = 0; i < devices_list->len; i++) { /* LCOV_EXCL_START */ ptr = g_ptr_array_index(devices_list, i); @@ -1600,7 +1614,7 @@ int ua_device_foreach_added_by_user( device_info->last_presence_timestamp = ptr->last_seen; device_info->discriminant = ptr->discriminant; device_info->user = (ua_user_h)user; - ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info); + ua_devices_user_list = g_slist_append(ua_devices_user_list, device_info); } else { UA_ERR("OPERATION_FAILED(0x%08x)", UA_ERROR_OPERATION_FAILED); @@ -1610,7 +1624,7 @@ int ua_device_foreach_added_by_user( /* LCOV_EXCL_STOP */ } - for (l = ua_devices_db_list; l; l = g_slist_next(l)) { + for (l = ua_devices_user_list; l; l = g_slist_next(l)) { /* LCOV_EXCL_START */ ua_dev_info_s *u = l->data; @@ -1623,9 +1637,6 @@ int ua_device_foreach_added_by_user( } done: - g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t); - ua_devices_db_list = NULL; - g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL); g_ptr_array_free(devices_list, TRUE); diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c index 74e2a63..5fd129b 100644..100755 --- a/src/user-awareness-event-handler.c +++ b/src/user-awareness-event-handler.c @@ -30,7 +30,7 @@ extern GSList *ua_user_list; extern GSList *ua_services_list; extern GSList *ua_users_list; -extern GSList *ua_devices_db_list; +extern GSList *ua_devices_user_list; extern GSList *ua_devices_list; /* LCOV_EXCL_START */ @@ -374,8 +374,11 @@ int ua_deinitialize(void) g_slist_free_full(ua_users_list, _ua_free_ua_user_info_t); ua_users_list = NULL; - g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t); - ua_devices_db_list = NULL; + g_slist_free_full(ua_devices_user_list, _ua_free_ua_device_info_t); + ua_devices_user_list = NULL; + + g_slist_free_full(ua_devices_list, _ua_free_ua_device_info_t); + ua_devices_list = NULL; ret = _ua_get_error_code(_uam_deinit()); if (UA_ERROR_NONE != ret) { diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index ba890ad..ba890ad 100644..100755 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c diff --git a/src/user-awareness-service.c b/src/user-awareness-service.c index 95a33b0..1575402 100644 --- a/src/user-awareness-service.c +++ b/src/user-awareness-service.c @@ -23,6 +23,7 @@ #include <user-awareness-private.h> #include <user-awareness-util.h> +extern GSList *ua_users_list; GSList *ua_services_list; static ua_service_info_s* __ua_get_service_from_list(const char *service_name) @@ -252,7 +253,6 @@ int _ua_foreach_registered_services(ua_service_added_cb foreach_cb, /* LCOV_EXCL_START */ UA_ERR("g_malloc0 failed"); ret = UA_ERROR_OUT_OF_MEMORY; - _ua_free_ua_service_info_s(service_info); /* LCOV_EXCL_STOP */ goto done; } @@ -609,6 +609,9 @@ int ua_service_add_user(ua_service_h service_handle, ua_user_h user_handle) UA_VALIDATE_INPUT_PARAMETER(service_handle); UA_VALIDATE_INPUT_PARAMETER(user_handle); + UA_IS_EXIST(_ua_get_user_from_list(user_info->account)); + UA_IS_EXIST(__ua_get_service_from_list(service_info->name)); + retv_if(user_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); tmp = service_info; @@ -634,6 +637,8 @@ int ua_service_remove_user(ua_service_h service_handle, ua_user_h user_handle) UA_VALIDATE_INPUT_PARAMETER(service_info); UA_VALIDATE_INPUT_PARAMETER(user_handle); + UA_IS_EXIST(_ua_get_user_from_list(user_info->account)); + UA_IS_EXIST(__ua_get_service_from_list(service_info->name)); ret = _ua_get_error_code(_uam_service_remove_user(service_info->name, user_info->account)); if (UA_ERROR_NONE != ret) { @@ -652,36 +657,21 @@ int ua_service_add_device(ua_service_h service_handle, ua_device_h device_handle int ret; ua_service_info_s* service_info = (ua_service_info_s*)service_handle; - ua_dev_info_s* device_info = (ua_dev_info_s*)device_handle; - ua_service_info_s *tmp = NULL; + ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle; UA_VALIDATE_INPUT_PARAMETER(service_info); UA_VALIDATE_INPUT_PARAMETER(device_handle); - UA_VALIDATE_HANDLE(service_handle, ua_services_list); - UA_PRINT_DEVICE_HANDLE(device_handle); - retv_if(device_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); - -#if 0 -//TODO lk, ideally the handle should be in the ua_services_list. - tmp = __ua_get_service_from_list(service_info->name); - if (!tmp) { - ua_service_info_s *tmp = g_malloc0(sizeof(ua_service_info_s)); - if (!tmp) { - UA_ERR("Memory allocation failed"); - return UA_ERROR_OUT_OF_MEMORY; - } - tmp->name = g_strdup(service_info->name); - tmp->create_by_app = true; - tmp->default_service = false; - tmp->isadded = true; - tmp->service_handle = tmp; - ua_services_list = g_slist_append(ua_services_list, tmp); - } -#else - tmp = service_info; -#endif - ret = _ua_get_error_code(_uam_service_add_device(tmp->name, device_info->device_id, - _ua_to_uam_tech_type(device_info->type))); + + UA_DBG("device_info->device_id [%s], device_info->mac [%s], device_info->type [%d]", + dev_info->device_id, dev_info->mac, dev_info->type); + + UA_IS_EXIST(_ua_get_device_from_list(dev_info->device_id, dev_info->mac, dev_info->type)); + UA_IS_EXIST(__ua_get_service_from_list(service_info->name)); + + retv_if(dev_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); + + ret = _ua_get_error_code(_uam_service_add_device(service_info->name, dev_info->device_id, + _ua_to_uam_tech_type(dev_info->type))); if (UA_ERROR_NONE != ret) { UA_ERR("_uam_service_add_device returned %s", _ua_get_error_string(ret)); @@ -698,18 +688,18 @@ int ua_service_remove_device(ua_service_h service_handle, ua_device_h device_han int ret; ua_service_info_s* service_info = (ua_service_info_s*)service_handle; - ua_dev_info_s* device_info = (ua_dev_info_s*)device_handle; + ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle; UA_VALIDATE_INPUT_PARAMETER(service_info); UA_VALIDATE_INPUT_PARAMETER(service_info->name); - UA_VALIDATE_INPUT_PARAMETER(device_info); - UA_VALIDATE_INPUT_PARAMETER(device_info->device_id); + UA_VALIDATE_INPUT_PARAMETER(dev_info); + UA_VALIDATE_INPUT_PARAMETER(dev_info->device_id); - UA_VALIDATE_HANDLE(service_handle, ua_services_list); - UA_PRINT_DEVICE_HANDLE(device_handle); + UA_IS_EXIST(_ua_get_device_from_list(dev_info->device_id, dev_info->mac, dev_info->type)); + UA_IS_EXIST(__ua_get_service_from_list(service_info->name)); ret = _ua_get_error_code(_uam_service_remove_device(service_info->name, - device_info->device_id, _ua_to_uam_tech_type(device_info->type))); + dev_info->device_id, _ua_to_uam_tech_type(dev_info->type))); if (UA_ERROR_NONE != ret) { UA_ERR("_uam_service_remove_device returned %s", _ua_get_error_string(ret)); @@ -727,16 +717,18 @@ int ua_service_set_device_discriminant(ua_service_h service_handle, int ret; ua_service_info_s* service_info = (ua_service_info_s*)service_handle; - ua_dev_info_s* device_info = (ua_dev_info_s*)device_handle; + ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle; UA_VALIDATE_INPUT_PARAMETER(service_info); UA_VALIDATE_INPUT_PARAMETER(device_handle); - UA_VALIDATE_HANDLE(service_handle, ua_services_list); - UA_PRINT_DEVICE_HANDLE(device_handle); - retv_if(device_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); + + UA_IS_EXIST(_ua_get_device_from_list(dev_info->device_id, dev_info->mac, dev_info->type)); + UA_IS_EXIST(__ua_get_service_from_list(service_info->name)); + + retv_if(dev_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); ret = _ua_get_error_code(_uam_service_set_device_discriminant(service_info->name, - device_info->device_id, _ua_to_uam_tech_type(device_info->type), + dev_info->device_id, _ua_to_uam_tech_type(dev_info->type), discriminant)); if (UA_ERROR_NONE != ret) { UA_ERR("_uam_service_set_device_discriminant returned %s", @@ -755,16 +747,18 @@ int ua_service_get_device_discriminant(ua_service_h service_handle, int ret; ua_service_info_s* service_info = (ua_service_info_s*)service_handle; - ua_dev_info_s* device_info = (ua_dev_info_s*)device_handle; + ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle; UA_VALIDATE_INPUT_PARAMETER(service_info); UA_VALIDATE_INPUT_PARAMETER(device_handle); - UA_VALIDATE_HANDLE(service_handle, ua_services_list); - UA_PRINT_DEVICE_HANDLE(device_handle); - retv_if(device_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); + + UA_IS_EXIST(_ua_get_device_from_list(dev_info->device_id, dev_info->mac, dev_info->type)); + UA_IS_EXIST(__ua_get_service_from_list(service_info->name)); + + retv_if(dev_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); ret = _ua_get_error_code(_uam_service_get_device_discriminant(service_info->name, - device_info->device_id, _ua_to_uam_tech_type(device_info->type), + dev_info->device_id, _ua_to_uam_tech_type(dev_info->type), discriminant)); if (UA_ERROR_NONE != ret) { UA_ERR("_uam_service_get_device_discriminant returned %s", diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c index ee9982b..ae9c42d 100644 --- a/src/user-awareness-users.c +++ b/src/user-awareness-users.c @@ -25,10 +25,10 @@ GSList *ua_users_list; extern GSList *ua_devices_list; -extern GSList *ua_devices_db_list; +extern GSList *ua_devices_user_list; extern ua_callback_s user_callbacks[UA_USER_EVENT_MAX]; -static ua_user_info_s *__ua_get_user_from_list(const char *account) +ua_user_info_s *_ua_get_user_from_list(const char *account) { GSList *l; ua_user_info_s *user_info; @@ -122,7 +122,7 @@ int _ua_user_add_info_to_list_from_uapi_data(uam_user_info_s *uam_info) ua_user_info_s* user_info; UA_VALIDATE_INPUT_PARAMETER(uam_info); - if (NULL != __ua_get_user_from_list(uam_info->account)) { + if (NULL != _ua_get_user_from_list(uam_info->account)) { UA_INFO("User already in list(added on user_create) [%s]", uam_info->account); return UA_ERROR_NONE; } @@ -171,7 +171,7 @@ int _ua_user_add_info_to_list(ua_user_info_s* ua_info) ua_user_info_s* user_info; UA_VALIDATE_INPUT_PARAMETER(ua_info); - if (NULL != __ua_get_user_from_list(ua_info->account)) + if (NULL != _ua_get_user_from_list(ua_info->account)) return UA_ERROR_ALREADY_DONE; // LCOV_EXCL_LINE user_info = g_malloc0(sizeof(ua_user_info_s)); @@ -474,8 +474,6 @@ int ua_user_create(ua_user_h *user_handle) user->user_handle = (ua_user_h)user; user->create_by_app = true; - ua_users_list = g_slist_append(ua_users_list, user); - FUNC_EXIT; return UA_ERROR_NONE; } @@ -506,6 +504,7 @@ int ua_user_clone(ua_user_h *dst, ua_user_h src) user_dst->name = g_strdup(user_src->name); if (!user_dst->name) { /* LCOV_EXCL_START */ + g_free(user_dst); UA_ERR("g_malloc0 failed"); return UA_ERROR_OUT_OF_MEMORY; /* LCOV_EXCL_STOP */ @@ -514,6 +513,7 @@ int ua_user_clone(ua_user_h *dst, ua_user_h src) if (!user_dst->account) { /* LCOV_EXCL_START */ g_free(user_dst->name); + g_free(user_dst); UA_ERR("g_malloc0 failed"); return UA_ERROR_OUT_OF_MEMORY; /* LCOV_EXCL_STOP */ @@ -535,7 +535,6 @@ int ua_user_add(ua_user_h user_handle) uam_user_info_s uam_user; UA_VALIDATE_INPUT_PARAMETER(user_handle); - UA_VALIDATE_HANDLE(user_handle, ua_users_list); retv_if(NULL == user->account, UA_ERROR_INVALID_PARAMETER); retv_if(TRUE == user->isadded, UA_ERROR_ALREADY_REGISTERED); @@ -556,6 +555,9 @@ int ua_user_add(ua_user_h user_handle) } user->isadded = true; + + ua_users_list = g_slist_append(ua_users_list, user); + FUNC_EXIT; return UA_ERROR_NONE; } @@ -564,11 +566,14 @@ int ua_user_remove(ua_user_h user_handle) { FUNC_ENTRY; int ret; + + GSList *l; + ua_dev_info_s* dev; ua_user_info_s *user = (ua_user_info_s *)user_handle; char account[UAM_USER_ACCOUNT_MAX_STRING_LEN]; UA_VALIDATE_INPUT_PARAMETER(user_handle); - UA_VALIDATE_HANDLE(user_handle, ua_users_list); + UA_IS_EXIST(_ua_get_user_from_list(user->account)); retv_if(NULL == user->account, UA_ERROR_INVALID_PARAMETER); @@ -583,8 +588,21 @@ int ua_user_remove(ua_user_h user_handle) /* LCOV_EXCL_STOP */ } + for (l = ua_devices_list; l; l = g_slist_next(l)) { + dev = (ua_dev_info_s *)l->data; + + if (dev->user == user_handle) { + /* LCOV_EXCL_START */ + UA_INFO("User found in device handle"); + dev->user = NULL; + /* LCOV_EXCL_STOP */ + } + } + user->isadded = false; + ua_users_list = g_slist_remove(ua_users_list, user); + FUNC_EXIT; return UA_ERROR_NONE; } @@ -741,7 +759,6 @@ int ua_user_set_name( UA_VALIDATE_INPUT_PARAMETER(handle); UA_VALIDATE_INPUT_PARAMETER(name); - UA_VALIDATE_HANDLE(handle, ua_users_list); retv_if(user->isadded, UA_ERROR_INVALID_PARAMETER); retv_if((strlen(name) > UAM_USER_NAME_MAX_STRING_LEN), UA_ERROR_INVALID_PARAMETER); @@ -792,11 +809,8 @@ int ua_user_destroy(ua_user_h user_handle) { FUNC_ENTRY; ua_user_info_s *user = (ua_user_info_s *)user_handle; - ua_dev_info_s* dev; - GSList *l; UA_VALIDATE_INPUT_PARAMETER(user_handle); - UA_VALIDATE_HANDLE(user_handle, ua_users_list); retv_if(FALSE == user->create_by_app, UA_ERROR_INVALID_PARAMETER); @@ -808,18 +822,6 @@ int ua_user_destroy(ua_user_h user_handle) /* LCOV_EXCL_STOP */ } - for (l = ua_devices_list; l; l = g_slist_next(l)) { - dev = (ua_dev_info_s *)l->data; - - if (dev->user == user_handle) { - /* LCOV_EXCL_START */ - UA_INFO("User found in device handle"); - dev->user = NULL; - /* LCOV_EXCL_STOP */ - } - } - - ua_users_list = g_slist_remove(ua_users_list, user); _ua_free_ua_user_info_t(user); FUNC_EXIT; @@ -945,6 +947,7 @@ int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle) /* LCOV_EXCL_STOP */ } else { user = (ua_user_info_s *)user_handle; + UA_IS_EXIST(_ua_get_user_from_list(user->account)); } memset(&uam_device, 0, sizeof(uam_device_info_s)); @@ -1046,6 +1049,11 @@ int ua_user_foreach_added_devices( return ret; } + if (ua_devices_user_list) { + g_slist_free_full(ua_devices_user_list, _ua_free_ua_device_info_t); + ua_devices_user_list = NULL; + } + for (i = 0; i < devices_list->len; i++) { /* LCOV_EXCL_START */ ptr = g_ptr_array_index(devices_list, i); @@ -1097,7 +1105,7 @@ int ua_user_foreach_added_devices( device_info->last_presence_timestamp = ptr->last_seen; device_info->discriminant = ptr->discriminant; device_info->user = (ua_user_h)user; - ua_devices_db_list = g_slist_append(ua_devices_db_list, device_info); + ua_devices_user_list = g_slist_append(ua_devices_user_list, device_info); } else { UA_ERR("OPERATION_FAILED(0x%08x)", UA_ERROR_OPERATION_FAILED); @@ -1107,7 +1115,7 @@ int ua_user_foreach_added_devices( /* LCOV_EXCL_STOP */ } - for (l = ua_devices_db_list; l; l = g_slist_next(l)) { + for (l = ua_devices_user_list; l; l = g_slist_next(l)) { /* LCOV_EXCL_START */ ua_dev_info_s *u = l->data; @@ -1120,9 +1128,6 @@ int ua_user_foreach_added_devices( } done: - g_slist_free_full(ua_devices_db_list, _ua_free_ua_device_info_t); - ua_devices_db_list = NULL; - g_ptr_array_foreach(devices_list, (GFunc)g_free, NULL); g_ptr_array_free(devices_list, TRUE); |