• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ECMASCRIPT_TOOLING_CLIENT_ARK_CLI_CLI_COMMAND_H
17 #define ECMASCRIPT_TOOLING_CLIENT_ARK_CLI_CLI_COMMAND_H
18 
19 #include <cstdlib>
20 #include <functional>
21 #include <map>
22 #include <vector>
23 
24 #include "common/log_wrapper.h"
25 #include "tooling/client/domain/heapprofiler_client.h"
26 #include "tooling/client/domain/profiler_client.h"
27 #include "tooling/client/manager/domain_manager.h"
28 #include "tooling/client/utils/utils.h"
29 #include "tooling/client/session/session.h"
30 
31 namespace OHOS::ArkCompiler::Toolchain {
32 using StrPair = std::pair<std::string, std::string>;
33 using VecStr = std::vector<std::string>;
34 
35 enum class ErrCode : uint8_t {
36     ERR_OK   = 0,
37     ERR_FAIL = 1
38 };
39 
40 class CliCommand {
41 public:
CliCommand(std::vector<std::string> cliCmdStr,uint32_t sessionId)42     CliCommand(std::vector<std::string> cliCmdStr, uint32_t sessionId)
43         : cmd_(cliCmdStr[0]), sessionId_(sessionId)
44     {
45         for (size_t i = 1u; i < cliCmdStr.size(); i++) {
46             argList_.push_back(cliCmdStr[i]);
47         }
48     }
49 
50     ~CliCommand() = default;
51 
52     ErrCode OnCommand();
53     ErrCode ExecCommand();
54     void CreateCommandMap();
55     ErrCode HeapProfilerCommand(const std::string &cmd);
56     ErrCode DebuggerCommand(const std::string &cmd);
57     ErrCode CpuProfileCommand(const std::string &cmd);
58     ErrCode RuntimeCommand(const std::string &cmd);
59     ErrCode BreakCommand(const std::string &cmd);
60     ErrCode DeleteCommand(const std::string &cmd);
61     ErrCode StepCommand(const std::string &cmd);
62     ErrCode ShowstackCommand(const std::string &cmd);
63     ErrCode DisplayCommand(const std::string &cmd);
64     ErrCode InfosourceCommand(const std::string &cmd);
65     ErrCode ListCommand(const std::string &cmd);
66     ErrCode PrintCommand(const std::string &cmd);
67     ErrCode WatchCommand(const std::string &cmd);
68     ErrCode SessionAddCommand(const std::string &cmd);
69     ErrCode SessionDelCommand(const std::string &cmd);
70     ErrCode SessionListCommand(const std::string &cmd);
71     ErrCode SessionSwitchCommand(const std::string &cmd);
72     ErrCode TestCommand(const std::string &cmd);
73     ErrCode ExecHelpCommand();
74     void OutputCommand(const std::string &cmd, bool flag);
75 
GetArgList()76     VecStr GetArgList()
77     {
78         return argList_;
79     }
80 
81 private:
82     std::string cmd_ ;
83     VecStr argList_ {};
84     std::map<StrPair, std::function<ErrCode()>> commandMap_;
85     std::string resultReceiver_ = "";
86     uint32_t sessionId_;
87 };
88 } // namespace OHOS::ArkCompiler::Toolchain
89 
90 #endif // ECMASCRIPT_TOOLING_CLIENT_ARK_CLI_CLI_COMMAND_H