• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 UPDATER_UI_FACADE_H
17 #define UPDATER_UI_FACADE_H
18 
19 #include "macros.h"
20 #include "strategy/ui_strategy.h"
21 #include "updater_ui.h"
22 
23 namespace Updater {
24 class UpdaterUiFacade {
25     DISALLOW_COPY_MOVE(UpdaterUiFacade);
26     using StrategyMap = std::unordered_map<UpdaterMode, UiStrategyCfg>;
27 public:
28     UpdaterUiFacade();
29     ~UpdaterUiFacade() = default;
30     static UpdaterUiFacade &GetInstance();
31 
32     void InitEnv() const;
33 
34     [[nodiscard]] bool SetMode(UpdaterMode mode);
35     UpdaterMode GetMode() const;
36 
37     void ShowLog(const std::string &tag, bool isClear = false) const;
38     void ShowLogRes(const std::string &tag, bool isClear = false) const;
39     void ShowUpdInfo(const std::string &tag, bool isClear = false) const;
40     void ClearText() const;
41     void ClearLog() const;
42 
43     void ShowProgress(float value) const;
44     void ShowProgressPage() const;
45     void ShowSuccessPage() const;
46     void ShowFailedPage() const;
47     void ShowFactoryConfirmPage();
48     void ShowMainpage() const;
49     void ShowProgressWarning(bool isShow) const;
50     bool IsInProgress() const;
51 
52     void Sleep(int ms) const;
53     void SaveScreen() const;
54 private:
55     std::pair<bool, StrategyMap::const_iterator> CheckMode() const;
56     void SetLogoVisible(bool isVisible) const;
57     void SetProgressVisible(bool isVisible) const;
58     void ShowMsg(const ComInfo &id, const std::string &tag, bool isClear) const;
59     void ShowMsg(const ComInfo &id, const std::string &tag) const;
60 
61     void SetLogoProgress();
62     const StrategyMap &strategies_;
63     PageManager &pgMgr_;
64     UpdaterMode mode_;
65     std::unordered_map<UpdaterMode, std::unique_ptr<ProgressStrategy>> progressMap_ {};
66     std::unordered_map<UpdaterMode, std::unique_ptr<LogoStrategy>> logoMap_ {};
67 };
68 void OnKeyUpEvent();
69 void OnKeyDownEvent();
70 } // namespace Updater
71 #endif
72