summaryrefslogtreecommitdiff
path: root/src/components/policy/policy_regular/src/policy_manager_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/policy/policy_regular/src/policy_manager_impl.cc')
-rw-r--r--src/components/policy/policy_regular/src/policy_manager_impl.cc42
1 files changed, 41 insertions, 1 deletions
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 8c3fbe5178..9aac892300 100644
--- a/src/components/policy/policy_regular/src/policy_manager_impl.cc
+++ b/src/components/policy/policy_regular/src/policy_manager_impl.cc
@@ -76,7 +76,8 @@ PolicyManagerImpl::PolicyManagerImpl()
, timer_retry_sequence_("Retry sequence timer",
new timer::TimerTaskImpl<PolicyManagerImpl>(
this, &PolicyManagerImpl::RetrySequence))
- , ignition_check(true) {}
+ , ignition_check(true)
+ , retry_sequence_url_(0, 0, "") {}
void PolicyManagerImpl::set_listener(PolicyListener* listener) {
listener_ = listener;
@@ -899,6 +900,45 @@ std::string PolicyManagerImpl::RetrieveCertificate() const {
return cache_->GetCertificate();
}
+AppIdURL PolicyManagerImpl::GetNextUpdateUrl(const EndpointUrls& urls) {
+ LOG4CXX_AUTO_TRACE(logger_);
+
+ const AppIdURL next_app_url = RetrySequenceUrl(retry_sequence_url_, urls);
+
+ retry_sequence_url_.url_idx_ = next_app_url.second + 1;
+ retry_sequence_url_.app_idx_ = next_app_url.first;
+ retry_sequence_url_.policy_app_id_ = urls[next_app_url.first].app_id;
+
+ return next_app_url;
+}
+
+AppIdURL PolicyManagerImpl::RetrySequenceUrl(const struct RetrySequenceURL& rs,
+ const EndpointUrls& urls) const {
+ uint32_t url_idx = rs.url_idx_;
+ uint32_t app_idx = rs.app_idx_;
+ const std::string& app_id = rs.policy_app_id_;
+
+ if (urls.size() <= app_idx) {
+ // Index of current application doesn't exist any more due to app(s)
+ // unregistration
+ url_idx = 0;
+ app_idx = 0;
+ } else if (urls[app_idx].app_id != app_id) {
+ // Index of current application points to another one due to app(s)
+ // registration/unregistration
+ url_idx = 0;
+ } else if (url_idx >= urls[app_idx].url.size()) {
+ // Index of current application is OK, but all of its URL are sent,
+ // move to the next application
+ url_idx = 0;
+ if (++app_idx >= urls.size()) {
+ app_idx = 0;
+ }
+ }
+
+ return std::make_pair(app_idx, url_idx);
+}
+
class CallStatusChange : public utils::Callable {
public:
CallStatusChange(UpdateStatusManager& upd_manager,