buffet: Allow configurable polling period
While here, switch to using a repeating timer, which is cleaner.
BUG=brillo:564,brillo:522
TEST=buffet_Registration passes. Can touch the polling period config
flag and see that polling period changes.
Change-Id: I8d0cca5d38e8ba91dad1a97311cc20603e300654
Reviewed-on: https://chromium-review.googlesource.com/260920
Tested-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
diff --git a/buffet/buffet_config.cc b/buffet/buffet_config.cc
index 36acee9..e4f6209 100644
--- a/buffet/buffet_config.cc
+++ b/buffet/buffet_config.cc
@@ -4,6 +4,9 @@
#include "buffet/buffet_config.h"
+#include <base/logging.h>
+#include <base/strings/string_number_conversions.h>
+
namespace buffet {
namespace config_keys {
@@ -18,6 +21,7 @@
const char kDefaultDescription[] = "default_description";
const char kDefaultLocation[] = "default_location";
const char kModelId[] = "model_id";
+const char kPollingPeriodMs[] = "polling_period_ms";
} // namespace config_keys
@@ -40,6 +44,13 @@
store.GetString(config_keys::kDefaultDescription, &default_description_);
store.GetString(config_keys::kDefaultLocation, &default_location_);
store.GetString(config_keys::kModelId, &model_id_);
+ std::string polling_period_str;
+ if (store.GetString(config_keys::kPollingPeriodMs, &polling_period_str)) {
+ CHECK(base::StringToUint64(polling_period_str, &polling_period_ms_))
+ << "Failed to parse polling period in configuration file.";
+ VLOG(1) << "Using a polling period of " << polling_period_ms_
+ << " milliseconds.";
+ }
}
} // namespace buffet