diff options
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 |