summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/resumption
diff options
context:
space:
mode:
authorAndriy Byzhynar (GitHub) <AByzhynar@luxoft.com>2016-06-23 17:33:32 +0300
committerGitHub <noreply@github.com>2016-06-23 17:33:32 +0300
commit827bcaf0aa39348fa7ec4df796c4e124f7143169 (patch)
tree517a69ced2f09b702cb2368e7ae412efec2ea838 /src/components/application_manager/src/resumption
parent833cac1b1de464f53d5709904a4ee24634be2936 (diff)
downloadsdl_core-827bcaf0aa39348fa7ec4df796c4e124f7143169.tar.gz
Revert "Cover resumption with unit tests"revert-618-feature/Cover_resumption_with_unit_tests
Diffstat (limited to 'src/components/application_manager/src/resumption')
-rw-r--r--src/components/application_manager/src/resumption/resumption_data.cc2
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_db.cc60
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_json.cc29
3 files changed, 70 insertions, 21 deletions
diff --git a/src/components/application_manager/src/resumption/resumption_data.cc b/src/components/application_manager/src/resumption/resumption_data.cc
index d148f856a6..8e6282fc50 100644
--- a/src/components/application_manager/src/resumption/resumption_data.cc
+++ b/src/components/application_manager/src/resumption/resumption_data.cc
@@ -191,7 +191,7 @@ smart_objects::SmartObject ResumptionData::GetApplicationFiles(
int i = 0;
for (AppFilesMap::const_iterator file_it = app_files.begin();
file_it != app_files.end();
- ++file_it) {
+ file_it++) {
const AppFile& file = file_it->second;
if (file.is_persistent) {
smart_objects::SmartObject file_data =
diff --git a/src/components/application_manager/src/resumption/resumption_data_db.cc b/src/components/application_manager/src/resumption/resumption_data_db.cc
index 92e886f5e5..8c9fe7d57f 100644
--- a/src/components/application_manager/src/resumption/resumption_data_db.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_db.cc
@@ -61,26 +61,21 @@ ResumptionDataDB::ResumptionDataDB(
: ResumptionData(application_manager) {
if (db_storage == In_File_Storage) {
#ifndef __QNX__
- db_ = new utils::dbms::SQLDatabaseImpl(file_system::ConcatPath(
- application_manager_.get_settings().app_storage_folder(),
- kDatabaseName));
+ db_ = new utils::dbms::SQLDatabase(
+ file_system::ConcatPath(
+ application_manager_.get_settings().app_storage_folder(),
+ kDatabaseName),
+ "ResumptionDatabase");
#else
- db_ = new utils::dbms::SQLDatabaseImpl(kDatabaseName);
+ db_ = new utils::dbms::SQLDatabase(kDatabaseName);
#endif
} else if (db_storage == In_Memory_Storage) {
- db_ = new utils::dbms::SQLDatabaseImpl();
+ db_ = new utils::dbms::SQLDatabase();
} else {
SDL_ERROR("Get not existed type of database storage");
}
}
-#ifdef BUILD_TESTS
-ResumptionDataDB::ResumptionDataDB(
- utils::dbms::SQLDatabase* db,
- const application_manager::ApplicationManager& application_manager)
- : ResumptionData(application_manager), db_(db) {}
-#endif // BUILD_TESTS
-
ResumptionDataDB::~ResumptionDataDB() {
db_->Close();
delete db_;
@@ -366,13 +361,15 @@ bool ResumptionDataDB::GetSavedApplication(
bool ResumptionDataDB::RemoveApplicationFromSaved(
const std::string& policy_app_id, const std::string& device_id) {
SDL_AUTO_TRACE();
- bool result = false;
bool application_exist = false;
if (!CheckExistenceApplication(policy_app_id, device_id, application_exist) ||
!application_exist) {
- SDL_ERROR("Problem with access to DB or application does not exist");
- return result;
+ SDL_ERROR(
+ "Problem with access to DB or application does not"
+ " exist");
+ return false;
}
+ bool result = false;
if (DeleteSavedApplication(policy_app_id, device_id)) {
WriteDb();
result = true;
@@ -404,6 +401,32 @@ void ResumptionDataDB::GetDataForLoadResumeData(
SelectDataForLoadResumeData(saved_data);
}
+bool ResumptionDataDB::SelectHMILevel(const std::string& policy_app_id,
+ const std::string& device_id,
+ int& hmi_level) const {
+ SDL_AUTO_TRACE();
+ utils::dbms::SQLQuery query_count(db());
+ utils::dbms::SQLQuery query_select(db());
+ if (query_count.Prepare(kSelectCountHMILevel) &&
+ query_select.Prepare(kSelectHMILevel)) {
+ /* Positions of binding data for "query_count" and "query_select" :
+ field "deviceID" from table "application" = 0
+ field "appID" from table "application" = 1 */
+ query_count.Bind(0, device_id);
+ query_count.Bind(1, policy_app_id);
+ query_select.Bind(0, device_id);
+ query_select.Bind(1, policy_app_id);
+ /* Position of data in "query_select" :
+ field "hmiLevel" from table "application" = 0 */
+ if (query_count.Exec() && query_count.GetInteger(0) &&
+ query_select.Exec()) {
+ hmi_level = query_select.GetInteger(0);
+ return true;
+ }
+ }
+ return false;
+}
+
bool ResumptionDataDB::CheckExistenceHMIId(uint32_t hmi_app_id) const {
SDL_AUTO_TRACE();
@@ -2698,14 +2721,13 @@ bool ResumptionDataDB::UpdateGrammarID(const std::string& policy_app_id,
}
utils::dbms::SQLDatabase* ResumptionDataDB::db() const {
-#ifdef __QNX__
- utils::dbms::SQLDatabase* db =
- new utils::dbms::SQLDatabaseImpl(kDatabaseName);
+#if defined(__QNX__)
+ utils::dbms::SQLDatabase* db = new utils::dbms::SQLDatabase(kDatabaseName);
db->Open();
return db;
#else
return db_;
-#endif // __QNX__
+#endif
}
ApplicationParams::ApplicationParams(
diff --git a/src/components/application_manager/src/resumption/resumption_data_json.cc b/src/components/application_manager/src/resumption/resumption_data_json.cc
index 40262ff114..bb2faa412c 100644
--- a/src/components/application_manager/src/resumption/resumption_data_json.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_json.cc
@@ -442,6 +442,31 @@ ssize_t ResumptionDataJson::GetObjectIndex(const std::string& policy_app_id,
return -1;
}
+bool ResumptionDataJson::IsResumptionDataValid(uint32_t index) const {
+ using namespace app_mngr;
+ using namespace utils::json;
+ SDL_AUTO_TRACE();
+ sync_primitives::AutoLock autolock(resumption_lock_);
+ const JsonValueRef json_app = GetSavedApplications()[index];
+ if (!json_app.HasMember(strings::app_id) ||
+ !json_app.HasMember(strings::ign_off_count) ||
+ !json_app.HasMember(strings::hmi_level) ||
+ !json_app.HasMember(strings::hmi_app_id) ||
+ !json_app.HasMember(strings::time_stamp) ||
+ !json_app.HasMember(strings::device_id)) {
+ SDL_ERROR("Wrong resumption data");
+ return false;
+ }
+
+ if (json_app.HasMember(strings::hmi_app_id) &&
+ 0 >= json_app[strings::hmi_app_id].AsUInt()) {
+ SDL_ERROR("Wrong resumption hmi app ID");
+ return false;
+ }
+
+ return true;
+}
+
void ResumptionDataJson::SetSavedApplication(
utils::json::JsonValueRef apps_json) {
SDL_AUTO_TRACE();
@@ -483,7 +508,9 @@ bool ResumptionDataJson::DropAppDataResumption(const std::string& device_id,
application[strings::application_global_properties].Clear();
application[strings::application_subscribtions].Clear();
application[strings::application_files].Clear();
- application.RemoveMember(strings::grammar_id);
+ // Seems there is no interface for json wrapper - needs to be created
+ // application.removeMember(strings::grammar_id);
+ application[strings::grammar_id].Clear();
SDL_DEBUG("Resumption data for application " << app_id << " with device_id "
<< device_id
<< " has been dropped.");