libweave: Rename CommandProxyInterface to CommandObserver Implementation of this interface is not necessary should act as proxy. BUG=brillo:1245 TEST='FEATURES=test emerge-gizmo buffet' Change-Id: I6b987888f440a204af912749f7a17f740a3be01a Reviewed-on: https://chromium-review.googlesource.com/287266 Trybot-Ready: Vitaly Buka <vitalybuka@chromium.org> Tested-by: Vitaly Buka <vitalybuka@chromium.org> Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/libweave/src/commands/cloud_command_proxy.h b/libweave/src/commands/cloud_command_proxy.h index 5e3d42c..7998df6 100644 --- a/libweave/src/commands/cloud_command_proxy.h +++ b/libweave/src/commands/cloud_command_proxy.h
@@ -25,7 +25,7 @@ class CommandInstance; // Command proxy which publishes command updates to the cloud. -class CloudCommandProxy final : public CommandProxyInterface { +class CloudCommandProxy final : public CommandObserver { public: CloudCommandProxy(CommandInstance* command_instance, CloudCommandUpdateInterface* cloud_command_updater,
diff --git a/libweave/src/commands/cloud_command_proxy_unittest.cc b/libweave/src/commands/cloud_command_proxy_unittest.cc index 69e0b4b..06ff331 100644 --- a/libweave/src/commands/cloud_command_proxy_unittest.cc +++ b/libweave/src/commands/cloud_command_proxy_unittest.cc
@@ -156,7 +156,7 @@ &state_change_queue_, std::move(backoff), task_runner_}}; - command_instance_->AddProxy(proxy.release()); + command_instance_->AddObserver(proxy.release()); } StateChangeQueueInterface::UpdateID current_state_update_id_{0};
diff --git a/libweave/src/commands/command_instance.cc b/libweave/src/commands/command_instance.cc index 04401d1..2cfe3d5 100644 --- a/libweave/src/commands/command_instance.cc +++ b/libweave/src/commands/command_instance.cc
@@ -39,9 +39,8 @@ } CommandInstance::~CommandInstance() { - for (auto& proxy : proxies_) { - proxy->OnCommandDestroyed(); - } + for (auto observer : observers_) + observer->OnCommandDestroyed(); } const std::string& CommandInstance::GetCategory() const { @@ -173,17 +172,16 @@ return json; } -void CommandInstance::AddProxy(CommandProxyInterface* proxy) { - proxies_.push_back(proxy); +void CommandInstance::AddObserver(CommandObserver* observer) { + observers_.push_back(observer); } bool CommandInstance::SetResults(const native_types::Object& results) { // TODO(antonm): Add validation. if (results != results_) { results_ = results; - for (auto& proxy : proxies_) { - proxy->OnResultsChanged(); - } + for (auto observer : observers_) + observer->OnResultsChanged(); } return true; } @@ -193,9 +191,8 @@ SetStatus(kStatusInProgress); if (progress != progress_) { progress_ = progress; - for (auto& proxy : proxies_) { - proxy->OnProgressChanged(); - } + for (auto observer : observers_) + observer->OnProgressChanged(); } return true; } @@ -221,9 +218,8 @@ void CommandInstance::SetStatus(const std::string& status) { if (status != status_) { status_ = status; - for (auto& proxy : proxies_) { - proxy->OnStatusChanged(); - } + for (auto observer : observers_) + observer->OnStatusChanged(); } }
diff --git a/libweave/src/commands/command_instance.h b/libweave/src/commands/command_instance.h index ba11985..d80e0b9 100644 --- a/libweave/src/commands/command_instance.h +++ b/libweave/src/commands/command_instance.h
@@ -25,7 +25,7 @@ class CommandDefinition; class CommandDictionary; -class CommandProxyInterface; +class CommandObserver; class CommandQueue; class CommandInstance final : public Command { @@ -81,9 +81,9 @@ // Sets the command ID (normally done by CommandQueue when the command // instance is added to it). void SetID(const std::string& id) { id_ = id; } - // Adds a proxy for this command. - // The proxy object is not owned by this class. - void AddProxy(CommandProxyInterface* proxy); + // Adds a observer for this command. The observer object is not owned by this + // class. + void AddObserver(CommandObserver* observer); // Sets the pointer to queue this command is part of. void SetCommandQueue(CommandQueue* queue) { queue_ = queue; } @@ -141,8 +141,8 @@ native_types::Object results_; // Current command status. std::string status_ = kStatusQueued; - // Command proxies for the command. - std::vector<CommandProxyInterface*> proxies_; + // Command observer for the command. + std::vector<CommandObserver*> observers_; // Pointer to the command queue this command instance is added to. // The queue owns the command instance, so it outlives this object. CommandQueue* queue_ = nullptr;
diff --git a/libweave/src/commands/command_proxy_interface.h b/libweave/src/commands/command_proxy_interface.h index bf03f34..3aeb9bb 100644 --- a/libweave/src/commands/command_proxy_interface.h +++ b/libweave/src/commands/command_proxy_interface.h
@@ -14,9 +14,9 @@ // This interface lets the command instance to update its proxy of command // state changes, so that the proxy can then notify clients of the changes over // their supported protocol (e.g. D-Bus). -class CommandProxyInterface { +class CommandObserver { public: - virtual ~CommandProxyInterface() = default; + virtual ~CommandObserver() = default; virtual void OnResultsChanged() = 0; virtual void OnStatusChanged() = 0;
diff --git a/libweave/src/commands/dbus_command_dispatcher.cc b/libweave/src/commands/dbus_command_dispatcher.cc index 6800660..7c7cfdc 100644 --- a/libweave/src/commands/dbus_command_dispatcher.cc +++ b/libweave/src/commands/dbus_command_dispatcher.cc
@@ -27,7 +27,7 @@ object_manager_.get(), object_manager_->GetBus(), command_instance, buffet::kCommandServicePathPrefix + std::to_string(++next_id_))}; proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction()); - command_instance->AddProxy(proxy.release()); + command_instance->AddObserver(proxy.release()); } } // namespace weave
diff --git a/libweave/src/commands/dbus_command_dispatcher_unittest.cc b/libweave/src/commands/dbus_command_dispatcher_unittest.cc index e97aa53..7f1ac9a 100644 --- a/libweave/src/commands/dbus_command_dispatcher_unittest.cc +++ b/libweave/src/commands/dbus_command_dispatcher_unittest.cc
@@ -115,8 +115,8 @@ } DBusCommandProxy* FindProxy(CommandInstance* command_instance) { - CHECK_EQ(command_instance->proxies_.size(), 1U); - return static_cast<DBusCommandProxy*>(command_instance->proxies_[0]); + CHECK_EQ(command_instance->observers_.size(), 1U); + return static_cast<DBusCommandProxy*>(command_instance->observers_[0]); } void FinishCommand(DBusCommandProxy* proxy) { proxy->Done(); }
diff --git a/libweave/src/commands/dbus_command_proxy.h b/libweave/src/commands/dbus_command_proxy.h index 6780766..3f802ed 100644 --- a/libweave/src/commands/dbus_command_proxy.h +++ b/libweave/src/commands/dbus_command_proxy.h
@@ -24,7 +24,7 @@ class CommandInstance; -class DBusCommandProxy : public CommandProxyInterface, +class DBusCommandProxy : public CommandObserver, public org::chromium::Buffet::CommandInterface { public: DBusCommandProxy(chromeos::dbus_utils::ExportedObjectManager* object_manager,
diff --git a/libweave/src/commands/dbus_command_proxy_unittest.cc b/libweave/src/commands/dbus_command_proxy_unittest.cc index 7ae20ce..32a36b6 100644 --- a/libweave/src/commands/dbus_command_proxy_unittest.cc +++ b/libweave/src/commands/dbus_command_proxy_unittest.cc
@@ -109,9 +109,9 @@ EXPECT_CALL(*mock_exported_object_command_, ExportMethod(_, _, _, _)) .Times(AnyNumber()); - std::unique_ptr<CommandProxyInterface> command_proxy( + std::unique_ptr<CommandObserver> command_proxy( new DBusCommandProxy(nullptr, bus_, command_instance_.get(), cmd_path)); - command_instance_->AddProxy(command_proxy.release()); + command_instance_->AddObserver(command_proxy.release()); GetCommandProxy()->RegisterAsync( AsyncEventSequencer::GetDefaultCompletionAction()); } @@ -124,8 +124,8 @@ } DBusCommandProxy* GetCommandProxy() const { - CHECK_EQ(command_instance_->proxies_.size(), 1U); - return static_cast<DBusCommandProxy*>(command_instance_->proxies_[0]); + CHECK_EQ(command_instance_->observers_.size(), 1U); + return static_cast<DBusCommandProxy*>(command_instance_->observers_[0]); } org::chromium::Buffet::CommandAdaptor* GetCommandAdaptor() const {
diff --git a/libweave/src/device_registration_info.cc b/libweave/src/device_registration_info.cc index 340fb40..fdc933c 100644 --- a/libweave/src/device_registration_info.cc +++ b/libweave/src/device_registration_info.cc
@@ -938,13 +938,10 @@ << "' arrived, ID: " << command_instance->GetID(); std::unique_ptr<chromeos::BackoffEntry> backoff_entry{ new chromeos::BackoffEntry{cloud_backoff_policy_.get()}}; - std::unique_ptr<CommandProxyInterface> cloud_proxy{ - new CloudCommandProxy{command_instance.get(), - this, - state_manager_->GetStateChangeQueue(), - std::move(backoff_entry), - task_runner_}}; - command_instance->AddProxy(cloud_proxy.release()); + std::unique_ptr<CommandObserver> cloud_proxy{new CloudCommandProxy{ + command_instance.get(), this, state_manager_->GetStateChangeQueue(), + std::move(backoff_entry), task_runner_}}; + command_instance->AddObserver(cloud_proxy.release()); command_manager_->AddCommand(std::move(command_instance)); } }