1 #include <Elementary.h>
4 /* what are moodules in elementary for? for modularising behavior and features
5 * so they can be plugged in and out where you dont want the core source to
6 * always behave like that or do it that way. plug it at runtime!
8 * they have module names (in config) and "slots" to plug that module into
9 * to server a purpose. eg you plug plugin "xx" into the "entry-copy-paste"
10 * slot so it would provide replacement copy & paste ui functionality and
13 * config is something like:
15 * export ELM_MODULES="xx>slot1:yy>slot2"
17 * where a module named xx is plugged into slot1 & yy is plugged into slot2
21 * export ELM_MODULES="my_module>entry/api"
23 * this loads the module called "my_module" into the slot "entry/api" which
24 * is an api slot for entry modules to modify behavior and hook to
25 * creation/deletion of the entry as well as replace the longpress behavior.
29 # include "elementary_config.h"
32 #include <dlfcn.h> /* dlopen,dlclose,etc */
34 static Eina_Hash *modules = NULL;
35 static Eina_Hash *modules_as = NULL;
38 _elm_module_init(void)
40 modules = eina_hash_string_small_new(NULL);
41 modules_as = eina_hash_string_small_new(NULL);
45 _elm_module_shutdown(void)
47 // FIXME: unload all modules
48 if (modules) eina_hash_free(modules);
50 if (modules_as) eina_hash_free(modules_as);
55 _elm_module_parse(const char *s)
63 if ((*pe == ':') || (!*pe))
64 { // p -> pe == 'name:'
67 char *n = malloc(pe - p + 1);
72 strncpy(n, p, pe - p);
79 _elm_module_add(n, nn);
94 _elm_module_find_as(const char *as)
98 m = eina_hash_find(modules_as, as);
103 _elm_module_add(const char *name, const char *as)
108 m = eina_hash_find(modules, name);
114 m = calloc(1, sizeof(Elm_Module));
119 const char *home = getenv("HOME");
123 snprintf(buf, sizeof(buf), "%s/.elementary/modules/%s/%s/module" EFL_SHARED_EXTENSION, home, name, MODULE_ARCH);
124 m->handle = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
127 m->init_func = dlsym(m->handle, "elm_modapi_init");
130 m->shutdown_func = dlsym(m->handle, "elm_modapi_shutdown");
131 m->so_path = eina_stringshare_add(buf);
132 m->name = eina_stringshare_add(name);
133 snprintf(buf, sizeof(buf), "%s/.elementary/modules/%s/%s", home, name, MODULE_ARCH);
134 m->bin_dir = eina_stringshare_add(buf);
135 snprintf(buf, sizeof(buf), "%s/.elementary/modules/%s", home, name);
136 m->data_dir = eina_stringshare_add(buf);
148 snprintf(buf, sizeof(buf), "%s/elementary/modules/%s/%s/module" EFL_SHARED_EXTENSION, _elm_lib_dir, name, MODULE_ARCH);
149 m->handle = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
152 m->init_func = dlsym(m->handle, "elm_modapi_init");
155 m->shutdown_func = dlsym(m->handle, "elm_modapi_shutdown");
156 m->so_path = eina_stringshare_add(buf);
157 m->name = eina_stringshare_add(name);
158 snprintf(buf, sizeof(buf), "%s/elementary/modules/%s/%s", _elm_lib_dir, name, MODULE_ARCH);
159 m->bin_dir = eina_stringshare_add(buf);
160 snprintf(buf, sizeof(buf), "%s/elementary/modules/%s", _elm_lib_dir, name);
161 m->data_dir = eina_stringshare_add(buf);
177 if (!m->init_func(m))
180 eina_stringshare_del(m->name);
181 eina_stringshare_del(m->so_path);
182 eina_stringshare_del(m->data_dir);
183 eina_stringshare_del(m->bin_dir);
188 eina_hash_direct_add(modules, m->name, m);
189 m->as = eina_stringshare_add(as);
190 eina_hash_direct_add(modules_as, m->as, m);
195 _elm_module_del(Elm_Module *m)
198 if (m->references > 0) return;
199 if (m->shutdown_func) m->shutdown_func(m);
200 eina_hash_del(modules, m->name, m);
201 eina_hash_del(modules_as, m->as, m);
202 if (m->api) free(m->api);
203 eina_stringshare_del(m->name);
204 eina_stringshare_del(m->as);
205 eina_stringshare_del(m->so_path);
206 eina_stringshare_del(m->data_dir);
207 eina_stringshare_del(m->bin_dir);
213 _elm_module_symbol_get(Elm_Module *m, const char *name)
215 return dlsym(m->handle, name);