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 COMMANDLINEINTERFACE_H 17 #define COMMANDLINEINTERFACE_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "CommandLine.h" 23 #include "LocalSocket.h" 24 #include "json.h" 25 26 class CommandLineInterface { 27 public: 28 CommandLineInterface(const CommandLineInterface&) = delete; 29 CommandLineInterface& operator=(const CommandLineInterface&) = delete; 30 void InitPipe(const std::string name); 31 static CommandLineInterface& GetInstance(); 32 static void SendJsonData(const Json::Value&); 33 void SendJSHeapMemory(size_t total, size_t alloc, size_t peak) const; 34 void SendWebsocketStartupSignal() const; 35 void ProcessCommand() const; 36 void ProcessCommandMessage(std::string message) const; 37 void ApplyConfig(const Json::Value& val) const; 38 void ApplyConfigMembers(const Json::Value& commands, const Json::Value::Members& members) const; 39 void ApplyConfigCommands(const std::string& key, const std::unique_ptr<CommandLine>& command) const; 40 void Init(std::string pipeBaseName); 41 void ReadAndApplyConfig(std::string path) const; 42 void CreatCommandToSendData(const std::string, const Json::Value, const std::string) const; 43 44 const static std::string COMMAND_VERSION; 45 46 private: 47 explicit CommandLineInterface(); 48 virtual ~CommandLineInterface(); 49 bool ProcessCommandValidate(bool parsingSuccessful, const Json::Value& jsonData, const std::string& errors) const; 50 CommandLine::CommandType GetCommandType(std::string) const; 51 std::unique_ptr<LocalSocket> socket; 52 const static uint32_t MAX_COMMAND_LENGTH = 128; 53 static bool isFirstWsSend; 54 static bool isPipeConnected; 55 std::vector<std::string> staticIgnoreCmd = { "ResolutionSwitch" }; 56 bool IsStaticIgnoreCmd(const std::string cmd) const; 57 }; 58 59 #endif // COMMANDLINEINTERFACE_H 60