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_unittest.cc b/buffet/commands/command_queue_unittest.cc
index a9d5ad9..ce81ea4 100644
--- a/buffet/commands/command_queue_unittest.cc
+++ b/buffet/commands/command_queue_unittest.cc
@@ -14,9 +14,9 @@
namespace {
-std::unique_ptr<const buffet::CommandInstance> CreateDummyCommandInstance(
+std::unique_ptr<buffet::CommandInstance> CreateDummyCommandInstance(
const std::string& name = "base.reboot") {
- return std::unique_ptr<const buffet::CommandInstance>(
+ return std::unique_ptr<buffet::CommandInstance>(
new buffet::CommandInstance(name, "powerd", {}));
}
@@ -25,20 +25,16 @@
// Aborts if duplicate commands are added or non-existent commands are removed.
class FakeDispatchInterface : public buffet::CommandDispachInterface {
public:
- void OnCommandAdded(
- const std::string& command_id,
- const buffet::CommandInstance* command_instance) override {
- CHECK(ids_.insert(command_id).second)
- << "Command ID already exists: " << command_id;
+ void OnCommandAdded(buffet::CommandInstance* command_instance) override {
+ CHECK(ids_.insert(command_instance->GetID()).second)
+ << "Command ID already exists: " << command_instance->GetID();
CHECK(commands_.insert(command_instance).second)
<< "Command instance already exists";
}
- void OnCommandRemoved(
- const std::string& command_id,
- const buffet::CommandInstance* command_instance) override {
- CHECK_EQ(1, ids_.erase(command_id))
- << "Command ID not found: " << command_id;
+ void OnCommandRemoved(buffet::CommandInstance* command_instance) override {
+ CHECK_EQ(1, ids_.erase(command_instance->GetID()))
+ << "Command ID not found: " << command_instance->GetID();
CHECK_EQ(1, commands_.erase(command_instance))
<< "Command instance not found";
}
@@ -52,7 +48,7 @@
private:
std::set<std::string> ids_;
- std::set<const buffet::CommandInstance*> commands_;
+ std::set<buffet::CommandInstance*> commands_;
};
} // anonymous namespace
@@ -116,7 +112,9 @@
auto cmd1 = queue.Find(id1);
EXPECT_NE(nullptr, cmd1);
EXPECT_EQ("base.reboot", cmd1->GetName());
+ EXPECT_EQ(id1, cmd1->GetID());
auto cmd2 = queue.Find(id2);
EXPECT_NE(nullptr, cmd2);
EXPECT_EQ("base.shutdown", cmd2->GetName());
+ EXPECT_EQ(id2, cmd2->GetID());
}