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_updater.h"
25#include "page.h"
26#include "updater_ui.h"
27#include "view_api.h"
28
29namespace Updater {
30class PageManager final {
31    DISALLOW_COPY_MOVE(PageManager);
32public:
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    std::string GetCurPageId();
43#ifdef UPDATER_UT
44    std::vector<std::string> Report();
45#endif
46private:
47    PageManager() = default;
48    ~PageManager() = default;
49    bool InitImpl(UxPageInfo &pageInfo, std::string_view entry);
50    void EnQueuePage(const std::shared_ptr<Page> &page);
51    bool BuildSubPages(const std::string &pageId, const std::shared_ptr<Page> &basePage,
52        std::vector<UxSubPageInfo> &subPageInfos, std::string_view entry);
53    bool IsValidPage(const std::shared_ptr<Page> &pg) const;
54    static constexpr size_t MAX_PAGE_QUEUE_SZ = 3;
55    std::deque<std::shared_ptr<Page>> pageQueue_ {};
56    std::unordered_map<std::string, std::shared_ptr<Page>> pageMap_ {};
57    std::vector<std::shared_ptr<Page>> pages_ {};
58    std::shared_ptr<Page> curPage_ {};
59    std::shared_ptr<Page> mainPage_ {};
60};
61} // namespace Updater
62#endif
63