From: rohit singh Date: Sun, 16 May 2021 13:21:34 +0000 (+0530) Subject: Change implentation for ua_service_add_user X-Git-Tag: submit/tizen/20210601.231319~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bfa397530ec2911f04c70e69a6b399d609bb2b22;p=platform%2Fcore%2Fconnectivity%2Fua-manager.git Change implentation for ua_service_add_user Issue: Earlier ua_service_add_user is not having the support for Service -> User -> Device hierarchy structure. Solution: Added implementation to maintain service_user mapping at the daemon side so that whenever a device gets added to user it automatically gets added to the respective service with which the user is mapped to. Change-Id: I4cfca7db3f6e8fa6616d68c0570f86f23838022c Signed-off-by: rohit.singh --- diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 5fc3d10..a9904f6 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -106,6 +106,11 @@ typedef struct uam_db_device_info { int app_num; /**< Identity of respective app */ } uam_db_device_info_t; +typedef struct uam_svc_user_info { + char* account; /**< Account */ + char* svc_name; /**< Service name */ +} uam_svc_user_info_t; + typedef struct uam_db_user_info { int user_id; /**< User ID */ char *name; /**< User name */ diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index ffad383..ea17f9f 100755 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -49,6 +49,8 @@ static GSList *users; /* List of users - uam_db_user_info_t */ static GSList *devices; /* List of devices - uam_db_device_info_t */ static GSList *services; /* List of services - uam_db_service_info_t */ static GSList *svc_devs; /* List of service device mapping - uam_svc_dev_info_t */ +static GSList *svc_users; /* List of service user mapping - uam_svc_user_info_t */ + static GSList *payloads; /* List of payloads - uam_db_payload_info_t */ static GSList *temp_devices; /* List of devices whichi will be temporary and \ will be cleared in the end of addition \ @@ -184,6 +186,35 @@ static gint __compare_svc_name(gconstpointer data, gconstpointer user_data) return g_strcmp0(service->name, svc_name); } +static gint __compare_svc_user(gconstpointer data, gconstpointer user_data) +{ + const uam_svc_user_info_t *svc_user = data; + const uam_svc_user_info_t *tmp_svc_user = user_data; + + retv_if(NULL == svc_user, -1); + retv_if(NULL == tmp_svc_user, -1); + retv_if(NULL == svc_user->svc_name, -1); + retv_if(NULL == tmp_svc_user->svc_name, -1); + retv_if(NULL == svc_user->account, -1); + retv_if(NULL == tmp_svc_user->account, -1); + + if (g_strcmp0(svc_user->svc_name, tmp_svc_user->svc_name) == 0) + return g_strcmp0(svc_user->account, tmp_svc_user->account); + else + return g_strcmp0(svc_user->svc_name, tmp_svc_user->svc_name); +} + +static gint __compare_svc_user_account(gconstpointer data, gconstpointer user_data) +{ + const uam_svc_user_info_t *svc_user = data; + const char *account = user_data; + + retv_if(NULL == svc_user, -1); + retv_if(NULL == account, -1); + + return g_strcmp0(svc_user->account, account); +} + static gint __compare_payload(gconstpointer data, gconstpointer user_data) { const uam_db_payload_info_t *db_payload = data; @@ -952,6 +983,44 @@ static void _uam_device_match_count(const char *device_id, int tech_type, FUNC_EXIT; } +/* Initial service_user mapping. Here, using user's device list information + * and the service_device mapping, service and user are mapped. + */ +static void __init_svc_user_mapping() +{ + FUNC_ENTRY; + GSList *l, *ll, *tmp; + + for (l = svc_devs; NULL != l; l = g_slist_next(l)) { + + uam_svc_dev_info_t *svc_dev = l->data; + char *device_id = svc_dev->device_id; + + /* Search for devices */ + ll = __search_device(device_id, svc_dev->app_num); + + uam_db_device_info_t *device = ll->data; + uam_db_user_info_t *user_info = device->user; + + if (!user_info) + continue; + + uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + + svc_user->svc_name = g_strdup(svc_dev->service); + svc_user->account = g_strdup(user_info->account); + + tmp = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); + if (!tmp) + svc_users = g_slist_prepend(svc_users, svc_user); + else { + free_n_null(&(svc_user->svc_name)); + free_n_null(&(svc_user->account)); + free_n_null(&svc_user); + } + } +} + static int __get_uam_db_dev_list_to_uam_dev_list( GSList *db_dev_list, uam_device_info_s **device_list, int *count, const int app_num) @@ -1504,7 +1573,7 @@ int _uam_core_is_device_added(uam_device_info_s *dev, gboolean *is_added) continue; if (__is_mac_addr(addr->addr_type) && - !strcasecmp(addr->address,dev->mac)) { + !strcasecmp(addr->address, dev->mac)) { *is_added = TRUE; break; } @@ -2259,6 +2328,17 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const } } + /* Add service to user mapping */ + uam_svc_user_info_t *svc_user = g_new0(uam_svc_user_info_t, 1); + svc_user->svc_name = g_strdup(svc_name); + svc_user->account = g_strdup(account); + + l = g_slist_find_custom(svc_users, svc_user, __compare_svc_user); + if (!l) + svc_users = g_slist_prepend(svc_users, svc_user); + else + UAM_INFO("USER SERVICE MAPPING ALLREADY PRESENT."); + __uam_db_end_transaction(1); FUNC_EXIT; @@ -3045,6 +3125,9 @@ int _uam_core_init(void) } } + /* Update user_service_mapping */ + __init_svc_user_mapping(); + /* Fetch iBeacon adv list */ db_adv_list = _uam_db_get_all_advs(-1); if (!db_adv_list) { @@ -3163,6 +3246,20 @@ void _uam_core_deinit(void) g_slist_free(svc_devs); svc_devs = NULL; + /* Release allocated memory for service users */ + for (l = svc_users; NULL != l; l = g_slist_next(l)) { + uam_svc_user_info_t *svc_user = l->data; + + if (!svc_user) + continue; + + g_free(svc_user->svc_name); + g_free(svc_user->account); + g_free(svc_user); + } + g_slist_free(svc_users); + svc_users = NULL; + /* Release allocated memory for payloads */ for (l = payloads; NULL != l; l = g_slist_next(l)) { uam_db_payload_info_t *payload = l->data; @@ -3346,6 +3443,20 @@ int _uam_core_handle_device_added(int status, __uam_db_end_transaction(0); goto done; } + + /* Add device to user mapped service */ + uam_svc_user_info_t* svc_user = NULL; + + l = g_slist_find_custom(svc_users, user->account, __compare_svc_user_account); + if (!l) + UAM_WARN("User service mapping not found."); + else + svc_user = l->data; + + if (svc_user != NULL && svc_user->svc_name) + _uam_core_service_add_device(svc_user->svc_name, dev_info->device_id, + dev_info->type, dev_info->app_num); + __uam_db_end_transaction(1); /** End database transaction */