• 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 SHELL_COMMAND
17 #define SHELL_COMMAND
18 
19 #include <functional>
20 #include <map>
21 #include <string>
22 
23 #include "ibundle_active_service.h"
24 
25 namespace OHOS {
26 namespace DeviceUsageStats {
27 class ShellCommand {
28 public:
29     ShellCommand(int32_t argc, char *argv[], std::string name);
30 
31     /**
32      * @brief The OnCommand callback.
33      *
34      * @return ERR_OK on success, others on failure.
35      */
36     int32_t OnCommand();
37     /**
38      * @brief Exec command.
39      *
40      * @return Result receiver.
41      */
42     std::string ExecCommand();
43     /**
44      * @brief Get command error msg.
45      *
46      * @return Command error msg.
47      */
48     std::string GetCommandErrorMsg() const;
49 
50     /**
51      * @brief Create command map.
52      *
53      * @return 0 on success, others on failure.
54      */
55     virtual int32_t CreateCommandMap() = 0;
56     /**
57      * @brief Create message map.
58      *
59      * @return 0 on success, others on failure.
60      */
61     virtual int32_t CreateMessageMap() = 0;
62     /**
63      * @brief Init.
64      *
65      * @return 0 on success, others on failure.
66      */
67     virtual int32_t init() = 0;
68 
69 protected:
70     static constexpr int32_t MIN_ARGUMENT_NUMBER = 2;
71 
72     int32_t argc_;
73     char **argv_;
74 
75     std::string cmd_;
76     std::vector<std::string> argList_;
77 
78     std::string name_;
79     std::map<std::string, std::function<int32_t()>> commandMap_;
80     std::map<int32_t, std::string> messageMap_;
81 
82     std::string resultReceiver_ = "";
83 };
84 }  // namespace DeviceUsageStats
85 }  // namespace OHOS
86 #endif  // SHELL_COMMAND
87 
88