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