diff options
5 files changed, 81 insertions, 2 deletions
diff --git a/src/components/policy/policy_external/include/policy/status.h b/src/components/policy/policy_external/include/policy/status.h index 336d59e869..de36f23fe1 100644 --- a/src/components/policy/policy_external/include/policy/status.h +++ b/src/components/policy/policy_external/include/policy/status.h @@ -52,6 +52,7 @@ enum UpdateEvent { kOnResetPolicyTableRequireUpdate, kOnResetPolicyTableNoUpdate, kScheduleUpdate, + kPendingUpdate, kScheduleManualUpdate, kOnResetRetrySequence, kNoEvent @@ -162,6 +163,37 @@ class UpdateNeededStatus : public Status { }; /** + * @brief The UpdatePendingStatus class represents 'update pending' status + */ +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(UpdateStatusManager* 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 UpdatingStatus class represents 'updating' status */ class UpdatingStatus : public Status { diff --git a/src/components/policy/policy_external/include/policy/update_status_manager.h b/src/components/policy/policy_external/include/policy/update_status_manager.h index 9c0e29407e..4ca7c7f162 100644 --- a/src/components/policy/policy_external/include/policy/update_status_manager.h +++ b/src/components/policy/policy_external/include/policy/update_status_manager.h @@ -149,6 +149,8 @@ class UpdateStatusManager { */ void ScheduleUpdate(); + 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_external/src/policy_manager_impl.cc b/src/components/policy/policy_external/src/policy_manager_impl.cc index 6868b9060c..152a94b963 100644 --- a/src/components/policy/policy_external/src/policy_manager_impl.cc +++ b/src/components/policy/policy_external/src/policy_manager_impl.cc @@ -745,6 +745,7 @@ void PolicyManagerImpl::StartPTExchange() { if (listener_ && listener_->CanUpdate()) { LOG4CXX_INFO(logger_, "Listener CanUpdate"); if (update_status_manager_.IsUpdateRequired()) { + update_status_manager_.PendingUpdate(); LOG4CXX_INFO(logger_, "IsUpdateRequired"); RequestPTUpdate(); } @@ -1975,7 +1976,8 @@ void PolicyManagerImpl::OnUpdateStarted() { uint32_t update_timeout = TimeoutExchangeMSec(); LOG4CXX_DEBUG(logger_, "Update timeout will be set to (milisec): " << update_timeout); - send_on_update_sent_out_ = !update_status_manager_.IsUpdatePending(); + send_on_update_sent_out_ = + policy::kUpdating != update_status_manager_.StringifiedUpdateStatus(); if (send_on_update_sent_out_) { update_status_manager_.OnUpdateSentOut(update_timeout); diff --git a/src/components/policy/policy_external/src/status.cc b/src/components/policy/policy_external/src/status.cc index 3d1cae3eba..7162410731 100644 --- a/src/components/policy/policy_external/src/status.cc +++ b/src/components/policy/policy_external/src/status.cc @@ -67,6 +67,9 @@ void policy::UpdateNeededStatus::ProcessEvent( case kOnResetPolicyTableNoUpdate: manager->SetNextStatus(std::make_shared<UpToDateStatus>()); break; + case kPendingUpdate: + manager->SetNextStatus(std::make_shared<UpdatePendingStatus>()); + break; default: break; } @@ -76,6 +79,35 @@ bool policy::UpdateNeededStatus::IsUpdateRequired() const { return true; } +policy::UpdatePendingStatus::UpdatePendingStatus() + : Status(kUpdateNeeded, policy::PolicyTableStatus::StatusUpdatePending) {} + +void policy::UpdatePendingStatus::ProcessEvent( + policy::UpdateStatusManager* manager, policy::UpdateEvent event) { + switch (event) { + case kOnUpdateSentOut: + manager->SetNextStatus(std::make_shared<UpdatingStatus>()); + break; + case kOnResetPolicyTableRequireUpdate: + manager->SetNextStatus(std::make_shared<UpToDateStatus>()); + manager->SetPostponedStatus(std::make_shared<UpdateNeededStatus>()); + break; + case kOnResetPolicyTableNoUpdate: + manager->SetNextStatus(std::make_shared<UpToDateStatus>()); + break; + default: + break; + } +} + +bool policy::UpdatePendingStatus::IsUpdatePending() const { + return true; +} + +bool policy::UpdatePendingStatus::IsUpdateRequired() const { + return true; +} + policy::UpdatingStatus::UpdatingStatus() : Status(kUpdating, policy::PolicyTableStatus::StatusUpdatePending) {} 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 050908f3a0..4d5967aca6 100644 --- a/src/components/policy/policy_external/src/update_status_manager.cc +++ b/src/components/policy/policy_external/src/update_status_manager.cc @@ -61,6 +61,7 @@ UpdateStatusManager::~UpdateStatusManager() { } void UpdateStatusManager::ProcessEvent(UpdateEvent event) { + LOG4CXX_AUTO_TRACE(logger_); sync_primitives::AutoLock lock(status_lock_); current_status_->ProcessEvent(this, event); last_processed_event_ = event; @@ -164,9 +165,15 @@ bool UpdateStatusManager::IsUpdatePending() const { } void UpdateStatusManager::ScheduleUpdate() { + LOG4CXX_AUTO_TRACE(logger_); ProcessEvent(kScheduleUpdate); } +void UpdateStatusManager::PendingUpdate() { + LOG4CXX_AUTO_TRACE(logger_); + ProcessEvent(kPendingUpdate); +} + void UpdateStatusManager::ScheduleManualUpdate() { ProcessEvent(kScheduleManualUpdate); } @@ -202,7 +209,11 @@ void UpdateStatusManager::DoTransition() { current_status_ = next_status_; next_status_.reset(); - if (last_processed_event_ != kScheduleManualUpdate) { + const bool is_update_pending = + (policy::kUpdateNeeded == current_status_->get_status_string() && + policy::StatusUpdatePending == current_status_->get_status()); + + if (last_processed_event_ != kScheduleManualUpdate && !is_update_pending) { listener_->OnUpdateStatusChanged(current_status_->get_status_string()); } |