buffet: Add an abstract command dispatch interface
Added simple framework for implementing command dispatch from
buffet to command-handling daemons which concrete delivery
layers, such as D-Bus, can use to actually implement the command
delivery.
Also changed some CommandQueue unit tests to remove the
implementation detail knowledge of how the command IDs are generated.
BUG=chromium:374864
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2
Change-Id: Ic7a719a09e924fefedc72cc0bb675adf1acd3713
Reviewed-on: https://chromium-review.googlesource.com/211485
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_queue.h b/buffet/commands/command_queue.h
index 3f269f1..e70fb8d 100644
--- a/buffet/commands/command_queue.h
+++ b/buffet/commands/command_queue.h
@@ -15,10 +15,19 @@
namespace buffet {
+class CommandDispachInterface;
+
class CommandQueue final {
public:
CommandQueue() = default;
+ // Sets a command dispatch notifications for changes in command queue.
+ // |dispatch_interface| must outlive the CommandQueue object instance
+ // or be nullptr.
+ void SetCommandDispachInterface(CommandDispachInterface* dispatch_interface) {
+ dispatch_interface_ = dispatch_interface;
+ }
+
// Checks if the command queue is empty.
bool IsEmpty() const { return map_.empty(); }
@@ -47,6 +56,8 @@
std::map<std::string, std::unique_ptr<const CommandInstance>> map_;
// Counter for generating unique command IDs.
int next_id_ = 0;
+ // Callback interface for command dispatch, if provided.
+ CommandDispachInterface* dispatch_interface_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(CommandQueue);
};