• 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_INSTALL_H
17 #define FIRMWARE_INSTALL_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "error_message.h"
23 #include "firmware_common.h"
24 #include "firmware_component.h"
25 #include "progress.h"
26 
27 namespace OHOS {
28 namespace UpdateService {
29 constexpr int32_t SLEEP_INSTALL = 1;
30 
31 struct InstallProgress {
32     Progress progress;
33     uint32_t dealLen = 0;
34     ErrorMessage errMsg;
35 };
36 
37 using OnFirmwareProgress = std::function<void(const FirmwareComponent &component)>;
38 using OnFirmwareEvent = std::function<void(bool result, const ErrorMessage &errMsg, UpgradeStatus status)>;
39 using OnFirmwareStatus = std::function<void(UpgradeStatus status)>;
40 struct FirmwareInstallCallback {
41     OnFirmwareProgress onFirmwareProgress;
42     OnFirmwareEvent onFirmwareEvent;
43     OnFirmwareStatus onFirmwareStatus;
44 };
45 
46 class FirmwareInstall {
47 public:
48     virtual ~FirmwareInstall() = default;
49     void StartInstall(const std::vector<FirmwareComponent> &componentList, FirmwareInstallCallback &cb);
50 
51 private:
52     virtual bool IsComponentLegal(const std::vector<FirmwareComponent> &componentList) = 0;
53     virtual bool PerformInstall(const std::vector<FirmwareComponent> &componentList, UpgradeStatus &status) = 0;
54 
55     void SetIsInstalling(bool isInstalling);
56     bool IsInstalling();
57     void CallbackResult(FirmwareInstallCallback &cb, bool result, UpgradeStatus status);
58     void CallbackFailedResult(FirmwareInstallCallback &cb, const std::string &errorMsg, int32_t errCode);
59 
60 protected:
61     FirmwareInstallCallback onInstallCallback_;
62     ErrorMessage errMsg_;
63 
64 private:
65     std::mutex mutex_;
66     bool isInstalling_ = false;
67 };
68 } // namespace UpdateService
69 } // namespace OHOS
70 #endif // FIRMWARE_INSTALL_H