Add multi-application support for service api's 96/259796/2
authorrohit singh <rohit.singh@samsung.com>
Mon, 14 Jun 2021 11:05:39 +0000 (16:35 +0530)
committerrohit singh <rohit.singh@samsung.com>
Wed, 16 Jun 2021 06:41:44 +0000 (12:11 +0530)
This patch adds the multi-applcation support for service
based api's and methods.

Change-Id: I21f73c208825161d547f052eb2eebfd4c37c1c21
Signed-off-by: rohit.singh <rohit.singh@samsung.com>
ua-daemon/include/ua-manager-core.h
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-request-handler.c

index d94526e..b3970fd 100644 (file)
@@ -190,16 +190,16 @@ int _uam_core_set_detection_threshold(unsigned int sensor,
                int presence_threshold, int absence_threshold);
 
 int _uam_core_start_presence_detection(const char *svc_name, char *sender,
-       unsigned int sensors);
+       unsigned int sensors, int app_num);
 
 int _uam_core_stop_presence_detection(const char *svc_name, char *sender,
-       unsigned int sensors);
+       unsigned int sensors, int app_num);
 
 int _uam_core_start_absence_detection(const char *svc_name, char *sender,
-       unsigned int sensors);
+       unsigned int sensors, int app_num);
 
 int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
-       unsigned int sensors);
+       unsigned int sensors, int app_num);
 
 int _uam_core_set_low_power_mode(unsigned int bit_mask, gboolean mode);
 
index 6195c78..75d1685 100755 (executable)
@@ -174,16 +174,20 @@ static gint __compare_user_id(gconstpointer data, gconstpointer user_data)
        return 0;
 }
 
-static gint __compare_svc_name(gconstpointer data, gconstpointer user_data)
+static gint __compare_service(gconstpointer data, gconstpointer user_data)
 {
        const uam_db_service_info_t *service = data;
-       const char *svc_name = user_data;
+       const uam_db_service_info_t *tmp = user_data;
 
        retv_if(NULL == service, -1);
        retv_if(NULL == service->name, -1);
-       retv_if(NULL == svc_name, -1);
+       retv_if(NULL == tmp, -1);
+       retv_if(NULL == tmp->name, -1);
 
-       return g_strcmp0(service->name, svc_name);
+       if (service->app_num == tmp->app_num)
+               return g_strcmp0(service->name, tmp->name);
+       else
+               return -1;
 }
 
 static gint __compare_svc_user(gconstpointer data, gconstpointer user_data)
@@ -584,6 +588,24 @@ static void __uam_copy_db_service_info(
 }
 
 /* Utility functions to search */
