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