From a743ec2e07ccada0286085ecec54f4d87ed49d44 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 1 Apr 2016 21:29:29 +0200 Subject: UPDATES: Implement and use method for normalizing interval value to accepted values --- common/updates.cpp | 10 ++++++++++ common/updates.h | 9 +++++++++ 2 files changed, 19 insertions(+) (limited to 'common') diff --git a/common/updates.cpp b/common/updates.cpp index 0318864881..552324ef5a 100644 --- a/common/updates.cpp +++ b/common/updates.cpp @@ -38,6 +38,16 @@ const int *UpdateManager::getUpdateIntervals() { return updateIntervals; } +int UpdateManager::normalizeInterval(int interval) { + const int *val = updateIntervals; + + while (*val != -1) + if (*val > interval) + return *val; + + return val[-1]; // Return maximal acceptable value +} + const char *UpdateManager::updateIntervalToString(int interval) { switch (interval) { case kUpdateIntervalNotSupported: diff --git a/common/updates.h b/common/updates.h index fa6f79fb91..65eb5ac095 100644 --- a/common/updates.h +++ b/common/updates.h @@ -105,9 +105,18 @@ public: /** * Returns string representation of a given interval. * + * @param interval The interval. * @return pointer to localized string of given interval. */ static const char *updateIntervalToString(int interval); + + /** + * Rounds up the given interval to acceptable value. + * + * @param interval The interval. + * @return rounded up interval + */ + static int normalizeInterval(int interval); }; } // End of namespace Common -- cgit v1.2.3