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
25class CommandLineInterface {
26public:
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 Json2::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 Json2::Value& val) const;
37    void ApplyConfigMembers(const Json2::Value& commands, const Json2::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 Json2::Value&, const std::string) const;
42
43    const static std::string COMMAND_VERSION;
44
45private:
46    explicit CommandLineInterface();
47    virtual ~CommandLineInterface();
48    bool ProcessCommandValidate(bool parsingSuccessful, const Json2::Value& jsonData, const std::string& errors) const;
49    CommandLine::CommandType GetCommandType(std::string name) 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    std::vector<std::string> staticIgnoreCmd = { "ResolutionSwitch", "exit", "Language", "SupportedLanguages" };
55    bool IsStaticIgnoreCmd(const std::string cmd) const;
56};
57
58#endif // COMMANDLINEINTERFACE_H
59