input: Simplify input_plugin_init()/input_plugin_exit() 24/294124/1
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 13 Jun 2023 11:15:19 +0000 (20:15 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 13 Jun 2023 11:27:02 +0000 (20:27 +0900)
Change-Id: Ifaf1a2e359b8f639a05836e32ff351b58940ffae
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/input/input-plugin.c

index ff894ca..03b30b7 100644 (file)
 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)
@@ -73,11 +43,13 @@ int input_plugin_init(void *data)
 
 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;
 }