Update svc_dev info while adding payload to service
authorAbhay agarwal <ay.agarwal@samsung.com>
Fri, 20 Dec 2019 12:49:30 +0000 (18:19 +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/include/ua-manager-core.h
ua-daemon/include/ua-manager-database.h
ua-daemon/src/pm/ua-pm-util.c
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-payload-db.c
ua-plugins/include/ua-plugin.h

index fcf2c32..a26762f 100644 (file)
@@ -60,6 +60,8 @@ typedef struct {
        char secondary_key; /** Purpose */
        char *device_uid; /** DEVICE_UID */
        char *bt_mac; /** BT MAC Address */
+       char *device_id; /**< Device ID */
+       uam_tech_type_e tech_type; /**< Connectivity type */
 } uam_db_payload_info_t;
 
 typedef struct {
index 66760ff..07cf3fc 100644 (file)
@@ -251,6 +251,8 @@ int _uam_adv_db_clear(void);
 /* PAYLOAD QUERIES */
 typedef struct {
        uam_ble_payload_s payload_info;
+       char device_id[UAM_DEVICE_ID_MAX_STRING_LEN];
+       uam_tech_type_e type;
 } db_payload_info_t;
 
 /* db init/deinit */
index 6fbe543..6bab1d5 100644 (file)
@@ -257,6 +257,8 @@ uas_device_info_t *_pm_util_uam_dev_info_to_uas_dev_info(const uam_device_info_s
                device->addr_list[i++].address = ipv4_addr;
        }
 
+       device->payload = NULL;
+
        FUNC_EXIT;
        return device;
 }
index 5da6d1a..a29582f 100644 (file)
@@ -100,6 +100,34 @@ static gint __compare_svc_name(gconstpointer data, gconstpointer user_data)
        return g_strcmp0(service->name, svc_name);
 }
 
