From 14873b942d5e876ea119cc19846a454d06007f1f Mon Sep 17 00:00:00 2001 From: "Maksym Ked (GitHub)" <41471947+mked-luxoft@users.noreply.github.com> Date: Thu, 20 Feb 2020 21:12:32 +0200 Subject: Adapt fix #3203 for PROPRIETARY flow (#3242) * Adapt fix #3203 for PROPRIETARY flow * fixup! Adapt fix #3203 for PROPRIETARY flow Co-authored-by: Ira Lytvynenko (GitHub) --- .../policy_external/include/policy/policy_types.h | 3 +- .../policy/policy_external/src/status.cc | 3 +- .../policy_external/src/update_status_manager.cc | 3 +- .../policy_regular/include/policy/policy_types.h | 3 +- .../policy/policy_regular/include/policy/status.h | 34 ++++++++++++++++++++++ .../include/policy/update_status_manager.h | 6 ++++ .../policy_regular/src/policy_manager_impl.cc | 1 + src/components/policy/policy_regular/src/status.cc | 33 +++++++++++++++++++++ .../policy_regular/src/update_status_manager.cc | 10 ++++++- 9 files changed, 90 insertions(+), 6 deletions(-) diff --git a/src/components/policy/policy_external/include/policy/policy_types.h b/src/components/policy/policy_external/include/policy/policy_types.h index ee2d806ba5..879eb0aa9b 100644 --- a/src/components/policy/policy_external/include/policy/policy_types.h +++ b/src/components/policy/policy_external/include/policy/policy_types.h @@ -75,7 +75,8 @@ enum PolicyTableStatus { StatusUpToDate = 0, StatusUpdatePending, StatusUpdateRequired, - StatusUnknown + StatusUnknown, + StatusProcessingSnapshot }; // Code generator uses String class name, so this typedef was renamed to PTSring diff --git a/src/components/policy/policy_external/src/status.cc b/src/components/policy/policy_external/src/status.cc index 687bea1c3f..f605a51a98 100644 --- a/src/components/policy/policy_external/src/status.cc +++ b/src/components/policy/policy_external/src/status.cc @@ -83,7 +83,8 @@ bool policy::UpdateNeededStatus::IsUpdateRequired() const { } policy::UpdatePendingStatus::UpdatePendingStatus() - : Status(kUpdateNeeded, policy::PolicyTableStatus::StatusUpdatePending) {} + : Status(kUpdateNeeded, + policy::PolicyTableStatus::StatusProcessingSnapshot) {} void policy::UpdatePendingStatus::ProcessEvent( policy::UpdateStatusManager* manager, policy::UpdateEvent event) { diff --git a/src/components/policy/policy_external/src/update_status_manager.cc b/src/components/policy/policy_external/src/update_status_manager.cc index 3653983c8f..cfbd2fe32b 100644 --- a/src/components/policy/policy_external/src/update_status_manager.cc +++ b/src/components/policy/policy_external/src/update_status_manager.cc @@ -217,8 +217,7 @@ void UpdateStatusManager::DoTransition() { next_status_.reset(); const bool is_update_pending = - (policy::kUpdateNeeded == current_status_->get_status_string() && - policy::StatusUpdatePending == current_status_->get_status()); + policy::StatusProcessingSnapshot == current_status_->get_status(); if (last_processed_event_ != kScheduleManualUpdate && !is_update_pending) { listener_->OnUpdateStatusChanged(current_status_->get_status_string()); diff --git a/src/components/policy/policy_regular/include/policy/policy_types.h b/src/components/policy/policy_regular/include/policy/policy_types.h index 9fddb9761b..f8d71ecb13 100644 --- a/src/components/policy/policy_regular/include/policy/policy_types.h +++ b/src/components/policy/policy_regular/include/policy/policy_types.h @@ -75,7 +75,8 @@ enum PolicyTableStatus { StatusUpToDate = 0, StatusUpdatePending, StatusUpdateRequired, - StatusUnknown + StatusUnknown, + StatusProcessingSnapshot }; enum class PTUIterationType { DefaultIteration = 0, RetryIteration }; diff --git a/src/components/policy/policy_regular/include/policy/status.h b/src/components/policy/policy_regular/include/policy/status.h index 8fd3ff559e..4d8bc47dae 100644 --- a/src/components/policy/policy_regular/include/policy/status.h +++ b/src/components/policy/policy_regular/include/policy/status.h @@ -52,6 +52,7 @@ enum UpdateEvent { kOnResetPolicyTableRequireUpdate, kOnResetPolicyTableNoUpdate, kScheduleUpdate, + kPendingUpdate, kScheduleManualUpdate, kOnResetRetrySequence, kNoEvent @@ -117,6 +118,39 @@ class Status { const PolicyTableStatus enum_status_; }; +/** + * @brief The UpdatePendingStatus class represents cases when SDL knows that an + * update is required but before the snapshot is sent to the HMI + */ +class UpdatePendingStatus : public Status { + public: + /** + * @brief Constructor + */ + UpdatePendingStatus(); + + /** + * @brief Process event by setting next status in case event can affect + * current status or ignores the event + * @param manager Status manager pointer + * @param event Event which needs to be processed + */ + void ProcessEvent(UpdateStatusManagerInterface* manager, + UpdateEvent event) OVERRIDE; + + /** + * @brief Check whether update is required in terms of status + * @return True if update is required, otherwise - false + */ + bool IsUpdateRequired() const OVERRIDE; + + /** + * @brief Check whether update is pending in terms of status + * @return True if update is pending, otherwise - false + */ + bool IsUpdatePending() const OVERRIDE; +}; + /** * @brief The UpToDateStatus class represents 'up-to-date' status */ diff --git a/src/components/policy/policy_regular/include/policy/update_status_manager.h b/src/components/policy/policy_regular/include/policy/update_status_manager.h index 0c79bf0ba4..fb679ac10b 100644 --- a/src/components/policy/policy_regular/include/policy/update_status_manager.h +++ b/src/components/policy/policy_regular/include/policy/update_status_manager.h @@ -148,6 +148,12 @@ class UpdateStatusManager : public UpdateStatusManagerInterface { */ void ScheduleUpdate(); + /** + * @brief PendingUpdate will change state from Update_Needed + * to Update_Pending + */ + void PendingUpdate(); + /** * @brief ScheduleUpdate allows to schedule next update. * It will change state to Update_Needed, that's is diff --git a/src/components/policy/policy_regular/src/policy_manager_impl.cc b/src/components/policy/policy_regular/src/policy_manager_impl.cc index 22205763a9..b93850f579 100644 --- a/src/components/policy/policy_regular/src/policy_manager_impl.cc +++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc @@ -650,6 +650,7 @@ void PolicyManagerImpl::StartPTExchange() { } if (update_status_manager_.IsUpdateRequired()) { + update_status_manager_.PendingUpdate(); if (RequestPTUpdate(PTUIterationType::DefaultIteration) && !timer_retry_sequence_.is_running()) { // Start retry sequency diff --git a/src/components/policy/policy_regular/src/status.cc b/src/components/policy/policy_regular/src/status.cc index 114ecb9f97..29d1bbf6b7 100644 --- a/src/components/policy/policy_regular/src/status.cc +++ b/src/components/policy/policy_regular/src/status.cc @@ -67,6 +67,9 @@ void policy::UpdateNeededStatus::ProcessEvent( case kOnResetPolicyTableNoUpdate: manager->SetNextStatus(std::make_shared()); break; + case kPendingUpdate: + manager->SetNextStatus(std::make_shared()); + break; case kOnNewAppRegistered: manager->SetNextStatus(std::make_shared()); break; @@ -79,6 +82,36 @@ bool policy::UpdateNeededStatus::IsUpdateRequired() const { return true; } +policy::UpdatePendingStatus::UpdatePendingStatus() + : Status(kUpdateNeeded, + policy::PolicyTableStatus::StatusProcessingSnapshot) {} + +void policy::UpdatePendingStatus::ProcessEvent( + policy::UpdateStatusManagerInterface* manager, policy::UpdateEvent event) { + switch (event) { + case kOnUpdateSentOut: + manager->SetNextStatus(std::make_shared()); + break; + case kOnResetPolicyTableRequireUpdate: + manager->SetNextStatus(std::make_shared()); + manager->SetPostponedStatus(std::make_shared()); + break; + case kOnResetPolicyTableNoUpdate: + manager->SetNextStatus(std::make_shared()); + break; + default: + break; + } +} + +bool policy::UpdatePendingStatus::IsUpdatePending() const { + return true; +} + +bool policy::UpdatePendingStatus::IsUpdateRequired() const { + return true; +} + policy::UpdatingStatus::UpdatingStatus() : Status("UPDATING", policy::PolicyTableStatus::StatusUpdatePending) {} diff --git a/src/components/policy/policy_regular/src/update_status_manager.cc b/src/components/policy/policy_regular/src/update_status_manager.cc index c37f8bbadc..aa8d8cb3a2 100644 --- a/src/components/policy/policy_regular/src/update_status_manager.cc +++ b/src/components/policy/policy_regular/src/update_status_manager.cc @@ -54,6 +54,11 @@ void UpdateStatusManager::ProcessEvent(UpdateEvent event) { DoTransition(); } +void UpdateStatusManager::PendingUpdate() { + LOG4CXX_AUTO_TRACE(logger_); + ProcessEvent(kPendingUpdate); +} + void UpdateStatusManager::SetNextStatus(std::shared_ptr status) { next_status_ = status; } @@ -173,7 +178,10 @@ void UpdateStatusManager::DoTransition() { current_status_ = next_status_; next_status_.reset(); LOG4CXX_DEBUG(logger_, "last_processed_event_ = " << last_processed_event_); - if (last_processed_event_ != kScheduleManualUpdate) { + const bool is_update_pending = + policy::StatusProcessingSnapshot == current_status_->get_status(); + + if (last_processed_event_ != kScheduleManualUpdate && !is_update_pending) { listener_->OnUpdateStatusChanged(current_status_->get_status_string()); } if (!postponed_status_) { -- cgit v1.2.1