1 /*
2  * Copyright (c) 2024 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 EDM_TOOLS_EDM_INCLUDE_SHELL_COMMAND_H
17 #define EDM_TOOLS_EDM_INCLUDE_SHELL_COMMAND_H
18 
19 #include <map>
20 #include <string>
21 #include <functional>
22 #include <vector>
23 
24 #include "errors.h"
25 
26 namespace OHOS {
27 namespace EDM {
28 class ShellCommand {
29 public:
30     ShellCommand(int argc, char *argv[], std::string name);
31     virtual ~ShellCommand() = default;
32 
33     ErrCode OnCommand();
34     std::string ExecCommand();
35     [[nodiscard]] std::string GetMessageFromCode(int32_t code) const;
36 
37     virtual ErrCode CreateCommandMap() = 0;
38     virtual ErrCode CreateMessageMap() = 0;
39     virtual ErrCode Init() = 0;
40 
41 protected:
42     static constexpr int MIN_ARGUMENT_NUMBER = 2;
43 
44     int argc_;
45     char **argv_;
46 
47     std::string cmd_;
48     std::vector<std::string> argList_;
49 
50     std::string name_;
51     std::map<std::string, std::function<int()>> commandMap_;
52     std::map<int32_t, std::string> messageMap_;
53 
54     std::string resultReceiver_;
55 };
56 } // namespace EDM
57 } // namespace OHOS
58 #endif // EDM_TOOLS_EDM_INCLUDE_SHELL_COMMAND_H
59