return error_code;
}
-GSList *_uam_db_get_service_devices_payloads_info(const int app_num)
+static GSList *__uam_db_get_service_devices(const int app_num, gboolean have_payload)
{
FUNC_ENTRY;
int error_code = UAM_ERROR_NONE;
GSList *svc_dev_list = NULL;
db_svc_dev_info_t *info = NULL;
int sql_ret = SQLITE_OK;
- char *buf = NULL;
- int uid_len = 0;
- if (app_num == -1) {
+ if (have_payload && app_num == -1) {
stmt = select_device_services_payloads_without_app_num;
- } else {
+ } else if (have_payload) {
stmt = select_device_services_payloads;
DB_ACTION(sqlite3_bind_int(stmt, 1, app_num), error_code, handle_error);
- }
-
- do {
- sql_ret = sqlite3_step(stmt);
-
- switch (sql_ret) {
- case SQLITE_DONE:
- break;
- case SQLITE_ROW:
- UAM_DBG("Device services info found");
- info = g_new0(db_svc_dev_info_t, 1);
- g_strlcpy(info->device_id, (char *)sqlite3_column_text(stmt, 0),
- UAM_DEVICE_ID_MAX_STRING_LEN);
- info->type = sqlite3_column_int(stmt, 1);
- g_strlcpy(info->svc, (char *)sqlite3_column_text(stmt, 2),
- UAM_SERVICE_MAX_STRING_LEN);
- info->discriminant = sqlite3_column_int(stmt, 3);
- info->last_seen = sqlite3_column_int64(stmt, 4);
- buf = (char *)sqlite3_column_text(stmt, 5);
- info->payload_info.primary_key = buf ? *buf : 13;
- buf = (char *)sqlite3_column_text(stmt, 6);
- info->payload_info.secondary_key = buf ? *buf : 1;
- uid_len = sqlite3_column_int(stmt, 7);
- info->payload_info.device_uid_len = uid_len >= 0 ? uid_len : 0;
- buf = (char *)sqlite3_column_text(stmt, 8);
- if (buf)
- memcpy(info->payload_info.device_uid, buf,
- info->payload_info.device_uid_len);
- buf = (char *)sqlite3_column_text(stmt, 9);
- info->payload_info.device_type = buf ? *buf : 1;
-
- UAM_INFO("device id:%s-%d-%s-%d-%llu " \
- "primary key: %d secondary key: %d",
- info->device_id,
- info->type,
- info->svc,
- info->discriminant,
- info->last_seen,
- info->payload_info.primary_key,
- info->payload_info.secondary_key);
-
- svc_dev_list = g_slist_append(svc_dev_list, info);
- break;
- case SQLITE_ERROR:
- default:
- UAM_ERR("Failed to enumerate device info [%d:%s]",
- sql_ret, sqlite3_errmsg(database_handle));
- }
- } while (sql_ret == SQLITE_ROW);
-handle_error:
- if (error_code != UAM_ERROR_NONE)
- UAM_ERR("_uam_db_get_service_devices_payloads_info failed");
- sqlite3_reset(stmt);
- FUNC_EXIT;
- return svc_dev_list;
-}
-
-GSList *_uam_db_get_service_devices_info(const int app_num)
-{
- FUNC_ENTRY;
- int error_code = UAM_ERROR_NONE;
- sqlite3_stmt *stmt;
- GSList *svc_dev_list = NULL;
- db_svc_dev_info_t *info = NULL;
- int sql_ret = SQLITE_OK;
-
- if (app_num == -1) {
+ } else if (app_num == -1) {
stmt = select_device_services_without_app_num;
} else {
stmt = select_device_services;
UAM_SERVICE_MAX_STRING_LEN);
info->discriminant = sqlite3_column_int(stmt, 3);
info->last_seen = sqlite3_column_int64(stmt, 4);
- info->app_num = sqlite3_column_int(stmt, 5);
+
+ if (!have_payload) {
+ info->app_num = sqlite3_column_int(stmt, 5);
+ } else {
+ char *buf = NULL;
+ int uid_len = 0;
+
+ buf = (char *)sqlite3_column_text(stmt, 5);
+ info->payload_info.primary_key = buf ? *buf : 13;
+ buf = (char *)sqlite3_column_text(stmt, 6);
+ info->payload_info.secondary_key = buf ? *buf : 1;
+ uid_len = sqlite3_column_int(stmt, 7);
+ info->payload_info.device_uid_len = uid_len >= 0 ? uid_len : 0;
+ buf = (char *)sqlite3_column_text(stmt, 8);
+ if (buf)
+ memcpy(info->payload_info.device_uid, buf,
+ info->payload_info.device_uid_len);
+ buf = (char *)sqlite3_column_text(stmt, 9);
+ info->payload_info.device_type = buf ? *buf : 1;
+ }
UAM_INFO("device id:%s-%d-%s-%d-%llu-%d ",
info->device_id,
info->last_seen,
info->app_num);
+ if (have_payload)
+ UAM_INFO("DevicePrimary key: %d secondary key: %d",
+ info->payload_info.primary_key,
+ info->payload_info.secondary_key);
+
svc_dev_list = g_slist_append(svc_dev_list, info);
break;
case SQLITE_ERROR:
sql_ret, sqlite3_errmsg(database_handle));
}
} while (sql_ret == SQLITE_ROW);
-
handle_error:
if (error_code != UAM_ERROR_NONE)
- UAM_ERR("_uam_db_get_service_devices_info failed");
+ UAM_ERR("_uam_db_get_service_devices failed");
sqlite3_reset(stmt);
FUNC_EXIT;
return svc_dev_list;
+
+}
+
+GSList *_uam_db_get_service_devices_payloads_info(const int app_num)
+{
+ return __uam_db_get_service_devices(app_num, TRUE);
+}
+
+GSList *_uam_db_get_service_devices_info(const int app_num)
+{
+ return __uam_db_get_service_devices(app_num, FALSE);
}
static int __uam_db_update_dev_svc_payload(int device_number,