| Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 1 | // | 
|  | 2 | // Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | // | 
|  | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | // you may not use this file except in compliance with the License. | 
|  | 6 | // You may obtain a copy of the License at | 
|  | 7 | // | 
|  | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | // | 
|  | 10 | // Unless required by applicable law or agreed to in writing, software | 
|  | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | // See the License for the specific language governing permissions and | 
|  | 14 | // limitations under the License. | 
|  | 15 | // | 
|  | 16 | #include "update_engine/update_status_utils.h" | 
|  | 17 |  | 
|  | 18 | #include <base/logging.h> | 
|  | 19 | #include <update_engine/dbus-constants.h> | 
|  | 20 |  | 
|  | 21 | using update_engine::UpdateStatus; | 
|  | 22 |  | 
| Alex Deymo | f7ead81 | 2015-10-23 17:37:27 -0700 | [diff] [blame] | 23 | namespace { | 
|  | 24 |  | 
|  | 25 | const char kWeaveStatusIdle[] = "idle"; | 
|  | 26 | const char kWeaveStatusCheckingForUpdate[] = "checkingForUpdate"; | 
|  | 27 | const char kWeaveStatusUpdateAvailable[] = "updateAvailable"; | 
|  | 28 | const char kWeaveStatusDownloading[] = "downloading"; | 
|  | 29 | const char kWeaveStatusVerifying[] = "verifying"; | 
|  | 30 | const char kWeaveStatusFinalizing[] = "finalizing"; | 
|  | 31 | const char kWeaveStatusUpdatedNeedReboot[] = "updatedNeedReboot"; | 
|  | 32 | const char kWeaveStatusReportingErrorEvent[] = "reportingErrorEvent"; | 
|  | 33 | const char kWeaveStatusAttemptingRollback[] = "attemptingRollback"; | 
|  | 34 | const char kWeaveStatusDisabled[] = "disabled"; | 
|  | 35 |  | 
|  | 36 | }  // namespace | 
|  | 37 |  | 
| Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 38 | namespace chromeos_update_engine { | 
|  | 39 |  | 
|  | 40 | const char* UpdateStatusToString(const UpdateStatus& status) { | 
|  | 41 | switch (status) { | 
|  | 42 | case UpdateStatus::IDLE: | 
|  | 43 | return update_engine::kUpdateStatusIdle; | 
|  | 44 | case UpdateStatus::CHECKING_FOR_UPDATE: | 
|  | 45 | return update_engine::kUpdateStatusCheckingForUpdate; | 
|  | 46 | case UpdateStatus::UPDATE_AVAILABLE: | 
|  | 47 | return update_engine::kUpdateStatusUpdateAvailable; | 
|  | 48 | case UpdateStatus::DOWNLOADING: | 
|  | 49 | return update_engine::kUpdateStatusDownloading; | 
|  | 50 | case UpdateStatus::VERIFYING: | 
|  | 51 | return update_engine::kUpdateStatusVerifying; | 
|  | 52 | case UpdateStatus::FINALIZING: | 
|  | 53 | return update_engine::kUpdateStatusFinalizing; | 
|  | 54 | case UpdateStatus::UPDATED_NEED_REBOOT: | 
|  | 55 | return update_engine::kUpdateStatusUpdatedNeedReboot; | 
|  | 56 | case UpdateStatus::REPORTING_ERROR_EVENT: | 
|  | 57 | return update_engine::kUpdateStatusReportingErrorEvent; | 
|  | 58 | case UpdateStatus::ATTEMPTING_ROLLBACK: | 
|  | 59 | return update_engine::kUpdateStatusAttemptingRollback; | 
|  | 60 | case UpdateStatus::DISABLED: | 
|  | 61 | return update_engine::kUpdateStatusDisabled; | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | NOTREACHED(); | 
|  | 65 | return nullptr; | 
|  | 66 | } | 
|  | 67 |  | 
| Alex Deymo | f7ead81 | 2015-10-23 17:37:27 -0700 | [diff] [blame] | 68 | const char* UpdateStatusToWeaveStatus(const UpdateStatus& status) { | 
|  | 69 | switch (status) { | 
|  | 70 | case UpdateStatus::IDLE: | 
|  | 71 | return kWeaveStatusIdle; | 
|  | 72 | case UpdateStatus::CHECKING_FOR_UPDATE: | 
|  | 73 | return kWeaveStatusCheckingForUpdate; | 
|  | 74 | case UpdateStatus::UPDATE_AVAILABLE: | 
|  | 75 | return kWeaveStatusUpdateAvailable; | 
|  | 76 | case UpdateStatus::DOWNLOADING: | 
|  | 77 | return kWeaveStatusDownloading; | 
|  | 78 | case UpdateStatus::VERIFYING: | 
|  | 79 | return kWeaveStatusVerifying; | 
|  | 80 | case UpdateStatus::FINALIZING: | 
|  | 81 | return kWeaveStatusFinalizing; | 
|  | 82 | case UpdateStatus::UPDATED_NEED_REBOOT: | 
|  | 83 | return kWeaveStatusUpdatedNeedReboot; | 
|  | 84 | case UpdateStatus::REPORTING_ERROR_EVENT: | 
|  | 85 | return kWeaveStatusReportingErrorEvent; | 
|  | 86 | case UpdateStatus::ATTEMPTING_ROLLBACK: | 
|  | 87 | return kWeaveStatusAttemptingRollback; | 
|  | 88 | case UpdateStatus::DISABLED: | 
|  | 89 | return kWeaveStatusDisabled; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | NOTREACHED(); | 
|  | 93 | return nullptr; | 
|  | 94 | } | 
|  | 95 |  | 
| Christopher Wiley | 3f97b5d | 2015-10-01 17:17:41 -0700 | [diff] [blame] | 96 | bool StringToUpdateStatus(const std::string& s, | 
|  | 97 | UpdateStatus* status) { | 
|  | 98 | if (s == update_engine::kUpdateStatusIdle) { | 
|  | 99 | *status = UpdateStatus::IDLE; | 
|  | 100 | return true; | 
|  | 101 | } else if (s == update_engine::kUpdateStatusCheckingForUpdate) { | 
|  | 102 | *status = UpdateStatus::CHECKING_FOR_UPDATE; | 
|  | 103 | return true; | 
|  | 104 | } else if (s == update_engine::kUpdateStatusUpdateAvailable) { | 
|  | 105 | *status = UpdateStatus::UPDATE_AVAILABLE; | 
|  | 106 | return true; | 
|  | 107 | } else if (s == update_engine::kUpdateStatusDownloading) { | 
|  | 108 | *status = UpdateStatus::DOWNLOADING; | 
|  | 109 | return true; | 
|  | 110 | } else if (s == update_engine::kUpdateStatusVerifying) { | 
|  | 111 | *status = UpdateStatus::VERIFYING; | 
|  | 112 | return true; | 
|  | 113 | } else if (s == update_engine::kUpdateStatusFinalizing) { | 
|  | 114 | *status = UpdateStatus::FINALIZING; | 
|  | 115 | return true; | 
|  | 116 | } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) { | 
|  | 117 | *status = UpdateStatus::UPDATED_NEED_REBOOT; | 
|  | 118 | return true; | 
|  | 119 | } else if (s == update_engine::kUpdateStatusReportingErrorEvent) { | 
|  | 120 | *status = UpdateStatus::REPORTING_ERROR_EVENT; | 
|  | 121 | return true; | 
|  | 122 | } else if (s == update_engine::kUpdateStatusAttemptingRollback) { | 
|  | 123 | *status = UpdateStatus::ATTEMPTING_ROLLBACK; | 
|  | 124 | return true; | 
|  | 125 | } else if (s == update_engine::kUpdateStatusDisabled) { | 
|  | 126 | *status = UpdateStatus::DISABLED; | 
|  | 127 | return true; | 
|  | 128 | } | 
|  | 129 | return false; | 
|  | 130 | } | 
|  | 131 |  | 
| Christopher Wiley | cc8ce0e | 2015-10-01 16:48:47 -0700 | [diff] [blame] | 132 | }  // namespace chromeos_update_engine |