Modify service API's 06/252006/4
authorAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 21 Jan 2021 07:59:30 +0000 (13:29 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Wed, 27 Jan 2021 04:19:11 +0000 (09:49 +0530)
This patch modifies service based API's (renames/ parameter modifications)

New API's to be used in place of deprecated API's

- ua_service_foreach_added()
=> ua_foreach_services()
- ua_service_foreach_added_users()
=> ua_service_foreach_users()
- ua_service_create(ua_service_h *service_handle)
=> ua_service_create(const char *name, ua_service_h *service_handle);

Change-Id: Ic9b5ee8b7e5b84704807fc943007831b901f1bf9
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness-internal.h
include/user-awareness.h
src/user-awareness-service.c
test/uat-scenarios.c
test/uat-service.c

index 90b1b0c3e1f05ad771510fc042e99a0e6d82143b..62b521ff33c4264d874312530cf503dd90bd5234 100755 (executable)
@@ -256,7 +256,8 @@ int ua_service_add_device(ua_service_h service_handle, ua_device_h device_handle
  *
  * @see ua_service_add_device()
  */
-int ua_service_remove_device(ua_service_h service_handle, ua_device_h device_handle) TIZEN_DEPRECATED_API;
+int ua_service_remove_device(ua_service_h service_handle,
+               ua_device_h device_handle) TIZEN_DEPRECATED_API;
 
 /**
  * @internal
@@ -300,7 +301,8 @@ int ua_service_foreach_added_devices(ua_service_h service_handle,
  * @post
  */
 
-int ua_device_set_discriminant(ua_device_h device_handle, bool discriminant) TIZEN_DEPRECATED_API;
+int ua_device_set_discriminant(ua_device_h device_handle,
+                       bool discriminant) TIZEN_DEPRECATED_API;
 
 /**
  * @internal
index 8e9608963a5cbcc2c95accc4f9573aaa6c069a88..d11c18fa3178d0cb77ffd9615011368b231b962a 100755 (executable)
@@ -460,13 +460,13 @@ typedef bool (*ua_registered_user_cb)(
  * @remarks The @a service_handle can be used only in the callback.
  *
  * @param[in] service_handle The service handle.
- * @param[in] user_data User data passed in ua_service_foreach_added().
+ * @param[in] user_data User data passed in ua_foreach_services().
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_service_foreach_added()
+ * @see ua_foreach_services()
  */
 typedef bool (*ua_service_added_cb)(
                ua_service_h service_handle,
@@ -484,13 +484,13 @@ typedef bool (*ua_service_added_cb)(
  *
  * @param[in] service_handle The service handle.
  * @param[in] user_handle The user handle.
- * @param[in] user_data User data passed in ua_service_foreach_added_users().
+ * @param[in] user_data User data passed in ua_service_foreach_users().
  *
  * @exception
  * @pre
  * @post
  *
- * @see ua_service_foreach_added_users()
+ * @see ua_service_foreach_users()
  */
 typedef bool (*ua_service_added_user_cb)(
                ua_service_h service_handle,
@@ -1183,7 +1183,8 @@ int ua_user_foreach_devices(
  *
  * @remarks The @a service_handle should be destroyed by using #ua_service_destroy().
  *
- * @param[in] service_handle The service handle
+ * @param[in] name The service name information
+ * @param[out] service_handle The service handle
  *
  * @return 0 on success, otherwise a negative error value
  * @retval #UA_ERROR_NONE Successful
@@ -1197,7 +1198,8 @@ int ua_user_foreach_devices(
  * @see ua_service_destroy()
  */
 int ua_service_create(
-               ua_service_h *service_handle);
+       const char *name,
+       ua_service_h *service_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -1403,7 +1405,7 @@ int ua_service_get_detection_threshold(
  */
 int ua_service_set_name(
                ua_service_h service_handle,
-               const char *name);
+               const char *name) TIZEN_DEPRECATED_API;
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -1542,7 +1544,7 @@ int ua_service_get_device_discriminant(
  *
  * @see ua_service_added_cb()
  */
-int ua_service_foreach_added(
+int ua_foreach_services(
                ua_service_added_cb foreach_cb,
                void *user_data);
 
@@ -1565,7 +1567,7 @@ int ua_service_foreach_added(
  *
  * @see ua_service_added_user_cb()
  */
-int ua_service_foreach_added_users(
+int ua_service_foreach_users(
                ua_service_h service_handle,
                ua_service_added_user_cb foreach_cb,
                void *user_data);
index bb7acfe61ce93d25a8399eb67f603b61f8820927..7a6d7e94451295ad07aa61b6cd018357f6fab872 100755 (executable)
@@ -315,13 +315,17 @@ done:
        return ret;
 }
 
-int ua_service_create(ua_service_h *service_handle)
+int ua_service_create(const char *name,
+               ua_service_h *service_handle)
 {
        FUNC_ENTRY;
        ua_service_info_s *service = NULL;
 
        UA_CHECK_INIT_STATUS();
        UA_VALIDATE_INPUT_PARAMETER(service_handle);
+       UA_VALIDATE_INPUT_PARAMETER(name);
+       retv_if((strlen(name) > UAM_SERVICE_MAX_STRING_LEN),
+                                       UA_ERROR_INVALID_PARAMETER);
 
        service = g_malloc0(sizeof(ua_service_info_s));
        if (!service) {
@@ -330,7 +334,7 @@ int ua_service_create(ua_service_h *service_handle)
                return UA_ERROR_OUT_OF_MEMORY;
                /* LCOV_EXCL_STOP */
        }
-       service->name = NULL;
+       service->name = g_strdup(name);
 
        /* Add service to list of services*/
        *service_handle = (ua_service_h)service;
@@ -469,6 +473,8 @@ int ua_service_set_name(ua_service_h service_handle, const char *name)
 {
        FUNC_ENTRY;
 
+       UA_DEPRECATED_LOG(__FUNCTION__, "ua_service_create");
+
        ua_service_info_s *service = (ua_service_info_s *)service_handle;
 
        UA_CHECK_INIT_STATUS();
@@ -686,7 +692,7 @@ int ua_service_add_device(ua_service_h service_handle, ua_device_h device_handle
        ua_service_info_s* service_info = (ua_service_info_s*)service_handle;
        ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle;
 
-       UA_DEPRECATED_LOG(__FUNCTION__, "TODO");
+       UA_DEPRECATED_LOG(__FUNCTION__, "ua_service_add_user");
 
        UA_CHECK_INIT_STATUS();
        UA_VALIDATE_INPUT_PARAMETER(service_handle);
@@ -726,7 +732,7 @@ int ua_service_remove_device(ua_service_h service_handle, ua_device_h device_han
        ua_service_info_s* service_info = (ua_service_info_s*)service_handle;
        ua_dev_info_s* dev_info = (ua_dev_info_s*)device_handle;
 
-       UA_DEPRECATED_LOG(__FUNCTION__, "TODO");
+       UA_DEPRECATED_LOG(__FUNCTION__, "ua_service_remove_user");
 
        UA_CHECK_INIT_STATUS();
        UA_VALIDATE_INPUT_PARAMETER(service_handle);
@@ -832,7 +838,7 @@ int ua_service_get_device_discriminant(ua_service_h service_handle,
        return UA_ERROR_NONE;
 }
 
-int ua_service_foreach_added(ua_service_added_cb foreach_cb,
+int ua_foreach_services(ua_service_added_cb foreach_cb,
                void *user_data)
 {
        FUNC_ENTRY;
@@ -856,7 +862,7 @@ int ua_service_foreach_added(ua_service_added_cb foreach_cb,
        return UA_ERROR_NONE;
 }
 
-int ua_service_foreach_added_users(
+int ua_service_foreach_users(
                ua_service_h service_handle,
                ua_service_added_user_cb foreach_cb,
                void *user_data)
index ea2e48103d6e219305af2c312e0a2de239a14554..c092486f62747bc4428168fdfef213bfee77a4f9 100755 (executable)
@@ -365,8 +365,8 @@ static int run_ua_scenario_foreach(MManager *mm, struct menu_data *menu)
 
        /* Get service list */
        uat_clear_service_list();
-       ret = ua_service_foreach_added(_foreach_added_service_cb, NULL);
-       msg(" - ua_service_foreach_added() ret: [0x%X] [%s]",
+       ret = ua_foreach_services(_foreach_added_service_cb, NULL);
+       msg(" - ua_foreach_services() ret: [0x%X] [%s]",
                                ret, uat_get_error_str(ret));
 
        /* Get user list */
index 0bbaec7cf5542c7d5de5b80dad2ce189c9b2fe5c..6c55458824e9de4728993c414986cd12b312c5ad 100755 (executable)
@@ -296,7 +296,7 @@ int _uat_service_create()
                g_service_h = NULL;
        }
 
-       ret = ua_service_create(&g_service_h);
+       ret = ua_service_create(g_service_str, &g_service_h);
 
        msg(" - ua_service_create() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
@@ -327,22 +327,6 @@ static int run_ua_service_destroy(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static int run_ua_service_set_name(MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-
-       msg("ua_service_set_name");
-
-       check_if(NULL == g_service_h);
-
-       ret = ua_service_set_name(g_service_h, g_service_str);
-
-       msg(" - ua_service_set_name() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
 static int run_ua_service_set_detection_threshold(MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
@@ -462,17 +446,17 @@ static int run_ua_service_get_by_name(MManager *mm, struct menu_data *menu)
        return RET_SUCCESS;
 }
 
-static int run_ua_service_foreach_added(
+static int run_ua_foreach_services(
        MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
-       msg("ua_service_foreach_added");
+       msg("ua_foreach_services");
 
        uat_clear_service_list();
 
-       ret = ua_service_foreach_added(_foreach_added_service_cb, NULL);
+       ret = ua_foreach_services(_foreach_added_service_cb, NULL);
 
-       msg(" - ua_service_foreach_added() ret: [0x%X] [%s]",
+       msg(" - ua_foreach_services() ret: [0x%X] [%s]",
                                ret, uat_get_error_str(ret));
 
        return RET_SUCCESS;
@@ -630,30 +614,30 @@ static int run_ua_service_remove_user(MManager *mm, struct menu_data *menu)
 }
 
 
-static int run_ua_service_foreach_added_users(
+static int run_ua_service_foreach_users(
        MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
-       msg("ua_service_foreach_added_users");
+       msg("ua_service_foreach_users");
 
        check_if(NULL == g_service_h);
 
        uat_clear_user_list();
 
-       ret = ua_service_foreach_added_users(g_service_h,
+       ret = ua_service_foreach_users(g_service_h,
                                _service_foreach_added_user_cb, NULL);
 
-       msg(" - ua_service_foreach_added_users() ret: [0x%X] [%s]",
+       msg(" - ua_service_foreach_users() ret: [0x%X] [%s]",
                                ret, uat_get_error_str(ret));
 
        return RET_SUCCESS;
 }
 
-static struct menu_data menu_ua_service_set_name[] = {
+static struct menu_data menu_ua_service_create[] = {
        { "1", "name", NULL,
                NULL, g_service_str },
        { "2", "run", NULL,
-               run_ua_service_set_name, NULL },
+               run_ua_service_create, NULL },
        { NULL, NULL, },
 };
 
@@ -685,7 +669,7 @@ static struct menu_data menu_ua_service_set_device_discriminant[] = {
 
 struct menu_data menu_sel_service[] = {
        { "1", "Service list", NULL,
-               run_ua_service_foreach_added, g_selected_service_id},
+               run_ua_foreach_services, g_selected_service_id},
        { "2", "Apply", NULL, uat_select_service, NULL },
        { NULL, NULL, },
 };
@@ -723,31 +707,29 @@ struct menu_data menu_sel_service_added_device[] = {
 
 struct menu_data menu_sel_service_added_user[] = {
        { "1", "User list", NULL,
-               run_ua_service_foreach_added_users, g_selected_user_idx},
+               run_ua_service_foreach_users, g_selected_user_idx},
        { "2", "Apply", NULL, uat_select_user, NULL },
        { NULL, NULL, },
 };
 
 struct menu_data menu_ua_services[] = {
        { "1", "ua_service_create",
-               NULL, run_ua_service_create, NULL },
-       { "2", "ua_service_set_name",
-               menu_ua_service_set_name, NULL, g_service_str },
-       { "3", "ua_service_set_detection_threshold",
+               menu_ua_service_create, NULL, g_service_str },
+       { "2", "ua_service_set_detection_threshold",
                menu_ua_service_set_detection_threshold, NULL, NULL },
-       { "4", "ua_service_add",
+       { "3", "ua_service_add",
                NULL, run_ua_service_add, NULL },
-       { "5", "ua_service_update",
+       { "4", "ua_service_update",
                NULL, run_ua_service_update, NULL },
-       { "6", "ua_service_remove",
+       { "5", "ua_service_remove",
                NULL, run_ua_service_remove, NULL},
-       { "7", "ua_service_destroy",
+       { "6", "ua_service_destroy",
                NULL, run_ua_service_destroy, NULL},
-       { "8", "ua_service_get_default_service",
+       { "7", "ua_service_get_default_service",
                NULL, run_ua_service_get_default_service, NULL },
-       { "9", "ua_service_get_by_name",
+       { "8", "ua_service_get_by_name",
                menu_ua_service_get_by_name, NULL, NULL },
-       { "10", ANSI_COLOR_LIGHTMAGENTA "ua_service_foreach_added" ANSI_COLOR_NORMAL,
+       { "9", ANSI_COLOR_LIGHTMAGENTA "ua_foreach_services" ANSI_COLOR_NORMAL,
                menu_sel_service, NULL, NULL },
        { "21", ANSI_COLOR_LIGHTGREEN "ua_service_add_device" ANSI_COLOR_NORMAL,
                NULL, run_ua_service_add_device, NULL },
@@ -763,7 +745,7 @@ struct menu_data menu_ua_services[] = {
                menu_ua_service_add_user, NULL, NULL },
        { "32", ANSI_COLOR_LIGHTRED "ua_service_remove_user" ANSI_COLOR_NORMAL,
                menu_ua_service_remove_user, NULL, NULL },
-       { "33", ANSI_COLOR_LIGHTMAGENTA "ua_service_foreach_added_users" ANSI_COLOR_NORMAL,
+       { "33", ANSI_COLOR_LIGHTMAGENTA "ua_service_foreach_users" ANSI_COLOR_NORMAL,
                menu_sel_service_added_user, NULL, NULL },
        { NULL, NULL, },
 };