From 07b06b34818d9c731b1fd835df0672519dce8f68 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Thu, 28 Nov 2019 16:18:30 +0530 Subject: [PATCH] Seperate payload database table from device table For a device, each service can have different payload. Signed-off-by: Abhay agarwal --- include/ua-api.h | 20 ++++++++++++++++++++ ua-api/src/ua-api.c | 27 +++++++++++++++++++++++++++ ua-daemon/data/ua_db.sql | 15 +++++++++++---- ua-daemon/src/ua-manager-db.c | 12 ++++++++++-- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 846750f..0c74194 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -1395,6 +1395,26 @@ int _uam_request_update_device(uam_device_info_s *device); */ int _uam_add_ibeacon_adv_data(unsigned int adv_len, const char *ibeacon_adv); +/** + * @brief Adds a payload for a device. + * @since_tizen 5.5 + * + * @param[in] payload Payload information. + * @param[in] device_id Device id. + * @param[in] tech_type Sensor type. + * + * @return 0 on success, otherwise a negative error value + * @retval #UAM_ERROR_NONE Successful + * @retval #UAM_ERROR_INVALID_PARAMETER Invalid parameters + * @retval #UAM_ERROR_INTERNAL Internal error + * + * @exception + * @pre + * @post + */ +int _uam_request_add_payload(uam_ble_payload_s *payload, + char *device_id, uam_tech_type_e tech_type); + #ifdef __cplusplus } #endif diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index 95539c7..9607710 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -1437,3 +1437,30 @@ UAM_EXPORT_API int _uam_add_ibeacon_adv_data(unsigned int adv_len, const char *i FUNC_EXIT; return ret; } + +UAM_EXPORT_API int _uam_request_add_payload(uam_ble_payload_s *payload, + char *device_id, uam_tech_type_e tech_type) +{ + FUNC_ENTRY; + int ret; + char str[UAM_DEVICE_ID_MAX_STRING_LEN]; + + UAM_VALIDATE_INPUT_PARAMETER(payload); + UAM_VALIDATE_INPUT_PARAMETER(device_id); + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, payload, sizeof(uam_ble_payload_s)); + g_strlcpy(str, device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + g_array_append_vals(in_param2, str, sizeof(str)); + g_array_append_vals(in_param3, &tech_type, sizeof(int)); + +// ret = _uam_async_request(UAM_REQUEST_ADD_PAYLOAD, in_param1, in_param2, +// in_param3, in_param4, cb_info.callback, cb_info.user_data); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/data/ua_db.sql b/ua-daemon/data/ua_db.sql index 22cefee..dac1447 100644 --- a/ua-daemon/data/ua_db.sql +++ b/ua-daemon/data/ua_db.sql @@ -36,14 +36,21 @@ CREATE TABLE IF NOT EXISTS devices ( presence_state INTEGER, os_type INTEGER, discriminant INTEGER, - service_id TEXT, - purpose TEXT, - duid TEXT, - device_icon TEXT, FOREIGN KEY(user_id) REFERENCES userdata(user_id), UNIQUE (device_id, tech_type) ); +CREATE TABLE IF NOT EXISTS payloads ( + payload_number INTEGER PRIMARY KEY AUTOINCREMENT, + primary_key TEXT, + secondary_key TEXT, + device_uid TEXT, + device_icon TEXT, + device_number INTEGER, + FOREIGN KEY(device_number) REFERENCES devices(device_number), + UNIQUE (primary_key, secondary_key, device_uid) +); + CREATE TABLE IF NOT EXISTS services ( service_number INTEGER PRIMARY KEY AUTOINCREMENT, service_name TEXT, diff --git a/ua-daemon/src/ua-manager-db.c b/ua-daemon/src/ua-manager-db.c index ead3598..35f91c1 100644 --- a/ua-daemon/src/ua-manager-db.c +++ b/ua-daemon/src/ua-manager-db.c @@ -30,6 +30,7 @@ #define UAM_DB_SERVICES_TABLE "services" /**< Service DB table name */ #define UAM_DB_DEVICE_SERVICES_TABLE "device_services" /**< Device services DB table name */ #define UAM_DB_IBEACON_ADV_TABLE "ibeacon_adv" /**< iBeacon adv DB table name */ +#define UAM_DB_PAYLOAD_TABLE "payload" /**< payload DB table name */ #define CREATE_USERDATA_TABLE "CREATE TABLE IF NOT EXISTS userdata ( " \ "name TEXT, " \ @@ -49,12 +50,19 @@ "presence_state INTEGER, " \ "os_type INTEGER, " \ "discriminant INTEGER, " \ + "FOREIGN KEY(user_id) REFERENCES userdata(user_id), " \ + "UNIQUE (device_id, tech_type, address) " \ + "); " + +#define CREATE_PAYLOAD_TABLE "CREATE TABLE IF NOT EXISTS payloads ( " \ + "payload_number INTEGER PRIMARY KEY AUTOINCREMENT, " \ "primary_key TEXT, " \ "secondary_key TEXT, " \ "device_uid TEXT, " \ "device_icon TEXT, " \ - "FOREIGN KEY(user_id) REFERENCES userdata(user_id), " \ - "UNIQUE (device_id, tech_type) " \ + "device_number INTEGER, " \ + "FOREIGN KEY(device_number) REFERENCES devices(device_number), " \ + "UNIQUE (primary_key, secondary_key, device_uid) " \ "); " #define CREATE_SERVICES_TABLE "CREATE TABLE IF NOT EXISTS services ( " \ -- 2.7.4