diff options
author | Vitaly Buka <vitalybuka@google.com> | 2016-01-15 14:48:54 -0800 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2016-01-30 01:11:15 +0000 |
commit | ac18fcf3e15a74d9980ea6b09d2482a86d7fdf18 (patch) | |
tree | 6a7c5c15db74b6fa7e79482268de79d974d0a908 /examples | |
parent | d1e6c4ffefd875409426388ec54cc122253a05bb (diff) | |
download | libweave-ac18fcf3e15a74d9980ea6b09d2482a86d7fdf18.tar.gz |
Merge: Add write callback into SaveSettings function
Saving critical settings needs confirmation.
When command alters device config, it should be set "Done" only after
settings are actually saved.
BUG:25776798
Reviewed-on: https://weave-review.googlesource.com/2199
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
(cherry picked from commit 42e508f2559e019d2fcc8f88adfd184b7a6bc3a4)
Change-Id: I693e3c17b3f2f707c8df7af29eefd48362980bce
Reviewed-on: https://weave-review.googlesource.com/2421
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/daemon/common/daemon.h | 11 | ||||
-rw-r--r-- | examples/provider/file_config_store.cc | 14 | ||||
-rw-r--r-- | examples/provider/file_config_store.h | 9 |
3 files changed, 24 insertions, 10 deletions
diff --git a/examples/daemon/common/daemon.h b/examples/daemon/common/daemon.h index 4cccff3..6dc021d 100644 --- a/examples/daemon/common/daemon.h +++ b/examples/daemon/common/daemon.h @@ -69,10 +69,11 @@ class Daemon { }; Daemon(const Options& opts) - : config_store_{new weave::examples::FileConfigStore( - opts.disable_security_, - opts.model_id_)}, - task_runner_{new weave::examples::EventTaskRunner}, + : task_runner_{new weave::examples::EventTaskRunner}, + config_store_{ + new weave::examples::FileConfigStore(opts.disable_security_, + opts.model_id_, + task_runner_.get())}, http_client_{new weave::examples::CurlHttpClient(task_runner_.get())}, network_{new weave::examples::EventNetworkImpl(task_runner_.get())}, bluetooth_{new weave::examples::BluetoothImpl} { @@ -114,8 +115,8 @@ class Daemon { LOG(INFO) << "Device registered: " << device->GetSettings().cloud_id; } - std::unique_ptr<weave::examples::FileConfigStore> config_store_; std::unique_ptr<weave::examples::EventTaskRunner> task_runner_; + std::unique_ptr<weave::examples::FileConfigStore> config_store_; std::unique_ptr<weave::examples::CurlHttpClient> http_client_; std::unique_ptr<weave::examples::EventNetworkImpl> network_; std::unique_ptr<weave::examples::BluetoothImpl> bluetooth_; diff --git a/examples/provider/file_config_store.cc b/examples/provider/file_config_store.cc index af887a7..31efaa7 100644 --- a/examples/provider/file_config_store.cc +++ b/examples/provider/file_config_store.cc @@ -12,14 +12,19 @@ #include <string> #include <vector> +#include <base/bind.h> + namespace weave { namespace examples { const char kSettingsDir[] = "/var/lib/weave/"; FileConfigStore::FileConfigStore(bool disable_security, - const std::string& model_id) - : disable_security_{disable_security}, model_id_{model_id} {} + const std::string& model_id, + provider::TaskRunner* task_runner) + : disable_security_{disable_security}, + model_id_{model_id}, + task_runner_{task_runner} {} std::string FileConfigStore::GetPath(const std::string& name) const { std::string path{kSettingsDir}; @@ -72,11 +77,14 @@ std::string FileConfigStore::LoadSettings(const std::string& name) { } void FileConfigStore::SaveSettings(const std::string& name, - const std::string& settings) { + const std::string& settings, + const DoneCallback& callback) { CHECK(mkdir(kSettingsDir, S_IRWXU) == 0 || errno == EEXIST); LOG(INFO) << "Saving settings to " << GetPath(name); std::ofstream str(GetPath(name)); str << settings; + if (!callback.is_null()) + task_runner_->PostDelayedTask(FROM_HERE, base::Bind(callback, nullptr), {}); } } // namespace examples diff --git a/examples/provider/file_config_store.h b/examples/provider/file_config_store.h index 214194e..e7398d1 100644 --- a/examples/provider/file_config_store.h +++ b/examples/provider/file_config_store.h @@ -10,18 +10,22 @@ #include <vector> #include <weave/provider/config_store.h> +#include <weave/provider/task_runner.h> namespace weave { namespace examples { class FileConfigStore : public provider::ConfigStore { public: - FileConfigStore(bool disable_security, const std::string& model_id); + FileConfigStore(bool disable_security, + const std::string& model_id, + provider::TaskRunner* task_runner); bool LoadDefaults(Settings* settings) override; std::string LoadSettings(const std::string& name) override; void SaveSettings(const std::string& name, - const std::string& settings) override; + const std::string& settings, + const DoneCallback& callback) override; std::string LoadSettings() override; @@ -29,6 +33,7 @@ class FileConfigStore : public provider::ConfigStore { std::string GetPath(const std::string& name) const; const bool disable_security_; const std::string model_id_; + provider::TaskRunner* task_runner_{nullptr}; }; } // namespace examples |