summaryrefslogtreecommitdiff
path: root/src/components/application_manager/src/resumption
diff options
context:
space:
mode:
authorAndriy Byzhynar <abyzhynar@luxoft.com>2018-07-28 20:02:20 +0300
committerAlexander <akutsan@luxoft.com>2018-08-21 12:30:03 +0300
commit79b4ac8e5659afe08cbc5a7e322a7621119664c6 (patch)
tree86a404ea4a1fa04ea7abd489679fab103a0576a7 /src/components/application_manager/src/resumption
parentc6d78822277b599826d1c4eedc7e00ce3e4b8c95 (diff)
downloadsdl_core-79b4ac8e5659afe08cbc5a7e322a7621119664c6.tar.gz
Simplify resumption logic
Removed redundant functions Simplified ingintion cycle data correctness check
Diffstat (limited to 'src/components/application_manager/src/resumption')
-rw-r--r--src/components/application_manager/src/resumption/resume_ctrl_impl.cc32
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_db.cc15
-rw-r--r--src/components/application_manager/src/resumption/resumption_data_json.cc48
3 files changed, 32 insertions, 63 deletions
diff --git a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc
index d52a495d17..80f45d6980 100644
--- a/src/components/application_manager/src/resumption/resume_ctrl_impl.cc
+++ b/src/components/application_manager/src/resumption/resume_ctrl_impl.cc
@@ -130,6 +130,8 @@ bool ResumeCtrlImpl::Init(resumption::LastState& last_state) {
application_manager_.get_settings()
.app_resumption_save_persistent_data_timeout(),
timer::kPeriodic);
+
+ resumption_storage_->IncrementGlobalIgnOnCounter();
return true;
}
@@ -335,6 +337,7 @@ void ResumeCtrlImpl::OnIgnitionOff() {
LOG4CXX_AUTO_TRACE(logger_);
if (!application_manager_.IsLowVoltage()) {
resumption_storage_->IncrementIgnOffCount();
+ resumption_storage_->ResetGlobalIgnOnCount();
FinalPersistData();
}
}
@@ -347,28 +350,16 @@ void ResumeCtrlImpl::OnAwake() {
}
void ResumeCtrlImpl::SaveLowVoltageTime() {
- ResetLowVoltageTime();
low_voltage_time_ = time(nullptr);
LOG4CXX_DEBUG(logger_,
"Low Voltage timestamp : " << low_voltage_time_ << " saved");
}
-void ResumeCtrlImpl::ResetLowVoltageTime() {
- low_voltage_time_ = 0;
- LOG4CXX_DEBUG(logger_, "Resetting Low Voltage timestamp");
-}
-
void ResumeCtrlImpl::SaveWakeUpTime() {
- ResetWakeUpTime();
wake_up_time_ = std::time(nullptr);
LOG4CXX_DEBUG(logger_, "Wake Up timestamp : " << wake_up_time_ << " saved");
}
-void ResumeCtrlImpl::ResetWakeUpTime() {
- wake_up_time_ = 0;
- LOG4CXX_DEBUG(logger_, "Resetting Wake Up timestamp");
-}
-
time_t ResumeCtrlImpl::LowVoltageTime() const {
return low_voltage_time_;
}
@@ -967,15 +958,17 @@ bool ResumeCtrlImpl::CheckIcons(ApplicationSharedPtr application,
bool ResumeCtrlImpl::CheckIgnCyclesData() const {
LOG4CXX_AUTO_TRACE(logger_);
- const uint32_t global_ign_off_count =
- resumption_storage_->GetGlobalIgnOffCounter();
const uint32_t global_ign_on_count =
resumption_storage_->GetGlobalIgnOnCounter();
- const uint32_t diff = global_ign_on_count - global_ign_off_count;
- const bool is_ign_off_record_missed = diff >= 2;
- if (is_ign_off_record_missed) {
+ const uint32_t the_first_ignition = 1;
+ const bool is_emergency_ign_off_occurred =
+ global_ign_on_count > the_first_ignition;
+ // global_ign_on_count is reseting to 0 at ignition off
+ // global_ign_on_count is incrementing at ignition on
+ // global_ign_on_count > 1 means that correct ignition off was not present.
+ if (is_emergency_ign_off_occurred) {
LOG4CXX_WARN(logger_,
- "Some IGN OFF records missed. Possibly due to Low Voltage");
+ "Emergency IGN OFF occurred. Possibly after Low Voltage");
return false;
}
return true;
@@ -987,8 +980,7 @@ bool ResumeCtrlImpl::CheckDelayAfterIgnOn() const {
const time_t ign_off_time = GetIgnOffTime();
if (CheckIgnCyclesData() && 0 == ign_off_time) {
- LOG4CXX_DEBUG(
- logger_, "No IGNITION OFF records found: This is first Ignition cycle");
+ LOG4CXX_DEBUG(logger_, "This is first Ignition cycle");
return true;
}
const time_t curr_time = time(nullptr);
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 90c8a20e83..2dfb230c7e 100644
--- a/src/components/application_manager/src/resumption/resumption_data_db.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_db.cc
@@ -376,22 +376,20 @@ bool ResumptionDataDB::RemoveApplicationFromSaved(
uint32_t ResumptionDataDB::GetIgnOffTime() const {
LOG4CXX_AUTO_TRACE(logger_);
-
return SelectIgnOffTime();
}
uint32_t ResumptionDataDB::GetGlobalIgnOnCounter() const {
- return 0;
-}
-
-uint32_t ResumptionDataDB::GetGlobalIgnOffCounter() const {
- return 0;
+ // To be implemented
+ return 1;
}
-void ResumptionDataDB::IncrementGlobalIgnOffCounter() {
+void ResumptionDataDB::IncrementGlobalIgnOnCounter() {
+ // To be implemented
}
-void ResumptionDataDB::IncrementGlobalIgnOnCounter() {
+void ResumptionDataDB::ResetGlobalIgnOnCount() {
+ // To be implemented
}
ssize_t ResumptionDataDB::IsApplicationSaved(
@@ -571,7 +569,6 @@ void ResumptionDataDB::SelectDataForLoadResumeData(
using namespace app_mngr;
using namespace smart_objects;
LOG4CXX_AUTO_TRACE(logger_);
-
utils::dbms::SQLQuery select_data(db());
utils::dbms::SQLQuery count_application(db());
if (!select_data.Prepare(kSelectDataForLoadResumeData) ||
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 e11f482ad6..98e84cc3a8 100644
--- a/src/components/application_manager/src/resumption/resumption_data_json.cc
+++ b/src/components/application_manager/src/resumption/resumption_data_json.cc
@@ -149,7 +149,6 @@ void ResumptionDataJson::IncrementIgnOffCount() {
using namespace app_mngr;
LOG4CXX_AUTO_TRACE(logger_);
sync_primitives::AutoLock autolock(resumption_lock_);
- IncrementGlobalIgnOffCounter();
Json::Value to_save = Json::arrayValue;
for (Json::Value::iterator it = GetSavedApplications().begin();
it != GetSavedApplications().end();
@@ -290,42 +289,14 @@ uint32_t ResumptionDataJson::GetGlobalIgnOnCounter() const {
sync_primitives::AutoLock autolock(resumption_lock_);
Json::Value& resumption = GetResumptionData();
if (resumption.isMember(strings::global_ign_on_counter)) {
- return resumption[strings::global_ign_on_counter].asUInt();
+ const uint32_t global_ign_on_counter =
+ resumption[strings::global_ign_on_counter].asUInt();
+ LOG4CXX_DEBUG(logger_, "Global Ign On Counter = " << global_ign_on_counter);
+ return global_ign_on_counter;
}
return 1;
}
-uint32_t ResumptionDataJson::GetGlobalIgnOffCounter() const {
- using namespace app_mngr;
- LOG4CXX_AUTO_TRACE(logger_);
- sync_primitives::AutoLock autolock(resumption_lock_);
- Json::Value& resumption = GetResumptionData();
- if (resumption.isMember(strings::global_ign_off_counter)) {
- return resumption[strings::global_ign_off_counter].asUInt();
- }
- return 0;
-}
-
-void ResumptionDataJson::IncrementGlobalIgnOffCounter() {
- using namespace app_mngr;
- LOG4CXX_AUTO_TRACE(logger_);
- sync_primitives::AutoLock autolock(resumption_lock_);
- Json::Value& resumption = GetResumptionData();
- if (resumption.isMember(strings::global_ign_off_counter)) {
- const uint32_t global_ign_off_counter =
- resumption[strings::global_ign_off_counter].asUInt();
- LOG4CXX_DEBUG(logger_,
- "Global IGN OFF counter in resumption data: "
- << global_ign_off_counter);
- resumption[strings::global_ign_off_counter] = global_ign_off_counter + 1;
- LOG4CXX_DEBUG(logger_,
- "Global IGN OFF counter new value: "
- << resumption[strings::global_ign_off_counter].asUInt());
- } else {
- resumption[strings::global_ign_off_counter] = 1;
- }
-}
-
void ResumptionDataJson::IncrementGlobalIgnOnCounter() {
using namespace app_mngr;
LOG4CXX_AUTO_TRACE(logger_);
@@ -347,6 +318,16 @@ void ResumptionDataJson::IncrementGlobalIgnOnCounter() {
last_state().SaveStateToFileSystem();
}
+void ResumptionDataJson::ResetGlobalIgnOnCount() {
+ using namespace app_mngr;
+ LOG4CXX_AUTO_TRACE(logger_);
+ sync_primitives::AutoLock autolock(resumption_lock_);
+ Json::Value& resumption = GetResumptionData();
+
+ resumption[strings::global_ign_on_counter] = 0;
+ LOG4CXX_DEBUG(logger_, "Global IGN ON counter resetting");
+}
+
ssize_t ResumptionDataJson::IsApplicationSaved(
const std::string& policy_app_id, const std::string& device_id) const {
LOG4CXX_AUTO_TRACE(logger_);
@@ -518,7 +499,6 @@ void ResumptionDataJson::SetLastIgnOffTime(time_t ign_off_time) {
bool ResumptionDataJson::Init() {
LOG4CXX_AUTO_TRACE(logger_);
- IncrementGlobalIgnOnCounter();
return true;
}