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