Support plugin module. 28/200928/4 accepted/tizen/unified/20190312.113024 submit/tizen/20190311.073132 submit/tizen/20190311.073229 submit/tizen/20190311.073252
authorYunmi Ha <yunmi.ha@samsung.com>
Wed, 6 Mar 2019 06:06:52 +0000 (15:06 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 11 Mar 2019 07:08:04 +0000 (07:08 +0000)
Deviced will load "/usr/lib/deviced/*.so".
If someone wants to add their own device,
make plugin with DEVICE_PRIORITY_HIGH and place it in the lib folder.

Change-Id: I58b95b55a4c297c93b4f1e5bb17c9927d8d5d3c4
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/core/main.c
src/shared/plugin.c [changed mode: 0644->0755]

index 0ff129b..31d835d 100644 (file)
@@ -126,6 +126,8 @@ static int deviced_main(int argc, char **argv)
        g_main_loop_unref(mainloop);
 
        devices_exit(NULL);
+       unload_plugins();
+
        return 0;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index 72f291d..bcca658
 #ifndef LIBPATH
 #error LIBPATH is not defined.
 #endif
-#define MODULE_PATH            LIBPATH"/deviced"
+#define MODULE_PATH            LIBPATH"/deviced/"
 
 struct display_plugin disp_plgn;
+GList *plgn_list;
 
 int load_plugin(const char *id, void **h)
 {
@@ -52,7 +53,7 @@ int load_plugin(const char *id, void **h)
        }
 
        /* Find matched module path */
-       snprintf(path, sizeof(path), "%s/%s.so", MODULE_PATH, id);
+       snprintf(path, sizeof(path), "%s%s", MODULE_PATH, id);
        if (access(path, R_OK) != 0) {
                _E("There is no %s device", id);
                return -ENODEV;
@@ -80,7 +81,45 @@ int unload_plugin(void *h)
 
 void load_plugins()
 {
-       load_plugin("display", &disp_plgn.handle);
+       DIR *dir;
+       void *handle = NULL;
+       struct dirent *ent;
+
+       if ((dir = opendir(MODULE_PATH)) == NULL) {
+               _I("There is no plugin.");
+               return ;
+       }
+
+       while ((ent = readdir(dir)) != NULL) {
+               // skip (/.)(/..)(.so)
+               if (strlen(ent->d_name) < 4)
+                       continue;
+
+               if (strcmp((ent->d_name + strlen(ent->d_name)-3), ".so"))
+                       continue;
+
+               if (!load_plugin(ent->d_name, &handle)) {
+                       _I("Plugin(%s) is loaded. handle=0x%x", ent->d_name, (unsigned int)handle);
+                       plgn_list = g_list_append(plgn_list, handle);
+                       if (!strncmp(ent->d_name, "display", strlen("display")))
+                               disp_plgn.handle = handle;
+               }
+       }
+       closedir(dir);
 
        return;
 }
+
+void unload_plugins()
+{
+       GList *plugin = plgn_list;
+       void *handle = NULL;
+
+       for ( ; plugin != NULL; plugin = g_list_next(plugin)) {
+               handle = (void *)plugin->data;
+               _I("Plugin(0x%x) is unloaded.", (unsigned int)handle);
+               unload_plugin(handle);
+       }
+
+       g_list_free(plgn_list);
+}