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