buffet: Add DBusCommandDispacher and hook it up to CommandQueue
Added DBusCommandDispacher class that maintains DBusCommandProxy object
for each instance of CommandInstance class added to the CommandQueue.
As soon as a command instance is removed from the queue, D-Bus command
dispatcher removes the corresponding command proxy object from D-Bus.
BUG=chromium:374864
TEST=FEATURES=test emerge-link buffet
Change-Id: Ib7ce7370bd3ee471e22f02b8546675021ff063d7
Reviewed-on: https://chromium-review.googlesource.com/211642
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_manager.cc b/buffet/commands/command_manager.cc
index 3d55906..ae105b8 100644
--- a/buffet/commands/command_manager.cc
+++ b/buffet/commands/command_manager.cc
@@ -8,13 +8,26 @@
#include <base/files/file_enumerator.h>
#include <base/json/json_reader.h>
#include <base/values.h>
+#include <chromeos/dbus/exported_object_manager.h>
#include <chromeos/errors/error.h>
#include <chromeos/errors/error_codes.h>
#include "buffet/commands/schema_constants.h"
+using chromeos::dbus_utils::ExportedObjectManager;
+
namespace buffet {
+CommandManager::CommandManager() {
+ command_queue_.SetCommandDispachInterface(&command_dispatcher_);
+}
+
+CommandManager::CommandManager(
+ const base::WeakPtr<ExportedObjectManager>& object_manager)
+ : command_dispatcher_(object_manager->GetBus(), object_manager.get()) {
+ command_queue_.SetCommandDispachInterface(&command_dispatcher_);
+}
+
const CommandDictionary& CommandManager::GetCommandDictionary() const {
return dictionary_;
}
@@ -104,4 +117,9 @@
return std::unique_ptr<const base::DictionaryValue>(dict_value);
}
+std::string CommandManager::AddCommand(
+ std::unique_ptr<CommandInstance> command_instance) {
+ return command_queue_.Add(std::move(command_instance));
+}
+
} // namespace buffet