From db0a80112ffdba5a8ceb95b5ac4be8f6c1a9df80 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Thu, 1 Aug 2019 15:23:12 +0530 Subject: [PATCH] Update APIs to set/get BLE payload Change-Id: I97ca8cef7658d63bf47046ccd9ecb5ab4a9b9333 Signed-off-by: Abhay agarwal --- include/ua-api.h | 7 +++++++ ua-daemon/data/ua_db.sql | 1 + ua-daemon/include/ua-manager-core.h | 1 + ua-daemon/src/pm/ua-pm-util.c | 2 ++ ua-daemon/src/ua-manager-core.c | 9 ++++++++- ua-daemon/src/ua-manager-db.c | 1 + ua-daemon/src/ua-manager-device-db.c | 26 +++++++++++++++++--------- ua-daemon/src/ua-manager-request-handler.c | 5 +++-- ua-plugins/include/ua-plugin.h | 1 + 9 files changed, 41 insertions(+), 12 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 5c38b3b..c46289c 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -56,6 +56,12 @@ typedef enum { #define UAM_DEVICE_ID_MAX_STRING_LEN 50 /** + * @brief Max. device payload length. + * @since_tizen 5.5 + */ +#define UAM_PAYLOAD_MAX_STRING_LEN 50 + +/** * @brief Max. IP address length. * @since_tizen 5.5 */ @@ -441,6 +447,7 @@ typedef struct { char mac[UAM_MAC_ADDRESS_STRING_LEN]; /**< Device's MAC ADDRESS */ char ipv4_addr[UAM_IP_ADDRESS_MAX_STRING_LEN];/**< Device's IPv4 address optional */ char device_id[UAM_DEVICE_ID_MAX_STRING_LEN]; /**< Device's uniquie ID */ + char payload[UAM_PAYLOAD_MAX_STRING_LEN]; /**< Payload to scan ble devices*/ gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */ long last_seen; /**< Latest timestamp when device was discoverd */ } uam_device_info_s; diff --git a/ua-daemon/data/ua_db.sql b/ua-daemon/data/ua_db.sql index 3105942..751fd43 100644 --- a/ua-daemon/data/ua_db.sql +++ b/ua-daemon/data/ua_db.sql @@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS devices ( presence_state INTEGER, os_type INTEGER, discriminant INTETER, + payload TEXT, FOREIGN KEY(user_id) REFERENCES userdata(user_id), PRIMARY KEY(device_id, tech_type, address) ); diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 8ad7473..2b14111 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -65,6 +65,7 @@ typedef struct { gboolean discriminant; struct uam_db_device_info *device; GSList *svc_list; + char *payload; } uam_db_tech_info_t; typedef struct uam_db_device_info { diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index 426a676..287cb45 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -246,6 +246,7 @@ uas_device_info_t *_pm_util_uam_dev_info_to_uas_dev_info(const uam_device_info_s UAM_WARN("device->num_addr = %d", device->num_addr); device->device_id = g_strdup(dev->device_id); + device->payload = g_strdup(dev->payload); device->addr_list = g_new0(uas_address_info_t, device->num_addr); if (mac) { device->addr_list[i].type = type; @@ -276,6 +277,7 @@ uam_device_info_s *_pm_util_uas_dev_info_to_uam_dev_info(const uas_device_info_t device->discriminant = dev->discriminant; g_strlcpy(device->device_id, dev->device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + g_strlcpy(device->payload, dev->payload, UAM_PAYLOAD_MAX_STRING_LEN); for (i = 0; i < dev->num_addr; i++) { UAM_DBG("Address[%d]: %s", i, dev->addr_list[i].address); diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 95a2373..ace4182 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -454,6 +454,8 @@ static void __get_uam_db_dev_list_to_uam_dev_list( (*device_list)[indx].operating_system = db_info->os; g_strlcpy((*device_list)[indx].device_id, db_info->device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + g_strlcpy((*device_list)[indx].payload, tech->payload, + UAM_PAYLOAD_MAX_STRING_LEN); (*device_list)[indx].discriminant = tech->discriminant; (*device_list)[indx].last_seen = tech->timestamp; (*device_list)[indx++].type = tech->tech_type; @@ -500,7 +502,9 @@ static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_ g_strlcpy(device->device_id, tech->device->device_id, UAM_DEVICE_ID_MAX_STRING_LEN); device->type = tech->tech_type; - device->discriminant= tech->discriminant; + device->discriminant = tech->discriminant; + g_strlcpy(device->payload, tech->payload, + UAM_PAYLOAD_MAX_STRING_LEN); FUNC_EXIT; return UAM_ERROR_NONE; @@ -641,6 +645,7 @@ static void __uam_core_add_dev_to_list( tech->timestamp = timestamp; tech->device = device; tech->discriminant = dev_info->discriminant; + tech->payload = g_strdup(dev_info->payload); tech->svc_list = svc_list; g_slist_foreach(tech->svc_list, __print_service, tech); @@ -3088,6 +3093,8 @@ static void __get_service_dev_list( UAM_DEVICE_ID_MAX_STRING_LEN); (*device_list)[indx].last_seen = tech->timestamp; (*device_list)[indx].discriminant = tech->discriminant; + g_strlcpy((*device_list)[indx].payload, tech->payload, + UAM_PAYLOAD_MAX_STRING_LEN); (*device_list)[indx++].type = tech->tech_type; } diff --git a/ua-daemon/src/ua-manager-db.c b/ua-daemon/src/ua-manager-db.c index 68d8ceb..b9e50d7 100644 --- a/ua-daemon/src/ua-manager-db.c +++ b/ua-daemon/src/ua-manager-db.c @@ -47,6 +47,7 @@ "presence_state INTEGER, " \ "os_type INTEGER, " \ "discriminant INTETER, " \ + "payload TEXT, " \ "FOREIGN KEY(user_id) REFERENCES userdata(user_id), " \ "PRIMARY KEY(device_id, tech_type, address) " \ "); " diff --git a/ua-daemon/src/ua-manager-device-db.c b/ua-daemon/src/ua-manager-device-db.c index d5ac744..7f26a35 100644 --- a/ua-daemon/src/ua-manager-device-db.c +++ b/ua-daemon/src/ua-manager-device-db.c @@ -26,11 +26,11 @@ #define SELECT_ALL_DEVICES "SELECT device_id, tech_type, address, " \ "ip_address, timestamp, presence_state, os_type, " \ - "user_id, discriminant FROM devices" + "user_id, discriminant, payload FROM devices" #define SELECT_DEVICE "SELECT device_id, tech_type, address, " \ "ip_address, timestamp, presence_state, os_type, " \ - "user_id, discriminant FROM devices WHERE device_id = ? AND tech_type = ? " \ + "user_id, discriminant, payload FROM devices WHERE device_id = ? AND tech_type = ? " \ "AND address = ?" #define SELECT_DEVICE_NUMBER "SELECT device_number FROM devices " \ @@ -40,8 +40,8 @@ #define INSERT_DEVICE "insert into devices " \ "(device_id, tech_type, address, ip_address, timestamp, " \ - "presence_state, os_type, user_id, discriminant, device_number)" \ - "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + "presence_state, os_type, user_id, discriminant, payload, device_number)" \ + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" #define UPDATE_TIMESTAMP "UPDATE devices " \ "SET timestamp = ? WHERE device_id = ? AND tech_type = ? AND address = ?" @@ -463,10 +463,10 @@ int _ua_device_db_insert_device_info(int user_id, retv_if(NULL == dev_info, UAM_ERROR_INVALID_PARAMETER); - UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", dev_info->device_id, + UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d-%s", dev_info->device_id, dev_info->type, dev_info->mac, dev_info->ipv4_addr, timestamp, presence_state, dev_info->operating_system, dev_info->discriminant, - user_id); + user_id, dev_info->payload); DB_ACTION(sqlite3_bind_text(stmt, 1, dev_info->device_id, -1, SQLITE_TRANSIENT), error_code, handle_error); @@ -486,7 +486,9 @@ int _ua_device_db_insert_device_info(int user_id, error_code, handle_error); DB_ACTION(sqlite3_bind_int(stmt, 9, dev_info->discriminant), error_code, handle_error); - DB_ACTION(sqlite3_bind_int(stmt, 10, max_device_number + 1), + DB_ACTION(sqlite3_bind_text(stmt, 10, dev_info->payload, -1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 11, max_device_number + 1), error_code, handle_error); if (sqlite3_step(stmt) != SQLITE_DONE) { @@ -572,8 +574,10 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address, info->dev_info.operating_system = sqlite3_column_int(stmt, 6); info->user_id = sqlite3_column_int(stmt, 7); info->dev_info.discriminant = sqlite3_column_int(stmt, 8); + g_strlcpy(info->dev_info.payload, (char *)sqlite3_column_text(stmt, 9), + UAM_PAYLOAD_MAX_STRING_LEN); - UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", + UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d-%s", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac, @@ -583,6 +587,7 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address, info->dev_info.operating_system, info->user_id, info->dev_info.discriminant); + info->dev_info.payload); } handle_error: @@ -663,8 +668,10 @@ GSList *_ua_device_db_get_all_devices(void) info->dev_info.operating_system = sqlite3_column_int(stmt, 6); info->user_id = sqlite3_column_int(stmt, 7); info->dev_info.discriminant = sqlite3_column_int(stmt, 8); + g_strlcpy(info->dev_info.payload, (char *)sqlite3_column_text(stmt, 9), + UAM_PAYLOAD_MAX_STRING_LEN); - UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d", + UAM_INFO("%s-%d-%s-%s-%ld-%d-%d-%d-%d-%s", info->dev_info.device_id, info->dev_info.type, info->dev_info.mac, @@ -674,6 +681,7 @@ GSList *_ua_device_db_get_all_devices(void) info->dev_info.operating_system, info->user_id, info->dev_info.discriminant); + info->dev_info.payload); device_list = g_slist_append(device_list, info); break; diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 7b34b4f..f627726 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -702,10 +702,11 @@ static int __uam_manager_async_request_handler( account = (char *)g_variant_get_data(in_param1); __uam_manager_copy_params(in_param2, &dev_info, sizeof(uam_device_info_s)); - UAM_DBG("Account: [%s], Type: %d, MAC: [%s] IP: [%s], ID: [%s], Discriminant: [%s]", + UAM_DBG("Account: [%s], Type: %d, MAC: [%s] IP: [%s], ID: [%s], Discriminant: [%s], Payload: [%s]", account, dev_info.type, dev_info.mac, dev_info.ipv4_addr, dev_info.device_id, - dev_info.discriminant ? "true" : "false"); + dev_info.discriminant ? "true" : "false", + dev_info.payload); result = _uam_core_add_device(account, &dev_info); if (UAM_ERROR_NONE == result) { diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index 65a89ee..619a5a6 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -108,6 +108,7 @@ typedef struct { int num_addr; uas_address_info_t *addr_list; int discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */ + char *payload; } uas_device_info_t; /* Active scan event types */ -- 2.7.4