buffet: Multiple listeners of add/remove new command.
Replace CommandDispatchInterface with callbacks.
Lists of callbacks in CommandQueue.
BUG=brillo:697
TEST=FEATURE=test emerge-gizmo buffet
Change-Id: I3c164c8c7c2cb098b896aa8d5c9a99d856b05172
Reviewed-on: https://chromium-review.googlesource.com/270350
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Tested-by: Vitaly Buka <vitalybuka@chromium.org>
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/dbus_command_dispatcher.cc b/buffet/commands/dbus_command_dispatcher.cc
index 457ea88..2f5333c 100644
--- a/buffet/commands/dbus_command_dispatcher.cc
+++ b/buffet/commands/dbus_command_dispatcher.cc
@@ -7,6 +7,7 @@
#include <chromeos/dbus/exported_object_manager.h>
#include "buffet/commands/command_instance.h"
+#include "buffet/commands/dbus_command_proxy.h"
#include "buffet/dbus_constants.h"
using chromeos::dbus_utils::AsyncEventSequencer;
@@ -15,30 +16,18 @@
namespace buffet {
DBusCommandDispacher::DBusCommandDispacher(
- const scoped_refptr<dbus::Bus>& bus,
- ExportedObjectManager* object_manager)
- : bus_(bus), next_id_(0) {
- if (object_manager)
- object_manager_ = object_manager->AsWeakPtr();
+ const base::WeakPtr<ExportedObjectManager>& object_manager)
+ : object_manager_{object_manager} {
}
void DBusCommandDispacher::OnCommandAdded(CommandInstance* command_instance) {
- auto proxy = CreateDBusCommandProxy(command_instance);
+ if (!object_manager_)
+ return;
+ std::unique_ptr<DBusCommandProxy> proxy{new DBusCommandProxy(
+ object_manager_.get(), object_manager_->GetBus(), command_instance,
+ dbus_constants::kCommandServicePathPrefix + std::to_string(++next_id_))};
proxy->RegisterAsync(AsyncEventSequencer::GetDefaultCompletionAction());
command_instance->AddProxy(std::move(proxy));
}
-void DBusCommandDispacher::OnCommandRemoved(CommandInstance* command_instance) {
-}
-
-std::unique_ptr<DBusCommandProxy> DBusCommandDispacher::CreateDBusCommandProxy(
- CommandInstance* command_instance) {
- return std::unique_ptr<DBusCommandProxy>(
- new DBusCommandProxy(object_manager_.get(),
- bus_,
- command_instance,
- dbus_constants::kCommandServicePathPrefix +
- std::to_string(++next_id_)));
-}
-
} // namespace buffet