diff options
author | Alex Vakulenko <avakulenko@google.com> | 2015-12-10 10:16:21 -0800 |
---|---|---|
committer | Alex Vakulenko <avakulenko@google.com> | 2015-12-10 20:34:52 +0000 |
commit | ec9d8481ae5deaaf7901f944b06682e77b978881 (patch) | |
tree | d293e86692b4fb0c4b655b7ddc2444fa62ec8814 | |
parent | 72d8d1611efb8c0dd87d466e971bea9468b7c3a1 (diff) | |
download | libweave-ec9d8481ae5deaaf7901f944b06682e77b978881.tar.gz |
Mark old APIs officially deprecated
Marked the old state/commanddef APIs deprecated. Had to fix a couple
of issues on libweave side where old APIs were still called.
Also added AddTraitDefsChangedCallback() so weaved can listen to trait
updates and publish them onto its own RPC.
BUG: 25917706
Change-Id: I1e50e25c5251c12162c9b63e066f54c8a8f63c50
Reviewed-on: https://weave-review.googlesource.com/1877
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
-rw-r--r-- | examples/daemon/sample/sample.cc | 2 | ||||
-rw-r--r-- | include/weave/device.h | 12 | ||||
-rw-r--r-- | include/weave/export.h | 4 | ||||
-rw-r--r-- | include/weave/test/mock_device.h | 2 | ||||
-rw-r--r-- | src/device_manager.cc | 4 | ||||
-rw-r--r-- | src/device_manager.h | 1 |
6 files changed, 20 insertions, 5 deletions
diff --git a/examples/daemon/sample/sample.cc b/examples/daemon/sample/sample.cc index 97cef61..2ab4b27 100644 --- a/examples/daemon/sample/sample.cc +++ b/examples/daemon/sample/sample.cc @@ -104,7 +104,7 @@ class SampleHandler { device_->SetStateProperty(kComponent, "_sample._ping_count", base::FundamentalValue{++ping_count_}, nullptr); - LOG(INFO) << "New state: " << device_->GetState(); + LOG(INFO) << "New component state: " << device_->GetComponents(); base::DictionaryValue result; cmd->Complete(result, nullptr); diff --git a/include/weave/device.h b/include/weave/device.h index 2d7aaff..99035f4 100644 --- a/include/weave/device.h +++ b/include/weave/device.h @@ -53,6 +53,10 @@ class Device { // Returns the full JSON dictionary containing trait definitions. virtual const base::DictionaryValue& GetTraits() const = 0; + // Sets callback which is called when new trait definitions are added. + virtual void AddTraitDefsChangedCallback( + const base::Closure& callback) = 0; + // Adds a new component instance to device. Traits used by this component // must be already defined. virtual bool AddComponent(const std::string& name, @@ -172,6 +176,7 @@ class Device { // Adds provided commands definitions. Can be called multiple times with // condition that definitions do not conflict. // Invalid value is fatal. + // DO NOT USE IN YOUR CODE: use AddTraitDefinitions() instead. LIBWEAVE_DEPRECATED virtual void AddCommandDefinitionsFromJson( const std::string& json) = 0; LIBWEAVE_DEPRECATED virtual void AddCommandDefinitions( @@ -182,6 +187,7 @@ class Device { // "base.reboot". Each command can have no more than one handler. // Empty |command_name| sets default handler for all unhanded commands. // No new command handlers can be set after default handler was set. + // DO NOT USE IN YOUR CODE: use AddCommandHandler() with component parameter. LIBWEAVE_DEPRECATED virtual void AddCommandHandler( const std::string& command_name, const CommandHandlerCallback& callback) = 0; @@ -189,6 +195,7 @@ class Device { // Adds provided state definitions. Can be called multiple times with // condition that definitions do not conflict. // Invalid value is fatal. + // DO NOT USE IN YOUR CODE: use AddTraitDefinitions() instead. LIBWEAVE_DEPRECATED virtual void AddStateDefinitionsFromJson( const std::string& json) = 0; LIBWEAVE_DEPRECATED virtual void AddStateDefinitions( @@ -201,6 +208,7 @@ class Device { // device->SetStatePropertiesFromJson("{'base':{'firmwareVersion':'123'}}") // Method completely replaces properties included |json| or |dict|. // Properties of the state not included |json| or |dict| will stay unchanged. + // DO NOT USE IN YOUR CODE: use SetStateProperties() with component parameter. LIBWEAVE_DEPRECATED virtual bool SetStatePropertiesFromJson( const std::string& json, ErrorPtr* error) = 0; @@ -210,19 +218,21 @@ class Device { // Returns value of the single property. // |name| is full property name, including package name. e.g. "base.network". + // DO NOT USE IN YOUR CODE: use GetStateProperty() with component parameter. LIBWEAVE_DEPRECATED virtual const base::Value* GetStateProperty( const std::string& name) const = 0; // Sets value of the single property. // |name| is full property name, including package name. e.g. "base.network". + // DO NOT USE IN YOUR CODE: use SetStateProperty() with component parameter. LIBWEAVE_DEPRECATED virtual bool SetStateProperty( const std::string& name, const base::Value& value, ErrorPtr* error) = 0; // Returns aggregated state properties across all registered packages. + // DO NOT USE IN YOUR CODE: use GetComponents() instead. LIBWEAVE_DEPRECATED virtual const base::DictionaryValue& GetState() const = 0; - }; } // namespace weave diff --git a/include/weave/export.h b/include/weave/export.h index f698176..6a658f9 100644 --- a/include/weave/export.h +++ b/include/weave/export.h @@ -8,8 +8,6 @@ #define LIBWEAVE_EXPORT __attribute__((__visibility__("default"))) #define LIBWEAVE_PRIVATE __attribute__((__visibility__("hidden"))) -// TODO(avakulenko): Once all the sample clients are migrated to new APIs, -// mark the old one officially deprecated by uncomment the following attribute. -#define LIBWEAVE_DEPRECATED // __attribute__((deprecated)) +#define LIBWEAVE_DEPRECATED __attribute__((deprecated)) #endif // LIBWEAVE_INCLUDE_WEAVE_EXPORT_H_ diff --git a/include/weave/test/mock_device.h b/include/weave/test/mock_device.h index 88cc5e0..612afb9 100644 --- a/include/weave/test/mock_device.h +++ b/include/weave/test/mock_device.h @@ -24,6 +24,8 @@ class MockDevice : public Device { MOCK_METHOD1(AddTraitDefinitionsFromJson, void(const std::string& json)); MOCK_METHOD1(AddTraitDefinitions, void(const base::DictionaryValue& dict)); MOCK_CONST_METHOD0(GetTraits, const base::DictionaryValue&()); + MOCK_METHOD1(AddTraitDefsChangedCallback, + void(const base::Closure& callback)); MOCK_METHOD3(AddComponent, bool(const std::string& name, const std::vector<std::string>& traits, ErrorPtr* error)); diff --git a/src/device_manager.cc b/src/device_manager.cc index e99ca4d..cb575b8 100644 --- a/src/device_manager.cc +++ b/src/device_manager.cc @@ -105,6 +105,10 @@ const base::DictionaryValue& DeviceManager::GetTraits() const { return component_manager_->GetTraits(); } +void DeviceManager::AddTraitDefsChangedCallback(const base::Closure& callback) { + component_manager_->AddTraitDefChangedCallback(callback); +} + bool DeviceManager::AddComponent(const std::string& name, const std::vector<std::string>& traits, ErrorPtr* error) { diff --git a/src/device_manager.h b/src/device_manager.h index bf641e2..d21f398 100644 --- a/src/device_manager.h +++ b/src/device_manager.h @@ -39,6 +39,7 @@ class DeviceManager final : public Device { void AddTraitDefinitionsFromJson(const std::string& json) override; void AddTraitDefinitions(const base::DictionaryValue& dict) override; const base::DictionaryValue& GetTraits() const override; + void AddTraitDefsChangedCallback(const base::Closure& callback) override; bool AddComponent(const std::string& name, const std::vector<std::string>& traits, ErrorPtr* error) override; |