static void *g_input_plugin_handle;
static struct input_plugin_interface *g_input_plugin;
-static int load_input_plugin(void)
+int input_plugin_init(void *data)
{
- void *g_input_plugin_handle;
-
- if (g_input_plugin)
- return 0;
-
- if (access(INPUT_PLUGIN_PATH, F_OK) != 0)
+ if (access(INPUT_PLUGIN_PATH, F_OK) != 0) {
+ _D("There is no input plugin, %s", INPUT_PLUGIN_PATH);
return -ENOENT;
-
- g_input_plugin_handle = dlopen(INPUT_PLUGIN_PATH, RTLD_NOW | RTLD_GLOBAL);
- if (!g_input_plugin_handle) {
- _E("Failed to load input plugin shared object, %s", dlerror());
- return -1;
- }
-
- g_input_plugin = dlsym(g_input_plugin_handle, stringify(INPUT_PLUGIN_INTERFACE_SYMBOL));
- if (!g_input_plugin) {
- _E("Failed to load input plugin symbol, %s", dlerror());
- return -1;
}
- return 0;
-}
-
-static void unload_input_plugin(void)
-{
- int ret;
-
- if (!g_input_plugin_handle)
- return;
-
- g_input_plugin = NULL;
-
- ret = dlclose(g_input_plugin_handle);
- if (ret != 0) {
- _E("Failed to unload input plugin shared object, %s", dlerror());
- return;
+ if (!g_input_plugin_handle) {
+ g_input_plugin_handle = dlopen(INPUT_PLUGIN_PATH, RTLD_NOW | RTLD_GLOBAL);
+ if (!g_input_plugin_handle) {
+ _E("Failed to load input plugin shared object, %s", dlerror());
+ return -ENOTSUP;
+ }
}
- g_input_plugin_handle = NULL;
-}
-
-int input_plugin_init(void *data)
-{
- int ret;
-
if (!g_input_plugin) {
- ret = load_input_plugin();
- if (ret != 0)
- return ret;
+ g_input_plugin = dlsym(g_input_plugin_handle, stringify(INPUT_PLUGIN_INTERFACE_SYMBOL));
+ if (!g_input_plugin) {
+ _E("Failed to load input plugin symbol, %s", dlerror());
+ return -ENOTSUP;
+ }
}
if (!g_input_plugin->init)
void input_plugin_exit(void *data)
{
- if (!g_input_plugin)
- return;
-
- if (g_input_plugin->exit)
+ if (g_input_plugin && g_input_plugin->exit)
g_input_plugin->exit(data);
- unload_input_plugin();
+ g_input_plugin = NULL;
+
+ if (g_input_plugin_handle)
+ dlclose(g_input_plugin_handle);
+
+ g_input_plugin_handle = NULL;
}