• 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 STAGE_CONTEXT_H
17 #define STAGE_CONTEXT_H
18 
19 #include <string>
20 #include <vector>
21 #include "JsonReader.h"
22 
23 namespace OHOS::Ide {
24 struct SkillInfo {
25     std::vector<std::string> actions;
26     std::vector<std::string> entities;
27 };
28 
29 struct AbilityInfo {
30     std::string description;
31     uint32_t descriptionId;
32     bool exported = false;
33     std::string icon;
34     uint32_t iconId = 0;
35     std::string label;
36     uint32_t labelId = 0;
37     std::string name;
38     std::vector<SkillInfo> skills;
39     std::string srcEntrty;
40     std::string startWindowBackground;
41     uint32_t startWindowBackgroundId;
42     std::string startWindowIcon;
43     uint32_t startWindowIconId;
44 };
45 
46 struct HapModuleInfo {
47     std::vector<AbilityInfo> abilities;
48     std::string compileMode;
49     bool deliveryWithInstall = false;
50     std::vector<std::string> dependencies;
51     std::string description;
52     uint32_t descriptionId;
53     std::vector<std::string> deviceTypes;
54     bool installationFree = false;
55     std::string mainElement;
56     std::string name;
57     std::string pages;
58     std::string type;
59     std::string virtualMachine;
60     std::string srcEntry;
61     // from arkui
62     bool isPartialUpdate = true;
63     uint32_t labelId = 0;
64 };
65 
66 struct AppInfo {
67     // form mudule.json
68     std::string apiReleaseType;
69     std::string bundleName;
70     std::string compileSdkType;
71     std::string compileSdkVersion;
72     bool debug = false;
73     std::string icon;
74     uint32_t iconId = 0;
75     std::string label;
76     uint32_t labelId = 0;
77     uint32_t minAPIVersion = 0;
78     uint32_t targetAPIVersion = 0;
79     std::string vendor;
80     uint32_t versionCode = 0;
81     std::string versionName;
82     // from arkui
83     std::string bundleType;
84     bool distributedNotificationEnabled = true;
85 };
86 
87 class StageContext {
88 public:
89     static StageContext& GetInstance();
90     void ParseJsonFile(const std::string& filePath);
91     void ParseAppInfo(const Json::Value& root);
92     void ParseHapModuleInfo(const Json::Value& root);
93     void ParseAbilityInfo(const Json::Value& root);
94     void ParseSkillsInfo(const std::unique_ptr<Json::Value>& skillsArr, std::vector<SkillInfo>& skills);
95     const AppInfo& GetAppInfo() const;
96     const HapModuleInfo& GetHapModuleInfo() const;
97     const AbilityInfo& GetAbilityInfo(const std::string srcEntryVal) const;
98 private:
99     StageContext() = default;
100     ~StageContext() = default;
101     AppInfo appInfo;
102     HapModuleInfo hapModuleInfo;
103 };
104 }
105 #endif // STAGE_CONTEXT_H