+GSList* __search_service(GSList* list, const char *svc_name, int app_num)
+{
+       /* Search user in existing user list */
+       GSList *l;
+       uam_db_service_info_t *temp_svc;
+
+       temp_svc = g_new0(uam_db_service_info_t, 1);
+       temp_svc->name = g_strdup(svc_name);
+       temp_svc->app_num = app_num;
+
+       l = g_slist_find_custom(list, temp_svc, __compare_service);
+
+       g_free(temp_svc->name);
+       g_free(temp_svc);
+
+       return l;
+}
+
 GSList* __search_user(const char *account, int app_num)
 {
        /* Search user in existing user list */
@@ -671,7 +693,7 @@ static char *__get_mac_addr(uam_db_tech_info_t *tech)
 }
 
 static uam_monitor_info_t *__uam_find_monitor(GSList *monitor_list,
-               const char *name, const char *svc_name, uam_pm_detection_mode_e mode)
+               const char *name, const char *svc_name, uam_pm_detection_mode_e mode, const int app_num)
 {
 //     FUNC_ENTRY;
        GSList *l;
@@ -688,7 +710,8 @@ static uam_monitor_info_t *__uam_find_monitor(GSList *monitor_list,
 
                if ((mode == monitor->mode) &&
                                (0 == g_strcmp0(monitor->name, name)) &&
-                               (0 == g_strcmp0(monitor->service->name, svc_name))) {
+                               (0 == g_strcmp0(monitor->service->name, svc_name)) &&
+                               (monitor->service->app_num == app_num)) {
                        UAM_DBG("Monitoring application found in list");
                        return monitor;
                }
@@ -1233,19 +1256,19 @@ static GSList *__convert_db_svc_list_to_uam_svc_list(GSList *db_svc_list)
        for (l = db_svc_list; NULL != l; l = g_slist_next(l)) {
                db_service_info_t *db_svc = l->data;
                uam_db_service_info_t *service;
-               GSList *l1;
+               GSList *ll;
 
                if (!db_svc)
                        continue;
 
-               l1 = g_slist_find_custom(services,
-                               db_svc->service_name, __compare_svc_name);
-               if (!l1) {
+               ll = __search_service(services, db_svc->service_name, db_svc->app_num);
+
+               if (!ll) {
                        service = g_new0(uam_db_service_info_t, 1);
                        __uam_copy_db_service_info(service, db_svc);
                        services = g_slist_append(services, service);
                } else
-                       service = l1->data;
+                       service = ll->data;
 
                svc_list = g_slist_append(svc_list, service);
        }
@@ -2301,7 +2324,7 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const
        user = l->data;
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
 
        service = l->data;
@@ -2322,8 +2345,7 @@ int _uam_core_service_add_user(const char *svc_name, const char *account, const
                        if (!tech)
                                continue;
 
-                       l2 = g_slist_find_custom(tech->svc_list, svc_name,
-                                       __compare_svc_name);
+                       l2 = __search_service(tech->svc_list, svc_name, app_num);
                        if (NULL != l2)
                                continue;
 
@@ -2389,7 +2411,7 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account, con
        user = l->data;
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
 
        retv_if(UAM_ERROR_NONE != __uam_db_begin_transaction(), UAM_ERROR_DB_FAILED);
@@ -2408,8 +2430,7 @@ int _uam_core_service_remove_user(const char *svc_name, const char *account, con
                        if (!tech)
                                continue;
 
-                       l2 = g_slist_find_custom(tech->svc_list, svc_name,
-                                       __compare_svc_name);
+                       l2 = __search_service(tech->svc_list, svc_name, app_num);
                        if (NULL == l2)
                                continue;
 
@@ -2507,11 +2528,11 @@ int _uam_core_service_add_device(const char *svc_name, const char *device_id,
        tech_info = __uam_core_get_dev_tech_info(device_id, tech_type);
        retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER);
 
-       l = g_slist_find_custom(tech_info->svc_list, svc_name, __compare_svc_name);
+       l = __search_service(tech_info->svc_list, svc_name, app_num);
        retv_if(NULL != l, UAM_ERROR_ALREADY_REGISTERED);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
 
        service = l->data;
@@ -2557,13 +2578,13 @@ int _uam_core_service_remove_device(const char *svc_name,
        retv_if(UAM_TECH_TYPE_MAX <= tech_type, UAM_ERROR_INVALID_PARAMETER);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
 
        tech_info = __uam_core_get_dev_tech_info(device_id, tech_type);
        retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER);
 
-       l = g_slist_find_custom(tech_info->svc_list, svc_name, __compare_svc_name);
+       l = __search_service(tech_info->svc_list, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_NOT_REGISTERED);
 
        __remove_service_to_dev_tech_mapping(tech_info, (uam_db_service_info_t *)l->data);
@@ -2600,7 +2621,7 @@ int _uam_core_service_set_device_discriminant(const char *svc_name,
        retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        service = l->data;
 
@@ -2672,7 +2693,7 @@ int _uam_core_set_service_detection_cycle(const char *svc_name, unsigned int new
        retv_if(UAM_DETECTION_CYCLE_MIN > new_cycle, UAM_ERROR_INVALID_PARAMETER);
        retv_if(0 != (new_cycle % UAM_DETECTION_CYCLE_MIN), UAM_ERROR_INVALID_PARAMETER);
 
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        service = l->data;
 
@@ -2704,7 +2725,7 @@ int _uam_core_get_service_detection_cycle(const char *svc_name, unsigned int *cy
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
        retv_if(NULL == cycle, UAM_ERROR_INVALID_PARAMETER);
 
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
 
        service = l->data;
@@ -2797,7 +2818,7 @@ done:
 }
 
 static int __uam_core_start_detection(int detection_type,
-               const char *svc_name, char *sender, unsigned int sensors)
+               const char *svc_name, char *sender, unsigned int sensors, int app_num)
 {
        FUNC_ENTRY;
        uam_monitor_info_t *monitor;
@@ -2808,7 +2829,7 @@ static int __uam_core_start_detection(int detection_type,
        retv_if(NULL == sender, UAM_ERROR_INVALID_PARAMETER);
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
 
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        if (!l)
                UAM_ERR("Service not found");
 
@@ -2816,7 +2837,7 @@ static int __uam_core_start_detection(int detection_type,
        retv_if(NULL == l->data, UAM_ERROR_INTERNAL);
 
        service = l->data;
-       monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type);
+       monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type, app_num);
        if (!monitor) {
                monitor = g_malloc0(sizeof(uam_monitor_info_t));
                if (monitor) {
@@ -2830,7 +2851,8 @@ static int __uam_core_start_detection(int detection_type,
                }
        }
 
-       UAM_DBG("Name: %s, Service: %s, Mode: %d", monitor->name, svc_name, monitor->mode);
+       UAM_DBG("Name: %s, Service: %s, Mode: %d, App_num: %d", monitor->name, svc_name,
+                       monitor->mode, app_num);
 
        monitor->sensors |= sensors;
        if (!is_monitor_added) {
@@ -2851,7 +2873,7 @@ static int __uam_core_start_detection(int detection_type,
 }
 
 static int __uam_core_stop_detection(int detection_type,
-               const char *svc_name, char *sender, unsigned int sensors)
+               const char *svc_name, char *sender, unsigned int sensors, int app_num)
 {
        FUNC_ENTRY;
        int ret = UAM_ERROR_NONE;
@@ -2863,7 +2885,7 @@ static int __uam_core_stop_detection(int detection_type,
        retv_if(NULL == sender, UAM_ERROR_INVALID_PARAMETER);
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
 
-       monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type);
+       monitor = __uam_find_monitor(monitors, sender, svc_name, detection_type, app_num);
        retv_if(NULL == monitor, UAM_ERROR_NOT_IN_OPERATION);
        service = monitor->service;
        retv_if(0 != g_strcmp0(service->name, svc_name), UAM_ERROR_NOT_IN_OPERATION);
@@ -2917,45 +2939,53 @@ static int __uam_core_stop_detection(int detection_type,
        return ret;
 }
 
-int _uam_core_start_presence_detection(const char *svc_name, char *sender, unsigned int sensors)
+int _uam_core_start_presence_detection(const char *svc_name, char *sender,
+               unsigned int sensors, int app_num)
 {
        FUNC_ENTRY;
        int ret;
 
-       ret = __uam_core_start_detection(UAM_DETECT_PRESENCE, svc_name, sender, sensors);
+       ret = __uam_core_start_detection(UAM_DETECT_PRESENCE, svc_name,
+                       sender, sensors, app_num);
 
        FUNC_EXIT;
        return ret;
 }
 
-int _uam_core_stop_presence_detection(const char *svc_name, char *sender, unsigned int sensors)
+int _uam_core_stop_presence_detection(const char *svc_name, char *sender,
+               unsigned int sensors, int app_num)
 {
        FUNC_ENTRY;
        int ret;
 
-       ret = __uam_core_stop_detection(UAM_DETECT_PRESENCE, svc_name, sender, sensors);
+       ret = __uam_core_stop_detection(UAM_DETECT_PRESENCE, svc_name,
+                       sender, sensors, app_num);
 
        FUNC_EXIT;
        return ret;
 }
 
-int _uam_core_start_absence_detection(const char *svc_name, char *sender, unsigned int sensors)
+int _uam_core_start_absence_detection(const char *svc_name, char *sender,
+               unsigned int sensors, int app_num)
 {
        FUNC_ENTRY;
        int ret;
 
-       ret = __uam_core_start_detection(UAM_DETECT_ABSENCE, svc_name, sender, sensors);
+       ret = __uam_core_start_detection(UAM_DETECT_ABSENCE, svc_name, sender,
+                       sensors, app_num);
 
        FUNC_EXIT;
        return ret;
 }
 
-int _uam_core_stop_absence_detection(const char *svc_name, char *sender, unsigned int sensors)
+int _uam_core_stop_absence_detection(const char *svc_name, char *sender,
+               unsigned int sensors, int app_num)
 {
        FUNC_ENTRY;
        int ret;
 
-       ret = __uam_core_stop_detection(UAM_DETECT_ABSENCE, svc_name, sender, sensors);
+       ret = __uam_core_stop_detection(UAM_DETECT_ABSENCE, svc_name, sender,
+                       sensors, app_num);
 
        FUNC_EXIT;
        return ret;
@@ -3431,7 +3461,7 @@ int _uam_core_handle_device_added(int status,
        /* Get default service */
        __get_default_service_name(dev_info->app_num, &default_service_name);
 
-       l = g_slist_find_custom(services, default_service_name, __compare_svc_name);
+       l = __search_service(services, default_service_name, dev_info->app_num);
        if (!l)
                UAM_WARN("Default service not found");
        else
@@ -4130,7 +4160,7 @@ void _uam_core_cleanup_monitor(char *name)
                 * and free the monitor structure in the memory. */
                UAM_INFO("clear %s's monitor info.", monitor->name);
                __uam_core_stop_detection(monitor->mode,
-                       monitor->service->name, name, monitor->sensors);
+                       monitor->service->name, name, monitor->sensors, monitor->service->app_num);
        }
 }
 
@@ -4445,7 +4475,10 @@ int _uam_core_register_service(uam_service_info_s *svc, const int app_num)
        retv_if(NULL == svc->name, UAM_ERROR_INVALID_PARAMETER);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc->name, __compare_svc_name);
+       UAM_INFO("Registering for : service name->[%s] and app_num->[%d]",
+                       svc->name, app_num);
+
+       l = __search_service(services, svc->name, app_num);
        retv_if((NULL != l) && (l->data != NULL), UAM_ERROR_ALREADY_REGISTERED);
 
        service = g_new0(uam_db_service_info_t, 1);
@@ -4482,7 +4515,7 @@ int _uam_core_update_service(uam_service_info_s *svc)
        retv_if(NULL == svc->name, UAM_ERROR_INVALID_PARAMETER);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc->name, __compare_svc_name);
+       l = __search_service(services, svc->name, svc->app_num);
        retv_if((NULL == l) || (l->data == NULL), UAM_ERROR_NOT_REGISTERED);
 
        service = l->data;
@@ -4515,7 +4548,7 @@ int _uam_core_get_default_service(uam_service_info_s *service_info,
        __get_default_service_name(app_num, &default_service_name);
        UAM_DBG("default_service_name is [%s]", default_service_name);
 
-       l = g_slist_find_custom(services, default_service_name, __compare_svc_name);
+       l = __search_service(services, default_service_name, app_num);
        if (NULL == l) {
                /* Register default service */
                memset(service_info, 0x00, sizeof(uam_service_info_s));
@@ -4550,7 +4583,7 @@ int _uam_core_unregister_service(const char *svc_name, const int app_num)
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if((NULL == l), UAM_ERROR_NOT_REGISTERED);
        service = l->data;
 
@@ -4660,7 +4693,7 @@ int _uam_core_get_service_devices(const char *svc_name,
        GSList *l;
        int ret = UAM_ERROR_NONE;
 
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        service = l->data;
 
@@ -4863,7 +4896,7 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload,
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
 
        /* Retrieve service from list */
-       l = g_slist_find_custom(services, svc_name, __compare_svc_name);
+       l = __search_service(services, svc_name, app_num);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        service = l->data;
 
index e15b65b..9a6cc7b 100755 (executable)
@@ -679,7 +679,7 @@ static int __uam_manager_sync_request_handler(
                                &sensors, sizeof(unsigned int));
                svc_name = (char *)g_variant_get_data(in_param2);
 
-               result = _uam_core_start_presence_detection(svc_name, sender, sensors);
+               result = _uam_core_start_presence_detection(svc_name, sender, sensors, app_num);
                break;
        }
        case UAM_REQUEST_STOP_PRESENCE_DETECTION: {
@@ -690,7 +690,7 @@ static int __uam_manager_sync_request_handler(
                                &sensors, sizeof(unsigned int));
                svc_name = (char *)g_variant_get_data(in_param2);
 
-               result = _uam_core_stop_presence_detection(svc_name, sender, sensors);
+               result = _uam_core_stop_presence_detection(svc_name, sender, sensors, app_num);
                break;
        }
        case UAM_REQUEST_START_ABSENCE_DETECTION: {
@@ -701,7 +701,7 @@ static int __uam_manager_sync_request_handler(
                                &sensors, sizeof(unsigned int));
                svc_name = (char *)g_variant_get_data(in_param2);
 
-               result = _uam_core_start_absence_detection(svc_name, sender, sensors);
+               result = _uam_core_start_absence_detection(svc_name, sender, sensors, app_num);
                break;
        }
        case UAM_REQUEST_STOP_ABSENCE_DETECTION: {
@@ -712,7 +712,7 @@ static int __uam_manager_sync_request_handler(
                                &sensors, sizeof(unsigned int));
                svc_name = (char *)g_variant_get_data(in_param2);
 
-               result = _uam_core_stop_absence_detection(svc_name, sender, sensors);
+               result = _uam_core_stop_absence_detection(svc_name, sender, sensors, app_num);
                break;
        }
        case UAM_REQUEST_SET_LOW_POWER_MODE: {