• 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 
60 private:
61     CommandParser();
~CommandParser()62     ~CommandParser() {}
63     std::string errorInfo;
64     std::map<std::string, std::vector<std::string>> argsMap;
65     std::map<std::string, uint32_t> regsArgsCountMap;
66     std::map<std::string, std::string> regsHelpMap;
67     static CommandParser* example;
68     const std::vector<std::string> supportedDevices = {
69         "liteWearable",
70         "smartVision",
71         "wearable",
72         "tv",
73         "phone",
74         "tablet",
75         "car"
76     };
77     const std::vector<std::string> cardDisplayDevices = {"phone", "tablet", "wearable", "car", "tv"};
78     const std::vector<std::string> projectModels = {"FA", "Stage"};
79     const int MIN_PORT = 1024;
80     const int MAX_PORT = 65535;
81     const int32_t MIN_RESOLUTION = 1;
82     const int32_t MAX_RESOLUTION = 3840;
83     const int MAX_JSHEAPSIZE = 512 * 1024;
84     const int MIN_JSHEAPSIZE = 48 * 1024;
85     const size_t MAX_NAME_LENGTH = 256;
86     bool isSendJSHeap;
87     int32_t orignalResolutionWidth;
88     int32_t orignalResolutionHeight;
89     int32_t compressionResolutionWidth;
90     int32_t compressionResolutionHeight;
91     uint32_t jsHeapSize;
92     std::string deviceType;
93     std::string screenShape;
94     std::string appName;
95     std::string urlPath;
96     std::string configPath;
97     bool isRegionRefresh;
98     bool isCardDisplay;
99     std::string projectID;
100     CommandParser::ScreenMode screenMode;
101     std::string configChanges;
102     std::string appResourcePath;
103     std::string projectModel;
104     std::string pages;
105     std::string containerSdkPath;
106     std::string regex4Num = "^(?:0|[1-9])+(?:.[0-9]*)$";
107     std::string regex4Str = "^(?:[a-zA-Z0-9-_./\\s]+)$";
108     bool isComponentMode;
109 
110     bool IsDebugPortValid();
111     bool IsAppPathValid();
112     bool IsAppNameValid();
113     bool IsResolutionValid();
114     bool IsConfigPathValid();
115     bool IsAppResourcePathValid();
116     bool IsResolutionRangeValid(std::string value);
117     bool IsResolutionArgValid(std::string command);
118     bool IsJsHeapValid();
119     bool IsJsHeapFlagValid();
120     bool IsScreenShapeValid();
121     bool IsDeviceValid();
122     bool IsUrlValid();
123     bool IsRefreshValid();
124     bool IsCardValid();
125     bool IsProjectIDValid();
126     bool IsColorModeValid();
127     bool IsAceVersionValid();
128     bool IsOrientationValid();
129     bool IsWebSocketPortValid();
130     bool IsScreenModeValid();
131     bool IsProjectModelValid();
132     bool IsPagesValid();
133     bool IsLanguageValid();
134     bool IsTracePipeNameValid();
135     bool IsLocalSocketNameValid();
136     bool IsScreenDensityValid();
137     bool IsConfigChangesValid();
138     bool IsContainerSdkPathValid();
139     bool IsComponentModeValid();
140     std::string HelpText();
141     void ProcessingCommand(const std::vector<std::string>& strs);
142 };
143 
144 #endif // COMMANDPARSER_H
145