#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)
{
}
/* 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;
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);
+}