bmc: provide state change method
The state change method will allow pushing any state change logic that's
required into a convenient point where all state changes intersect.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Id44a5180bc8d901ce19da69b9b0362dc9f5fb630
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index e879529..4967536 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -233,12 +233,12 @@
{
if (item->second->activePath == verifyBlobId)
{
- state = UpdateState::verificationCompleted;
+ changeState(UpdateState::verificationCompleted);
}
else
{
/* item->second->activePath == updateBlobId */
- state = UpdateState::updateCompleted;
+ changeState(UpdateState::updateCompleted);
}
item->second->flags &= ~blobs::StateFlags::committing;
@@ -472,7 +472,7 @@
addBlobId(*active);
removeBlobId(verifyBlobId);
- state = UpdateState::uploadInProgress;
+ changeState(UpdateState::uploadInProgress);
fileOpen = true;
return true;
@@ -637,7 +637,7 @@
{
case UpdateState::uploadInProgress:
/* They are closing a data pathway (image, tarball, hash). */
- state = UpdateState::verificationPending;
+ changeState(UpdateState::verificationPending);
/* Add verify blob ID now that we can expect it. */
addBlobId(verifyBlobId);
@@ -656,7 +656,7 @@
case UpdateState::verificationCompleted:
if (lastVerificationStatus == ActionStatus::success)
{
- state = UpdateState::updatePending;
+ changeState(UpdateState::updatePending);
addBlobId(updateBlobId);
removeBlobId(verifyBlobId);
}
@@ -709,6 +709,11 @@
return true;
}
+void FirmwareBlobHandler::changeState(UpdateState next)
+{
+ state = next;
+}
+
bool FirmwareBlobHandler::expire(uint16_t session)
{
return false;
@@ -735,7 +740,7 @@
removeBlobId(activeImageBlobId);
removeBlobId(activeHashBlobId);
- state = UpdateState::notYetStarted;
+ changeState(UpdateState::notYetStarted);
}
void FirmwareBlobHandler::abortVerification()
@@ -748,7 +753,7 @@
bool result = verification->trigger();
if (result)
{
- state = UpdateState::verificationStarted;
+ changeState(UpdateState::verificationStarted);
}
return result;
@@ -764,7 +769,7 @@
bool result = update->trigger();
if (result)
{
- state = UpdateState::updateStarted;
+ changeState(UpdateState::updateStarted);
}
return result;
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index 0d86ef0..de37e20 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -167,6 +167,9 @@
return state;
};
+ /** Provide for any state change triggers in convenience handler. */
+ void changeState(UpdateState next);
+
private:
void addBlobId(const std::string& blob)
{