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 */
57 if ((m) && (m->enabled) && !(m->error))
63 e_object_del(E_OBJECT(m));
71 e_module_all_load(void)
78 eina_list_sort(e_config->modules, 0, _e_module_sort_priority);
80 EINA_LIST_FOREACH(e_config->modules, l, em)
84 printf ("[E17_MODULE_INFO] NAME:%s, ENABLE:%d, DELAYED:%d\n", em->name, em->enabled, em->delayed);
86 if ((em->delayed) && (em->enabled))
89 _e_module_idler = ecore_idler_add(_e_module_cb_idler, NULL);
91 eina_list_append(_e_modules_delayed,
92 eina_stringshare_add(em->name));
98 if (!em->name) continue;
100 setenv("E_MODULE_LOAD", em->name, 1);
101 snprintf (buf, sizeof(buf), _("Loading Module: %s"), em->name);
102 e_init_status_set(em->name);
104 m = e_module_new(em->name);
105 if (m) e_module_enable(m);
109 if (!_e_modules_delayed)
110 ecore_event_add(E_EVENT_MODULE_INIT_END, NULL, NULL, NULL);
112 unsetenv("E_MODULE_LOAD");
116 e_module_new(const char *name)
120 char body[PATH_MAX], title[1024];
127 if (!name) return NULL;
128 m = E_OBJECT_ALLOC(E_Module, E_MODULE_TYPE, _e_module_free);
131 snprintf(buf, sizeof(buf), "%s/%s/module.so", name, MODULE_ARCH);
132 modpath = e_path_find(path_modules, buf);
135 modpath = eina_stringshare_add(name);
138 snprintf(body, sizeof(body),
139 _("There was an error loading module named: %s<br>"
140 "No module named %s could be found in the<br>"
141 "module search directories.<br>"), name, buf);
142 _e_module_dialog_disable_show(_("Error loading Module"), body, m);
146 m->handle = dlopen(modpath, RTLD_NOW | RTLD_GLOBAL);
149 snprintf(body, sizeof(body),
150 _("There was an error loading module named: %s<br>"
151 "The full path to this module is:<br>"
153 "The error reported was:<br>"
154 "%s<br>"), name, buf, dlerror());
155 _e_module_dialog_disable_show(_("Error loading Module"), body, m);
159 m->api = dlsym(m->handle, "e_modapi");
160 m->func.init = dlsym(m->handle, "e_modapi_init");
161 m->func.shutdown = dlsym(m->handle, "e_modapi_shutdown");
162 m->func.save = dlsym(m->handle, "e_modapi_save");
164 if ((!m->func.init) || (!m->func.shutdown) || (!m->func.save) || (!m->api))
166 snprintf(body, sizeof(body),
167 _("There was an error loading module named: %s<br>"
168 "The full path to this module is:<br>"
170 "The error reported was:<br>"
172 name, buf, _("Module does not contain all needed functions"));
173 _e_module_dialog_disable_show(_("Error loading Module"), body, m);
176 m->func.shutdown = NULL;
184 if (m->api->version < E_MODULE_API_VERSION)
186 snprintf(body, sizeof(body),
187 _("Module API Error<br>Error initializing Module: %s<br>"
188 "It requires a minimum module API version of: %i.<br>"
189 "The module API advertized by Enlightenment is: %i.<br>"),
190 _(m->api->name), m->api->version, E_MODULE_API_VERSION);
192 snprintf(title, sizeof(title), _("Enlightenment %s Module"),
195 _e_module_dialog_disable_show(title, body, m);
198 m->func.shutdown = NULL;
208 _e_modules = eina_list_append(_e_modules, m);
209 m->name = eina_stringshare_add(name);
212 s = ecore_file_dir_get(modpath);
217 s2 = ecore_file_dir_get(s);
221 m->dir = eina_stringshare_add(s2);
226 EINA_LIST_FOREACH(e_config->modules, l, em)
229 if (!e_util_strcmp(em->name, m->name))
239 em = E_NEW(E_Config_Module, 1);
240 em->name = eina_stringshare_add(m->name);
242 e_config->modules = eina_list_append(e_config->modules, em);
243 e_config_save_queue();
245 if (modpath) eina_stringshare_del(modpath);
250 e_module_save(E_Module *m)
252 E_OBJECT_CHECK_RETURN(m, 0);
253 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
254 if ((!m->enabled) || (m->error)) return 0;
255 return m->func.save(m);
259 e_module_dir_get(E_Module *m)
261 E_OBJECT_CHECK_RETURN(m, NULL);
262 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
267 e_module_enable(E_Module *m)
270 E_Event_Module_Update *ev;
273 E_OBJECT_CHECK_RETURN(m, 0);
274 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
275 if ((m->enabled) || (m->error)) return 0;
276 m->data = m->func.init(m);
280 EINA_LIST_FOREACH(e_config->modules, l, em)
283 if (!e_util_strcmp(em->name, m->name))
286 e_config_save_queue();
288 ev = E_NEW(E_Event_Module_Update, 1);
289 ev->name = strdup(em->name);
291 ecore_event_add(E_EVENT_MODULE_UPDATE, ev,
292 _e_module_event_update_free, NULL);
302 e_module_disable(E_Module *m)
304 E_Event_Module_Update *ev;
309 E_OBJECT_CHECK_RETURN(m, 0);
310 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
311 if ((!m->enabled) || (m->error)) return 0;
312 ret = m->func.shutdown(m);
315 EINA_LIST_FOREACH(e_config->modules, l, em)
318 if (!e_util_strcmp(em->name, m->name))
321 e_config_save_queue();
323 ev = E_NEW(E_Event_Module_Update, 1);
324 ev->name = strdup(em->name);
326 ecore_event_add(E_EVENT_MODULE_UPDATE, ev,
327 _e_module_event_update_free, NULL);
335 e_module_enabled_get(E_Module *m)
337 E_OBJECT_CHECK_RETURN(m, 0);
338 E_OBJECT_TYPE_CHECK_RETURN(m, E_MODULE_TYPE, 0);
343 e_module_save_all(void)
349 EINA_LIST_FOREACH(_e_modules, l, m)
350 e_object_ref(E_OBJECT(m));
351 EINA_LIST_FOREACH(_e_modules, l, m)
352 if ((m->enabled) && (!m->error))
354 if (!m->func.save(m)) ret = 0;
356 EINA_LIST_FOREACH(_e_modules, l, m)
357 e_object_unref(E_OBJECT(m));
362 e_module_find(const char *name)
367 if (!name) return NULL;
368 EINA_LIST_FOREACH(_e_modules, l, m)
369 if (!e_util_strcmp(name, m->name)) return m;
380 e_module_dialog_show(E_Module *m, const char *title, const char *body)
385 const char *icon = NULL;
387 dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
388 "E", "_module_dialog");
391 e_dialog_title_set(dia, title);
394 Efreet_Desktop *desktop;
396 snprintf(buf, sizeof(buf), "%s/module.desktop", e_module_dir_get(m));
398 desktop = efreet_desktop_new(buf);
399 if ((desktop) && (desktop->icon))
401 icon = efreet_icon_path_find(e_config->icon_theme, desktop->icon, 64);
404 snprintf(buf, sizeof(buf), "%s/%s.edj",
405 e_module_dir_get(m), desktop->icon);
406 dia->icon_object = e_util_icon_add(buf, e_win_evas_get(dia->win));
409 dia->icon_object = e_util_icon_add(icon, e_win_evas_get(dia->win));
410 edje_extern_object_min_size_set(dia->icon_object, 64, 64);
411 edje_object_part_swallow(dia->bg_object, "e.swallow.icon", dia->icon_object);
412 evas_object_show(dia->icon_object);
414 if (desktop) efreet_desktop_free(desktop);
417 e_dialog_icon_set(dia, "preferences-plugin", 64);
419 e_dialog_text_set(dia, body);
420 e_dialog_button_add(dia, _("OK"), NULL, NULL, NULL);
421 e_dialog_button_focus_num(dia, 0);
422 e_win_centered_set(dia->win, 1);
425 bd = dia->win->border;
427 bd->internal_icon = eina_stringshare_add(icon);
431 e_module_delayed_set(E_Module *m, int delayed)
436 EINA_LIST_FOREACH(e_config->modules, l, em)
439 if (!e_util_strcmp(m->name, em->name))
441 if (em->delayed != delayed)
443 em->delayed = delayed;
444 e_config_save_queue();
452 e_module_priority_set(E_Module *m, int priority)
454 /* Set the loading order for a module.
455 More priority means load earlier */
459 EINA_LIST_FOREACH(e_config->modules, l, em)
462 if (!e_util_strcmp(m->name, em->name))
464 if (em->priority != priority)
466 em->priority = priority;
467 e_config_save_queue();
474 /* local subsystem functions */
477 _e_module_free(E_Module *m)
482 EINA_LIST_FOREACH(e_config->modules, l, em)
485 if (!e_util_strcmp(em->name, m->name))
487 e_config->modules = eina_list_remove(e_config->modules, em);
488 if (em->name) eina_stringshare_del(em->name);
494 if ((m->enabled) && (!m->error))
499 if (m->name) eina_stringshare_del(m->name);
500 if (m->dir) eina_stringshare_del(m->dir);
501 // if (m->handle) dlclose(m->handle); DONT dlclose! causes problems with deferred callbacks for free etc. - when their code goes away!
502 _e_modules = eina_list_remove(_e_modules, m);
507 _e_module_dialog_disable_show(const char *title, const char *body, E_Module *m)
512 printf("MODULE ERR:\n%s\n", body);
513 dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
514 "E", "_module_unload_dialog");
517 snprintf(buf, sizeof(buf), "%s<br>%s", body,
518 _("Would you like to unload this module?<br>"));
520 e_dialog_title_set(dia, title);
521 e_dialog_icon_set(dia, "enlightenment", 64);
522 e_dialog_text_set(dia, buf);
523 e_dialog_button_add(dia, _("Yes"), NULL, _e_module_cb_dialog_disable, m);
524 e_dialog_button_add(dia, _("No"), NULL, NULL, NULL);
525 e_win_centered_set(dia->win, 1);
530 _e_module_cb_dialog_disable(void *data, E_Dialog *dia)
536 e_object_del(E_OBJECT(m));
537 e_object_del(E_OBJECT(dia));
538 e_config_save_queue();
542 _e_module_cb_idler(void *data __UNUSED__)
544 if (_e_modules_delayed)
549 name = eina_list_data_get(_e_modules_delayed);
551 eina_list_remove_list(_e_modules_delayed, _e_modules_delayed);
553 if (name) m = e_module_new(name);
554 if (m) e_module_enable(m);
555 eina_stringshare_del(name);
557 if (_e_modules_delayed)
560 return ECORE_CALLBACK_RENEW;
563 ecore_event_add(E_EVENT_MODULE_INIT_END, NULL, NULL, NULL);
565 _e_module_idler = NULL;
566 return ECORE_CALLBACK_CANCEL;
570 _e_module_sort_priority(const void *d1, const void *d2)
572 const E_Config_Module *m1, *m2;
576 return (m2->priority - m1->priority);
581 _e_module_event_update_free(void *data __UNUSED__, void *event)
583 E_Event_Module_Update *ev;
585 if (!(ev = event)) return;