Modify user API's 40/251940/5
authorAbhay Agarwal <ay.agarwal@samsung.com>
Tue, 19 Jan 2021 07:21:53 +0000 (12:51 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Wed, 27 Jan 2021 04:18:05 +0000 (09:48 +0530)
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>
include/user-awareness-internal.h
include/user-awareness.h
src/user-awareness-device.c
src/user-awareness-service.c
src/user-awareness-users.c
test/uat-scenarios.c
test/uat-users.c

index 4b0a16b7eae5a77daa075819f57c9d9f334c09d5..90b1b0c3e1f05ad771510fc042e99a0e6d82143b 100755 (executable)
@@ -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
@@ -85,6 +84,29 @@ int ua_user_clone(ua_user_h *cloned, ua_user_h origin) TIZEN_DEPRECATED_API;
  */
 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
@@ -168,6 +190,31 @@ int ua_user_remove_device_by_device_id(const char *device_id, ua_mac_type_e mac_
  */
 int ua_user_foreach_added(ua_registered_user_cb foreach_cb, void *user_data) TIZEN_DEPRECATED_API;
 
+/**
+ * @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
index eb1858dac221dfdd8ec2cfe7a1a95ddb9a7b91d2..8e9608963a5cbcc2c95accc4f9573aaa6c069a88 100755 (executable)
@@ -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);
index d138a6705594c2727566e8eb23eb5cd2c697ac12..e14704c0bd60a7d9964d6abeb8238ee8606fcb67 100755 (executable)
@@ -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;
index 0cd5017861fa58e913f971c9ed6f7f903e5f2436..bb7acfe61ce93d25a8399eb67f603b61f8820927 100755 (executable)
@@ -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;
+}
index 391f37936845cb865ee92e99a11422bd76b12f64..18b48e79f8cc0422f53cbd3e30bed5032033a788 100755 (executable)
@@ -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 */
index c6aa07843358e2c41922149688ec7cbfd559bdb2..ea2e48103d6e219305af2c312e0a2de239a14554 100755 (executable)
@@ -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 */
index f1b7dca5dd8132bb3becf275a87d75a865b21286..39105eb06ce56cd2e808de3d3c9c333cb717dfd3 100755 (executable)
@@ -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, },
 };