• 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 COMMANDPARSER_H
17 #define COMMANDPARSER_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 class CommandInfo {
24 public:
25     std::string deviceType;
26     std::string pages;
27     std::string appResourcePath;
28     bool isCardDisplay;
29     std::string containerSdkPath;
30     bool isComponentMode;
31     std::string loaderJsonPath;
32     std::string abilityPath;
33     std::string abilityName;
34     std::string configPath;
35     std::string screenShape;
36     int32_t orignalResolutionWidth;
37     int32_t orignalResolutionHeight;
38     int32_t compressionResolutionWidth;
39     int32_t compressionResolutionHeight;
40 };
41 
42 class FoldInfo {
43 public:
44     bool foldable;
45     std::string foldStatus;
46     int32_t foldResolutionWidth;
47     int32_t foldResolutionHeight;
48 };
49 
50 class CommandParser {
51 public:
52     CommandParser(const CommandParser&) = delete;
53     CommandParser& operator=(const CommandParser&) = delete;
54     static CommandParser& GetInstance();
55     bool ProcessCommand(std::vector<std::string> strs);
56     bool IsCommandValid();
57     bool IsSet(std::string key);
58     std::string Value(std::string key);
59     std::vector<std::string> Values(std::string key);
60     void Register(std::string key, uint32_t argc, std::string help);
61     bool IsResolutionValid(int32_t resolution) const;
62     int32_t GetOrignalResolutionWidth() const;
63     int32_t GetOrignalResolutionHeight() const;
64     int32_t GetCompressionResolutionWidth() const;
65     int32_t GetCompressionResolutionHeight() const;
66     uint32_t GetJsHeapSize() const;
67     std::string GetAppName() const;
68     bool IsSendJSHeap() const;
69     std::string GetDeviceType() const;
70     bool IsRegionRefresh() const;
71     bool IsCardDisplay() const;
72     std::string GetConfigPath() const;
73     std::string GetProjectID() const;
74     enum class ScreenMode { DYNAMIC = 0, STATIC = 1};
75     CommandParser::ScreenMode GetScreenMode() const;
76     std::string GetConfigChanges() const;
77     std::string GetAppResourcePath() const;
78     std::string GetScreenShape() const;
79     std::string GetProjectModel() const;
80     int GetProjectModelEnumValue() const;
81     std::string GetProjectModelEnumName(int enumValue) const;
82     std::string GetPages() const;
83     std::string GetContainerSdkPath() const;
84     bool CheckParamInvalidity(std::string param, bool isNum);
85     bool IsComponentMode() const;
86     std::string GetAbilityPath() const;
87     std::string GetAbilityName() const;
88     bool IsStaticCard() const;
89     bool IsMainArgLengthInvalid(const char* str) const;
90     bool IsFoldable() const;
91     std::string GetFoldStatus() const;
92     int32_t GetFoldResolutionWidth() const;
93     int32_t GetFoldResolutionHeight() const;
94     std::string GetLoaderJsonPath() const;
95     int ParseArgs(int argc, char* argv[]);
96     void GetCommandInfo(CommandInfo& info) const;
97     void GetFoldInfo(FoldInfo& info) const;
98     std::string GetSid() const;
99 
100 private:
101     CommandParser();
~CommandParser()102     ~CommandParser() {}
103     std::string errorInfo;
104     std::map<std::string, std::vector<std::string>> argsMap;
105     std::map<std::string, uint32_t> regsArgsCountMap;
106     std::map<std::string, std::string> regsHelpMap;
107     static CommandParser* example;
108     const std::vector<std::string> supportedDevices = {
109         "liteWearable",
110         "smartVision",
111         "wearable",
112         "tv",
113         "phone",
114         "tablet",
115         "car",
116         "2in1",
117         "default"
118     };
119     const std::vector<std::string> cardDisplayDevices = {"phone", "tablet", "wearable", "car", "tv", "2in1", "default"};
120     const std::vector<std::string> projectModels = {"FA", "Stage"};
121     const int MIN_PORT = 1024;
122     const int MAX_PORT = 65535;
123     const int32_t MIN_RESOLUTION = 1;
124     const int32_t MAX_RESOLUTION = 3840;
125     const int MAX_JSHEAPSIZE = 512 * 1024;
126     const int MIN_JSHEAPSIZE = 48 * 1024;
127     const size_t MAX_NAME_LENGTH = 256;
128     bool isSendJSHeap;
129     int32_t orignalResolutionWidth;
130     int32_t orignalResolutionHeight;
131     int32_t compressionResolutionWidth;
132     int32_t compressionResolutionHeight;
133     uint32_t jsHeapSize;
134     std::string deviceType;
135     std::string screenShape;
136     std::string appName;
137     std::string urlPath;
138     std::string configPath;
139     bool isRegionRefresh;
140     bool isCardDisplay;
141     std::string projectID;
142     CommandParser::ScreenMode screenMode;
143     std::string configChanges;
144     std::string appResourcePath;
145     std::string projectModel;
146     std::string pages;
147     std::string containerSdkPath;
148     std::string regex4Num = "^(0|[1-9][0-9]*)(\\.[0-9]+)?$";
149     std::string regex4Str = "^(?:[a-zA-Z0-9-_./\\s]+)$";
150     std::string regex4Sid = "^[a-fA-F0-9]+$";
151     bool isComponentMode;
152     std::string abilityPath;
153     std::string abilityName;
154     bool staticCard;
155     const size_t maxMainArgLength = 1024;
156     bool foldable;
157     std::string foldStatus;
158     int32_t foldResolutionWidth;
159     int32_t foldResolutionHeight;
160     std::string loaderJsonPath;
161     std::string sid;
162 
163     bool IsDebugPortValid();
164     bool IsAppPathValid();
165     bool IsAppNameValid();
166     bool IsResolutionValid();
167     bool IsConfigPathValid();
168     bool IsAppResourcePathValid();
169     bool IsResolutionRangeValid(std::string value);
170     bool IsResolutionArgValid(std::string command);
171     bool IsJsHeapValid();
172     bool IsJsHeapFlagValid();
173     bool IsScreenShapeValid();
174     bool IsDeviceValid();
175     bool IsUrlValid();
176     bool IsRefreshValid();
177     bool IsCardValid();
178     bool IsProjectIDValid();
179     bool IsColorModeValid();
180     bool IsAceVersionValid();
181     bool IsOrientationValid();
182     bool IsWebSocketPortValid();
183     bool IsScreenModeValid();
184     bool IsProjectModelValid();
185     bool IsPagesValid();
186     bool IsLanguageValid();
187     bool IsTracePipeNameValid();
188     bool IsLocalSocketNameValid();
189     bool IsScreenDensityValid();
190     bool IsConfigChangesValid();
191     bool IsContainerSdkPathValid();
192     bool IsComponentModeValid();
193     bool IsAbilityPathValid();
194     bool IsAbilityNameValid();
195     bool IsStaticCardValid();
196     bool IsFoldableValid();
197     bool IsFoldStatusValid();
198     bool IsFoldResolutionValid();
199     bool IsLoaderJsonPathValid();
200     bool IsSidValid();
201     std::string HelpText();
202     void ProcessingCommand(const std::vector<std::string>& strs);
203 };
204 
205 #endif // COMMANDPARSER_H
206