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