1 /* 2 * Copyright (c) 2020-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 #ifndef STARTUP_INIT_CMD_EXECUTOR_H 16 #define STARTUP_INIT_CMD_EXECUTOR_H 17 #include <stdlib.h> 18 #include <string.h> 19 20 #include "list.h" 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 typedef struct { 29 ListNode cmdExecutor; 30 int cmdId; 31 char *name; 32 } PluginCmd; 33 34 typedef int (*CmdExecutor)(int id, const char *name, int argc, const char **argv); 35 typedef struct { 36 ListNode node; 37 int id; 38 CmdExecutor execCmd; 39 } PluginCmdExecutor; 40 41 void PluginExecCmdByName(const char *name, const char *cmdContent); 42 void PluginExecCmdByCmdIndex(int index, const char *cmdContent); 43 int PluginExecCmd(const char *name, int argc, const char **argv); 44 const char *PluginGetCmdIndex(const char *cmdStr, int *index); 45 const char *GetPluginCmdNameByIndex(int index); 46 47 int AddCmdExecutor(const char *cmdName, CmdExecutor execCmd); 48 49 int AddRebootCmdExecutor(const char *cmd, CmdExecutor executor); 50 51 #ifdef __cplusplus 52 #if __cplusplus 53 } 54 #endif 55 #endif 56 #endif 57