diff options
author | Paul Westbrook <pwestbro@google.com> | 2015-12-08 23:00:29 -0800 |
---|---|---|
committer | Paul Westbrook <pwestbro@google.com> | 2015-12-09 17:34:06 +0000 |
commit | 15a832ea6d37e3d0768804d363d493a81964c11d (patch) | |
tree | ed66694eec32098f2258d6c2948cc3349f5ee826 /examples | |
parent | 6a8bd5d74bb9d29060dd367ab9f4da7e257a3dda (diff) | |
download | libweave-15a832ea6d37e3d0768804d363d493a81964c11d.tar.gz |
Store the weave_settings by model manifest id
Create different weave_settings.json files for each model manifest id.
Since model manifest id is immutable on the server for a device id, this
prevents the model manifest id for a sample device from changing
Change-Id: I33ad00271efeca2f81ac4e1dcd27198cb1c576ca
Reviewed-on: https://weave-review.googlesource.com/1844
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/provider/file_config_store.cc | 13 | ||||
-rw-r--r-- | examples/provider/file_config_store.h | 7 |
2 files changed, 10 insertions, 10 deletions
diff --git a/examples/provider/file_config_store.cc b/examples/provider/file_config_store.cc index 7d4e31b..2214be8 100644 --- a/examples/provider/file_config_store.cc +++ b/examples/provider/file_config_store.cc @@ -16,11 +16,10 @@ namespace weave { namespace examples { const char kSettingsDir[] = "/var/lib/weave/"; -const char kSettingsPath[] = "/var/lib/weave/weave_settings.json"; -const char kCategory[] = "example"; FileConfigStore::FileConfigStore(bool disable_security, const std::string& model_id) - : disable_security_{disable_security}, model_id_{model_id} {} + : disable_security_{disable_security}, model_id_{model_id}, + settings_path_{"/var/lib/weave/weave_settings_" + model_id + ".json"} {} bool FileConfigStore::LoadDefaults(Settings* settings) { char host_name[HOST_NAME_MAX] = {}; @@ -54,16 +53,16 @@ bool FileConfigStore::LoadDefaults(Settings* settings) { } std::string FileConfigStore::LoadSettings() { - LOG(INFO) << "Loading settings from " << kSettingsPath; - std::ifstream str(kSettingsPath); + LOG(INFO) << "Loading settings from " << settings_path_; + std::ifstream str(settings_path_); return std::string(std::istreambuf_iterator<char>(str), std::istreambuf_iterator<char>()); } void FileConfigStore::SaveSettings(const std::string& settings) { CHECK(mkdir(kSettingsDir, S_IRWXU) == 0 || errno == EEXIST); - LOG(INFO) << "Saving settings to " << kSettingsPath; - std::ofstream str(kSettingsPath); + LOG(INFO) << "Saving settings to " << settings_path_; + std::ofstream str(settings_path_); str << settings; } diff --git a/examples/provider/file_config_store.h b/examples/provider/file_config_store.h index 8764cc5..578f940 100644 --- a/examples/provider/file_config_store.h +++ b/examples/provider/file_config_store.h @@ -16,15 +16,16 @@ namespace examples { class FileConfigStore : public provider::ConfigStore { public: - explicit FileConfigStore(bool disable_security, const std::string& model_id); + FileConfigStore(bool disable_security, const std::string& model_id); bool LoadDefaults(Settings* settings) override; std::string LoadSettings() override; void SaveSettings(const std::string& settings) override; private: - bool disable_security_{false}; - std::string model_id_{"AAAAA"}; + const bool disable_security_; + const std::string model_id_; + const std::string settings_path_; }; } // namespace examples |