• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FIRMWARE_RESULT_PROCESS_H
17 #define FIRMWARE_RESULT_PROCESS_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 #include <unistd.h>
23 
24 #include "firmware_component.h"
25 
26 namespace OHOS {
27 namespace UpdateEngine {
28 const std::string UPDATER_RESULT_SUCCESS = "pass";
29 const std::string UPDATER_RESULT_FAILURE = "fail";
30 const std::string UPDATER_RESULT_FAILURE_REASON = "compare version fail";
31 const std::string UPDATER_RESULT_SUCCESS_REASON = "compare version success";
32 
33 enum class UpdateResultCode {
34     SUCCESS = 0,
35     FAILURE,
36     PART_SUCCESS
37 };
38 
39 enum class UpdateComponentResultCode {
40     SUCCESS = 0,
41     FAILURE,
42     UNEXECUTED
43 };
44 
45 struct UpdateResult {
46     std::string spath;
47     std::string result;
48     std::string reason;
49 
GetUpdateResultCodeUpdateResult50     UpdateComponentResultCode GetUpdateResultCode() const
51     {
52         if (result == UPDATER_RESULT_SUCCESS) {
53             return UpdateComponentResultCode::SUCCESS;
54         }
55         if (result == UPDATER_RESULT_FAILURE) {
56             return UpdateComponentResultCode::FAILURE;
57         }
58         return UpdateComponentResultCode::UNEXECUTED;
59     };
60 };
61 
62 class FirmwareResultProcess {
63 public:
64     UpdateResultCode GetUpdaterResult(const std::vector<FirmwareComponent> &components,
65         std::map<std::string, UpdateResult> &resultMap);
66 
67 private:
68     UpdateResult CompareVersion(const FirmwareComponent &component);
69     void ParseUpdaterResultRecord(const std::string &resultLine, std::map<std::string, UpdateResult> &resultMap);
70     void HandleFileError(std::map<std::string, UpdateResult> &resultMap,
71         const std::vector<FirmwareComponent> &components);
72     UpdateResultCode HandleFileResults(std::map<std::string, UpdateResult> &resultMap,
73         const std::vector<FirmwareComponent> &components);
74 };
75 } // namespace UpdateEngine
76 } // namespace OHOS
77 #endif // FIRMWARE_RESULT_PROCESS_H