+static gint __compare_payload(gconstpointer data, gconstpointer user_data)
+{
+       const uam_db_payload_info_t *db_payload = data;
+       const uam_ble_payload_s *payload = user_data;
+
+       retv_if(NULL == db_payload, -1);
+       retv_if(NULL == payload, -1);
+
+       if ((db_payload->primary_key == payload->primary_key) &&
+               (0 == g_strcmp0(db_payload->device_uid, payload->device_uid)))
+               return 0;
+       return -1;
+}
+
+static gint __compare_db_payload(gconstpointer data, gconstpointer user_data)
+{
+       const uam_db_payload_info_t *db_payload = data;
+       const uam_ble_payload_s *payload = user_data;
+
+       retv_if(NULL == db_payload, -1);
+       retv_if(NULL == payload, -1);
+
+       if ((db_payload->primary_key == payload->primary_key) &&
+               (0 == g_strcmp0(db_payload->device_uid, payload->device_uid)))
+               return 0;
+       return -1;
+}
+
 static void __free_address_info(gpointer data)
 {
        FUNC_ENTRY;
@@ -1553,9 +1581,12 @@ static int _uam_core_update_svc_dev_info(const char *device_id, uam_tech_type_e
                svc_devs = g_slist_append(svc_devs, svc);
        }
 
-       svc->discriminant = discriminant;
-       svc->last_seen = last_seen;
-       __uam_copy_uam_payload_info(svc->payload, payload_info);
+       if (discriminant >= 0)
+               svc->discriminant = discriminant;
+       if (last_seen >= 0)
+               svc->last_seen = last_seen;
+       if (payload_info)
+               __uam_copy_uam_payload_info(svc->payload, payload_info);
 
        UAM_DBG("Service [%s] device [%s] tech_type [%d] discriminant [%d] " \
                "last_seen [%llu] payload primary key [%d]",
@@ -2398,11 +2429,12 @@ int _uam_core_init(void)
                        if (!db_payload)
                                continue;
 
-//                     l1 = g_slist_find_custom(payloads,
-//                                     db_payload->payload_name, __compare_payload_name);
+                       l1 = g_slist_find_custom(payloads, db_payload, __compare_db_payload);
                        if (!l1) {
                                payload = g_new0(uam_db_payload_info_t, 1);
                                __uam_copy_uam_payload_info(payload, &(db_payload->payload_info));
+                               payload->device_id = g_strdup(db_payload->device_id);
+                               payload->tech_type = db_payload->type;
                                payloads = g_slist_append(payloads, payload);
                        }
                }
@@ -4014,6 +4046,11 @@ int _uam_core_add_payload(uam_ble_payload_s *payload,
        retv_if(NULL == tech_info, UAM_ERROR_INVALID_PARAMETER);
        mac = __get_mac_addr(tech_info);
 
+       __uam_copy_uam_payload_info(db_payload, payload);
+       db_payload->device_id = g_strdup(device_id);
+       db_payload->tech_type = tech_type;
+       payloads = g_slist_append(payloads, db_payload);
+
        /*** Add payload to database ***/
        ret = _uam_db_insert_payload_info(device_id, tech_type, mac, payload);
        if (UAM_ERROR_NONE != ret) {
@@ -4021,9 +4058,6 @@ int _uam_core_add_payload(uam_ble_payload_s *payload,
                return ret;
        }
 
-       __uam_copy_uam_payload_info(db_payload, payload);
-       payloads = g_slist_append(payloads, db_payload);
-
        FUNC_EXIT;
        return UAM_ERROR_NONE;
 }
@@ -4034,20 +4068,34 @@ int _uam_core_service_add_payload(uam_ble_payload_s *payload,
        FUNC_ENTRY;
        int ret = UAM_ERROR_NONE;
        uam_db_service_info_t *service;
+       uam_db_payload_info_t *db_payload;
+       uam_svc_dev_info_t *svc_dev;
        GSList *l;
 
        retv_if(NULL == payload, UAM_ERROR_INVALID_PARAMETER);
        retv_if(NULL == svc_name, UAM_ERROR_INVALID_PARAMETER);
 
-       // <TO-DO> check if payload exist
-       // <TO-DO> check if service exist
-       // <TO-DO> check if device-service exist
-
        /* Retrieve service from list */
        l = g_slist_find_custom(services, svc_name, __compare_svc_name);
        retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
        service = l->data;
 
+       /* Retrieve payload from list */
+       l = g_slist_find_custom(payloads, payload, __compare_payload);
+       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
+       db_payload = l->data;
+
+       // <TO-DO> check if this device-service pair exist
+
+       /**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);
+       /**<TO-DO> Update svc_dev list for device*/
+       /**<TO-DO> Update registered devices for ble*/
+
        /*** Add payload service mapping to database ***/
        ret = _uam_db_update_device_service_payload_info(payload, service->name);
        if (UAM_ERROR_NONE != ret) {
index 1837dcb..8c60583 100644 (file)
@@ -24,8 +24,9 @@
 #include "ua-manager-common.h"
 #include "ua-manager-database.h"
 
-#define SELECT_ALL_PAYLOADS "SELECT primary_key, secondary_key, " \
-       "device_uid, device_icon FROM payloads"
+#define SELECT_ALL_PAYLOADS "SELECT P.primary_key, P.secondary_key, " \
+       "P.device_uid, P.device_icon, D.device_id, D.tech_type " \
+       "FROM payloads as P JOIN devices as D USING(device_number)"
 
 #define SELECT_PAYLOAD_DEVICE "SELECT device_number FROM payloads " \
        "where primary_key = ? AND secondary_key = ? AND device_uid = ?"
@@ -416,6 +417,9 @@ GSList *_uam_db_get_all_payloads(void)
                                        UAM_BLE_PAYLOAD_DEVICE_UID_LEN);
                        buf = (char *)sqlite3_column_text(stmt, 3);
                        info->payload_info.device_icon = buf ? *buf : 1;
+                       g_strlcpy(info->device_id, (char *)sqlite3_column_text(stmt, 4),
+                               UAM_DEVICE_ID_MAX_STRING_LEN);
+                       info->type = sqlite3_column_int(stmt, 5);
 
                        UAM_INFO("primary key: %d secondary key: %d",
                                info->payload_info.primary_key,
index ccdcc7d..3cc420e 100644 (file)
@@ -103,10 +103,10 @@ typedef struct {
 typedef struct {
        char primary_key; /** Primary Key */
        char device_icon; /** Device icon */
-       char secondary_key; /** Purpose */
+       char secondary_key; /** Secondary key */
        char *device_uid; /** DEVICE_UID */
        char *bt_mac; /** BT MAC Address */
-} uas_ble_payload_t;
+} uas_payload_info_t;
 
 /* Device information structure */
 typedef struct {
@@ -118,7 +118,7 @@ typedef struct {
        uas_address_info_t *addr_list; /**< Address list (IP, Subnet Mask, Gateway etc) */
        int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */
        unsigned long long last_seen; /**< Last seen time */
-       uas_ble_payload_t *payload; /**< BLE payload for BLE device filtering */
+       uas_payload_info_t *payload; /**< Payload for device filtering */
 } uas_device_info_t;
 
 /* Sensor information structure */