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 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(); 32 33 ErrCode OnCommand(); 34 std::string ExecCommand(); 35 std::string GetCommandErrorMsg() const; 36 std::string GetMessageFromCode(const int32_t code) const; 37 38 virtual ErrCode CreateCommandMap() = 0; 39 virtual ErrCode CreateMessageMap() = 0; 40 virtual ErrCode init() = 0; 41 42 protected: 43 static constexpr int MIN_ARGUMENT_NUMBER = 2; 44 45 int argc_; 46 char **argv_; 47 48 std::string cmd_; 49 std::vector<std::string> argList_; 50 51 std::string name_; 52 std::map<std::string, std::function<int()>> commandMap_; 53 std::map<int32_t, std::string> messageMap_; 54 55 std::string resultReceiver_ = ""; 56 }; 57 } // namespace EDM 58 } // namespace OHOS 59 #endif // EDM_TOOLS_EDM_INCLUDE_SHELL_COMMAND_H 60