• 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 #ifdef COMPONENT_TEST_ENABLED
100     std::string GetComponentTestConfig() const;
101 #endif // COMPONENT_TEST_ENABLED
102 
103 private:
104     CommandParser();
~CommandParser()105     ~CommandParser() {}
106     std::string errorInfo;
107     std::map<std::string, std::vector<std::string>> argsMap;
108     std::map<std::string, uint32_t> regsArgsCountMap;
109     std::map<std::string, std::string> regsHelpMap;
110     static CommandParser* example;
111     const std::vector<std::string> supportedDevices = {
112         "liteWearable",
113         "smartVision",
114         "wearable",
115         "tv",
116         "phone",
117         "tablet",
118         "car",
119         "2in1",
120         "default"
121     };
122     const std::vector<std::string> cardDisplayDevices = {"phone", "tablet", "wearable", "car", "tv", "2in1", "default"};
123     const std::vector<std::string> projectModels = {"FA", "Stage"};
124     const int MIN_PORT = 1024;
125     const int MAX_PORT = 65535;
126     const int32_t MIN_RESOLUTION = 1;
127     const int32_t MAX_RESOLUTION = 3840;
128     const int MAX_JSHEAPSIZE = 512 * 1024;
129     const int MIN_JSHEAPSIZE = 48 * 1024;
130     const size_t MAX_NAME_LENGTH = 256;
131     bool isSendJSHeap;
132     int32_t orignalResolutionWidth;
133     int32_t orignalResolutionHeight;
134     int32_t compressionResolutionWidth;
135     int32_t compressionResolutionHeight;
136     uint32_t jsHeapSize;
137     std::string deviceType;
138     std::string screenShape;
139     std::string appName;
140     std::string urlPath;
141     std::string configPath;
142     bool isRegionRefresh;
143     bool isCardDisplay;
144     std::string projectID;
145     CommandParser::ScreenMode screenMode;
146     std::string configChanges;
147     std::string appResourcePath;
148     std::string projectModel;
149     std::string pages;
150     std::string containerSdkPath;
151     std::string regex4Num = "^(0|[1-9][0-9]*)(\\.[0-9]+)?$";
152     std::string regex4Str = "^(?:[a-zA-Z0-9-_./\\s]+)$";
153     std::string regex4Sid = "^[a-fA-F0-9]+$";
154     bool isComponentMode;
155     std::string abilityPath;
156     std::string abilityName;
157 #ifdef COMPONENT_TEST_ENABLED
158     std::string componentTestConfig;
159 #endif // COMPONENT_TEST_ENABLED
160     bool staticCard;
161     const size_t maxMainArgLength = 1024;
162     bool foldable;
163     std::string foldStatus;
164     int32_t foldResolutionWidth;
165     int32_t foldResolutionHeight;
166     std::string loaderJsonPath;
167     std::string sid;
168 
169     bool IsDebugPortValid();
170     bool IsAppPathValid();
171     bool IsAppNameValid();
172     bool IsResolutionValid();
173     bool IsConfigPathValid();
174     bool IsAppResourcePathValid();
175     bool IsResolutionRangeValid(std::string value);
176     bool IsResolutionArgValid(std::string command);
177     bool IsJsHeapValid();
178     bool IsJsHeapFlagValid();
179     bool IsScreenShapeValid();
180     bool IsDeviceValid();
181     bool IsUrlValid();
182     bool IsRefreshValid();
183     bool IsCardValid();
184     bool IsProjectIDValid();
185     bool IsColorModeValid();
186     bool IsAceVersionValid();
187     bool IsOrientationValid();
188     bool IsWebSocketPortValid();
189     bool IsScreenModeValid();
190     bool IsProjectModelValid();
191     bool IsPagesValid();
192     bool IsLanguageValid();
193     bool IsTracePipeNameValid();
194     bool IsLocalSocketNameValid();
195     bool IsScreenDensityValid();
196     bool IsConfigChangesValid();
197     bool IsContainerSdkPathValid();
198     bool IsComponentModeValid();
199     bool IsAbilityPathValid();
200     bool IsAbilityNameValid();
201     bool IsStaticCardValid();
202     bool IsFoldableValid();
203     bool IsFoldStatusValid();
204     bool IsFoldResolutionValid();
205     bool IsLoaderJsonPathValid();
206     bool IsSidValid();
207     std::string HelpText();
208     void ProcessingCommand(const std::vector<std::string>& strs);
209 };
210 
211 #endif // COMMANDPARSER_H
212