diff options
author | saerome.kim <saerome.kim@samsung.com> | 2019-10-28 21:11:31 +0900 |
---|---|---|
committer | saerome.kim <saerome.kim@samsung.com> | 2019-10-29 09:48:49 +0900 |
commit | ad9159cf16366d7bd63b307d1dbc15a718e76ebe (patch) | |
tree | bdee4b2af598922f3c29a3c8bf69d19d44d65963 | |
parent | 403cb654158f24de61d79972a51ec139973f3f45 (diff) | |
download | user-awareness-ad9159cf16366d7bd63b307d1dbc15a718e76ebe.tar.gz user-awareness-ad9159cf16366d7bd63b307d1dbc15a718e76ebe.tar.bz2 user-awareness-ad9159cf16366d7bd63b307d1dbc15a718e76ebe.zip |
Modify the test app to support service functionalitysubmit/tizen/20191030.083316accepted/tizen/unified/20191101.042013
- Problem: Can't remove/add devices or users to a service
- Cause: The request goes to the service module includes a useless data that
the current instance does not have is ignored.
- Solution: Make userless data ignore and modified a ua-test app to explain
how to manipulate the service functionality.
Change-Id: I913a5f7f2722bc473bdd50605c79630860fc2285
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
-rw-r--r-- | packaging/capi-network-ua.spec | 2 | ||||
-rw-r--r-- | src/user-awareness-users.c | 3 | ||||
-rw-r--r-- | test/uat-common.c | 72 | ||||
-rw-r--r-- | test/uat-common.h | 15 | ||||
-rw-r--r-- | test/uat-detections.c | 2 | ||||
-rw-r--r-- | test/uat-devices.c | 696 | ||||
-rw-r--r-- | test/uat-init.c | 4 | ||||
-rw-r--r-- | test/uat-menu.c | 13 | ||||
-rw-r--r-- | test/uat-service.c | 470 | ||||
-rw-r--r-- | test/uat-users.c | 599 |
10 files changed, 1063 insertions, 813 deletions
diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec index 4a4e406..2348fa5 100644 --- a/packaging/capi-network-ua.spec +++ b/packaging/capi-network-ua.spec @@ -1,6 +1,6 @@ Name: capi-network-ua Summary: User Awareness Framework CAPI -Version: 0.12.5 +Version: 0.12.6 Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c index 3404f3b..adf1bcd 100644 --- a/src/user-awareness-users.c +++ b/src/user-awareness-users.c @@ -513,6 +513,7 @@ int ua_user_clone(ua_user_h *dst, ua_user_h src) user_dst->account = g_strdup(user_src->account); if (!user_dst->account) { /* LCOV_EXCL_START */ + g_free(user_dst->name); UA_ERR("g_malloc0 failed"); return UA_ERROR_OUT_OF_MEMORY; /* LCOV_EXCL_STOP */ @@ -944,8 +945,6 @@ int ua_user_remove_device(ua_user_h user_handle, ua_device_h device_handle) user = (ua_user_info_s *)handle; /* LCOV_EXCL_STOP */ } else { - UA_VALIDATE_HANDLE(user_handle, ua_users_list); - retv_if((device->user != user_handle), UA_ERROR_INVALID_PARAMETER); user = (ua_user_info_s *)user_handle; } diff --git a/test/uat-common.c b/test/uat-common.c index 466a757..66c5163 100644 --- a/test/uat-common.c +++ b/test/uat-common.c @@ -19,6 +19,8 @@ #include <time.h> #include <user-awareness.h> + +#include "uat-menu.h" #include "uat-common.h" #define CASE_TO_STR(x) case x: return #x; @@ -151,3 +153,73 @@ char* uat_get_time() return pbuf; } + + +void uat_print_duid(const char *duid) +{ + fprintf(stdout, ANSI_COLOR_WHITE "payload duid :" ANSI_COLOR_NORMAL); + if(!duid) + goto done; + + for (int i = 0; i < UA_BLE_PAYLOAD_DUID_LEN; i++) + fprintf(stdout, ANSI_COLOR_WHITE " %d" ANSI_COLOR_NORMAL, duid[i]); + +done: + fprintf(stdout, "\n"); + fflush(stdout); +} + +static void _free_device_handle(gpointer data) +{ + ua_device_h handle = data; + if (NULL == handle) + return; + ua_device_destroy(handle); + handle = NULL; +} + +GSList *g_device_list = NULL; /**< Device List */ +int g_device_count = 0; /**< Seletected service name */ + +void uat_clear_device_list(void) +{ + if (NULL == g_device_list) { + msgr("g_device_list is NULL"); + return; + } + g_slist_free_full(g_device_list, _free_device_handle); + g_device_list = NULL; + g_device_count = 0; +} + +ua_mac_type_e uat_convert_idx_to_device_type(int idx) +{ + switch (idx) { + case UAT_MAC_TYPE_BT: + return UA_MAC_TYPE_BT; + case UAT_MAC_TYPE_BLE: + return UA_MAC_TYPE_BLE; + case UAT_MAC_TYPE_WIFI: + return UA_MAC_TYPE_WIFI; + case UAT_MAC_TYPE_P2P: + return UA_MAC_TYPE_P2P; + default: + return UA_MAC_TYPE_INVALID; + } +} + +uat_mac_type_e uat_convert_device_type_to_idx(int mac_type) +{ + switch (mac_type) { + case UA_MAC_TYPE_BT: + return UAT_MAC_TYPE_BT; + case UA_MAC_TYPE_BLE: + return UAT_MAC_TYPE_BLE; + case UA_MAC_TYPE_WIFI: + return UAT_MAC_TYPE_WIFI; + case UA_MAC_TYPE_P2P: + return UAT_MAC_TYPE_P2P; + default: + return UAT_MAC_TYPE_MAX; + } +} diff --git a/test/uat-common.h b/test/uat-common.h index f009d54..a7f59d6 100644 --- a/test/uat-common.h +++ b/test/uat-common.h @@ -17,6 +17,10 @@ #ifndef __UAT_COMMON_H__ #define __UAT_COMMON_H__ +#include <user-awareness.h> + +#include "uat-menu.h" + #ifdef __cplusplus extern "C" { #endif @@ -50,7 +54,16 @@ const char* uat_get_mac_type_str(int sensor); const char* uat_get_str_from_uat_mac_type(int mac_type); const char* uat_get_sensor_bitmask_str(ua_sensor_e sensor); char* uat_get_time(void); -const char * __convert_device_mac_type_to_txt(ua_mac_type_e mac_type); +const char * uat_convert_device_mac_type_to_txt(ua_mac_type_e mac_type); +void uat_print_duid(const char *duid); +void uat_clear_device_list(void); +ua_mac_type_e uat_convert_idx_to_device_type(int idx); +uat_mac_type_e uat_convert_device_type_to_idx(int mac_type); +void uat_update_device_info(void); +void uat_print_duid(const char *duid); +void uat_clear_user_list(void); +int uat_select_device(MManager *mm, struct menu_data *menu); +int uat_select_user(MManager *mm, struct menu_data *menu); #ifdef __cplusplus } diff --git a/test/uat-detections.c b/test/uat-detections.c index 371e636..43f6d02 100644 --- a/test/uat-detections.c +++ b/test/uat-detections.c @@ -68,7 +68,7 @@ static void __sensor_presence_detected_device(ua_device_h device_handle) ret, uat_get_error_str(ret)); } msgb("[%s] Presence detected on [%s]", - __convert_device_mac_type_to_txt(mac_type), mac); + uat_convert_device_mac_type_to_txt(mac_type), mac); g_free(mac); } diff --git a/test/uat-devices.c b/test/uat-devices.c index 75e4087..e124d43 100644 --- a/test/uat-devices.c +++ b/test/uat-devices.c @@ -31,14 +31,14 @@ ua_device_h g_device_h = NULL; /**< Device handle */ extern ua_user_h g_user_h; /**< User handle */ extern ua_service_h g_service_h; /**< Service handle */ -static char g_device_type[MENU_DATA_SIZE + 1] = {"3"}; /**< Sensor type of the selected device */ -static char g_device_type_str[MENU_DATA_SIZE + 1] = { "WIFI" }; /**< Readable sensor type string */ +char g_device_type[MENU_DATA_SIZE + 1] = {"3"}; /**< Sensor type of the selected device */ +char g_device_type_str[MENU_DATA_SIZE + 1] = { "WIFI" }; /**< Readable sensor type string */ static char g_os_type[MENU_DATA_SIZE + 1] = {"2"}; /**< OS type of the selected device */ -static char g_os_type_str[MENU_DATA_SIZE + 1] = { "Android" }; /**< Readable OS type string */ +char g_os_type_str[MENU_DATA_SIZE + 1] = { "Android" }; /**< Readable OS type string */ -static char g_device_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< Mobile ID of the selected device */ -static char g_mac_addr_str[MENU_DATA_SIZE + 1] = {0,}; /**< MAC of the selected device */ +char g_device_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< Mobile ID of the selected device */ +char g_mac_addr_str[MENU_DATA_SIZE + 1] = {0,}; /**< MAC of the selected device */ static char g_bss_id_str[MENU_DATA_SIZE + 1] = {0,}; /**< BSSID of the selected device */ static char g_discriminant[MENU_DATA_SIZE + 1] = {"1",}; /**< Discrimniant for a device */ static char g_ipv4_address_str[MENU_DATA_SIZE + 1] = {0,}; /**< IPv4 of the selected device */ @@ -47,341 +47,119 @@ static char g_payload_service_id[MENU_DATA_SIZE + 1] = {0,}; /**< payload servic static char g_payload_device_icon[MENU_DATA_SIZE + 1] = {0,}; /**< payload device_icon for the selected device */ static char g_payload_purpose[MENU_DATA_SIZE + 1] = {0,}; /**< payload purpose for the selected device */ static char g_payload_duid_str[MENU_DATA_SIZE + 1] = {0,}; /**< payload duid for the selected device */ -static char g_service_device_discriminant[MENU_DATA_SIZE + 1] = {"1",}; /**< Discriminant for a device in a service */ -char g_selected_device_id[MENU_DATA_SIZE + 1] = {0,}; /**< Selected device id */ +char g_selected_device_idx[MENU_DATA_SIZE + 1] = {0,}; /**< Selected device id */ extern char g_service_str[MENU_DATA_SIZE + 1]; /**< Service name string */ extern char g_user_account_str[MENU_DATA_SIZE + 1]; /**< Find device by user ID */ -static GSList *g_device_list = NULL; /**< Device List */ -static int g_device_count = 0; /**< Seletected service name */ +extern GSList *g_device_list; /**< Device List */ +extern int g_device_count; /**< Seletected service name */ -static void ___free_device_handle(gpointer data) -{ - ua_device_h handle = data; - if (NULL == handle) - return; - ua_device_destroy(handle); - handle = NULL; -} - - -void ___print_duid(const char *duid) { - fprintf(stdout, ANSI_COLOR_LIGHTGREEN "payload duid :" ANSI_COLOR_NORMAL); - if(!duid) - goto done; - - for (int i = 0; i < UA_BLE_PAYLOAD_DUID_LEN; i++) - fprintf(stdout, ANSI_COLOR_LIGHTGREEN " %d" ANSI_COLOR_NORMAL, duid[i]); - -done: - fprintf(stdout, "\n"); - fflush(stdout); -} - - -static void __clear_device_list(void) +static bool __foreach_added_device_cb( + ua_device_h device_handle, void *user_data) { - if (NULL == g_device_list) - return; - - g_slist_free_full(g_device_list, ___free_device_handle); - g_device_list = NULL; - g_device_count = 0; -} + int ret, ret_temp; + ua_device_h handle = NULL; -static void __device_added_cb(int result, - ua_device_h handle, void *user_data) -{ - int ret; ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; char *device_id = NULL; char *mac = NULL; + char *wifi_bssid = NULL; char *ipv4 = NULL; + bool required = false; + unsigned long long timestamp = 0; + bool discriminant = false; + char service_id = 0; + char device_icon = 0; + char purpose = 0; + char *duid = NULL; - if (UA_ERROR_NONE != result) { - msgr("__device_added_cb() result: [0x%X] [%s]", - result, uat_get_error_str(result)); - return; + if (!device_handle) { + msgr("device_handle is NULL"); + return true; } - if (NULL == handle) { - msgr("Device handle is NULL"); - return; + ret = ua_device_clone(&handle, device_handle); + if (UA_ERROR_NONE != ret) { + msgr("ua_device_clone() result: [0x%X] [%s]", + ret, uat_get_error_str(ret)); } - msgb("__device_added_cb() result: [0x%X] [%s]", - result, uat_get_error_str(result)); + msgb("\n[%d]", ++g_device_count); - ret = ua_device_get_mac_type(handle, &mac_type); - if (UA_ERROR_NONE == ret) + ret_temp = ua_device_get_mac_type(handle, &mac_type); + if (UA_ERROR_NONE == ret_temp) msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - ret = ua_device_get_os_info(handle, &ostype); - if (UA_ERROR_NONE == ret) + ret_temp = ua_device_get_os_info(handle, &ostype); + if (UA_ERROR_NONE == ret_temp) { msgb("Device OS Type : %s", - ostype == 1 ? "Tizen" : - ostype == 2 ? "Android" : - ostype == 3 ? "iOS" : "N/A"); + ostype == 1 ? "Tizen" : + ostype == 2 ? "Android" : + ostype == 3 ? "iOS" : "N/A"); + } - ret = ua_device_get_device_id(handle, &device_id); - if (UA_ERROR_NONE == ret) { + ret_temp = ua_device_get_device_id(handle, &device_id); + if (UA_ERROR_NONE == ret_temp) { msgb("Device ID : %s", device_id); g_free(device_id); } - ret = ua_device_get_mac_address(handle, &mac); - if (UA_ERROR_NONE == ret) { + ret_temp = ua_device_get_mac_address(handle, &mac); + if (UA_ERROR_NONE == ret_temp) { msgb("Device MAC : %s", mac); g_free(mac); } - ret = ua_device_get_wifi_ipv4_address(handle, &ipv4); - if (UA_ERROR_NONE == ret) { + ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device BSSID : %s", wifi_bssid); + g_free(wifi_bssid); + } + + ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); + if (UA_ERROR_NONE == ret_temp) { msgb("Device IPv4 Addr : %s", ipv4); g_free(ipv4); } -} - -static bool __foreach_added_device_cb( - ua_device_h device_handle, void *user_data) -{ - int ret, ret_temp; + ret_temp = ua_device_get_discriminant(handle, &discriminant); + if (UA_ERROR_NONE == ret_temp) + msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; - ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; - char *device_id = NULL; - char *mac = NULL; - char *wifi_bssid = NULL; - char *ipv4 = NULL; - bool required = false; - unsigned long long timestamp = 0; - bool discriminant = false; - char service_id = 0; - char device_icon = 0; - char purpose = 0; - char *duid = NULL; + ret_temp = ua_device_get_pairing_required(handle, &required); + if (UA_ERROR_NONE == ret_temp) + msgb("Pairing Required : %s", required ? "YES" : "NO"); - if (device_handle) { - ua_device_h handle = NULL; - - ret = ua_device_clone(&handle, device_handle); - if (UA_ERROR_NONE == ret) { - - msgb("\n[%d]", ++g_device_count); - - ret_temp = ua_device_get_mac_type(handle, &mac_type); - if (UA_ERROR_NONE == ret_temp) - msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - - ret_temp = ua_device_get_os_info(handle, &ostype); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device OS Type : %s", - ostype == 1 ? "Tizen" : - ostype == 2 ? "Android" : - ostype == 3 ? "iOS" : "N/A"); - } - - ret_temp = ua_device_get_device_id(handle, &device_id); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device ID : %s", device_id); - g_free(device_id); - } - - ret_temp = ua_device_get_mac_address(handle, &mac); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device MAC : %s", mac); - g_free(mac); - } - - ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device BSSID : %s", wifi_bssid); - g_free(wifi_bssid); - } - - ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device IPv4 Addr : %s", ipv4); - g_free(ipv4); - } - - ret_temp = ua_device_get_discriminant(handle, &discriminant); - if (UA_ERROR_NONE == ret_temp) - msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - - ret_temp = ua_device_get_pairing_required(handle, &required); - if (UA_ERROR_NONE == ret_temp) - msgb("Pairing Required : %s", required ? "YES" : "NO"); - - ret_temp = ua_device_get_last_presence(handle, ×tamp); - if (UA_ERROR_NONE == ret_temp) - msgb("Last present at : %llu", timestamp); - - ret_temp = ua_device_get_payload_service_id(handle, &service_id); - if (UA_ERROR_NONE == ret_temp) - msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); - - ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); - if (UA_ERROR_NONE == ret_temp) - msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); - - ret_temp = ua_device_get_payload_purpose(handle, &purpose); - if (UA_ERROR_NONE == ret_temp) - msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); - - ret_temp = ua_device_get_payload_duid(handle, &duid); - if (UA_ERROR_NONE == ret_temp) { - ___print_duid(duid); - g_free(duid); - } - - g_device_list = g_slist_append(g_device_list, handle); - } - } + ret_temp = ua_device_get_last_presence(handle, ×tamp); + if (UA_ERROR_NONE == ret_temp) + msgb("Last present at : %llu", timestamp); - return true; -} + ret_temp = ua_device_get_payload_service_id(handle, &service_id); + if (UA_ERROR_NONE == ret_temp) + msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); -static bool __service_foreach_added_device_cb( - ua_service_h service_tmp, ua_device_h handle, void *user_data) -{ - int ret, ret_temp; + ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); + if (UA_ERROR_NONE == ret_temp) + msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); - char *service_name = NULL; - ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; - ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; - char *device_id = NULL; - char *mac = NULL; - char *wifi_bssid = NULL; - char *ipv4 = NULL; - bool required = false; - bool discriminant = false; - unsigned long long timestamp = 0; - char service_id = 0; - char device_icon = 0; - char purpose = 0; - char *duid = NULL; + ret_temp = ua_device_get_payload_purpose(handle, &purpose); + if (UA_ERROR_NONE == ret_temp) + msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); - ret = ua_service_get_name(service_tmp, &service_name); - if (UA_ERROR_NONE == ret) - msgb("CB: Service name : %s", service_name); - - g_free(service_name); - - if (handle) { - if (UA_ERROR_NONE == ret) { - - msgb("\n[%d]", ++g_device_count); - - ret_temp = ua_device_get_mac_type(handle, &mac_type); - if (UA_ERROR_NONE == ret_temp) - msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - - ret_temp = ua_device_get_os_info(handle, &ostype); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device OS Type : %s", - ostype == 1 ? "Tizen" : - ostype == 2 ? "Android" : - ostype == 3 ? "iOS" : "N/A"); - } - - ret_temp = ua_device_get_device_id(handle, &device_id); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device ID : %s", device_id); - g_free(device_id); - } - - ret_temp = ua_device_get_mac_address(handle, &mac); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device MAC : %s", mac); - g_free(mac); - } - - ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device BSSID : %s", wifi_bssid); - g_free(wifi_bssid); - } - - ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); - if (UA_ERROR_NONE == ret_temp) { - msgb("Device IPv4 Addr : %s", ipv4); - g_free(ipv4); - } - - ret_temp = ua_device_get_pairing_required(handle, &required); - if (UA_ERROR_NONE == ret_temp) - msgb("Pairing Required : %s", required ? "YES" : "NO"); - - ret_temp = ua_device_get_discriminant(handle, &discriminant); - if (UA_ERROR_NONE == ret_temp) - msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - - ret_temp = ua_device_get_last_presence(handle, ×tamp); - if (UA_ERROR_NONE == ret_temp) - msgb("Last present at : %llu", timestamp); - - ret_temp = ua_device_get_payload_service_id(handle, &service_id); - if (UA_ERROR_NONE == ret_temp) - msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); - - ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); - if (UA_ERROR_NONE == ret_temp) - msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); - - ret_temp = ua_device_get_payload_purpose(handle, &purpose); - if (UA_ERROR_NONE == ret_temp) - msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); - - ret_temp = ua_device_get_payload_duid(handle, &duid); - if (UA_ERROR_NONE == ret_temp) { - ___print_duid(duid); - g_free(duid); - } - - g_device_list = g_slist_append(g_device_list, handle); - } + ret_temp = ua_device_get_payload_duid(handle, &duid); + if (UA_ERROR_NONE == ret_temp) { + uat_print_duid(duid); + g_free(duid); } - return true; -} - -ua_mac_type_e _convert_idx_to_device_type(int idx) -{ - switch (idx) { - case UAT_MAC_TYPE_BT: - return UA_MAC_TYPE_BT; - case UAT_MAC_TYPE_BLE: - return UA_MAC_TYPE_BLE; - case UAT_MAC_TYPE_WIFI: - return UA_MAC_TYPE_WIFI; - case UAT_MAC_TYPE_P2P: - return UA_MAC_TYPE_P2P; - default: - return UA_MAC_TYPE_INVALID; - } -} + g_device_list = g_slist_append(g_device_list, handle); -uat_mac_type_e _convert_device_type_to_idx(int mac_type) -{ - switch (mac_type) { - case UA_MAC_TYPE_BT: - return UAT_MAC_TYPE_BT; - case UA_MAC_TYPE_BLE: - return UAT_MAC_TYPE_BLE; - case UA_MAC_TYPE_WIFI: - return UAT_MAC_TYPE_WIFI; - case UA_MAC_TYPE_P2P: - return UAT_MAC_TYPE_P2P; - default: - return UAT_MAC_TYPE_MAX; - } + return true; } -static void _update_device_info(void) +void uat_update_device_info(void) { int ret = UA_ERROR_NONE; ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; @@ -405,7 +183,7 @@ static void _update_device_info(void) snprintf(g_device_type_str, MENU_DATA_SIZE, "%s", uat_get_mac_type_str(mac_type)); snprintf(g_device_type, MENU_DATA_SIZE, "%d", - _convert_device_type_to_idx(mac_type)); + uat_convert_device_type_to_idx(mac_type)); } ret = ua_device_get_os_info(g_device_h, &ostype); @@ -477,6 +255,7 @@ static void _update_device_info(void) } } + #ifndef SUPPORT_STRING_DUID static int _scan_payload_duid_str( MManager *mm, struct menu_data *menu) @@ -551,7 +330,7 @@ static int run_ua_device_set_mac_type( uat_get_str_from_uat_mac_type(mac_type)); } - ret = ua_device_set_mac_type(g_device_h, _convert_idx_to_device_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)); @@ -760,7 +539,7 @@ static int run_ua_device_get_by_mac_address( ret = ua_device_get_by_mac_address(g_mac_addr_str, &_device); if (UA_ERROR_NONE == ret) { g_device_h = _device; - _update_device_info(); + uat_update_device_info(); } @@ -781,7 +560,7 @@ static int run_ua_device_get_by_device_id( if (strlen(g_device_type)) { int temp = (unsigned char)strtol(g_device_type, NULL, 10); - mac_type = _convert_idx_to_device_type(temp); + mac_type = uat_convert_idx_to_device_type(temp); snprintf(g_device_type_str, MENU_DATA_SIZE + 1, "%s", uat_get_mac_type_str(mac_type)); } @@ -790,7 +569,7 @@ static int run_ua_device_get_by_device_id( ret = ua_device_get_by_device_id(g_device_id_str, mac_type, &_device); if (UA_ERROR_NONE == ret) { g_device_h = _device; - _update_device_info(); + uat_update_device_info(); } msg(" - ua_device_get_by_device_id() ret: [0x%X] [%s]", @@ -806,7 +585,7 @@ static int run_ua_device_foreach_added( msg("ua_device_foreach_added"); - __clear_device_list(); + uat_clear_device_list(); ret = ua_device_foreach_added( __foreach_added_device_cb, NULL); @@ -817,24 +596,6 @@ static int run_ua_device_foreach_added( return RET_SUCCESS; } -static int run_ua_device_foreach_added_by_user(MManager *mm, - struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_device_foreach_added_by_user"); - - __clear_device_list(); - - ret = ua_device_foreach_added_by_user(g_user_h, - __foreach_added_device_cb, NULL); - - msg(" - ua_device_foreach_added_by_user() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - static int run_ua_device_update( MManager *mm, struct menu_data *menu) { @@ -850,185 +611,6 @@ static int run_ua_device_update( return RET_SUCCESS; } -static int run_ua_user_add_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_user_add_device"); - - check_if(NULL == g_device_h); - - ret = ua_user_add_device(g_user_h, g_device_h, __device_added_cb, NULL); - - msg(" - ua_user_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_user_remove_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_user_remove_device"); - - check_if(NULL == g_user_h); - check_if(NULL == g_device_h); - - ret = ua_user_remove_device(g_user_h, g_device_h); - - msg(" - ua_user_remove_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_user_remove_device_by_device_id( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - uat_mac_type_e idx = UAT_MAC_TYPE_MAX; - - msg("ua_user_remove_device_by_device_id"); - - if (strlen(g_device_type)) - idx = (unsigned char)strtol(g_device_type, NULL, 10); - - msgb("idx [%d] mac_type[%d]", idx, _convert_idx_to_device_type(idx)); - - ret = ua_user_remove_device_by_device_id(g_device_id_str, _convert_idx_to_device_type(idx)); - - msg(" - ua_user_remove_device_by_device_id() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_user_remove_device_by_mac_address( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - uat_mac_type_e idx = UAT_MAC_TYPE_MAX; - - msg("ua_user_remove_device_by_mac_address"); - - if (strlen(g_device_type)) - idx = (unsigned char)strtol(g_device_type, NULL, 10); - - msgb("idx [%d] mac_type[%d]", idx, _convert_idx_to_device_type(idx)); - - ret = ua_user_remove_device_by_mac_address(g_mac_addr_str); - - msg(" - ua_user_remove_device_by_mac_address() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_add_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_service_add_device"); - - check_if(NULL == g_user_h); - check_if(NULL == g_device_h); - - ret = ua_service_add_device(g_service_h, g_device_h); - - msg(" - ua_service_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_remove_device( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_service_remove_device"); - - check_if(NULL == g_user_h); - check_if(NULL == g_device_h); - - ret = ua_service_remove_device(g_service_h, g_device_h); - - msg(" - ua_service_remove_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_set_device_discriminant( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - int temp = 1; - gboolean discriminant = true; - - msg("ua_service_set_device_discriminant"); - - check_if(NULL == g_service_h); - check_if(NULL == g_device_h); - - if (strlen(g_service_device_discriminant)) - temp = (int)strtol(g_service_device_discriminant, NULL, 10); - - if (0 == temp) - discriminant = false; - ret = ua_service_set_device_discriminant(g_service_h, g_device_h, discriminant); - - msg(" - ua_service_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - -static int run_ua_service_get_device_discriminant( - MManager *mm, struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - gboolean discriminant = true; - - msg("ua_service_get_device_discriminant"); - - check_if(NULL == g_service_h); - check_if(NULL == g_device_h); - - ret = ua_service_get_device_discriminant(g_service_h, g_device_h, &discriminant); - - msg(" - ua_service_add_device() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - if (UA_ERROR_NONE == ret) - msgb("Device Discriminant %d", discriminant); - - return RET_SUCCESS; -} - -static int run_ua_service_foreach_added_devices(MManager *mm, - struct menu_data *menu) -{ - int ret = UA_ERROR_NONE; - - msg("ua_service_foreach_added_devices"); - - __clear_device_list(); - - ret = ua_service_foreach_added_devices(g_service_h, - __service_foreach_added_device_cb, NULL); - - msg(" - ua_service_foreach_added_devices() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - - return RET_SUCCESS; -} - - static struct menu_data menu_ua_device_type[] = { { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", NULL, NULL, g_device_type }, @@ -1069,61 +651,6 @@ static struct menu_data menu_ua_ipv4_address[] = { { NULL, NULL, }, }; -static struct menu_data menu_ua_rm_dev_by_device_id[] = { - { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", - NULL, NULL, g_device_type }, - { "2", "device_id", - NULL, NULL, g_device_id_str }, - { "3", "run", NULL, - run_ua_user_remove_device_by_device_id, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_rm_dev_by_addr[] = { - { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", - NULL, NULL, g_device_type }, - { "2", "MAC", - NULL, NULL, g_mac_addr_str }, - { "3", "run", NULL, - run_ua_user_remove_device_by_mac_address, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_service_set_device_discriminant[] = { - { "1", "discriminant (0:disable 1:enable)", - NULL, NULL, g_service_device_discriminant }, - { "2", "run", NULL, - run_ua_service_set_device_discriminant, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_devlist_by_mac[] = { - { "1", "MAC", - NULL, NULL, g_mac_addr_str }, - { "2", "run", NULL, - run_ua_device_get_by_mac_address, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_devlist_by_device_id[] = { - { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", - NULL, NULL, g_device_type }, - { "2", "device_id", - NULL, NULL, g_device_id_str }, - { "3", "run", NULL, - run_ua_device_get_by_device_id, NULL }, - { NULL, NULL, }, -}; - -static struct menu_data menu_ua_devlist_by_user[] = { -//TODO lk, fix here - { "1", "Account", - NULL, NULL, g_user_account_str }, - { "2", "run", NULL, - run_ua_device_foreach_added_by_user, NULL }, - { NULL, NULL, }, -}; - static struct menu_data menu_ua_discrminiant[] = { { "1", "discriminant (0: Disable 1: Enable)", NULL, NULL, g_discriminant }, @@ -1168,6 +695,24 @@ static struct menu_data menu_ua_device_set_payload_duid[] = { { NULL, NULL, }, }; +static struct menu_data menu_ua_devlist_by_mac[] = { + { "1", "MAC", + NULL, NULL, g_mac_addr_str }, + { "2", "run", NULL, + run_ua_device_get_by_mac_address, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_devlist_by_device_id[] = { + { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", + NULL, NULL, g_device_type }, + { "2", "device_id", + NULL, NULL, g_device_id_str }, + { "3", "run", NULL, + run_ua_device_get_by_device_id, NULL }, + { NULL, NULL, }, +}; + struct menu_data menu_ua_devices[] = { { "1", "ua_device_create", NULL, run_ua_device_create, NULL }, @@ -1199,49 +744,22 @@ struct menu_data menu_ua_devices[] = { menu_ua_devlist_by_mac, NULL, NULL }, { "15", "ua_device_get_by_device_id", menu_ua_devlist_by_device_id, NULL, NULL }, - { "16", "ua_device_foreach_added", - NULL, run_ua_device_foreach_added, NULL }, - { "17", "ua_device_foreach_added_by_user", - menu_ua_devlist_by_user, NULL, NULL }, - { "18", "ua_device_update", + { "16", "ua_device_update", NULL, run_ua_device_update, NULL }, - { "19", "ua_user_add_device", - NULL, run_ua_user_add_device, NULL }, - { "20", "ua_user_remove_device", - NULL, run_ua_user_remove_device, NULL }, - { "21", "ua_user_remove_device_by_device_id", - menu_ua_rm_dev_by_device_id, NULL, NULL }, - { "22", "ua_user_remove_device_by_mac_address", - menu_ua_rm_dev_by_addr, NULL, NULL }, - { "23", "ua_service_add_device", - NULL, run_ua_service_add_device, NULL }, - { "24", "ua_service_remove_device", - NULL, run_ua_service_remove_device, NULL }, - { "25", "ua_service_set_device_discriminant", - menu_ua_service_set_device_discriminant, NULL, NULL }, - { "26", "ua_service_get_device_discriminant", - NULL, run_ua_service_get_device_discriminant, NULL }, - { "27", "ua_service_foreach_added_devices", - NULL, run_ua_service_foreach_added_devices, NULL }, + { "17", "ua_device_foreach_added", + NULL, run_ua_device_foreach_added, NULL }, { NULL, NULL, }, }; -static int run_choose_device_list(MManager *mm, struct menu_data *menu) -{ - __clear_device_list(); - ua_device_foreach_added(__foreach_added_device_cb, NULL); - return RET_SUCCESS; -} - -static int run_select_device(MManager *mm, struct menu_data *menu) +int uat_select_device(MManager *mm, struct menu_data *menu) { GSList *iter = g_device_list; int id = 0; int selected_id = 0; - if (strlen(g_selected_device_id)) - selected_id = (unsigned char)strtol(g_selected_device_id, NULL, 10); + if (strlen(g_selected_device_idx)) + selected_id = (unsigned char)strtol(g_selected_device_idx, NULL, 10); if (selected_id <= 0) { msg("Please select device first"); @@ -1253,7 +771,7 @@ static int run_select_device(MManager *mm, struct menu_data *menu) ua_device_h *handle = iter->data; if (handle && ++id == selected_id) { g_device_h = handle; /* Make selected device as a current one */ - _update_device_info(); /* Update device info. */ + uat_update_device_info(); /* Update device info. */ msg("[%d] device selected", selected_id); return RET_SUCCESS; } @@ -1264,8 +782,8 @@ static int run_select_device(MManager *mm, struct menu_data *menu) } struct menu_data menu_sel_device[] = { - { "1", "Device list", NULL, run_choose_device_list, g_selected_device_id}, - { "2", "Apply", NULL, run_select_device, NULL }, + { "1", "Device list", NULL, run_ua_device_foreach_added, g_selected_device_idx}, + { "2", "Apply", NULL, uat_select_device, NULL }, { NULL, NULL, }, }; diff --git a/test/uat-init.c b/test/uat-init.c index 2e58539..2a69056 100644 --- a/test/uat-init.c +++ b/test/uat-init.c @@ -119,7 +119,7 @@ static void __user_absence_detected_cb(int result, ua_monitor_h monitor, } } -const char * __convert_device_mac_type_to_txt(ua_mac_type_e mac_type) +const char * uat_convert_device_mac_type_to_txt(ua_mac_type_e mac_type) { switch (mac_type) { case UA_MAC_TYPE_BT: @@ -155,7 +155,7 @@ static void __user_presence_detected_foreach_devices(gpointer data, ret, uat_get_error_str(ret)); } msgbr("[%s] detected on [%s][%s]", account, - __convert_device_mac_type_to_txt(mac_type), mac); + uat_convert_device_mac_type_to_txt(mac_type), mac); g_free(mac); } diff --git a/test/uat-menu.c b/test/uat-menu.c index 12d2420..ba3f08d 100644 --- a/test/uat-menu.c +++ b/test/uat-menu.c @@ -60,9 +60,13 @@ extern char g_user_account_str[MENU_DATA_SIZE + 1]; /**< Selected user account s extern char g_user_name_str[MENU_DATA_SIZE + 1]; /** Selected user name */ extern char g_sensor_list_str[MENU_DATA_SIZE + 1]; /**< Added sensor list */ -extern char g_selected_device_id[MENU_DATA_SIZE + 1]; /**< Selected device id */ extern char g_service_str[MENU_DATA_SIZE + 1]; /**< Selected servie string */ +extern char g_device_type_str[MENU_DATA_SIZE + 1]; /**< Readable sensor type string */ +extern char g_os_type_str[MENU_DATA_SIZE + 1]; /**< Readable OS type string */ +extern char g_device_id_str[MENU_DATA_SIZE + 1]; /**< Mobile ID of the selected device */ +extern char g_mac_addr_str[MENU_DATA_SIZE + 1]; /**< MAC of the selected device */ + static void _show_prompt(void) { msgn("(%5d) >> ", get_tid()); @@ -85,14 +89,15 @@ static void _show_reserved_menu(void) msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL); msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY - " ] " ANSI_COLOR_NORMAL "Service Name [" ANSI_COLOR_YELLOW "%s" ANSI_COLOR_NORMAL + " ] " ANSI_COLOR_NORMAL "Service [" ANSI_COLOR_YELLOW "%s" ANSI_COLOR_NORMAL " ] ", DEFAULT_MENU_SERVICE, g_service_str); msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL); msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY - " ] " ANSI_COLOR_NORMAL "Device ID [" ANSI_COLOR_YELLOW "%s" ANSI_COLOR_NORMAL - " ] ", DEFAULT_MENU_DEVICE, g_selected_device_id); + " ] " ANSI_COLOR_NORMAL "Device [" ANSI_COLOR_YELLOW "%s %s %s %s" ANSI_COLOR_NORMAL + " ] ", DEFAULT_MENU_DEVICE, g_device_type_str, g_os_type_str, + g_device_id_str, g_mac_addr_str); msg(ANSI_COLOR_DARKGRAY HR_SINGLE2 ANSI_COLOR_NORMAL); msg(ANSI_COLOR_DARKGRAY " [ " ANSI_COLOR_NORMAL "%s" ANSI_COLOR_DARKGRAY diff --git a/test/uat-service.c b/test/uat-service.c index fe39bed..1e80093 100644 --- a/test/uat-service.c +++ b/test/uat-service.c @@ -21,21 +21,84 @@ #include <glib.h> #include <gio/gio.h> -#include <user-awareness.h> - -#include "uat-menu.h" #include "uat-common.h" +extern ua_device_h g_device_h; /**< Device handle */ +extern ua_user_h g_user_h; /**< User handle */ ua_service_h g_service_h = NULL; /**< Service handle */ char g_service_str[MENU_DATA_SIZE + 1] = { "ua.service.default" }; /**< Seletected service name */ +extern char g_user_account_str[MENU_DATA_SIZE + 1]; /**< User account */ +extern char g_user_name_str[MENU_DATA_SIZE + 1]; /**< User name */ + static char g_presence_threshold_str[MENU_DATA_SIZE + 1] = {0,}; /**< Seletected service presence threshold */ static char g_absence_threshold_str[MENU_DATA_SIZE + 1] = {0,}; /**< Seletected service absence threshold */ static char g_selected_service_id[MENU_DATA_SIZE + 1] = {0,}; /**< Selected service id in the list */ +static char g_service_device_discriminant[MENU_DATA_SIZE + 1] = {"1",}; /**< Discriminant for a device in a service */ + +extern char g_selected_device_idx[MENU_DATA_SIZE + 1]; /**< Selected device index */ +extern GSList *g_device_list; /**< Device List */ +extern int g_device_count; /**< Seletected service name */ + +extern char g_selected_user_idx[MENU_DATA_SIZE + 1]; /**< Selected user index */ +extern GSList *user_list; /**< User List */ +extern int idx_user; /**< Found device sequence number */ static GSList *g_service_list = NULL; /**< Service List */ static int g_service_count = 0; /**< Service count */ +static bool _service_foreach_added_user_cb( + ua_service_h service_handle, ua_user_h user_handle, void *user_data) +{ + int ret = UA_ERROR_NONE; + + ua_user_h handle = NULL; + char *service_name = NULL; + char *account = NULL; + char *name = NULL; + unsigned long long timestamp = 0; + + ret = ua_service_get_name(service_handle, &service_name); + if (UA_ERROR_NONE == ret) + msgp("Cur. Service name : %s\n", service_name); + + g_free(service_name); + + if (!user_handle) { + msgr("user_handle is NULL"); + return true; + } + + ret = ua_user_clone(&handle, user_handle); + if (UA_ERROR_NONE != ret) { + msgr("ua_user_clone() result: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + + user_list = g_slist_append(user_list, handle); + idx_user++; + + ret = ua_user_get_account(handle, &account); + if (UA_ERROR_NONE == ret) { + msglr("[%d]", idx_user); + msglr("User account info %s", account); + g_free(account); + } + + ret = ua_user_get_name(handle, &name); + if (UA_ERROR_NONE == ret) { + msglr("User Name : %s", name); + g_free(name); + } + + ret = ua_user_get_last_presence(handle, ×tamp); + if (UA_ERROR_NONE == ret) + msglr("last present at %llu", timestamp); + + + return true; +} + static void __update_service_info(void) { int ret = UA_ERROR_NONE; @@ -80,7 +143,10 @@ static bool __foreach_added_service_cb( unsigned int presence_threshold = 0; unsigned int absence_threshold = 0; - check_if(NULL == service_handle); + if (NULL == service_handle) { + msgr("service_handle is NULL"); + return true; + } ret = ua_service_get_name(service_handle, &name); if (UA_ERROR_NONE != ret) { @@ -98,8 +164,8 @@ static bool __foreach_added_service_cb( return RET_SUCCESS; } - msgb("[%d] %s ", ++g_service_count, name); - msgb("presence threshold :[%d] absence threshold :[%d]", + msgr("[%d] %s ", ++g_service_count, name); + msgr("presence threshold :[%d] absence threshold :[%d]", presence_threshold, absence_threshold); g_service_list = g_slist_append(g_service_list, service_handle); @@ -109,27 +175,120 @@ static bool __foreach_added_service_cb( return true; } - -static int run_ua_service_get_default_service(MManager *mm, struct menu_data *menu) +static bool _service_foreach_added_device_cb( + ua_service_h service_handle, ua_device_h device_handle, void *user_data) { - int ret = UA_ERROR_NONE; + int ret, ret_temp; + ua_device_h handle = NULL; + char *service_name = NULL; + + ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; + ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; + char *device_id = NULL; + char *mac = NULL; + char *wifi_bssid = NULL; + char *ipv4 = NULL; + bool required = false; + bool discriminant = false; + unsigned long long timestamp = 0; + char service_id = 0; + char device_icon = 0; + char purpose = 0; + char *duid = NULL; + + if (!service_handle) { + msgr("service_handle is NULL"); + return true; + } - msg("ua_service_get_default_service"); + ret = ua_service_get_name(service_handle, &service_name); + if (UA_ERROR_NONE == ret) + msgb("Cur. Service name : %s", service_name); + g_free(service_name); - if (g_service_h) { - ua_service_destroy(g_service_h); - g_service_h = NULL; + if (!device_handle) { + msgr("device_handle is NULL"); + return true; } - ret = ua_service_get_default_service(&g_service_h); + ret = ua_device_clone(&handle, device_handle); + if (UA_ERROR_NONE != ret) { + msgr(" - ua_device_clone() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + return true; + } - if (UA_ERROR_NONE == ret) - __update_service_info(); + msgb("\n[%d]", ++g_device_count); - msg(" - ua_service_get_default_service() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + ret_temp = ua_device_get_mac_type(handle, &mac_type); + if (UA_ERROR_NONE == ret_temp) + msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - return RET_SUCCESS; + ret_temp = ua_device_get_os_info(handle, &ostype); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device OS Type : %s", + ostype == 1 ? "Tizen" : + ostype == 2 ? "Android" : + ostype == 3 ? "iOS" : "N/A"); + } + + ret_temp = ua_device_get_device_id(handle, &device_id); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device ID : %s", device_id); + g_free(device_id); + } + + ret_temp = ua_device_get_mac_address(handle, &mac); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device MAC : %s", mac); + g_free(mac); + } + + ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device BSSID : %s", wifi_bssid); + g_free(wifi_bssid); + } + + ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); + if (UA_ERROR_NONE == ret_temp) { + msgb("Device IPv4 Addr : %s", ipv4); + g_free(ipv4); + } + + ret_temp = ua_device_get_pairing_required(handle, &required); + if (UA_ERROR_NONE == ret_temp) + msgb("Pairing Required : %s", required ? "YES" : "NO"); + + ret_temp = ua_device_get_discriminant(handle, &discriminant); + if (UA_ERROR_NONE == ret_temp) + msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); + + ret_temp = ua_device_get_last_presence(handle, ×tamp); + if (UA_ERROR_NONE == ret_temp) + msgb("Last present at : %llu", timestamp); + + ret_temp = ua_device_get_payload_service_id(handle, &service_id); + if (UA_ERROR_NONE == ret_temp) + msgb("payload service_id : %d[hex: 0x%X]", service_id, service_id); + + ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); + if (UA_ERROR_NONE == ret_temp) + msgb("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); + + ret_temp = ua_device_get_payload_purpose(handle, &purpose); + if (UA_ERROR_NONE == ret_temp) + msgb("payload purpose : %d[hex: 0x%X]", purpose, purpose); + + ret_temp = ua_device_get_payload_duid(handle, &duid); + if (UA_ERROR_NONE == ret_temp) { + uat_print_duid(duid); + g_free(duid); + } + + g_device_list = g_slist_append(g_device_list, handle); + + return true; } static int uat_select_service(MManager *mm, struct menu_data *menu) @@ -289,6 +448,28 @@ static int run_ua_service_remove( return RET_SUCCESS; } +static int run_ua_service_get_default_service(MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_service_get_default_service"); + + if (g_service_h) { + ua_service_destroy(g_service_h); + g_service_h = NULL; + } + + ret = ua_service_get_default_service(&g_service_h); + + if (UA_ERROR_NONE == ret) + __update_service_info(); + + msg(" - ua_service_get_default_service() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + static int run_ua_service_get_by_name(MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; @@ -327,6 +508,177 @@ static int run_ua_service_foreach_added( return RET_SUCCESS; } +static int run_ua_service_add_device( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_service_add_device"); + + check_if(NULL == g_service_h); + check_if(NULL == g_device_h); + + ret = ua_service_add_device(g_service_h, g_device_h); + + msg(" - ua_service_add_device() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_service_remove_device( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_service_remove_device"); + + check_if(NULL == g_service_h); + check_if(NULL == g_device_h); + + ret = ua_service_remove_device(g_service_h, g_device_h); + + msg(" - ua_service_remove_device() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_service_set_device_discriminant( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + int temp = 1; + gboolean discriminant = true; + + msg("ua_service_set_device_discriminant"); + + check_if(NULL == g_service_h); + check_if(NULL == g_device_h); + + if (strlen(g_service_device_discriminant)) + temp = (int)strtol(g_service_device_discriminant, NULL, 10); + + if (0 == temp) + discriminant = false; + ret = ua_service_set_device_discriminant(g_service_h, g_device_h, discriminant); + + msg(" - ua_service_add_device() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_service_get_device_discriminant( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + gboolean discriminant = true; + + msg("ua_service_get_device_discriminant"); + + check_if(NULL == g_service_h); + check_if(NULL == g_device_h); + + ret = ua_service_get_device_discriminant(g_service_h, g_device_h, &discriminant); + + msg(" - ua_service_add_device() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + if (UA_ERROR_NONE == ret) + msgb("Device Discriminant %d", discriminant); + + return RET_SUCCESS; +} + +static int run_ua_service_foreach_added_devices(MManager *mm, + struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + ua_service_h service_handle; + + msg("ua_service_foreach_added_devices"); + ret = ua_service_get_by_name(g_service_str, &service_handle); + if (UA_ERROR_NONE == ret) { + msgb("Service Handle [%p]", service_handle); + ua_service_destroy(g_service_h); + g_service_h = service_handle; + __update_service_info(); + } else { + msgr("ua_service_get_by_name() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } + + uat_clear_device_list(); + + ret = ua_service_foreach_added_devices(g_service_h, + _service_foreach_added_device_cb, NULL); + + msg(" - ua_service_foreach_added_devices() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_service_add_user(MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_service_add_user"); + + check_if('\0' == g_user_account_str[0]); + check_if(NULL == g_user_h); + check_if('\0' == g_service_str[0]); + check_if(NULL == g_service_h); + + ret = ua_service_add_user(g_service_h, g_user_h); + + msg(" - ua_service_add_user() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_service_remove_user(MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + + msg("ua_service_remove_user"); + + check_if('\0' == g_user_account_str[0]); + check_if(NULL == g_user_h); + check_if('\0' == g_service_str[0]); + check_if(NULL == g_service_h); + + ret = ua_service_remove_user(g_service_h, g_user_h); + + msg(" - ua_service_remove_user() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + + +static int run_ua_service_foreach_added_users( + MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + msg("ua_service_foreach_added_users"); + + check_if(NULL == g_service_h); + + uat_clear_user_list(); + + ret = ua_service_foreach_added_users(g_service_h, + _service_foreach_added_user_cb, NULL); + + msg(" - ua_service_foreach_added_users() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + static struct menu_data menu_ua_service_set_name[] = { { "1", "name", NULL, NULL, g_service_str }, @@ -353,6 +705,14 @@ static struct menu_data menu_ua_service_set_detection_threshold[] = { { NULL, NULL, }, }; +static struct menu_data menu_ua_service_set_device_discriminant[] = { + { "1", "discriminant (0:disable 1:enable)", + NULL, NULL, g_service_device_discriminant }, + { "2", "run", NULL, + run_ua_service_set_device_discriminant, NULL }, + { NULL, NULL, }, +}; + struct menu_data menu_sel_service[] = { { "1", "Service list", NULL, run_ua_service_foreach_added, g_selected_service_id}, @@ -360,26 +720,80 @@ struct menu_data menu_sel_service[] = { { NULL, NULL, }, }; +static struct menu_data menu_ua_service_add_user[] = { + { "-", "service", + NULL, NULL, g_service_str}, + { "-", "user account", + NULL, NULL, g_user_account_str}, + { "-", "user name", + NULL, NULL, g_user_name_str}, + { "1", "run", NULL, + run_ua_service_add_user, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_service_remove_user[] = { + { "-", "service", + NULL, NULL, g_service_str}, + { "-", "user account", + NULL, NULL, g_user_account_str}, + { "-", "user name", + NULL, NULL, g_user_name_str}, + { "1", "run", NULL, + run_ua_service_remove_user, NULL }, + { NULL, NULL, }, +}; + +struct menu_data menu_sel_service_added_device[] = { + { "1", "Device list", NULL, + run_ua_service_foreach_added_devices, g_selected_device_idx}, + { "2", "Apply", NULL, uat_select_device, NULL }, + { NULL, NULL, }, +}; + +struct menu_data menu_sel_service_added_user[] = { + { "1", "User list", NULL, + run_ua_service_foreach_added_users, g_selected_user_idx}, + { "2", "Apply", NULL, uat_select_user, NULL }, + { NULL, NULL, }, +}; + struct menu_data menu_ua_services[] = { - { "1", "ua_service_get_default_service", - NULL, run_ua_service_get_default_service, NULL }, - { "2", "ua_service_create", + { "1", "ua_service_create", NULL, run_ua_service_create, NULL }, - { "3", "ua_service_set_name", + { "2", "ua_service_set_name", menu_ua_service_set_name, NULL, g_service_str }, - { "4", "ua_service_set_detection_threshold", + { "3", "ua_service_set_detection_threshold", menu_ua_service_set_detection_threshold, NULL, NULL }, - { "5", "ua_service_add", + { "4", "ua_service_add", NULL, run_ua_service_add, NULL }, - { "6", "ua_service_update", + { "5", "ua_service_update", NULL, run_ua_service_update, NULL }, - { "7", "ua_service_remove", + { "6", "ua_service_remove", NULL, run_ua_service_remove, NULL}, - { "8", "ua_service_destroy", + { "7", "ua_service_destroy", NULL, run_ua_service_destroy, NULL}, + { "8", "ua_service_get_default_service", + NULL, run_ua_service_get_default_service, NULL }, { "9", "ua_service_get_by_name", menu_ua_service_get_by_name, NULL, NULL }, { "10", ANSI_COLOR_LIGHTMAGENTA "ua_service_foreach_added" ANSI_COLOR_NORMAL, menu_sel_service, NULL, NULL }, + { "21", "ua_service_add_device", + NULL, run_ua_service_add_device, NULL }, + { "22", "ua_service_remove_device", + NULL, run_ua_service_remove_device, NULL }, + { "23", "ua_service_set_device_discriminant", + menu_ua_service_set_device_discriminant, NULL, NULL }, + { "24", "ua_service_get_device_discriminant", + NULL, run_ua_service_get_device_discriminant, NULL }, + { "25", ANSI_COLOR_LIGHTMAGENTA "ua_service_foreach_added_devices" ANSI_COLOR_NORMAL, + menu_sel_service_added_device, NULL, NULL }, + { "31", "ua_service_add_user", + menu_ua_service_add_user, NULL, NULL }, + { "32", "ua_service_remove_user", + menu_ua_service_remove_user, NULL, NULL }, + { "33", ANSI_COLOR_LIGHTMAGENTA "ua_service_foreach_added_users" ANSI_COLOR_NORMAL, + menu_sel_service_added_user, NULL, NULL }, { NULL, NULL, }, };
\ No newline at end of file diff --git a/test/uat-users.c b/test/uat-users.c index 5e82157..ccccaeb 100644 --- a/test/uat-users.c +++ b/test/uat-users.c @@ -27,17 +27,28 @@ #include "uat-common.h" extern ua_monitor_h g_ua_mon_h; /**< Monitor handle */ +extern ua_device_h g_device_h; /**< Device handle */ ua_user_h g_user_h = NULL; /**< User handle */ extern ua_service_h g_service_h; /**< Service handle */ char g_user_account_str[MENU_DATA_SIZE + 1] = { "default@default.com" }; char g_user_name_str[MENU_DATA_SIZE + 1] = { "default" }; -extern char g_service_str[MENU_DATA_SIZE + 1]; -static char g_account_string[MENU_DATA_SIZE + 1] = {0}; +extern char g_device_type[MENU_DATA_SIZE + 1]; /**< Sensor type of the selected device */ +extern char g_device_type_str[MENU_DATA_SIZE + 1]; /**< Readable sensor type string */ +extern char g_device_id_str[MENU_DATA_SIZE + 1]; /**< Mobile ID of the selected device */ +extern char g_mac_addr_str[MENU_DATA_SIZE + 1]; /**< MAC of the selected device */ + +extern char g_service_str[MENU_DATA_SIZE + 1]; /**< Service name */ GSList *user_list = NULL; /**< User List */ -static int idx_user = 0; /**< Found device sequence number */ +int idx_user = 0; /**< Found device sequence number */ + +extern char g_selected_device_idx[MENU_DATA_SIZE + 1]; /**< Selected device id */ +extern GSList *g_device_list; /**< Device List */ +extern int g_device_count; /**< Seletected service name */ + +char g_selected_user_idx[MENU_DATA_SIZE + 1] = {0,}; /** Selected user id */ static void update_user_info(void) { @@ -45,12 +56,11 @@ static void update_user_info(void) char *account = NULL; char *name = NULL; - if (1 == idx_user) { + if (0 == idx_user) { if (g_user_h) { ua_user_destroy(g_user_h); g_user_h = NULL; } - ua_user_get_default_user(&g_user_h); } @@ -75,7 +85,7 @@ static void ___free_users(gpointer data) handle = NULL; } -static void __clear_user_list(void) +void uat_clear_user_list(void) { g_slist_free_full(user_list, ___free_users); user_list = NULL; @@ -86,90 +96,232 @@ static bool __foreach_registered_user_cb( ua_user_h user_handle, void *user_data) { int ret = UA_ERROR_NONE; - + ua_user_h handle = NULL; char *account = NULL; char *name = NULL; unsigned long long timestamp = 0; - if (user_handle) { + if (!user_handle) { + msgr("user_handle is NULL"); + return true; + } - user_list = g_slist_append(user_list, user_handle); - idx_user++; + ret = ua_user_clone(&handle, user_handle); + if (UA_ERROR_NONE != ret) { + msgr("ua_user_clone() result: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } - ret = ua_user_get_account(user_handle, &account); - if (UA_ERROR_NONE == ret) { - msgb("[%d]", idx_user); - msgb("User account info %s", account); - g_free(account); - } + user_list = g_slist_append(user_list, handle); + idx_user++; - ret = ua_user_get_name(user_handle, &name); - if (UA_ERROR_NONE == ret) { - msgb("User Name : %s", name); - g_free(name); - } + ret = ua_user_get_account(handle, &account); + if (UA_ERROR_NONE == ret) { + msglr("[%d]", idx_user); + msglr("User account info %s", account); + g_free(account); + } - ret = ua_user_get_last_presence(user_handle, ×tamp); - if (UA_ERROR_NONE == ret) - msgb("last present at %llu", timestamp); + ret = ua_user_get_name(handle, &name); + if (UA_ERROR_NONE == ret) { + msglr("User Name : %s", name); + g_free(name); } + ret = ua_user_get_last_presence(handle, ×tamp); + if (UA_ERROR_NONE == ret) + msglr("last present at %llu", timestamp); + return true; } -static bool __service_foreach_registered_user_cb( - ua_service_h service_tmp, ua_user_h user_handle, void *user_data) +static void __device_added_cb(int result, + ua_device_h handle, void *user_data) { - int ret = UA_ERROR_NONE; + int ret; + ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; + ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; + char *device_id = NULL; + char *mac = NULL; + char *ipv4 = NULL; + + if (UA_ERROR_NONE != result) { + msgr("__device_added_cb() result: [0x%X] [%s]", + result, uat_get_error_str(result)); + return; + } - char *service_name = NULL; - char *account = NULL; - char *name = NULL; + if (NULL == handle) { + msgr("Device handle is NULL"); + return; + } - ret = ua_service_get_name(service_tmp, &service_name); + msgb("__device_added_cb() result: [0x%X] [%s]", + result, uat_get_error_str(result)); + + ret = ua_device_get_mac_type(handle, &mac_type); if (UA_ERROR_NONE == ret) - msgb("CB: Service name : %s", service_name); + msgb("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); - g_free(service_name); + ret = ua_device_get_os_info(handle, &ostype); + if (UA_ERROR_NONE == ret) + msgb("Device OS Type : %s", + ostype == 1 ? "Tizen" : + ostype == 2 ? "Android" : + ostype == 3 ? "iOS" : "N/A"); - if (user_handle) { + ret = ua_device_get_device_id(handle, &device_id); + if (UA_ERROR_NONE == ret) { + msgb("Device ID : %s", device_id); + g_free(device_id); + } - user_list = g_slist_append(user_list, user_handle); - idx_user++; + ret = ua_device_get_mac_address(handle, &mac); + if (UA_ERROR_NONE == ret) { + msgb("Device MAC : %s", mac); + g_free(mac); + } - ret = ua_user_get_account(user_handle, &account); - if (UA_ERROR_NONE == ret) { - msgb("[%d]", idx_user); - msgb("User account info %s", account); - g_free(account); - } - ret = ua_user_get_name(user_handle, &name); - if (UA_ERROR_NONE == ret) { - msgb("User Name : %s", name); - g_free(name); - } + ret = ua_device_get_wifi_ipv4_address(handle, &ipv4); + if (UA_ERROR_NONE == ret) { + msgb("Device IPv4 Addr : %s", ipv4); + g_free(ipv4); } - return true; } -static int run_ua_get_default_user(MManager *mm, struct menu_data *menu) +static bool _user_foreach_added_device_cb(ua_device_h device_handle, + void *user_data) { - int ret = UA_ERROR_NONE; + int ret, ret_temp; + ua_device_h handle = NULL; - msg("ua_user_get_default_user"); + ua_mac_type_e mac_type = UA_MAC_TYPE_INVALID; + ua_os_type_e ostype = UA_OS_TYPE_NOT_DEFINE; - if (g_user_h) { - ua_user_destroy(g_user_h); - g_user_h = NULL; + char *device_id = NULL; + char *mac = NULL; + char *wifi_bssid = NULL; + char *ipv4 = NULL; + bool required = false; + unsigned long long timestamp = 0; + bool discriminant = false; + char service_id = 0; + char device_icon = 0; + char purpose = 0; + char *duid = NULL; + + if (!device_handle) { + msgr("device_handle is NULL"); + return true; } - ret = ua_user_get_default_user(&g_user_h); - if (UA_ERROR_NONE == ret) - update_user_info(); + ret = ua_device_clone(&handle, device_handle); + if (UA_ERROR_NONE != ret) { + msgr(" - ua_device_clone() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + return true; + } - msg(" - ua_get_default_user() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); + msgc("\n[%d]", ++g_device_count); + + ret_temp = ua_device_get_mac_type(handle, &mac_type); + if (UA_ERROR_NONE == ret_temp) + msgc("Device MAC Type : %s", uat_get_mac_type_str(mac_type)); + + ret_temp = ua_device_get_os_info(handle, &ostype); + if (UA_ERROR_NONE == ret_temp) { + msgc("Device OS Type : %s", + ostype == 1 ? "Tizen" : + ostype == 2 ? "Android" : + ostype == 3 ? "iOS" : "N/A"); + } + + ret_temp = ua_device_get_device_id(handle, &device_id); + if (UA_ERROR_NONE == ret_temp) { + msgc("Device ID : %s", device_id); + g_free(device_id); + } + + ret_temp = ua_device_get_mac_address(handle, &mac); + if (UA_ERROR_NONE == ret_temp) { + msgc("Device MAC : %s", mac); + g_free(mac); + } + + ret_temp = ua_device_get_wifi_bssid(handle, &wifi_bssid); + if (UA_ERROR_NONE == ret_temp) { + msgc("Device BSSID : %s", wifi_bssid); + g_free(wifi_bssid); + } + + ret_temp = ua_device_get_wifi_ipv4_address(handle, &ipv4); + if (UA_ERROR_NONE == ret_temp) { + msgc("Device IPv4 Addr : %s", ipv4); + g_free(ipv4); + } + + ret_temp = ua_device_get_discriminant(handle, &discriminant); + if (UA_ERROR_NONE == ret_temp) + msgc("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); + + ret_temp = ua_device_get_pairing_required(handle, &required); + if (UA_ERROR_NONE == ret_temp) + msgc("Pairing Required : %s", required ? "YES" : "NO"); + + ret_temp = ua_device_get_last_presence(handle, ×tamp); + if (UA_ERROR_NONE == ret_temp) + msgc("Last present at : %llu", timestamp); + + ret_temp = ua_device_get_payload_service_id(handle, &service_id); + if (UA_ERROR_NONE == ret_temp) + msgc("payload service_id : %d[hex: 0x%X]", service_id, service_id); + + ret_temp = ua_device_get_payload_device_icon(handle, &device_icon); + if (UA_ERROR_NONE == ret_temp) + msgc("payload device_icon : %d[hex: 0x%X]", device_icon, device_icon); + + ret_temp = ua_device_get_payload_purpose(handle, &purpose); + if (UA_ERROR_NONE == ret_temp) + msgc("payload purpose : %d[hex: 0x%X]", purpose, purpose); + + ret_temp = ua_device_get_payload_duid(handle, &duid); + if (UA_ERROR_NONE == ret_temp) { + uat_print_duid(duid); + g_free(duid); + } + + g_device_list = g_slist_append(g_device_list, handle); + + return true; +} + +int uat_select_user(MManager *mm, struct menu_data *menu) +{ + GSList *iter = user_list; + + int id = 0; + int selected_id = 0; + + if (strlen(g_selected_user_idx)) + selected_id = (unsigned char)strtol(g_selected_user_idx, NULL, 10); + + if (selected_id <= 0) { + msg("Please select user first"); + return RET_SUCCESS; + } + + while (NULL != iter) { + GSList *next = iter->next; + ua_user_h *handle = iter->data; + if (handle && ++id == selected_id) { + g_user_h = handle; /* Make selected user as a current one */ + update_user_info(); /* Update user info. */ + msg("Select user done"); + return RET_SUCCESS; + } + iter = next; + } return RET_SUCCESS; } @@ -274,13 +426,56 @@ 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) +{ + int ret = UA_ERROR_NONE; + + msg("ua_user_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); + if (UA_ERROR_NONE == ret) + update_user_info(); + + msg(" - ua_get_default_user() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + return RET_SUCCESS; +} + +static int run_ua_user_get_by_account(MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + ua_user_h user_handle; + + msg("ua_user_get_by_account"); + + ret = ua_user_get_by_account(g_user_account_str, &user_handle); + + msg(" - ua_user_get_by_account() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + + 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(); + } + return RET_SUCCESS; +} + static int run_ua_user_foreach( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; msg("ua_user_foreach_added"); - __clear_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]", @@ -289,191 +484,135 @@ static int run_ua_user_foreach( return RET_SUCCESS; } -static int run_ua_service_foreach_added_users( +static int run_ua_user_add_device( MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; - msg("ua_service_foreach_added_users"); - - __clear_user_list(); - ret = ua_service_foreach_added_users(g_service_h, - __service_foreach_registered_user_cb, NULL); - - msg(" - ua_service_foreach_added_users() ret: [0x%X] [%s]", - ret, uat_get_error_str(ret)); - return RET_SUCCESS; -} + msg("ua_user_add_device"); + check_if(NULL == g_device_h); + ret = ua_user_add_device(g_user_h, g_device_h, __device_added_cb, NULL); -static struct menu_data menu_ua_user_account[] = { - { "1", "account", - NULL, NULL, g_user_account_str }, - { "2", "run", NULL, - run_ua_user_set_account, NULL }, - { NULL, NULL, }, -}; + msg(" - ua_user_add_device() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); -static struct menu_data menu_ua_user_name[] = { - { "1", "name", - NULL, NULL, g_user_name_str }, - { "2", "run", NULL, - run_ua_user_set_name, NULL }, - { NULL, NULL, }, -}; + return RET_SUCCESS; +} -static int run_ua_user_get_handle_by_account(MManager *mm, struct menu_data *menu) +static int run_ua_user_remove_device( + 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_user_remove_device"); + + check_if(NULL == g_user_h); + check_if(NULL == g_device_h); - ret = ua_user_get_handle_by_account(g_account_string, &user_handle); + ret = ua_user_remove_device(g_user_h, g_device_h); - msg(" - ua_user_get_handle_by_account() ret: [0x%X] [%s]", + msg(" - ua_user_remove_device() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); - 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(); - } return RET_SUCCESS; } -static struct menu_data menu_ua_user_get_handle_by_account[] = { - { "1", "account", - NULL, NULL, g_account_string}, - { "2", "run", NULL, - run_ua_user_get_handle_by_account, NULL }, - { NULL, NULL, }, -}; - -static int run_ua_service_add_user(MManager *mm, struct menu_data *menu) +static int run_ua_user_remove_device_by_device_id( + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; + uat_mac_type_e idx = UAT_MAC_TYPE_MAX; - msg("ua_service_add_user"); + msg("ua_user_remove_device_by_device_id"); - check_if('\0' == g_user_account_str[0]); - check_if(NULL == g_user_h); - check_if('\0' == g_service_str[0]); - check_if(NULL == g_service_h); + if (strlen(g_device_type)) + idx = (unsigned char)strtol(g_device_type, NULL, 10); - ret = ua_service_add_user(g_service_h, g_user_h); + msgb("idx [%d] mac_type[%d]", idx, uat_convert_idx_to_device_type(idx)); - msg(" - ua_service_add_user() ret: [0x%X] [%s]", + ret = ua_user_remove_device_by_device_id(g_device_id_str, + uat_convert_idx_to_device_type(idx)); + + msg(" - ua_user_remove_device_by_device_id() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } -static int run_ua_service_remove_user(MManager *mm, struct menu_data *menu) +static int run_ua_user_remove_device_by_mac_address( + MManager *mm, struct menu_data *menu) { int ret = UA_ERROR_NONE; + uat_mac_type_e idx = UAT_MAC_TYPE_MAX; - msg("ua_service_remove_user"); + msg("ua_user_remove_device_by_mac_address"); - check_if('\0' == g_user_account_str[0]); - check_if(NULL == g_user_h); - check_if('\0' == g_service_str[0]); - check_if(NULL == g_service_h); + if (strlen(g_device_type)) + idx = (unsigned char)strtol(g_device_type, NULL, 10); + + msgb("idx [%d] mac_type[%d]", idx, uat_convert_idx_to_device_type(idx)); - ret = ua_service_remove_user(g_service_h, g_user_h); + ret = ua_user_remove_device_by_mac_address(g_mac_addr_str); - msg(" - ua_service_remove_user() ret: [0x%X] [%s]", + msg(" - ua_user_remove_device_by_mac_address() ret: [0x%X] [%s]", ret, uat_get_error_str(ret)); return RET_SUCCESS; } -static struct menu_data menu_ua_service_add_user[] = { - { "-", "service", - NULL, NULL, g_service_str}, - { "-", "user account", - NULL, NULL, g_user_account_str}, - { "-", "user name", - NULL, NULL, g_user_name_str}, - { "1", "run", NULL, - run_ua_service_add_user, NULL }, - { NULL, NULL, }, -}; +static int run_ua_user_foreach_added_devices(MManager *mm, struct menu_data *menu) +{ + int ret = UA_ERROR_NONE; + ua_user_h user_handle; -static struct menu_data menu_ua_service_remove_user[] = { - { "-", "service", - NULL, NULL, g_service_str}, - { "-", "user account", - NULL, NULL, g_user_account_str}, - { "-", "user name", - NULL, NULL, g_user_name_str}, - { "1", "run", NULL, - run_ua_service_remove_user, NULL }, - { NULL, NULL, }, -}; + msg("ua_user_foreach_added_devices"); -struct menu_data menu_ua_users[] = { - { "1", "ua_user_get_default_user", - NULL, run_ua_get_default_user, NULL }, - { "2", "ua_user_create", - NULL, run_ua_user_create, NULL }, - { "3", "ua_user_destroy", - NULL, run_ua_user_destroy, NULL }, - { "4", "ua_user_set_account", - menu_ua_user_account, NULL, g_user_account_str }, - { "5", "ua_user_set_name", - menu_ua_user_name, NULL, g_user_name_str }, - { "6", "ua_user_add", - NULL, run_ua_user_add, NULL }, - { "7", "ua_user_remove", - NULL, run_ua_user_remove, NULL}, - { "8", "ua_user_foreach_added", - NULL, run_ua_user_foreach, NULL }, - { "9", "ua_user_get_handle_by_account", - menu_ua_user_get_handle_by_account, NULL, NULL }, - { "10", "ua_service_add_user", - menu_ua_service_add_user, NULL, NULL }, - { "11", "ua_service_remove_user", - menu_ua_service_remove_user, NULL, NULL }, - { "12", "ua_service_foreach_added_users", - NULL, run_ua_service_foreach_added_users, NULL }, - { NULL, NULL, }, -}; + ret = ua_user_get_by_account(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_by_account() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); + } -static char data_choose_user[MENU_DATA_SIZE + 1] = {0,}; + uat_clear_device_list(); -static int run_choose_user_list(MManager *mm, struct menu_data *menu) -{ - __clear_user_list(); - ua_user_foreach_added(__foreach_registered_user_cb, NULL); + ret = ua_user_foreach_added_devices(g_user_h, + _user_foreach_added_device_cb, NULL); + + msg(" - ua_user_foreach_added_devices() ret: [0x%X] [%s]", + ret, uat_get_error_str(ret)); return RET_SUCCESS; } -static int run_select_user(MManager *mm, struct menu_data *menu) +static int run_select_device(MManager *mm, struct menu_data *menu) { - GSList *iter = user_list; + GSList *iter = g_device_list; int id = 0; int selected_id = 0; - if (strlen(data_choose_user)) - selected_id = (unsigned char)strtol(data_choose_user, NULL, 10); + if (strlen(g_selected_device_idx)) + selected_id = (unsigned char)strtol(g_selected_device_idx, NULL, 10); if (selected_id <= 0) { - msg("Please select user first"); + msg("Please select device first"); return RET_SUCCESS; } while (NULL != iter) { GSList *next = iter->next; - ua_user_h *handle = iter->data; + ua_device_h *handle = iter->data; if (handle && ++id == selected_id) { - g_user_h = handle; /* Make selected user as a current one */ - update_user_info(); /* Update user info. */ - msg("Select user done"); + g_device_h = handle; /* Make selected device as a current one */ + uat_update_device_info(); /* Update device info. */ + msg("[%d] device selected", selected_id); return RET_SUCCESS; } iter = next; @@ -482,9 +621,99 @@ static int run_select_user(MManager *mm, struct menu_data *menu) return RET_SUCCESS; } +static struct menu_data menu_ua_user_account[] = { + { "1", "account", + NULL, NULL, g_user_account_str }, + { "2", "run", NULL, + run_ua_user_set_account, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_user_name[] = { + { "1", "name", + NULL, NULL, g_user_name_str }, + { "2", "run", NULL, + run_ua_user_set_name, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_user_get_handle_by_account[] = { + { "1", "account", + NULL, NULL, g_user_account_str}, + { "2", "run", NULL, + run_ua_user_get_by_account, NULL }, + { NULL, NULL, }, +}; + +struct menu_data menu_sel_added_user[] = { + { "1", "User list", NULL, + run_ua_user_foreach, g_selected_user_idx}, + { "2", "Apply", NULL, uat_select_user, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_rm_dev_by_device_id[] = { + { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", + NULL, NULL, g_device_type }, + { "2", "device_id", + NULL, NULL, g_device_id_str }, + { "3", "run", NULL, + run_ua_user_remove_device_by_device_id, NULL }, + { NULL, NULL, }, +}; + +static struct menu_data menu_ua_rm_dev_by_addr[] = { + { "1", "type (1:BT 2:BLE 3:Wi-Fi 4:P2P)", + NULL, NULL, g_device_type }, + { "2", "MAC", + NULL, NULL, g_mac_addr_str }, + { "3", "run", NULL, + run_ua_user_remove_device_by_mac_address, NULL }, + { NULL, NULL, }, +}; + +struct menu_data menu_ua_user_added_devlist[] = { + { "1", "Device list", NULL, + run_ua_user_foreach_added_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 }, + { "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", + menu_ua_user_name, NULL, g_user_name_str }, + { "5", "ua_user_add", + NULL, run_ua_user_add, NULL }, + { "6", "ua_user_remove", + NULL, run_ua_user_remove, NULL}, + { "7", "ua_user_get_default_user", + NULL, run_ua_user_get_default_user, NULL }, + { "8", "ua_user_get_handle_by_account", + menu_ua_user_get_handle_by_account, NULL, NULL }, + { "9", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_added" ANSI_COLOR_NORMAL, + menu_sel_added_user, NULL, NULL }, + { "10", "ua_user_add_device", + NULL, run_ua_user_add_device, NULL }, + { "11", "ua_user_remove_device", + NULL, run_ua_user_remove_device, NULL }, + { "12", "ua_user_remove_device_by_device_id", + menu_ua_rm_dev_by_device_id, NULL, NULL }, + { "13", "ua_user_remove_device_by_mac_address", + menu_ua_rm_dev_by_addr, NULL, NULL }, + { "14", ANSI_COLOR_LIGHTMAGENTA "ua_user_foreach_added_devices" ANSI_COLOR_NORMAL, + menu_ua_user_added_devlist, NULL, NULL }, + { NULL, NULL, }, +}; + struct menu_data menu_sel_user[] = { - { "1", "User list", NULL, run_choose_user_list, data_choose_user}, - { "2", "Apply", NULL, run_select_user , NULL }, + { "1", "User list", NULL, run_ua_user_foreach, g_selected_user_idx}, + { "2", "Apply", NULL, uat_select_user , NULL }, { NULL, NULL, }, }; |