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