aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Wiley <wiley@google.com>2015-10-01 17:17:41 -0700
committerChristopher Wiley <wiley@google.com>2015-10-05 12:42:31 -0700
commit3f97b5d26350ae4e3029c148189e88b15805bf25 (patch)
treede25886761f6d224542ae5a55db28fbd27e51708
parentcc8ce0e3b11ac76412c26c687d11140cbe18ad91 (diff)
downloadupdate_engine-3f97b5d26350ae4e3029c148189e88b15805bf25.tar.gz
Add helper to convert strings to UpdateStatus values
This is useful for decyphering the statuses returned over the DBus interface. Bug: 24547247 Test: mmm system/update_engine; emerge-panther update_engine Change-Id: Ifce74450209a7e7cb632c2fee7b54364ffaf3ff5
-rw-r--r--update_status_utils.cc36
-rw-r--r--update_status_utils.h5
2 files changed, 41 insertions, 0 deletions
diff --git a/update_status_utils.cc b/update_status_utils.cc
index c1504fd4..ff039b8c 100644
--- a/update_status_utils.cc
+++ b/update_status_utils.cc
@@ -50,4 +50,40 @@ const char* UpdateStatusToString(const UpdateStatus& status) {
return nullptr;
}
+bool StringToUpdateStatus(const std::string& s,
+ UpdateStatus* status) {
+ if (s == update_engine::kUpdateStatusIdle) {
+ *status = UpdateStatus::IDLE;
+ return true;
+ } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
+ *status = UpdateStatus::CHECKING_FOR_UPDATE;
+ return true;
+ } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
+ *status = UpdateStatus::UPDATE_AVAILABLE;
+ return true;
+ } else if (s == update_engine::kUpdateStatusDownloading) {
+ *status = UpdateStatus::DOWNLOADING;
+ return true;
+ } else if (s == update_engine::kUpdateStatusVerifying) {
+ *status = UpdateStatus::VERIFYING;
+ return true;
+ } else if (s == update_engine::kUpdateStatusFinalizing) {
+ *status = UpdateStatus::FINALIZING;
+ return true;
+ } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
+ *status = UpdateStatus::UPDATED_NEED_REBOOT;
+ return true;
+ } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
+ *status = UpdateStatus::REPORTING_ERROR_EVENT;
+ return true;
+ } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
+ *status = UpdateStatus::ATTEMPTING_ROLLBACK;
+ return true;
+ } else if (s == update_engine::kUpdateStatusDisabled) {
+ *status = UpdateStatus::DISABLED;
+ return true;
+ }
+ return false;
+}
+
} // namespace chromeos_update_engine
diff --git a/update_status_utils.h b/update_status_utils.h
index 8a07ebe3..78d35302 100644
--- a/update_status_utils.h
+++ b/update_status_utils.h
@@ -17,12 +17,17 @@
#ifndef CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_
#define CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_
+#include <string>
+
#include "update_engine/update_status.h"
namespace chromeos_update_engine {
const char* UpdateStatusToString(const update_engine::UpdateStatus& status);
+bool StringToUpdateStatus(const std::string& update_status_as_string,
+ update_engine::UpdateStatus* status);
+
} // namespace chromeos_update_engine
#endif // CLIENT_LIBRARY_UPDATE_STATUS_TO_STRING_H_