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;
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]",
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);
}
}
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) {
return ret;
}
- __uam_copy_uam_payload_info(db_payload, payload);
- payloads = g_slist_append(payloads, db_payload);
-
FUNC_EXIT;
return UAM_ERROR_NONE;
}
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) {
#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 = ?"
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,