diff options
author | Abhay Agarwal <ay.agarwal@samsung.com> | 2021-01-19 12:51:53 +0530 |
---|---|---|
committer | Abhay Agarwal <ay.agarwal@samsung.com> | 2021-01-27 09:48:05 +0530 |
commit | af3931cfc2522307956e0ec18da8e2aaf4db0a4c (patch) | |
tree | fb430f6faae4cf56d31067eb6226da9870f3d170 | |
parent | 375ef8f3cc395f6f1ea070ee92fc8c01387713aa (diff) | |
download | user-awareness-af3931cfc2522307956e0ec18da8e2aaf4db0a4c.tar.gz user-awareness-af3931cfc2522307956e0ec18da8e2aaf4db0a4c.tar.bz2 user-awareness-af3931cfc2522307956e0ec18da8e2aaf4db0a4c.zip |
Modify user API's
This patch modifies user based API's (renames/ parameter modifications)
New API's to be used in place of deprecated API's
- ua_user_foreach_added() [deprecated]
=> ua_foreach_users()
- ua_user_get_default_user() [deprecated]
=> ua_get_default_user()
- ua_user_get_handle_by_account() [deprecated]
=> ua_service_get_user_by_account()
- ua_user_foreach_added_devices()
=> ua_user_foreach_devices()
- ua_user_create(ua_user_h *user_handle)
=> ua_user_create(const char* account, ua_user_h *user_handle)
Change-Id: Iffc42e23e0e86bcb82498542536482f00241bf6f
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
-rwxr-xr-x | include/user-awareness-internal.h | 51 | ||||
-rwxr-xr-x | include/user-awareness.h | 40 | ||||
-rwxr-xr-x | src/user-awareness-device.c | 5 | ||||
-rwxr-xr-x | src/user-awareness-service.c | 22 | ||||
-rwxr-xr-x | src/user-awareness-users.c | 55 | ||||
-rwxr-xr-x | test/uat-scenarios.c | 9 | ||||
-rwxr-xr-x | test/uat-users.c | 86 |
7 files changed, 194 insertions, 74 deletions
diff --git a/include/user-awareness-internal.h b/include/user-awareness-internal.h index 4b0a16b..90b1b0c 100755 --- a/include/user-awareness-internal.h +++ b/include/user-awareness-internal.h @@ -55,7 +55,7 @@ extern "C" { * @pre * @post * - * @see ua_user_foreach_added() + * @see ua_foreach_users() * @see ua_service_foreach_added_user() * @see ua_user_destroy() */ @@ -67,7 +67,6 @@ int ua_user_clone(ua_user_h *cloned, ua_user_h origin) TIZEN_DEPRECATED_API; * @brief Gets default user handle. * @since_tizen 6.5 * - *TODO lk, shall we destroy?? * @remarks The @a user_handle should be released using #ua_user_destroy(). * * @param[out] user_handle The user handle @@ -88,6 +87,29 @@ int ua_user_get_default_user(ua_user_h *user_handle) TIZEN_DEPRECATED_API; /** * @internal * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Gets default user handle. + * @since_tizen 6.5 + * + * @remarks The @a user_handle should be released using #ua_user_destroy(). + * + * @param[out] user_handle The user handle + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #UA_ERROR_OPERATION_FAILED Operation failed + * + * @exception + * @pre + * @post + * + * @see ua_user_get_account() + */ +int ua_get_default_user(ua_user_h *user_handle); + +/** + * @internal + * @ingroup CAPI_NETWORK_UA_MODULE * @brief Sets account info for device handle. * @since_tizen 6.5 * @@ -171,6 +193,31 @@ int ua_user_foreach_added(ua_registered_user_cb foreach_cb, void *user_data) TIZ /** * @internal * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Retrieves the user handle of all the registered users. + * @since_tizen 6.5 + * + * @param[in] foreach_cb Callback function to be invoked with user handle. + * @param[in] user_data The user data to be passed when callback is called. + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #UA_ERROR_OUT_OF_MEMORY Out of memory + * @retval #UA_ERROR_OPERATION_FAILED Operation failed + * + * @exception + * @pre + * @post + * + * @see ua_registered_user_cb() + */ +int ua_foreach_users( + ua_registered_user_cb foreach_cb, + void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_UA_MODULE * @brief Adds device for a specific service. * @since_tizen 6.5 * diff --git a/include/user-awareness.h b/include/user-awareness.h index eb1858d..8e96089 100755 --- a/include/user-awareness.h +++ b/include/user-awareness.h @@ -439,13 +439,13 @@ typedef bool (*ua_registered_dev_cb)( * @remarks The @a user_handle can be used only in the callback. * * @param[in] user_handle The user handle. - * @param[in] user_data User data passed in ua_user_foreach_added(). + * @param[in] user_data User data passed in ua_foreach_users(). * * @exception * @pre * @post * - * @see ua_user_foreach_added() + * @see ua_foreach_users() */ typedef bool (*ua_registered_user_cb)( ua_user_h user_handle, @@ -928,7 +928,8 @@ int ua_monitor_stop_absence_detection( * * @remarks The @a user_handle should be destroyed by using #ua_user_destroy(). * - * @param[in] user_handle The user handle + * @param[in] account Account information + * @param[out] user_handle The user handle * * @return 0 on success, otherwise a negative error value * @retval #UA_ERROR_NONE Successful @@ -941,7 +942,7 @@ int ua_monitor_stop_absence_detection( * * @see ua_user_destroy() */ -int ua_user_create( +int ua_user_create(const char *account, ua_user_h *user_handle); /** @@ -1035,8 +1036,32 @@ int ua_user_get_account(ua_user_h user_handle, char **account); * @since_tizen 6.5 * * @remarks The @a user_handle should not be released. - * @remarks The @a user_handle can be used only in the fuction. + * @remarks The @a user_handle can be used only in the function. + * + * @param[in] account The user account information + * @param[out] user_handle The user handle + * + * @return 0 on success, otherwise a negative error value + * @retval #UA_ERROR_NONE Successful + * @retval #UA_ERROR_INVALID_PARAMETER Invalid parameter * + * @exception + * @pre + * @post + * + */ +int ua_user_get_handle_by_account(const char* account, + ua_user_h *user_handle) TIZEN_DEPRECATED_API; + +/** + * @ingroup CAPI_NETWORK_UA_MODULE + * @brief Gets user handle by account. + * @since_tizen 6.5 + * + * @remarks The @a user_handle should not be released. + * @remarks The @a user_handle can be used only in the function. + * + * @param[in] service_handle The service handle * @param[in] account The user account information * @param[out] user_handle The user handle * @@ -1049,7 +1074,8 @@ int ua_user_get_account(ua_user_h user_handle, char **account); * @post * */ -int ua_user_get_handle_by_account(const char* account, ua_user_h *user_handle); +int ua_service_get_user_by_account(ua_service_h service_handle, + const char* account, ua_user_h *user_handle); /** * @ingroup CAPI_NETWORK_UA_MODULE @@ -1145,7 +1171,7 @@ int ua_user_remove_device( * * @see ua_registered_dev_cb() */ -int ua_user_foreach_added_devices( +int ua_user_foreach_devices( ua_user_h user_handle, ua_registered_dev_cb foreach_cb, void *user_data); diff --git a/src/user-awareness-device.c b/src/user-awareness-device.c index d138a67..e14704c 100755 --- a/src/user-awareness-device.c +++ b/src/user-awareness-device.c @@ -549,6 +549,9 @@ int ua_device_get_parent_service(ua_device_h handle, ua_service_h *service_handl user = device->user; } + if (!user) + return UA_ERROR_NOT_FOUND; + if (user->service_handle == NULL) { int ret = ua_service_get_default_service((ua_service_h *)service); if (ret != UA_ERROR_NONE) { @@ -1242,7 +1245,7 @@ int ua_device_foreach_added_by_user( UA_DEPRECATED_LOG(__FUNCTION__, "TODO"); - ret = ua_user_foreach_added_devices(user_handle, foreach_cb, user_data); + ret = ua_user_foreach_devices(user_handle, foreach_cb, user_data); FUNC_EXIT; return ret; diff --git a/src/user-awareness-service.c b/src/user-awareness-service.c index 0cd5017..bb7acfe 100755 --- a/src/user-awareness-service.c +++ b/src/user-awareness-service.c @@ -1033,3 +1033,25 @@ done: FUNC_EXIT; return ret; } + +int ua_service_get_user_by_account(ua_service_h service_handle, + const char* account, ua_user_h *user_handle) +{ + FUNC_ENTRY; + + UA_CHECK_INIT_STATUS(); + UA_VALIDATE_INPUT_PARAMETER(service_handle); + UA_VALIDATE_INPUT_PARAMETER(account); + UA_VALIDATE_INPUT_PARAMETER(user_handle); + + *user_handle = _ua_get_user_handle_by_account(account); + if (*user_handle == NULL) { + UA_ERR("Failed to get user_handle for given account %s)", account); + return UA_ERROR_INVALID_PARAMETER; + } + + /* TODO: verify if user is part of the service */ + + FUNC_EXIT; + return UA_ERROR_NONE; +} diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c index 391f379..18b48e7 100755 --- a/src/user-awareness-users.c +++ b/src/user-awareness-users.c @@ -440,13 +440,18 @@ done: return ret; } -int ua_user_create(ua_user_h *user_handle) +int ua_user_create(const char *account, + ua_user_h *user_handle) { FUNC_ENTRY; ua_user_info_s *user = NULL; UA_CHECK_INIT_STATUS(); 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); user = g_malloc0(sizeof(ua_user_info_s)); if (!user) { @@ -456,7 +461,7 @@ int ua_user_create(ua_user_h *user_handle) /* LCOV_EXCL_STOP */ } user->state = UA_PRSENCE_STATE_INVALID; - user->account = NULL; + user->account = g_strdup(account); /* Add user to list of users*/ *user_handle = (ua_user_h)user; @@ -592,7 +597,21 @@ int ua_user_get_default_user(ua_user_h *user_handle) FUNC_ENTRY; int ret; - UA_DEPRECATED_LOG(__FUNCTION__, ""); + UA_DEPRECATED_LOG(__FUNCTION__, "ua_get_default_user"); + + UA_CHECK_INIT_STATUS(); + UA_VALIDATE_INPUT_PARAMETER(user_handle); + + ret = _ua_intr_get_default_user(user_handle); + + FUNC_EXIT; + return ret; +} + +int ua_get_default_user(ua_user_h *user_handle) +{ + FUNC_ENTRY; + int ret; UA_CHECK_INIT_STATUS(); UA_VALIDATE_INPUT_PARAMETER(user_handle); @@ -679,10 +698,14 @@ int ua_user_set_name(ua_user_h user_handle, const char *name) return UA_ERROR_NONE; } -int ua_user_get_handle_by_account(const char* account, ua_user_h *user_handle) +int ua_user_get_handle_by_account(const char* account, + ua_user_h *user_handle) { FUNC_ENTRY; + UA_DEPRECATED_LOG(__FUNCTION__, + "ua_service_get_user_by_account"); + UA_CHECK_INIT_STATUS(); UA_VALIDATE_INPUT_PARAMETER(account); UA_VALIDATE_INPUT_PARAMETER(user_handle); @@ -728,7 +751,22 @@ int ua_user_foreach_added(ua_registered_user_cb foreach_cb, void *user_data) { FUNC_ENTRY; - UA_DEPRECATED_LOG(__FUNCTION__, "TODO"); + UA_DEPRECATED_LOG(__FUNCTION__, "ua_foreach_users"); + + UA_CHECK_INIT_STATUS(); + UA_VALIDATE_INPUT_PARAMETER(foreach_cb); + + int ret = _ua_foreach_registered_users(foreach_cb, user_data); + + FUNC_EXIT; + return ret; +} + +int ua_foreach_users( + ua_registered_user_cb foreach_cb, + void *user_data) +{ + FUNC_ENTRY; UA_CHECK_INIT_STATUS(); UA_VALIDATE_INPUT_PARAMETER(foreach_cb); @@ -873,8 +911,8 @@ int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle) return UA_ERROR_NONE; } -int ua_user_remove_device_by_device_id(const char *device_id, - ua_mac_type_e mac_type) +int ua_user_remove_device_by_device_id( + const char *device_id, ua_mac_type_e mac_type) { FUNC_ENTRY; int ret; @@ -901,7 +939,7 @@ int ua_user_remove_device_by_device_id(const char *device_id, return UA_ERROR_NONE; } -int ua_user_foreach_added_devices( +int ua_user_foreach_devices( ua_user_h user_handle, ua_registered_dev_cb foreach_cb, void *user_data) @@ -920,5 +958,4 @@ int ua_user_foreach_added_devices( return ret; } - /* LCOV_EXCL_STOP */ diff --git a/test/uat-scenarios.c b/test/uat-scenarios.c index c6aa078..ea2e481 100755 --- a/test/uat-scenarios.c +++ b/test/uat-scenarios.c @@ -129,8 +129,9 @@ static int __uat_scenario_user_startup() if (ret != UA_ERROR_NONE) { ua_user_destroy(g_user_h); g_user_h = NULL; - ret = ua_user_get_handle_by_account(user_account, &g_user_h); - msg(" - ua_user_get_handle_by_account() ret: [0x%X] [%s]", + ret = ua_service_get_user_by_account(g_service_h, + user_account, &g_user_h); + msg(" - ua_service_get_user_by_account() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); } @@ -370,8 +371,8 @@ static int run_ua_scenario_foreach(MManager *mm, struct menu_data *menu) /* Get user list */ uat_clear_user_list(); - ret = ua_user_foreach_added(_foreach_registered_user_cb, NULL); - msg(" - ua_user_foreach_added() ret: [0x%X] [%s]", + ret = ua_foreach_users(_foreach_registered_user_cb, NULL); + msg(" - ua_foreach_users() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); /* Get devices list */ diff --git a/test/uat-users.c b/test/uat-users.c index f1b7dca..39105eb 100755 --- a/test/uat-users.c +++ b/test/uat-users.c @@ -61,7 +61,7 @@ static void update_user_info(void) ua_user_destroy(g_user_h); g_user_h = NULL; } - ua_user_get_default_user(&g_user_h); + ua_get_default_user(&g_user_h); } ret = ua_user_get_account(g_user_h, &account); @@ -294,7 +294,7 @@ int _uat_user_create() g_user_h = NULL; } - ret = ua_user_create(&g_user_h); + ret = ua_user_create(g_user_account_str, &g_user_h); msg(" - ua_user_create() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); @@ -326,22 +326,6 @@ static int run_ua_user_destroy(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_ua_user_set_account(MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_user_set_account"); - - check_if(NULL == g_user_h); - - ret = ua_user_set_account(g_user_h, g_user_account_str); - - msg(" - ua_user_set_account() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - static int run_ua_user_set_name(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; @@ -390,18 +374,18 @@ static int run_ua_user_remove(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_ua_user_get_default_user(MManager *mm, struct menu_data *menu) +static int run_ua_get_default_user(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; - msg("ua_user_get_default_user"); + msg("ua_get_default_user"); if (g_user_h) { ua_user_destroy(g_user_h); g_user_h = NULL; } - ret = ua_user_get_default_user(&g_user_h); + ret = ua_get_default_user(&g_user_h); if (UA_ERROR_NONE == ret) update_user_info(); @@ -411,16 +395,17 @@ static int run_ua_user_get_default_user(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static int run_ua_user_get_by_account(MManager *mm, struct menu_data *menu) +static int run_ua_service_get_user_by_account(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; ua_user_h user_handle; - msg("ua_user_get_handle_by_account"); + msg("ua_service_get_user_by_account"); - ret = ua_user_get_handle_by_account(g_user_account_str, &user_handle); + ret = ua_service_get_user_by_account(g_service_h, + g_user_account_str, &user_handle); - msg(" - ua_user_get_handle_by_account() ret: [0x%X] [%s]", + msg(" - ua_service_get_user_by_account() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); if (UA_ERROR_NONE == ret) { @@ -436,13 +421,13 @@ static int run_ua_user_foreach( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; - msg("ua_user_foreach_added"); + msg("ua_foreach_users"); uat_clear_user_list(); - ret = ua_user_foreach_added(_foreach_registered_user_cb, NULL); + ret = ua_foreach_users(_foreach_registered_user_cb, NULL); - msg(" - ua_user_foreach_added() ret: [0x%X] [%s]", + msg(" - ua_foreach_users() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; @@ -505,30 +490,31 @@ static int run_ua_user_remove_device_by_device_id( return RET_SUCCESS; } -static int run_ua_user_foreach_added_devices(MManager *mm, struct menu_data *menu) +static int run_ua_user_foreach_devices(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; ua_user_h user_handle; - msg("ua_user_foreach_added_devices"); + msg("ua_user_foreach_devices"); - ret = ua_user_get_handle_by_account(g_user_account_str, &user_handle); + ret = ua_service_get_user_by_account(g_service_h, + g_user_account_str, &user_handle); if (UA_ERROR_NONE == ret) { msgb("User Handle [%p]", user_handle); ua_user_destroy(g_user_h); g_user_h = user_handle; update_user_info(); } else { - msg(" - ua_user_get_handle_by_account() ret: [0x%X] [%s]", + msg(" - ua_service_get_user_by_account() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); } uat_clear_device_list(); - ret = ua_user_foreach_added_devices(g_user_h, + ret = ua_user_foreach_devices(g_user_h, _user_foreach_added_device_cb, NULL); - msg(" - ua_user_foreach_added_devices() ret: [0x%X] [%s]", + msg(" - ua_user_foreach_devices() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; @@ -564,11 +550,11 @@ static int run_select_device(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } -static struct menu_data menu_ua_user_account[] = { +static struct menu_data menu_ua_user_create[] = { { "1", "account", NULL, NULL, g_user_account_str }, { "2", "run", NULL, - run_ua_user_set_account, NULL }, + run_ua_user_create, NULL }, { NULL, NULL, }, }; @@ -580,11 +566,11 @@ static struct menu_data menu_ua_user_name[] = { { NULL, NULL, }, }; -static struct menu_data menu_ua_user_get_handle_by_account[] = { +static struct menu_data menu_ua_service_get_user_by_account[] = { { "1", "account", NULL, NULL, g_user_account_str}, { "2", "run", NULL, - run_ua_user_get_by_account, NULL }, + run_ua_service_get_user_by_account, NULL }, { NULL, NULL, }, }; @@ -607,29 +593,27 @@ static struct menu_data menu_ua_rm_dev_by_device_id[] = { struct menu_data menu_ua_user_added_devlist[] = { { "1", "Device list", NULL, - run_ua_user_foreach_added_devices, g_selected_device_idx}, + run_ua_user_foreach_devices, g_selected_device_idx}, { "2", "Apply", NULL, run_select_device, NULL }, { NULL, NULL, }, }; struct menu_data menu_ua_users[] = { { "1", "ua_user_create", - NULL, run_ua_user_create, NULL }, + menu_ua_user_create, NULL, NULL }, { "2", "ua_user_destroy", NULL, run_ua_user_destroy, NULL }, - { "3", "ua_user_set_account", - menu_ua_user_account, NULL, g_user_account_str }, - { "4", "ua_user_set_name", + { "3", "ua_user_set_name", menu_ua_user_name, NULL, g_user_name_str }, - { "5", "ua_user_add", + { "4", "ua_user_add", NULL, run_ua_user_add, NULL }, - { "6", "ua_user_remove", + { "5", "ua_user_remove", NULL, run_ua_user_remove, NULL}, - { "8", "ua_user_get_default_user", - NULL, run_ua_user_get_default_user, NULL }, - { "9", "ua_user_get_handle_by_account", - menu_ua_user_get_handle_by_account, NULL, NULL }, - { "10", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_added" ANSI_COLOR_NORMAL, + { "6", "ua_get_default_user", + NULL, run_ua_get_default_user, NULL }, + { "7", "ua_service_get_user_by_account", + menu_ua_service_get_user_by_account, NULL, NULL }, + { "8", ANSI_COLOR_LIGHTMAGENTA "ua_foreach_users" ANSI_COLOR_NORMAL, menu_sel_added_user, NULL, NULL }, { "11", ANSI_COLOR_LIGHTGREEN "ua_user_add_device" ANSI_COLOR_NORMAL, NULL, run_ua_user_add_device, NULL }, @@ -637,7 +621,7 @@ struct menu_data menu_ua_users[] = { NULL, run_ua_user_remove_device, NULL }, { "13", "ua_user_remove_device_by_device_id", menu_ua_rm_dev_by_device_id, NULL, NULL }, - { "14", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_added_devices" ANSI_COLOR_NORMAL, + { "14", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_devices" ANSI_COLOR_NORMAL, menu_ua_user_added_devlist, NULL, NULL }, { NULL, NULL, }, }; |