• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 PAGE_MANANGER_H
17 #define PAGE_MANANGER_H
18 
19 #include <filesystem>
20 #include <stack>
21 #include <string_view>
22 #include <vector>
23 #include "base_page.h"
24 #include "macros.h"
25 #include "page.h"
26 #include "updater_ui.h"
27 #include "view_api.h"
28 
29 namespace Updater {
30 class PageManager final {
31     DISALLOW_COPY_MOVE(PageManager);
32 public:
33     static PageManager &GetInstance();
34     bool Init(std::vector<UxPageInfo> &pageInfos, std::string_view entry);
35     bool ShowPage(const std::string &id);
36     void GoBack();
37     bool IsValidCom(const ComInfo &pageComId) const;
38     Page &operator[](const std::string &id) const;
39     void ShowMainPage();
40     ViewProxy &operator[](const ComInfo &comInfo) const;
41     void Reset();
42 #ifdef UPDATER_UT
43     std::vector<std::string> Report();
44 #endif
45 private:
46     PageManager() = default;
47     ~PageManager() = default;
48     bool InitImpl(UxPageInfo &pageInfo, std::string_view entry);
49     void EnQueuePage(const std::shared_ptr<Page> &page);
50     bool BuildSubPages(const std::string &pageId, const std::shared_ptr<Page> &basePage,
51         std::vector<UxSubPageInfo> &subPageInfos, std::string_view entry);
52     bool IsValidPage(const std::shared_ptr<Page> &pg) const;
53     static constexpr size_t MAX_PAGE_QUEUE_SZ = 3;
54     std::deque<std::shared_ptr<Page>> pageQueue_ {};
55     std::unordered_map<std::string, std::shared_ptr<Page>> pageMap_ {};
56     std::vector<std::shared_ptr<Page>> pages_ {};
57     std::shared_ptr<Page> curPage_ {};
58     std::shared_ptr<Page> mainPage_ {};
59 };
60 } // namespace Updater
61 #endif
62