buffet: Add command ID to CommandInstance class
Rather than passing command ID along with CommandInstance class,
make it to be part of CommandInstance itself. When a command
instance is added to CommandQueue, the command queue will generate
a new ID and set it to the command instance.
Because CommandInstance, when saved in CommandQueue, is now mutable,
remove 'const' in a bunch of places to allow the command instance
to be modifiable.
BUG=chromium:374864
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2
Change-Id: Ia30dd4c9bd86b51694d9345dd91f6ed2ae0cb138
Reviewed-on: https://chromium-review.googlesource.com/213266
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_queue.h b/buffet/commands/command_queue.h
index e70fb8d..4e2706b 100644
--- a/buffet/commands/command_queue.h
+++ b/buffet/commands/command_queue.h
@@ -39,21 +39,21 @@
// has no relation to any GCD command identifiers or anything else. Just a
// unique key in this queue class.
// The ID string of the added command is returned by this method.
- std::string Add(std::unique_ptr<const CommandInstance> instance);
+ std::string Add(std::unique_ptr<CommandInstance> instance);
// Removes a command identified by |id| from the queue. Returns a unique
// pointer to the command instance if removed successfully, or an empty
// unique_ptr if the command with the given ID doesn't exist in the queue.
- std::unique_ptr<const CommandInstance> Remove(const std::string& id);
+ std::unique_ptr<CommandInstance> Remove(const std::string& id);
// Finds a command instance in the queue by the instance |id|. Returns
// nullptr if the command with the given |id| is not found. The returned
// pointer should not be persisted for a long period of time.
- const CommandInstance* Find(const std::string& id) const;
+ CommandInstance* Find(const std::string& id) const;
private:
// ID-to-CommandInstance map.
- std::map<std::string, std::unique_ptr<const CommandInstance>> map_;
+ std::map<std::string, std::unique_ptr<CommandInstance>> map_;
// Counter for generating unique command IDs.
int next_id_ = 0;
// Callback interface for command dispatch, if provided.