Modify device API's 07/252007/4
authorAbhay Agarwal <ay.agarwal@samsung.com>
Thu, 21 Jan 2021 10:17:45 +0000 (15:47 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Wed, 27 Jan 2021 04:33:37 +0000 (10:03 +0530)
This patch modifies device based API's (renames/parameter modifications)

Deprecated API's
- ua_device_clone
- ua_device_set_mac_type
- ua_device_set_mac_address
- ua_device_set_device_id
- ua_device_get_parent_service
- ua_device_get_parent_user

New API's to be used in place of deprecated API's
- ua_device_foreach_added()
=> ua_foreach_devices()
- ua_device_create(ua_device_h * device_handle)
=> ua_device_create(ua_mac_type_e mac_type, const char* mac_address,
const char *device_id, ua_device_h *device_handle)

Change-Id: I1270d118fdd393e638e30e3f0ae5b4dcadc3e7c8
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
include/user-awareness.h
src/user-awareness-device.c
src/user-awareness-event-handler.c
src/user-awareness-users.c
test/uat-devices.c
test/uat-scenarios.c

index d11c18fa3178d0cb77ffd9615011368b231b962a..5bc3987f6ed54a1b815db9808e244fd1985d304d 100755 (executable)
@@ -424,7 +424,7 @@ typedef void (*ua_absence_detected_cb)(
  * @pre
  * @post
  *
- * @see ua_device_foreach_added()
+ * @see ua_foreach_devices()
  */
 typedef bool (*ua_registered_dev_cb)(
                ua_device_h device_handle,
@@ -1579,6 +1579,10 @@ int ua_service_foreach_users(
  *
  * @remarks The @a device_handle should be destroyed by using #ua_user_destroy().
  *
+ * @param[in] mac_type The MAC address type of the device
+ * @param[in] mac_address The device's MAC address.
+ * @param[in] device_id The device ID.
+ *
  * @param[out] device_handle The device handle
  *
  * @return 0 on success, otherwise a negative error value
@@ -1592,8 +1596,10 @@ int ua_service_foreach_users(
  *
  * @see ua_device_destroy()
  */
-int ua_device_create(
-               ua_device_h * device_handle);
+int ua_device_create(ua_mac_type_e mac_type,
+                       const char* mac_address,
+                       const char *device_id,
+                       ua_device_h *device_handle);
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -1620,7 +1626,7 @@ int ua_device_create(
  */
 int ua_device_clone(
                ua_device_h *cloned,
-               ua_device_h origin);
+               ua_device_h origin) TIZEN_DEPRECATED_API;
 
 
 /**
@@ -1645,46 +1651,6 @@ int ua_device_clone(
 int ua_device_destroy(
                ua_device_h device_handle);
 
-/**
- * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets parent user handle from device.
- * @since_tizen 6.5
- *
- * @param[in] device_handle The device handle
- * @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_device_get_parent_user(
-               ua_device_h device_handle,
-               ua_user_h *user_handle);
-
-/**
- * @ingroup CAPI_NETWORK_UA_MODULE
- * @brief Gets parent service handle from device.
- * @since_tizen 6.5
- *
- * @param[in] device_handle The device handle
- * @param[out] service_handle The service 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_device_get_parent_service(
-               ua_device_h device_handle,
-               ua_service_h *service_handle);
-
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
  * @brief Sets a device type info for a device.
@@ -1705,7 +1671,7 @@ int ua_device_get_parent_service(
  */
 int ua_device_set_mac_type(
                ua_device_h device_handle,
-               ua_mac_type_e mac_type);
+               ua_mac_type_e mac_type) TIZEN_DEPRECATED_API;
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -1793,7 +1759,7 @@ int ua_device_get_os_info(
  */
 int ua_device_set_mac_address(
                ua_device_h device_handle,
-               const char *mac_address);
+               const char *mac_address) TIZEN_DEPRECATED_API;
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -1839,7 +1805,7 @@ int ua_device_get_mac_address(
  */
 int ua_device_set_device_id(
                ua_device_h device_handle,
-               const char *device_id);
+               const char *device_id) TIZEN_DEPRECATED_API;
 
 /**
  * @ingroup CAPI_NETWORK_UA_MODULE
@@ -2085,7 +2051,7 @@ int ua_device_get_by_device_id(
  *
  * @see ua_registered_dev_cb()
  */
-int ua_device_foreach_added(
+int ua_foreach_devices(
                ua_registered_dev_cb foreach_cb,
                void *user_data);
 
index e14704c0bd60a7d9964d6abeb8238ee8606fcb67..ec8b53f9e13e4fcad62411628360fc54ecabc43e 100755 (executable)
@@ -435,13 +435,23 @@ done:
        return ret;
 }
 
-int ua_device_create(ua_device_h *device_handle)
+int ua_device_create(ua_mac_type_e mac_type,
+                       const char *mac_address,
+                       const char *device_id,
+                       ua_device_h *device_handle)
 {
        FUNC_ENTRY;
        ua_dev_info_s *device = NULL;
 
        UA_CHECK_INIT_STATUS();
        UA_VALIDATE_INPUT_PARAMETER(device_handle);
+       UA_VALIDATE_INPUT_PARAMETER(mac_address);
+       UA_VALIDATE_INPUT_PARAMETER(device_id);
+
+       retv_if(UA_MAC_TYPE_NONE >= mac_type, UA_ERROR_INVALID_PARAMETER);
+       retv_if(UA_MAC_TYPE_INVALID <= mac_type, UA_ERROR_INVALID_PARAMETER);
+       retv_if((strlen(mac_address) != (UA_MAC_ADDRESS_STRING_LEN -1)),
+                                               UA_ERROR_INVALID_PARAMETER);
 
        device = g_malloc0(sizeof(ua_dev_info_s));
        if (!device) {
@@ -452,17 +462,17 @@ int ua_device_create(ua_device_h *device_handle)
        }
 
        device->user = NULL;
-       device->mac = NULL;
        device->bssid = NULL;
        device->ipv4 = NULL;
        device->ipv6 = NULL;
-       device->device_id = NULL;
-       device->type = 0;
+       device->type = mac_type;
+       device->device_id = g_strdup(device_id);
        device->pairing_required = FALSE;
        device->state = UA_PRSENCE_STATE_INVALID;
        device->os = UA_OS_TYPE_NOT_DEFINE;
        device->isadded = false;
        device->discriminant = true;
+       device->mac = g_strdup(mac_address);
 
        /* Add device to list of devices */
        *device_handle = (ua_device_h)device;
@@ -499,75 +509,6 @@ int ua_device_destroy(ua_device_h device_handle)
        return UA_ERROR_NONE;
 }
 
-int ua_device_get_parent_user(ua_device_h handle, ua_user_h *user_handle)
-{
-       FUNC_ENTRY;
-
-       UA_CHECK_INIT_STATUS();
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-
-       UA_VALIDATE_INPUT_PARAMETER(user_handle);
-       UA_PRINT_DEVICE_HANDLE(handle);
-
-       if (device->user == NULL) {
-               int ret = _ua_intr_get_default_user(user_handle);
-               if (ret != UA_ERROR_NONE) {
-                       UA_ERR("Failed to get default user with error");
-                       return ret;
-               }
-       } else {
-               *user_handle = device->user;
-       }
-
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
-int ua_device_get_parent_service(ua_device_h handle, ua_service_h *service_handle)
-{
-       FUNC_ENTRY;
-
-       UA_CHECK_INIT_STATUS();
-       UA_VALIDATE_INPUT_PARAMETER(handle);
-
-       ua_dev_info_s *device = (ua_dev_info_s *)handle;
-       ua_user_info_s *user = NULL;
-       ua_service_info_s *service = NULL;
-
-       UA_VALIDATE_INPUT_PARAMETER(service_handle);
-       UA_PRINT_DEVICE_HANDLE(handle);
-
-       if (device->user == NULL) {
-               int ret = _ua_intr_get_default_user((ua_user_h *)user);
-               if (ret != UA_ERROR_NONE) {
-                       UA_ERR("Failed to get default user with error");
-                       return ret;
-               }
-       } else {
-               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) {
-                       UA_ERR("Failed to get default service with error");
-                       return ret;
-               }
-       } else {
-               service = user->service_handle;
-       }
-
-       *service_handle = service;
-
-       FUNC_EXIT;
-       return UA_ERROR_NONE;
-}
-
 int ua_device_set_mac_type(ua_device_h handle, ua_mac_type_e mac_type)
 {
        FUNC_ENTRY;
@@ -613,6 +554,7 @@ int ua_device_set_mac_address(
        int ret;
        gboolean status = false;
 
+       UA_DEPRECATED_LOG(__FUNCTION__, "ua_device_create");
        UA_CHECK_INIT_STATUS();
        UA_VALIDATE_INPUT_PARAMETER(handle);
 
@@ -680,6 +622,7 @@ int ua_device_set_device_id(
        int ret;
        gboolean status = false;
 
+       UA_DEPRECATED_LOG(__FUNCTION__, "ua_device_create");
        UA_CHECK_INIT_STATUS();
        UA_VALIDATE_INPUT_PARAMETER(handle);
        UA_VALIDATE_INPUT_PARAMETER(device_id);
@@ -1097,6 +1040,7 @@ int ua_device_clone(ua_device_h *cloned,
        ua_dev_info_s *device;
        uam_user_info_s uam_user;
 
+       UA_DEPRECATED_LOG(__FUNCTION__, "");
        UA_CHECK_INIT_STATUS();
 
        /* LCOV_EXCL_START */
@@ -1171,7 +1115,7 @@ int ua_device_clone(ua_device_h *cloned,
        return UA_ERROR_NONE;
 }
 
-int ua_device_foreach_added(
+int ua_foreach_devices(
                ua_registered_dev_cb foreach_cb,
                void *user_data)
 {
@@ -1243,7 +1187,8 @@ int ua_device_foreach_added_by_user(
        FUNC_ENTRY;
        int ret;
 
-       UA_DEPRECATED_LOG(__FUNCTION__, "TODO");
+       UA_DEPRECATED_LOG(__FUNCTION__, "ua_user_foreach_devices");
+       UA_CHECK_INIT_STATUS();
 
        ret = ua_user_foreach_devices(user_handle, foreach_cb, user_data);
 
index ccfac01f837c4fbe53cee6511e9a15a3226befee..c5d9d4787bc26758c15567a5177febc4c812bbbc 100755 (executable)
@@ -334,7 +334,7 @@ int ua_initialize(void)
                /* LCOV_EXCL_STOP */
        }
 
-       ret = ua_device_foreach_added(__foreach_added_device_cb, NULL);
+       ret = ua_foreach_devices(__foreach_added_device_cb, NULL);
        if (UA_ERROR_NONE != ret) {
                /* LCOV_EXCL_START */
                UA_ERR("Failed with error: %s(0x%X)",
index 18b48e79f8cc0422f53cbd3e30bed5032033a788..e909642951cde6b1ff811070ab9f61879e8fefaf 100755 (executable)
@@ -957,5 +957,4 @@ int ua_user_foreach_devices(
        FUNC_EXIT;
        return ret;
 }
-
 /* LCOV_EXCL_STOP */
index e1c39abc6ff008c21d760e6a50621afacdc058f6..784f3323ab58442dd738f515f1cd35c7b7508fa1 100755 (executable)
@@ -198,6 +198,7 @@ static int run_ua_device_create(
        MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
+       uat_mac_type_e mac_type = UAT_MAC_TYPE_MAX;
 
        msg("ua_device_create");
 
@@ -206,7 +207,14 @@ static int run_ua_device_create(
                g_device_h = NULL;
        }
 
-       ret = ua_device_create(&g_device_h);
+       if (strlen(g_device_type)) {
+               mac_type = (unsigned char)strtol(g_device_type, NULL, 10);
+               snprintf(g_device_type_str, MENU_DATA_SIZE, "%s",
+                       uat_get_str_from_uat_mac_type(mac_type));
+       }
+
+       ret = ua_device_create(uat_convert_idx_to_device_type(mac_type),
+                               g_mac_addr_str, g_device_id_str, &g_device_h);
 
        msg(" - ua_device_create() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
@@ -232,28 +240,6 @@ static int run_ua_device_destroy(
        return RET_SUCCESS;
 }
 
-static int run_ua_device_set_mac_type(
-               MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-       uat_mac_type_e mac_type = UAT_MAC_TYPE_MAX;
-
-       msg("ua_device_set_mac_type");
-
-       if (strlen(g_device_type)) {
-               mac_type = (unsigned char)strtol(g_device_type, NULL, 10);
-               snprintf(g_device_type_str, MENU_DATA_SIZE, "%s",
-                       uat_get_str_from_uat_mac_type(mac_type));
-       }
-
-       ret = ua_device_set_mac_type(g_device_h, uat_convert_idx_to_device_type(mac_type));
-
-       msg(" - ua_device_set_mac_type() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
 static int run_ua_device_set_os_info(
        MManager *mm, struct menu_data *menu)
 {
@@ -283,36 +269,6 @@ static int run_ua_device_set_os_info(
        return RET_SUCCESS;
 }
 
-static int run_ua_device_set_mobile_id(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-
-       msg("ua_device_set_device_id");
-
-       ret = ua_device_set_device_id(g_device_h, g_device_id_str);
-
-       msg(" - ua_device_set_device_id() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
-static int run_ua_device_set_mac_address(
-       MManager *mm, struct menu_data *menu)
-{
-       int ret = UA_ERROR_NONE;
-
-       msg("ua_device_set_mac_address");
-
-       ret = ua_device_set_mac_address(g_device_h, g_mac_addr_str);
-
-       msg(" - ua_device_set_mac_address() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       return RET_SUCCESS;
-}
-
 static int run_ua_device_get_wifi_bssid(
        MManager *mm, struct menu_data *menu)
 {
@@ -422,18 +378,18 @@ static int run_ua_device_get_by_device_id(
        return RET_SUCCESS;
 }
 
-static int run_ua_device_foreach_added(
+static int run_ua_foreach_devices(
        MManager *mm, struct menu_data *menu)
 {
        int ret = UA_ERROR_NONE;
 
-       msg("ua_device_foreach_added");
+       msg("ua_foreach_devices");
 
        uat_clear_device_list();
 
-       ret = ua_device_foreach_added(_foreach_added_device_cb, NULL);
+       ret = ua_foreach_devices(_foreach_added_device_cb, NULL);
 
-       msg(" - ua_device_foreach_added() ret: [0x%X] [%s]",
+       msg(" - ua_foreach_devices() ret: [0x%X] [%s]",
                ret, uat_get_error_str(ret));
 
        return RET_SUCCESS;
@@ -454,11 +410,15 @@ static int run_ua_device_update(
        return RET_SUCCESS;
 }
 
-static struct menu_data menu_ua_device_type[] = {
-       { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)",
+static struct menu_data menu_ua_device_create[] = {
+       { "1", "device_id",
+               NULL, NULL, g_device_id_str },
+       { "2", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)",
                NULL, NULL, g_device_type },
-       { "2", "run", NULL,
-               run_ua_device_set_mac_type, NULL },
+       { "3", "MAC",
+               NULL, NULL, g_mac_addr_str },
+       { "4", "run", NULL,
+               run_ua_device_create, NULL },
        { NULL, NULL, },
 };
 
@@ -470,22 +430,6 @@ static struct menu_data menu_ua_os_type[] = {
        { NULL, NULL, },
 };
 
-static struct menu_data menu_ua_mobile_id[] = {
-       { "1", "device_id",
-               NULL, NULL, g_device_id_str },
-       { "2", "run", NULL,
-               run_ua_device_set_mobile_id, NULL },
-       { NULL, NULL, },
-};
-
-static struct menu_data menu_ua_mac_address[] = {
-       { "1", "MAC",
-               NULL, NULL, g_mac_addr_str },
-       { "2", "run", NULL,
-               run_ua_device_set_mac_address, NULL },
-       { NULL, NULL, },
-};
-
 static struct menu_data menu_ua_ipv4_address[] = {
        { "1", "IPv4 address",
                NULL, NULL, g_ipv4_address_str },
@@ -522,31 +466,25 @@ static struct menu_data menu_ua_devlist_by_device_id[] = {
 
 struct menu_data menu_ua_devices[] = {
        { "1", "ua_device_create",
-               NULL, run_ua_device_create, NULL },
+               menu_ua_device_create, NULL, NULL},
        { "2", "ua_device_destroy",
                NULL, run_ua_device_destroy, NULL },
-       { "3", "ua_device_set_mac_type",
-               menu_ua_device_type, NULL, g_device_type_str},
-       { "4", "ua_device_set_os_info",
+       { "3", "ua_device_set_os_info",
                menu_ua_os_type, NULL, g_os_type_str },
-       { "5", "ua_device_set_device_id",
-               menu_ua_mobile_id, NULL, g_device_id_str },
-       { "6", "ua_device_set_mac_address",
-               menu_ua_mac_address, NULL, g_mac_addr_str },
-       { "7", "ua_device_set_discriminant",
+       { "4", "ua_device_set_discriminant",
                menu_ua_discrminiant, NULL, g_discriminant},
-       { "8", "ua_device_set_wifi_ipv4_address",
+       { "5", "ua_device_set_wifi_ipv4_address",
                menu_ua_ipv4_address, NULL, g_ipv4_address_str },
-       { "13", "ua_device_get_wifi_bssid",
+       { "11", "ua_device_get_wifi_bssid",
                NULL, run_ua_device_get_wifi_bssid, NULL },
-       { "14", "ua_device_get_by_mac_address",
+       { "12", "ua_device_get_by_mac_address",
                menu_ua_devlist_by_mac, NULL, NULL },
-       { "15", "ua_device_get_by_device_id",
+       { "13", "ua_device_get_by_device_id",
                menu_ua_devlist_by_device_id, NULL, NULL },
-       { "16", "ua_device_update",
+       { "14", "ua_device_update",
                NULL, run_ua_device_update, NULL },
-       { "17", "ua_device_foreach_added",
-               NULL, run_ua_device_foreach_added, NULL },
+       { "15", "ua_foreach_devices",
+               NULL, run_ua_foreach_devices, NULL },
        { NULL, NULL, },
 };
 
@@ -583,7 +521,7 @@ int uat_select_device(MManager *mm, struct menu_data *menu)
 }
 
 struct menu_data menu_sel_device[] = {
-       { "1", "Device list", NULL, run_ua_device_foreach_added, g_selected_device_idx},
+       { "1", "Device list", NULL, run_ua_foreach_devices, g_selected_device_idx},
        { "2", "Apply", NULL, uat_select_device, NULL },
        { NULL, NULL, },
 };
index c092486f62747bc4428168fdfef213bfee77a4f9..2862a3d8677f26b912218701b95a4d945a573f3c 100755 (executable)
@@ -292,26 +292,15 @@ static int __create_add_device(int device_type, int ostype,
 
        ua_device_h device_h = NULL;
 
-       ret = ua_device_create(&device_h);
+       ret = ua_device_create(device_type, mac_addr_str,
+                               device_id_str, &device_h);
        msg(" - ua_device_create() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
 
-       ret = ua_device_set_mac_type(device_h, device_type);
-       msg(" - ua_device_set_mac_type() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
        ret = ua_device_set_os_info(device_h, ostype);
        msg(" - ua_device_set_os_info() ret: [0x%X] [%s]",
                        ret, uat_get_error_str(ret));
 
-       ret = ua_device_set_device_id(device_h, device_id_str);
-       msg(" - ua_device_set_device_id() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
-       ret = ua_device_set_mac_address(device_h, mac_addr_str);
-       msg(" - ua_device_set_mac_address() ret: [0x%X] [%s]",
-                       ret, uat_get_error_str(ret));
-
        if (device_type == UA_MAC_TYPE_WIFI) {
                if (ipv4_addr_str) {
                        ret = ua_device_set_wifi_ipv4_address(device_h, ipv4_addr_str);
@@ -377,8 +366,8 @@ static int run_ua_scenario_foreach(MManager *mm, struct menu_data *menu)
 
        /* Get devices list */
        uat_clear_device_list();
-       ret = ua_device_foreach_added(_foreach_added_device_cb, NULL);
-       msg(" - ua_device_foreach_added() ret: [0x%X] [%s]",
+       ret = ua_foreach_devices(_foreach_added_device_cb, NULL);
+       msg(" - ua_foreach_devices() ret: [0x%X] [%s]",
                ret, uat_get_error_str(ret));
 
        return RET_SUCCESS;