Add callback support to triggerable actions
Change-Id: Icc27fbe9403eda418f41e12c76af7f3216f4b72a
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/bmc/firmware-handler/test/firmware_skip_unittest.cpp b/bmc/firmware-handler/test/firmware_skip_unittest.cpp
index a549582..243380d 100644
--- a/bmc/firmware-handler/test/firmware_skip_unittest.cpp
+++ b/bmc/firmware-handler/test/firmware_skip_unittest.cpp
@@ -13,7 +13,12 @@
{
SkipAction skip;
EXPECT_TRUE(skip.trigger());
+ size_t i = 0;
+ skip.setCallback([&](TriggerableActionInterface&) { i++; });
EXPECT_TRUE(skip.trigger());
+ EXPECT_EQ(1, i);
+ EXPECT_TRUE(skip.trigger());
+ EXPECT_EQ(2, i);
}
TEST(SkipActionTest, ValidateStatusAlwaysSuccess)
diff --git a/bmc/general_systemd.cpp b/bmc/general_systemd.cpp
index 3c59c11..ecd15d4 100644
--- a/bmc/general_systemd.cpp
+++ b/bmc/general_systemd.cpp
@@ -144,6 +144,11 @@
job = std::nullopt;
currentStatus =
result == "done" ? ActionStatus::success : ActionStatus::failed;
+
+ if (cb)
+ {
+ cb(*this);
+ }
}
std::unique_ptr<TriggerableActionInterface>
diff --git a/bmc/skip_action.cpp b/bmc/skip_action.cpp
index 4392e97..f1a67e0 100644
--- a/bmc/skip_action.cpp
+++ b/bmc/skip_action.cpp
@@ -26,4 +26,21 @@
return std::make_unique<SkipAction>();
}
+bool SkipAction::trigger()
+{
+ if (cb)
+ {
+ cb(*this);
+ }
+ return true;
+}
+
+void SkipAction::abort()
+{}
+
+ActionStatus SkipAction::status()
+{
+ return ActionStatus::success;
+}
+
} // namespace ipmi_flash
diff --git a/bmc/skip_action.hpp b/bmc/skip_action.hpp
index 65fcfc8..4fc9462 100644
--- a/bmc/skip_action.hpp
+++ b/bmc/skip_action.hpp
@@ -23,16 +23,9 @@
SkipAction(SkipAction&&) = default;
SkipAction& operator=(SkipAction&&) = default;
- bool trigger() override
- {
- return true;
- }
- void abort() override
- {}
- ActionStatus status() override
- {
- return ActionStatus::success;
- }
+ bool trigger() override;
+ void abort() override;
+ ActionStatus status() override;
};
} // namespace ipmi_flash
diff --git a/bmc/test/triggerable_mock.hpp b/bmc/test/triggerable_mock.hpp
index 9a63dcb..de2b025 100644
--- a/bmc/test/triggerable_mock.hpp
+++ b/bmc/test/triggerable_mock.hpp
@@ -18,6 +18,7 @@
MOCK_METHOD0(trigger, bool());
MOCK_METHOD0(abort, void());
MOCK_METHOD0(status, ActionStatus());
+ using TriggerableActionInterface::cb;
};
std::unique_ptr<TriggerableActionInterface> CreateTriggerMock()