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>
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 @@ 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 @@ // 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 @@ // 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 @@ // "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 @@ // 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 @@ // 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 @@ // 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 @@ 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 @@ 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 @@ 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;