diff options
author | Andriy Byzhynar <abyzhynar@luxoft.com> | 2018-07-28 20:02:20 +0300 |
---|---|---|
committer | Alexander <akutsan@luxoft.com> | 2018-08-21 12:30:03 +0300 |
commit | 79b4ac8e5659afe08cbc5a7e322a7621119664c6 (patch) | |
tree | 86a404ea4a1fa04ea7abd489679fab103a0576a7 | |
parent | c6d78822277b599826d1c4eedc7e00ce3e4b8c95 (diff) | |
download | sdl_core-79b4ac8e5659afe08cbc5a7e322a7621119664c6.tar.gz |
Simplify resumption logic
Removed redundant functions
Simplified ingintion cycle data correctness check
8 files changed, 39 insertions, 124 deletions
diff --git a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h index 85e232fe92..c316d11d86 100644 --- a/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h +++ b/src/components/application_manager/include/application_manager/resumption/resume_ctrl_impl.h @@ -336,16 +336,6 @@ class ResumeCtrlImpl : public ResumeCtrl, time_t WakeUpTime() const; /** - * @brief Resets Low Voltage signal timestamp to zero - */ - void ResetLowVoltageTime(); - - /** - * @brief Resets Wake Up signal timestamp to zero - */ - void ResetWakeUpTime(); - - /** * @brief restores saved data of application * @param application contains application for which restores data * @return true if success, otherwise return false diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data.h b/src/components/application_manager/include/application_manager/resumption/resumption_data.h index ee866719c8..8d88f3a420 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data.h @@ -123,16 +123,9 @@ class ResumptionData { virtual uint32_t GetGlobalIgnOnCounter() const = 0; /** - * @brief Increments global ignition off counter - * by 1 - */ - virtual void IncrementGlobalIgnOffCounter() = 0; - - /** - * @brief Get the global ignition off counter - * @return the global ignition off counter + * @brief Resets global ignition on counter */ - virtual uint32_t GetGlobalIgnOffCounter() const = 0; + virtual void ResetGlobalIgnOnCount() = 0; /** * @brief Retrieves hash ID for the given mobile app ID diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h index 08e9b04e62..007b6064b5 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_db.h @@ -110,29 +110,11 @@ class ResumptionDataDB : public ResumptionData { virtual uint32_t GetHMIApplicationID(const std::string& policy_app_id, const std::string& device_id) const; - /** - * @brief Increments global ignition on counter - * by 1 - */ void IncrementGlobalIgnOnCounter() OVERRIDE; - /** - * @brief Get the global ignition on counter - * @return the global ignition on counter - */ - virtual uint32_t GetGlobalIgnOnCounter() const OVERRIDE; + uint32_t GetGlobalIgnOnCounter() const OVERRIDE; - /** - * @brief Increments global ignition off counter - * by 1 - */ - virtual void IncrementGlobalIgnOffCounter() OVERRIDE; - - /** - * @brief Get the global ignition off counter - * @return the global ignition off counter - */ - virtual uint32_t GetGlobalIgnOffCounter() const OVERRIDE; + void ResetGlobalIgnOnCount() OVERRIDE; /** * @brief Increments ignition counter for all registered applications diff --git a/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h b/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h index 1a48ff20d5..5683d4f533 100644 --- a/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h +++ b/src/components/application_manager/include/application_manager/resumption/resumption_data_json.h @@ -145,29 +145,11 @@ class ResumptionDataJson : public ResumptionData { */ virtual uint32_t GetIgnOffTime() const; - /** - * @brief Increments global ignition on counter - * by 1 - */ void IncrementGlobalIgnOnCounter() OVERRIDE; - /** - * @brief Get the global ignition on counter - * @return the global ignition on counter - */ - virtual uint32_t GetGlobalIgnOnCounter() const OVERRIDE; + uint32_t GetGlobalIgnOnCounter() const OVERRIDE; - /** - * @brief Increments global ignition off counter - * by 1 - */ - virtual void IncrementGlobalIgnOffCounter() OVERRIDE; - - /** - * @brief Get the global ignition off counter - * @return the global ignition off counter - */ - virtual uint32_t GetGlobalIgnOffCounter() const OVERRIDE; + void ResetGlobalIgnOnCount() OVERRIDE; /** * @brief Checks if saved data have application 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; } diff --git a/src/components/application_manager/test/include/application_manager/mock_resumption_data.h b/src/components/application_manager/test/include/application_manager/mock_resumption_data.h index a3ac670fa4..38d1944dba 100644 --- a/src/components/application_manager/test/include/application_manager/mock_resumption_data.h +++ b/src/components/application_manager/test/include/application_manager/mock_resumption_data.h @@ -68,8 +68,7 @@ class MockResumptionData : public ::resumption::ResumptionData { MOCK_METHOD0(OnAwake, void()); MOCK_METHOD0(IncrementGlobalIgnOnCounter, void()); MOCK_CONST_METHOD0(GetGlobalIgnOnCounter, uint32_t()); - MOCK_METHOD0(IncrementGlobalIgnOffCounter, void()); - MOCK_CONST_METHOD0(GetGlobalIgnOffCounter, uint32_t()); + MOCK_METHOD0(ResetGlobalIgnOnCount, void()); MOCK_METHOD0(DecrementIgnOffCount, void()); MOCK_CONST_METHOD3(GetSavedApplication, |