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_PULUGIN_MANAGER_H 16 #define STARTUP_INIT_PULUGIN_MANAGER_H 17 #include <stdlib.h> 18 #include <string.h> 19 20 #include "init_plugin.h" 21 #include "list.h" 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 #define DEFAULT_PLUGIN_PATH "/system/lib/plugin" 30 #define DEFAULT_PLUGIN_CFG "/system/etc/plugin_modules.cfg" 31 typedef enum { 32 PLUGIN_STATE_IDLE, 33 PLUGIN_STATE_INIT, 34 PLUGIN_STATE_RUNNING, 35 PLUGIN_STATE_DESTORYED 36 } PluginState; 37 38 typedef struct PluginInfo_ { 39 int state; 40 int startMode; 41 int (*pluginInit)(); 42 void (*pluginExit)(); 43 char *name; 44 char *libName; 45 } PluginInfo; 46 47 typedef struct { 48 ListNode cmdExecutor; 49 int cmdId; 50 char *name; 51 } PluginCmd; 52 53 typedef int (*CmdExecutor)(int id, const char *name, int argc, const char **argv); 54 typedef struct { 55 ListNode node; 56 int id; 57 CmdExecutor execCmd; 58 } PluginCmdExecutor; 59 60 void PluginExecCmdByName(const char *name, const char *cmdContent); 61 void PluginExecCmdByCmdIndex(int index, const char *cmdContent); 62 int PluginExecCmd(const char *name, int argc, const char **argv); 63 const char *PluginGetCmdIndex(const char *cmdStr, int *index); 64 65 int PluginUninstall(const char *name); 66 int PluginInstall(const char *name, const char *libName); 67 void PluginManagerInit(void); 68 69 int AddCmdExecutor(const char *cmdName, CmdExecutor execCmd); 70 71 int ParseInitCfg(const char *configFile, void *context); 72 typedef PluginInterface *(*GetPluginInterfaceFunc)(); 73 int SetPluginInterface(void); 74 #ifdef __cplusplus 75 #if __cplusplus 76 } 77 #endif 78 #endif 79 #endif // STARTUP_INIT_PULUGIN_MANAGER_H 80