blob: ff039b8c1cc711bd4f7b4332f11c691193663611 [file] [log] [blame]
Christopher Wileycc8ce0e2015-10-01 16:48:47 -07001//
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
21using update_engine::UpdateStatus;
22
23namespace chromeos_update_engine {
24
25const char* UpdateStatusToString(const UpdateStatus& status) {
26 switch (status) {
27 case UpdateStatus::IDLE:
28 return update_engine::kUpdateStatusIdle;
29 case UpdateStatus::CHECKING_FOR_UPDATE:
30 return update_engine::kUpdateStatusCheckingForUpdate;
31 case UpdateStatus::UPDATE_AVAILABLE:
32 return update_engine::kUpdateStatusUpdateAvailable;
33 case UpdateStatus::DOWNLOADING:
34 return update_engine::kUpdateStatusDownloading;
35 case UpdateStatus::VERIFYING:
36 return update_engine::kUpdateStatusVerifying;
37 case UpdateStatus::FINALIZING:
38 return update_engine::kUpdateStatusFinalizing;
39 case UpdateStatus::UPDATED_NEED_REBOOT:
40 return update_engine::kUpdateStatusUpdatedNeedReboot;
41 case UpdateStatus::REPORTING_ERROR_EVENT:
42 return update_engine::kUpdateStatusReportingErrorEvent;
43 case UpdateStatus::ATTEMPTING_ROLLBACK:
44 return update_engine::kUpdateStatusAttemptingRollback;
45 case UpdateStatus::DISABLED:
46 return update_engine::kUpdateStatusDisabled;
47 }
48
49 NOTREACHED();
50 return nullptr;
51}
52
Christopher Wiley3f97b5d2015-10-01 17:17:41 -070053bool StringToUpdateStatus(const std::string& s,
54 UpdateStatus* status) {
55 if (s == update_engine::kUpdateStatusIdle) {
56 *status = UpdateStatus::IDLE;
57 return true;
58 } else if (s == update_engine::kUpdateStatusCheckingForUpdate) {
59 *status = UpdateStatus::CHECKING_FOR_UPDATE;
60 return true;
61 } else if (s == update_engine::kUpdateStatusUpdateAvailable) {
62 *status = UpdateStatus::UPDATE_AVAILABLE;
63 return true;
64 } else if (s == update_engine::kUpdateStatusDownloading) {
65 *status = UpdateStatus::DOWNLOADING;
66 return true;
67 } else if (s == update_engine::kUpdateStatusVerifying) {
68 *status = UpdateStatus::VERIFYING;
69 return true;
70 } else if (s == update_engine::kUpdateStatusFinalizing) {
71 *status = UpdateStatus::FINALIZING;
72 return true;
73 } else if (s == update_engine::kUpdateStatusUpdatedNeedReboot) {
74 *status = UpdateStatus::UPDATED_NEED_REBOOT;
75 return true;
76 } else if (s == update_engine::kUpdateStatusReportingErrorEvent) {
77 *status = UpdateStatus::REPORTING_ERROR_EVENT;
78 return true;
79 } else if (s == update_engine::kUpdateStatusAttemptingRollback) {
80 *status = UpdateStatus::ATTEMPTING_ROLLBACK;
81 return true;
82 } else if (s == update_engine::kUpdateStatusDisabled) {
83 *status = UpdateStatus::DISABLED;
84 return true;
85 }
86 return false;
87}
88
Christopher Wileycc8ce0e2015-10-01 16:48:47 -070089} // namespace chromeos_update_engine