5 * * add module types/classes
6 * * add list of exclusions that a module can't work withApi
10 /* local subsystem functions */
11 static void _e_module_free(E_Module *m);
12 static void _e_module_dialog_disable_show(const char *title, const char *body, E_Module *m);
13 static void _e_module_cb_dialog_disable(void *data, E_Dialog *dia);
14 static void _e_module_event_update_free(void *data, void *event);
15 static Eina_Bool _e_module_cb_idler(void *data);
16 static int _e_module_sort_priority(const void *d1, const void *d2);
18 /* local subsystem globals */
19 static Eina_List *_e_modules = NULL;
20 static Ecore_Idler *_e_module_idler = NULL;
21 static Eina_List *_e_modules_delayed = NULL;
23 EAPI int E_EVENT_MODULE_UPDATE = 0;
24 EAPI int E_EVENT_MODULE_INIT_END = 0;
26 /* externally accessible functions */
30 E_EVENT_MODULE_UPDATE = ecore_event_type_new();
31 E_EVENT_MODULE_INIT_END = ecore_event_type_new();
36 e_module_shutdown(void)
41 /* do a leak check now before we dlclose() all those plugins, cause
42 * that means we won't get a decent backtrace to leaks in there
44 VALGRIND_DO_LEAK_CHECK
47 /* do not use EINA_LIST_FREE! e_object_del modifies list */
55 if ((m) && (m->enabled) && !(m->error))
61 e_object_del(E_OBJECT(m));
69 e_module_all_load(void)
76 eina_list_sort(e_config->modules, 0, _e_module_sort_priority);
78 EINA_LIST_FOREACH(e_config->modules, l, em)
82 printf ("[E17_MODULE_INFO] NAME:%s, ENABLE:%d, DELAYED:%d\n", em->name, em->enabled, em->delayed);
84 if ((em->delayed) && (em->enabled))
87 _e_module_idler = ecore_idler_add(_e_module_cb_idler, NULL);
89 eina_list_append(_e_modules_delayed,
90 eina_stringshare_add(em->name));
96 if (!em->name) continue;
98 e_util_env_set("E_MODULE_LOAD", em->name);
99 snprintf (buf, sizeof(buf), _("Loading Module: %s"), em->name);
100 e_init_status_set(buf);
102 m = e_module_new(em->name);
103 if (m) e_module_enable(m);
107 if (!_e_modules_delayed)
108 ecore_event_add(E_EVENT_MODULE_INIT_END, NULL, NULL, NULL);
110 unsetenv("E_MODULE_LOAD");
114 e_module_new(const char *name)
118 char body[PATH_MAX], title[1024];
125 if (!name) return NULL;
126 m = E_OBJECT_ALLOC(E_Module, E_MODULE_TYPE, _e_module_free);
129 snprintf(buf, sizeof(buf), "%s/%s/module.so", name, MODULE_ARCH);
130 modpath = e_path_find(path_modules, buf);
133 modpath = eina_stringshare_add(name);
136 snprintf(body, sizeof(body),
137 _("There was an error loading module named: %s<br>"
138 "No module named %s could be found in the<br>"
139 "module search directories.<br>"), name, buf);
140 _e_module_dialog_disable_show(_("Error loading Module"), body, m);
144 m->handle = dlopen(modpath, (RTLD_NOW | RTLD_GLOBAL));
147 snprintf(body, sizeof(body),
148 _("There was an error loading module named: %s<br>"
149 "The full path to this module is:<br>"
151 "The error reported was:<br>"
152 "%s<br>"), name, buf, dlerror());
153 _e_module_dialog_disable_show(_("Error loading Module"), body, m);
157 m->api = dlsym(m->handle, "e_modapi");
158 m->func.init = dlsym(m->handle, "e_modapi_init");
159 m->func.shutdown = dlsym(m->handle, "e_modapi_shutdown");
160 m->func.save = dlsym(m->handle, "e_modapi_save");
162 if ((!m->func.init) || (!m->func.shutdown) || (!m->func.save) || (!m->api))
164 snprintf(body, sizeof(body),
165 _("There was an error loading module named: %s<br>"
166 "The full path to this module is:<br>"
168 "The error reported was:<br>"
170 name, buf, _("Module does not contain all needed functions"));
171 _e_module_dialog_disable_show(_("Error loading Module"), body, m);
174 m->func.shutdown = NULL;
182 if (m->api->version < E_MODULE_API_VERSION)
184 snprintf(body, sizeof(body),
185 _("Module API Error<br>Error initializing Module: %s<br>"
186 "It requires a minimum module API version of: %i.<br>"
187 "The module API advertized by Enlightenment is: %i.<br>"),
188 _(m->api->name), m->api->version, E_MODULE_API_VERSION);
190 snprintf(title, sizeof(title), _("Enlightenment %s Module"),
193 _e_module_dialog_disable_show(title, body, m);
196 m->func.shutdown = NULL;
206 _e_modules = eina_list_append(_e_modules, m);
207 m->name = eina_stringshare_add(name);
210 s = ecore_file_dir_get(modpath);
215 s2 = ecore_file_dir_get(s);
219 m->dir = eina_stringshare_add(s2);
224 EINA_LIST_FOREACH(e_config->modules, l, em)
227 if (!e_util_strcmp(em->name, m->name))
237 em = E_NEW(E_Config_Module, 1);
238 em->name = eina_stringshare_add(m->name);
240 e_config->modules = eina_list_append(e_config->modules, em);
241 e_config_save_queue();
243 if (modpath) eina_stringshare_del(modpath);
248 e_module_save(E_Module *m)
250 E_OBJECT_CHECK_RETURN(m, 0);
251 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
252 if ((!m->enabled) || (m->error)) return 0;
253 return m->func.save(m);
257 e_module_dir_get(E_Module *m)
259 E_OBJECT_CHECK_RETURN(m, NULL);
260 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
265 e_module_enable(E_Module *m)
268 E_Event_Module_Update *ev;
271 E_OBJECT_CHECK_RETURN(m, 0);
272 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
273 if ((m->enabled) || (m->error)) return 0;
274 m->data = m->func.init(m);
278 EINA_LIST_FOREACH(e_config->modules, l, em)
281 if (!e_util_strcmp(em->name, m->name))
284 e_config_save_queue();
286 ev = E_NEW(E_Event_Module_Update, 1);
287 ev->name = strdup(em->name);
289 ecore_event_add(E_EVENT_MODULE_UPDATE, ev,
290 _e_module_event_update_free, NULL);
300 e_module_disable(E_Module *m)
302 E_Event_Module_Update *ev;
307 E_OBJECT_CHECK_RETURN(m, 0);
308 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
309 if ((!m->enabled) || (m->error)) return 0;
310 ret = m->func.shutdown(m);
313 EINA_LIST_FOREACH(e_config->modules, l, em)
316 if (!e_util_strcmp(em->name, m->name))
319 e_config_save_queue();
321 ev = E_NEW(E_Event_Module_Update, 1);
322 ev->name = strdup(em->name);
324 ecore_event_add(E_EVENT_MODULE_UPDATE, ev,
325 _e_module_event_update_free, NULL);
333 e_module_enabled_get(E_Module *m)
335 E_OBJECT_CHECK_RETURN(m, 0);
336 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
341 e_module_save_all(void)
347 EINA_LIST_FOREACH(_e_modules, l, m)
348 e_object_ref(E_OBJECT(m));
349 EINA_LIST_FOREACH(_e_modules, l, m)
350 if ((m->enabled) && (!m->error))
352 if (!m->func.save(m)) ret = 0;
354 EINA_LIST_FOREACH(_e_modules, l, m)
355 e_object_unref(E_OBJECT(m));
360 e_module_find(const char *name)
365 if (!name) return NULL;
366 EINA_LIST_FOREACH(_e_modules, l, m)
367 if (!e_util_strcmp(name, m->name)) return m;
378 e_module_dialog_show(E_Module *m, const char *title, const char *body)
383 const char *icon = NULL;
385 dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
386 "E", "_module_dialog");
389 e_dialog_title_set(dia, title);
392 Efreet_Desktop *desktop;
394 snprintf(buf, sizeof(buf), "%s/module.desktop", e_module_dir_get(m));
396 desktop = efreet_desktop_new(buf);
397 if ((desktop) && (desktop->icon))
399 icon = efreet_icon_path_find(e_config->icon_theme, desktop->icon, 64);
402 snprintf(buf, sizeof(buf), "%s/%s.edj",
403 e_module_dir_get(m), desktop->icon);
404 dia->icon_object = e_util_icon_add(buf, e_win_evas_get(dia->win));
407 dia->icon_object = e_util_icon_add(icon, e_win_evas_get(dia->win));
408 edje_extern_object_min_size_set(dia->icon_object, 64, 64);
409 edje_object_part_swallow(dia->bg_object, "e.swallow.icon", dia->icon_object);
410 evas_object_show(dia->icon_object);
412 if (desktop) efreet_desktop_free(desktop);
415 e_dialog_icon_set(dia, "preferences-plugin", 64);
417 e_dialog_text_set(dia, body);
418 e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
419 e_dialog_button_focus_num(dia, 0);
420 e_win_centered_set(dia->win, 1);
423 bd = dia->win->border;
425 bd->internal_icon = eina_stringshare_add(icon);
429 e_module_delayed_set(E_Module *m, int delayed)
434 EINA_LIST_FOREACH(e_config->modules, l, em)
437 if (!e_util_strcmp(m->name, em->name))
439 if (em->delayed != delayed)
441 em->delayed = delayed;
442 e_config_save_queue();
450 e_module_priority_set(E_Module *m, int priority)
452 /* Set the loading order for a module.
453 More priority means load earlier */
457 EINA_LIST_FOREACH(e_config->modules, l, em)
460 if (!e_util_strcmp(m->name, em->name))
462 if (em->priority != priority)
464 em->priority = priority;
465 e_config_save_queue();
472 /* local subsystem functions */
475 _e_module_free(E_Module *m)
480 EINA_LIST_FOREACH(e_config->modules, l, em)
483 if (!e_util_strcmp(em->name, m->name))
485 e_config->modules = eina_list_remove(e_config->modules, em);
486 if (em->name) eina_stringshare_del(em->name);
492 if ((m->enabled) && (!m->error))
497 if (m->name) eina_stringshare_del(m->name);
498 if (m->dir) eina_stringshare_del(m->dir);
499 // if (m->handle) dlclose(m->handle); DONT dlclose! causes problems with deferred callbacks for free etc. - when their code goes away!
500 _e_modules = eina_list_remove(_e_modules, m);
505 _e_module_dialog_disable_show(const char *title, const char *body, E_Module *m)
510 printf("MODULE ERR:\n%s\n", body);
511 dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
512 "E", "_module_unload_dialog");
515 snprintf(buf, sizeof(buf), "%s<br>%s", body,
516 _("Would you like to unload this module?<br>"));
518 e_dialog_title_set(dia, title);
519 e_dialog_icon_set(dia, "enlightenment", 64);
520 e_dialog_text_set(dia, buf);
521 e_dialog_button_add(dia, _("Yes"), NULL, _e_module_cb_dialog_disable, m);
522 e_dialog_button_add(dia, _("No"), NULL, NULL, NULL);
523 e_win_centered_set(dia->win, 1);
528 _e_module_cb_dialog_disable(void *data, E_Dialog *dia)
534 e_object_del(E_OBJECT(m));
535 e_object_del(E_OBJECT(dia));
536 e_config_save_queue();
540 _e_module_cb_idler(void *data __UNUSED__)
542 if (_e_modules_delayed)
547 name = eina_list_data_get(_e_modules_delayed);
549 eina_list_remove_list(_e_modules_delayed, _e_modules_delayed);
551 if (name) m = e_module_new(name);
552 if (m) e_module_enable(m);
553 eina_stringshare_del(name);
555 if (_e_modules_delayed)
558 return ECORE_CALLBACK_RENEW;
561 ecore_event_add(E_EVENT_MODULE_INIT_END, NULL, NULL, NULL);
563 _e_module_idler = NULL;
564 return ECORE_CALLBACK_CANCEL;
568 _e_module_sort_priority(const void *d1, const void *d2)
570 const E_Config_Module *m1, *m2;
574 return (m2->priority - m1->priority);
578 _e_module_event_update_free(void *data __UNUSED__, void *event)
580 E_Event_Module_Update *ev;
582 if (!(ev = event)) return;