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.h b/buffet/commands/dbus_command_dispatcher.h
index 35d258b..ab63a6c 100644
--- a/buffet/commands/dbus_command_dispatcher.h
+++ b/buffet/commands/dbus_command_dispatcher.h
@@ -10,10 +10,6 @@
#include <base/macros.h>
#include <base/memory/weak_ptr.h>
-#include <dbus/bus.h>
-
-#include "buffet/commands/command_dispatch_interface.h"
-#include "buffet/commands/dbus_command_proxy.h"
namespace chromeos {
namespace dbus_utils {
@@ -23,37 +19,29 @@
namespace buffet {
-// Implements D-Bus dispatch of commands. When OnCommandAdded is called over
-// CommandDispachInterface, DBusCommandDispacher creates an instance of
-// DBusCommandProxy object and advertises it through ExportedObjectManager on
-// D-Bus. Command handling processes can watch the new D-Bus object appear
-// and communicate with it to update the command handling progress.
-// Once command is handled, DBusCommandProxy::Done() is called and the command
-// is removed from the command queue and D-Bus ExportedObjectManager.
-class DBusCommandDispacher : public CommandDispachInterface {
+class CommandInstance;
+
+// Implements D-Bus dispatch of commands. When OnCommandAdded is called,
+// DBusCommandDispacher creates an instance of DBusCommandProxy object and
+// advertises it through ExportedObjectManager on D-Bus. Command handling
+// processes can watch the new D-Bus object appear and communicate with it to
+// update the command handling progress. Once command is handled,
+// DBusCommandProxy::Done() is called and the command is removed from the
+// command queue and D-Bus ExportedObjectManager.
+class DBusCommandDispacher {
public:
- DBusCommandDispacher(
- const scoped_refptr<dbus::Bus>& bus,
- chromeos::dbus_utils::ExportedObjectManager* object_manager = nullptr);
- virtual ~DBusCommandDispacher() = default;
+ explicit DBusCommandDispacher(const base::WeakPtr<
+ chromeos::dbus_utils::ExportedObjectManager>& object_manager);
- // CommandDispachInterface overrides. Called by CommandQueue.
- void OnCommandAdded(CommandInstance* command_instance) override;
- void OnCommandRemoved(CommandInstance* command_instance) override;
-
- protected:
- virtual std::unique_ptr<DBusCommandProxy> CreateDBusCommandProxy(
- CommandInstance* command_instance);
+ void OnCommandAdded(CommandInstance* command_instance);
private:
- scoped_refptr<dbus::Bus> bus_;
base::WeakPtr<chromeos::dbus_utils::ExportedObjectManager> object_manager_;
- int next_id_;
+ int next_id_{0};
// Default constructor is used in special circumstances such as for testing.
DBusCommandDispacher() = default;
- friend class DBusCommandDispacherTest;
friend class CommandManager;
DISALLOW_COPY_AND_ASSIGN(DBusCommandDispacher);
};