update svc_dev list while registering device to service
authorAbhay agarwal <ay.agarwal@samsung.com>
Mon, 23 Dec 2019 13:45:09 +0000 (19:15 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 30 Dec 2019 07:29:56 +0000 (16:29 +0900)
Signed-off-by: Abhay agarwal <ay.agarwal@samsung.com>
ua-daemon/src/pm/ua-pm-util.c
ua-daemon/src/ua-manager-core.c

index b698b27..964b247 100644 (file)
@@ -211,6 +211,7 @@ void _pm_util_uam_db_dev_to_uas_dev(unsigned int tech_type,
                len = g_slist_length(tech->svc_dev_list);
                (*device)->num_payload = len;
                (*device)->payload = g_new0(uas_payload_info_t, len);
+               i = 0;
                for (l1 = tech->svc_dev_list; NULL != l1; l1 = g_slist_next(l1)) {
                        uam_svc_dev_info_t *svc_dev = l1->data;
                        uam_db_payload_info_t *payload = svc_dev->payload;
@@ -219,6 +220,7 @@ void _pm_util_uam_db_dev_to_uas_dev(unsigned int tech_type,
                                continue;
 
                        _pm_util_uam_db_payload_to_uas_payload(&(*device)->payload[i], payload);
+                       i++;
                }
        }
 
index 05fb7b5..e96df7b 100644 (file)
@@ -250,6 +250,20 @@ static void __add_service_to_dev_tech_mapping(
        FUNC_EXIT;
 }
 
+static void __add_svc_dev_to_dev_tech_mapping(
+               uam_db_tech_info_t *tech, uam_svc_dev_info_t *svc_dev)
+{
+       FUNC_ENTRY;
+
+       ret_if(NULL == tech);
+       ret_if(NULL == svc_dev);
+
+       tech->svc_dev_list = g_slist_append(tech->svc_dev_list, svc_dev);
+       g_slist_foreach(tech->svc_dev_list, __print_svc_dev, NULL);
+
+       FUNC_EXIT;
+}
+
 static void __remove_service_to_dev_tech_mapping(
                uam_db_tech_info_t *tech, uam_db_service_info_t *service)
 {
@@ -1807,6 +1821,7 @@ int _uam_core_service_add_device(const char *svc_name, const char *device_id,
        int ret = UAM_ERROR_NONE;
        uam_db_tech_info_t *tech_info;
        uam_db_service_info_t *service;
+       uam_svc_dev_info_t *svc_dev = NULL;
 
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
        retv_if(NULL == device_id, UAM_ERROR_INVALID_PARAMETER);
@@ -1826,6 +1841,11 @@ int _uam_core_service_add_device(const char *svc_name, const char *device_id,
 
        __add_service_to_dev_tech_mapping(tech_info, service);
 
+       _uam_core_update_svc_dev_info(device_id, tech_type,
+               service->name, -1, -1, NULL);
+       svc_dev = _uam_core_find_svc_dev_info(device_id, tech_type, service->name);
+       __add_svc_dev_to_dev_tech_mapping(tech_info, svc_dev);
+
        mac = __get_mac_addr(tech_info);
        /* Insert device service info to db */
        ret = _uam_db_insert_device_service_info(device_id, tech_type, mac,
@@ -4070,7 +4090,6 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload,
        uam_db_service_info_t *service;
        uam_db_payload_info_t *db_payload;
        uam_svc_dev_info_t *svc_dev;
-       uam_db_device_info_t *device;
        GSList *l;
 
        retv_if(NULL == payload, UAM_ERROR_INVALID_PARAMETER);
@@ -4086,36 +4105,22 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload,
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        db_payload = l->data;
 
-       // <TO-DO> check if this device-service pair exist
+       /* Retrieve device from list */
+       l = g_slist_find_custom(devices, db_payload->device_id, __compare_device_id);
+       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
 
-       /**Update svc_dev*/
-       _uam_core_update_svc_dev_info(db_payload->device_id, db_payload->tech_type,
-               service->name, -1, -1, payload);
        svc_dev = _uam_core_find_svc_dev_info(db_payload->device_id,
                db_payload->tech_type, service->name);
        retv_if(NULL == svc_dev, UAM_ERROR_INVALID_PARAMETER);
 
-       /**Update svc_dev list for device*/
-       l = g_slist_find_custom(devices, db_payload->device_id, __compare_device_id);
-       device = l->data;
-
-       for (l = device->tech_list; NULL != l; l = g_slist_next(l)) {
-               uam_db_tech_info_t *tech = l->data;
-
-               if (!tech)
-                       continue;
-
-               if (db_payload->tech_type != tech->tech_type)
-                       continue;
-
-               tech->svc_dev_list = g_slist_append(tech->svc_dev_list, svc_dev);
-       }
+       /**Update svc_dev*/
+       _uam_core_update_svc_dev_info(db_payload->device_id, db_payload->tech_type,
+               service->name, -1, -1, payload);
 
        /* Set/update registered device list to plugins */
        if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices))
                UAM_ERR("_uam_pm_set_registered_devices failed");
 
-
        /*** Add payload service mapping to database ***/
        ret = _uam_db_update_device_service_payload_info(payload, service->name);
        if (UAM_ERROR_NONE != ret) {