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