1fb299fa2Sopenharmony_ci/*
2fb299fa2Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at
6fb299fa2Sopenharmony_ci *
7fb299fa2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb299fa2Sopenharmony_ci *
9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and
13fb299fa2Sopenharmony_ci * limitations under the License.
14fb299fa2Sopenharmony_ci */
15fb299fa2Sopenharmony_ci
16fb299fa2Sopenharmony_ci#ifndef PAGE_MANANGER_H
17fb299fa2Sopenharmony_ci#define PAGE_MANANGER_H
18fb299fa2Sopenharmony_ci
19fb299fa2Sopenharmony_ci#include <filesystem>
20fb299fa2Sopenharmony_ci#include <stack>
21fb299fa2Sopenharmony_ci#include <string_view>
22fb299fa2Sopenharmony_ci#include <vector>
23fb299fa2Sopenharmony_ci#include "base_page.h"
24fb299fa2Sopenharmony_ci#include "macros_updater.h"
25fb299fa2Sopenharmony_ci#include "page.h"
26fb299fa2Sopenharmony_ci#include "updater_ui.h"
27fb299fa2Sopenharmony_ci#include "view_api.h"
28fb299fa2Sopenharmony_ci
29fb299fa2Sopenharmony_cinamespace Updater {
30fb299fa2Sopenharmony_ciclass PageManager final {
31fb299fa2Sopenharmony_ci    DISALLOW_COPY_MOVE(PageManager);
32fb299fa2Sopenharmony_cipublic:
33fb299fa2Sopenharmony_ci    static PageManager &GetInstance();
34fb299fa2Sopenharmony_ci    bool Init(std::vector<UxPageInfo> &pageInfos, std::string_view entry);
35fb299fa2Sopenharmony_ci    bool ShowPage(const std::string &id);
36fb299fa2Sopenharmony_ci    void GoBack();
37fb299fa2Sopenharmony_ci    bool IsValidCom(const ComInfo &pageComId) const;
38fb299fa2Sopenharmony_ci    Page &operator[](const std::string &id) const;
39fb299fa2Sopenharmony_ci    void ShowMainPage();
40fb299fa2Sopenharmony_ci    ViewProxy &operator[](const ComInfo &comInfo) const;
41fb299fa2Sopenharmony_ci    void Reset();
42fb299fa2Sopenharmony_ci    std::string GetCurPageId();
43fb299fa2Sopenharmony_ci#ifdef UPDATER_UT
44fb299fa2Sopenharmony_ci    std::vector<std::string> Report();
45fb299fa2Sopenharmony_ci#endif
46fb299fa2Sopenharmony_ciprivate:
47fb299fa2Sopenharmony_ci    PageManager() = default;
48fb299fa2Sopenharmony_ci    ~PageManager() = default;
49fb299fa2Sopenharmony_ci    bool InitImpl(UxPageInfo &pageInfo, std::string_view entry);
50fb299fa2Sopenharmony_ci    void EnQueuePage(const std::shared_ptr<Page> &page);
51fb299fa2Sopenharmony_ci    bool BuildSubPages(const std::string &pageId, const std::shared_ptr<Page> &basePage,
52fb299fa2Sopenharmony_ci        std::vector<UxSubPageInfo> &subPageInfos, std::string_view entry);
53fb299fa2Sopenharmony_ci    bool IsValidPage(const std::shared_ptr<Page> &pg) const;
54fb299fa2Sopenharmony_ci    static constexpr size_t MAX_PAGE_QUEUE_SZ = 3;
55fb299fa2Sopenharmony_ci    std::deque<std::shared_ptr<Page>> pageQueue_ {};
56fb299fa2Sopenharmony_ci    std::unordered_map<std::string, std::shared_ptr<Page>> pageMap_ {};
57fb299fa2Sopenharmony_ci    std::vector<std::shared_ptr<Page>> pages_ {};
58fb299fa2Sopenharmony_ci    std::shared_ptr<Page> curPage_ {};
59fb299fa2Sopenharmony_ci    std::shared_ptr<Page> mainPage_ {};
60fb299fa2Sopenharmony_ci};
61fb299fa2Sopenharmony_ci} // namespace Updater
62fb299fa2Sopenharmony_ci#endif
63