diff options
author | Lokesh <l.kasana@samsung.com> | 2019-07-16 09:13:31 +0530 |
---|---|---|
committer | saerome.kim <saerome.kim@samsung.com> | 2019-07-23 15:13:59 +0900 |
commit | d3ed9fa37de5fd29a6dac435ac3c7ff71e98167e (patch) | |
tree | 838e047a6fbf7b2656cf3402d6c1dcf23f57aba6 | |
parent | dff7e0ebaa0c80e49221a42685b831d9538dca0c (diff) | |
download | user-awareness-d3ed9fa37de5fd29a6dac435ac3c7ff71e98167e.tar.gz user-awareness-d3ed9fa37de5fd29a6dac435ac3c7ff71e98167e.tar.bz2 user-awareness-d3ed9fa37de5fd29a6dac435ac3c7ff71e98167e.zip |
Added APIs for support of service_handle
Change-Id: I3fbeffcc24244484d45408a52227a4f10cbe545f
Signed-off-by: Lokesh <l.kasana@samsung.com>
-rw-r--r-- | include/user-awareness-private.h | 62 | ||||
-rw-r--r-- | include/user-awareness.h | 3 | ||||
-rw-r--r-- | src/user-awareness-event-handler.c | 37 | ||||
-rw-r--r-- | src/user-awareness-service.c | 229 | ||||
-rw-r--r-- | src/user-awareness-users.c | 5 |
5 files changed, 310 insertions, 26 deletions
diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index 5546637..824e32e 100644 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -469,6 +469,54 @@ int _ua_user_add_info_to_list_from_uapi_data(uam_user_info_s *uam_info); int _ua_remove_user_info_from_list(char *account); /** + * @brief Adds a service info to the list. + * @since_tizen 5.5 + * + * @param[in] ua_info Service info. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory + * + * @exception + * @pre + * @post + */ +int _ua_service_add_info_to_list(ua_service_info_s* ua_info); + +/** + * @brief Adds a service info of initial type as uam_service_info_s to the list. + * @since_tizen 5.5 + * + * @param[in] uam_info Service info. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory + * + * @exception + * @pre + * @post + */ +int _ua_service_add_info_to_list_from_uam_data(uam_service_info_s *uam_info); + +/** + * @brief Removes a service info from the list. + * @since_tizen 5.5 + * + * @param[in] uam_info Service info. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_NO_DATA No data + * + * @exception + * @pre + * @post + */ +int _ua_service_remove_info_from_list(uam_service_info_s *uam_info); + +/** * @brief Adds a device info. to DB in ua-manager. * @since_tizen 5.5 * @@ -553,6 +601,20 @@ int _ua_foreach_registered_services(ua_service_added_service_cb foreach_cb, void *user_data); /** + * @brief Gets default service data. + * @since_tizen 5.5 + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory + * + * @exception + * @pre + * @post + */ +int _ua_intr_get_default_service(void); + +/** * @brief Callback to get the user handle added to the service. * @since_tizen 5.5 * diff --git a/include/user-awareness.h b/include/user-awareness.h index 2a809ec..158fa9c 100644 --- a/include/user-awareness.h +++ b/include/user-awareness.h @@ -1501,7 +1501,7 @@ int ua_service_remove( * @brief Gets default service handle. * @since_tizen 5.5 * - * @remarks The @a service_handle should NOT be released. + * @remarks The @a service_handle should not be released. * * @param[out] service_handle The service handle * @@ -1516,7 +1516,6 @@ int ua_service_remove( * * @see ua_service_get_name() * @see ua_service_set_name() - * @see ua_service_destroy() */ int ua_service_get_default_service( ua_service_h * service_handle); diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c index 9b0304a..c690e2b 100644 --- a/src/user-awareness-event-handler.c +++ b/src/user-awareness-event-handler.c @@ -154,7 +154,30 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, void *u _ua_handle_device_removed(event_param->result, dev_info); break; } + case UAM_EVENT_SERVICE_REGISTERED: { + uam_service_info_s *event_data = NULL; + event_data = event_param->data; + ret_if(NULL == event_data); + + if (_ua_service_add_info_to_list_from_uam_data(event_data) != UA_ERROR_NONE) + UA_ERR("Fail to add service"); + else + UA_INFO("Service Added"); + break; + } + case UAM_EVENT_SERVICE_UNREGISTERED: { + uam_service_info_s *event_data = NULL; + + event_data = event_param->data; + ret_if(NULL == event_data); + + if (_ua_service_remove_info_from_list(event_data) != UA_ERROR_NONE) + UA_ERR("Fail to remove service"); + else + UA_INFO("Removed service"); + break; + } case UAM_EVENT_DEVICE_FOUND: { uam_device_info_s *dev_info = NULL; @@ -187,10 +210,8 @@ static bool __foreach_intr_registered_service_info( retv_if(NULL == handle, false); service_info = (ua_service_info_s*)handle; -//TODO: why not directly append? -#if 0 + ret = _ua_service_add_info_to_list(service_info); -#endif if (ret != UA_ERROR_NONE) return false; @@ -238,7 +259,6 @@ int ua_initialize(void) /* LCOV_EXCL_STOP */ } - ret = _ua_intr_foreach_registered_users(__foreach_intr_registered_user_info, NULL); if (UA_ERROR_NONE != ret) { /* LCOV_EXCL_START */ @@ -248,6 +268,15 @@ int ua_initialize(void) /* LCOV_EXCL_STOP */ } + ret = _ua_intr_get_default_service(); + if (UA_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ + UA_ERR("Failed with error: %s(0x%X)", + _ua_get_error_string(ret), ret); + return ret; + /* LCOV_EXCL_STOP */ + } + ret = _ua_intr_get_default_user(); if (UA_ERROR_NONE != ret) { /* LCOV_EXCL_START */ diff --git a/src/user-awareness-service.c b/src/user-awareness-service.c index b0d660f..f632e2c 100644 --- a/src/user-awareness-service.c +++ b/src/user-awareness-service.c @@ -25,6 +25,37 @@ GSList *ua_services_list; +static ua_mac_type_e __to_ua_mac_type(uam_tech_type_e tech_type) +{ + switch (tech_type) { + case UAM_TECH_TYPE_BT: + return UA_MAC_TYPE_BT; + case UAM_TECH_TYPE_BLE: + return UA_MAC_TYPE_BLE; + case UAM_TECH_TYPE_WIFI: + return UA_MAC_TYPE_WIFI; + case UAM_TECH_TYPE_P2P: + return UA_MAC_TYPE_P2P; + default: + return UA_MAC_TYPE_INVALID; + } +} + +void _ua_free_ua_service_info_s(ua_service_info_s *service_info) +{ + FUNC_ENTRY; + + ret_if(NULL == service_info); + + if (service_info->name) + g_free(service_info->name); + + g_free(service_info); + service_info = NULL; + + FUNC_EXIT; +} + static ua_service_info_s* __ua_get_service_from_list(const char *service_name) { GSList *l; @@ -42,21 +73,105 @@ static ua_service_info_s* __ua_get_service_from_list(const char *service_name) return NULL; } -void _ua_free_ua_service_info_s(ua_service_info_s *service_info) +int _ua_service_add_info_to_list(ua_service_info_s* ua_info) { FUNC_ENTRY; + ua_service_info_s* service_info; + UA_VALIDATE_INPUT_PARAMETER(ua_info); - ret_if(NULL == service_info); + if (NULL != __ua_get_service_from_list(ua_info->name)) + return UA_ERROR_ALREADY_DONE; // LCOV_EXCL_LINE - if (service_info->name) - g_free(service_info->name); + service_info = g_malloc0(sizeof(ua_service_info_s)); - g_free(service_info); - service_info = NULL; + if (!service_info) { + /* LCOV_EXCL_START */ + UA_ERR("g_malloc0 failed"); + return UA_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ + } + + service_info->name = g_strdup(ua_info->name); + if (service_info->name == NULL) { + /* LCOV_EXCL_START */ + UA_ERR("g_malloc0 failed"); + _ua_free_ua_service_info_s(service_info); + return UA_ERROR_OUT_OF_MEMORY; + /* LCOV_EXCL_STOP */ + } + + service_info->isadded = true; + service_info->service_handle = (ua_service_h)service_info; + ua_services_list = g_slist_append(ua_services_list, service_info); FUNC_EXIT; + return UA_ERROR_NONE; } +/* LCOV_EXCL_START */ +int _ua_service_add_info_to_list_from_uam_data(uam_service_info_s *uam_info) +{ + FUNC_ENTRY; + ua_service_info_s* service_info; + UA_VALIDATE_INPUT_PARAMETER(uam_info); + + if (NULL != __ua_get_service_from_list(uam_info->name)) + return UA_ERROR_ALREADY_DONE; + + service_info = g_malloc0(sizeof(ua_service_info_s)); + if (!service_info) { + UA_ERR("g_malloc0 failed"); + return UA_ERROR_OUT_OF_MEMORY; + } + + service_info->name = g_strdup(uam_info->name); + if (service_info->name == NULL) { + UA_ERR("g_malloc0 failed"); + _ua_free_ua_service_info_s(service_info); + return UA_ERROR_OUT_OF_MEMORY; + } + + service_info->isadded = true; + service_info->service_handle = (ua_service_h)service_info; + ua_services_list = g_slist_append(ua_services_list, service_info); + + FUNC_EXIT; + return UA_ERROR_NONE; +} +/* LCOV_EXCL_STOP */ + +/* LCOV_EXCL_START */ +int _ua_service_remove_info_from_list(uam_service_info_s *uam_info) +{ + FUNC_ENTRY; + int ret = UA_ERROR_NO_DATA; + GSList *l; + ua_service_info_s *s; + UA_VALIDATE_INPUT_PARAMETER(uam_info); + + for (l = ua_services_list; l; l = g_slist_next(l)) { + s = (ua_service_info_s *)l->data; + + if (!g_strcmp0(uam_info->name, s->name)) { + if (s->create_by_app == false) { + UA_INFO("Service found [%s]", s->name); + + ua_services_list = g_slist_remove(ua_services_list, s); + _ua_free_ua_service_info_s(s); + break; + } else { + UA_INFO("Service created by APP"); + s->isadded = false; + } + ret = UA_ERROR_NONE; + } + } + + FUNC_EXIT; + return ret; +} +/* LCOV_EXCL_STOP */ + int ua_service_create(ua_service_h *service_handle) { FUNC_ENTRY; @@ -144,17 +259,16 @@ int ua_service_remove(ua_service_h service_handle) { FUNC_ENTRY; int ret; - + uam_service_info_s uam_service; ua_service_info_s *service = (ua_service_info_s *)service_handle; - char name[UAM_SERVICE_MAX_STRING_LEN]; UA_VALIDATE_INPUT_PARAMETER(service_handle); UA_VALIDATE_HANDLE(service_handle, ua_services_list); - retv_if(NULL == service->name, UA_ERROR_INVALID_PARAMETER); //TODO lk, return if is_added == false - g_strlcpy(name, service->name, UAM_SERVICE_MAX_STRING_LEN); + memset(&uam_service, 0, sizeof(uam_service_info_s)); + g_strlcpy(uam_service.name, service->name, UAM_SERVICE_MAX_STRING_LEN); ret = _ua_get_error_code(_uam_unregister_service(&uam_service)); if (UA_ERROR_NONE != ret) { @@ -278,7 +392,7 @@ int ua_service_add_user(ua_service_h service_handle, ua_user_h user_handle) UA_VALIDATE_INPUT_PARAMETER(user_handle); UA_VALIDATE_HANDLE(user_handle, user_list); UA_VALIDATE_HANDLE(service_handle, ua_services_list); - retv_if(user_info->is_added == FALSE, UA_ERROR_INVALID_PARAMETER); + retv_if(user_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); #if 0 //TODO lk, ideally the handle should be in the ua_services_list. @@ -349,7 +463,7 @@ int ua_service_add_device(ua_service_h service_handle, ua_device_h device_handle UA_VALIDATE_INPUT_PARAMETER(device_handle); UA_VALIDATE_HANDLE(service_handle, ua_services_list); UA_PRINT_DEVICE_HANDLE(device_handle); - retv_if(device_info->is_added == FALSE, UA_ERROR_INVALID_PARAMETER); + retv_if(device_info->isadded == FALSE, UA_ERROR_INVALID_PARAMETER); #if 0 //TODO lk, ideally the handle should be in the ua_services_list. @@ -484,9 +598,9 @@ int ua_service_foreach_added_users( user_info->isadded = true; user_info->user_handle = (ua_user_h)user_info; - user_info->ua_presence_state_e = UA_PRSENCE_STATE_INVALID; + user_info->state = UA_PRSENCE_STATE_INVALID; - if (!foreach_cb(service_info->service_handle, user_info->user_handle, user_data)) { + if (!foreach_cb(service->service_handle, user_info->user_handle, user_data)) { _ua_free_ua_user_info_t(user_info); break; } else @@ -519,6 +633,7 @@ int ua_service_foreach_added_devices( ua_service_info_s *service = (ua_service_info_s *)service_handle; GPtrArray *devices_list = NULL; uam_device_info_s *ptr; + uam_user_info_s uam_user; UA_VALIDATE_INPUT_PARAMETER(foreach_cb); UA_VALIDATE_INPUT_PARAMETER(service_handle); @@ -575,13 +690,46 @@ int ua_service_foreach_added_devices( device_info->handle = (ua_device_h)device_info; device_info->type = __to_ua_mac_type(ptr->type); device_info->os = ptr->operating_system; -// device_info->user = (ua_user_h)user; // go in device_list - if (!foreach_cb(service_info->service_handle, device_info->handle, user_data)) { + if (!device_info->user) { + ret = _ua_get_error_code(_uam_request_get_user_by_deviceid(device_info->mobile_id, &uam_user)); + if (UA_ERROR_NONE != ret) { + UA_ERR("Failed with error: %s(0x%X)", + _ua_get_error_string(ret), ret); + _ua_free_ua_device_info_t((gpointer)device_info); + goto done; + } else { + GSList *l; + ua_user_info_s *user_info; + GSList *ua_users_list = _ua_user_get_users(); + int found = 0; + + for (l = ua_users_list; l; l = g_slist_next(l)) { + user_info = (ua_user_info_s *)l->data; + + if (!g_strcmp0(uam_user.account, user_info->account)) { + UA_INFO("User found [%s]", user_info->account); + device_info->user = (ua_user_h)user_info; + found = 1; + break; + } + } + + if (!found) + UA_ERR("User not found [%s]", uam_user.account); + else + UA_ERR("User found [%s]", uam_user.account); + + } + } else + UA_INFO("user handle is already present!"); + + if (!foreach_cb(service->service_handle, device_info->handle, user_data)) { _ua_free_ua_device_info_t(device_info); break; } else _ua_free_ua_device_info_t(device_info); + } else { UA_ERR("OPERATION_FAILED(0x%08x)", UA_ERROR_OPERATION_FAILED); @@ -639,7 +787,7 @@ int _ua_foreach_registered_services( goto done; } - service_info->name = g_strdup(ptr->name); + service_info->name = g_strndup(ptr->name, UAM_SERVICE_MAX_STRING_LEN); if (service_info->name == NULL) { /* LCOV_EXCL_START */ UA_ERR("g_malloc0 failed"); @@ -675,7 +823,7 @@ done: } int _ua_intr_foreach_registered_services( - ua_service_added_service_cb foreach_cb, + _ua_intr_registered_service_cb foreach_cb, void *user_data) { int ret; @@ -685,3 +833,48 @@ int _ua_intr_foreach_registered_services( return ret; } +int _ua_intr_get_default_service(void) +{ + FUNC_ENTRY; + int ret; + uam_service_info_s uam_service; + ua_service_info_s *service = NULL; + GSList *l; + + ret = _ua_get_error_code(_uam_get_default_service(&uam_service)); + if (UA_ERROR_NONE != ret) { + /* LCOV_EXCL_START */ + UA_ERR("Failed with error: %s(0x%X)", + _ua_get_error_string(ret), ret); + /* LCOV_EXCL_STOP */ + return ret; + } + + for (l = ua_services_list; l; l = g_slist_next(l)) { + service = (ua_service_info_s *)l->data; + + if (!g_strcmp0(uam_service.name, service->name)) { + UA_INFO("Service found [%s]", service->name); + service->default_service = true; + service->isadded = true; + return UA_ERROR_NONE; + } + } + + /* LCOV_EXCL_START */ + service = g_malloc0(sizeof(ua_service_info_s)); + if (!service) { + UA_ERR("Failed to allocate memory"); + return UA_ERROR_OUT_OF_MEMORY; + } + service->name = g_strdup(uam_service.name); + service->service_handle = (ua_service_h)service; + service->default_service = true; + service->isadded = true; + + ua_services_list = g_slist_append(ua_services_list, service); + FUNC_EXIT; + /* LCOV_EXCL_STOP */ + return UA_ERROR_NONE; +} + diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c index 2636700..92748b3 100644 --- a/src/user-awareness-users.c +++ b/src/user-awareness-users.c @@ -749,7 +749,7 @@ int ua_user_set_account(ua_user_h user_handle, const char *account) UA_VALIDATE_INPUT_PARAMETER(user_handle); UA_VALIDATE_INPUT_PARAMETER(account); retv_if((strlen(account) > UAM_USER_ACCOUNT_MAX_STRING_LEN), UA_ERROR_INVALID_PARAMETER); -//TODO lk, check is_added == FALSE +//TODO lk, check is_added && validate_handle if (user->account) { /* LCOV_EXCL_START */ @@ -1564,6 +1564,7 @@ int ua_device_clone(ua_device_h *cloned, device = __ua_get_device_from_list(org_device->mobile_id, org_device->mac, org_device->type); if (device) { +//TODO lk, in this case cloned will be destroyed as per description of API, which will then delete device from list. ??? *cloned = (ua_device_h)device; return UA_ERROR_NONE; } @@ -1632,7 +1633,7 @@ int ua_device_clone(ua_device_h *cloned, } else UA_INFO("user handle is already present!"); - /* Add user to list of devices */ + /* Add device to list of devices */ *cloned = (ua_device_h)device; device->handle = (ua_device_h)device; device->create_by_app = true; |