diff options
Diffstat (limited to 'libraries/evas/src/lib/file/evas_module.c')
-rw-r--r-- | libraries/evas/src/lib/file/evas_module.c | 586 |
1 files changed, 586 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/file/evas_module.c b/libraries/evas/src/lib/file/evas_module.c new file mode 100644 index 0000000..6b4d4f6 --- /dev/null +++ b/libraries/evas/src/lib/file/evas_module.c | |||
@@ -0,0 +1,586 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <string.h> | ||
6 | |||
7 | #include <evas_common.h> | ||
8 | #include <evas_private.h> | ||
9 | #include <evas_module.h> | ||
10 | |||
11 | |||
12 | static Eina_Hash *evas_modules[4] = { | ||
13 | NULL, | ||
14 | NULL, | ||
15 | NULL, | ||
16 | NULL | ||
17 | }; | ||
18 | |||
19 | static Eina_List *eina_evas_modules = NULL; | ||
20 | static Eina_List *evas_module_paths = NULL; | ||
21 | static Eina_Array *evas_engines = NULL; | ||
22 | |||
23 | static Eina_List * | ||
24 | _evas_module_append(Eina_List *list, char *path) | ||
25 | { | ||
26 | if (path) | ||
27 | { | ||
28 | if (evas_file_path_exists(path)) | ||
29 | list = eina_list_append(list, path); | ||
30 | else | ||
31 | free(path); | ||
32 | } | ||
33 | return list; | ||
34 | } | ||
35 | |||
36 | /* this will alloc a list of paths to search for the modules */ | ||
37 | /* by now these are: */ | ||
38 | /* 1. ~/.evas/modules/ */ | ||
39 | /* 2. $(EVAS_MODULE_DIR)/evas/modules/ */ | ||
40 | /* 3. dladdr/evas/modules/ */ | ||
41 | /* 4. PREFIX/evas/modules/ */ | ||
42 | void | ||
43 | evas_module_paths_init(void) | ||
44 | { | ||
45 | char *path; | ||
46 | |||
47 | /* 1. ~/.evas/modules/ */ | ||
48 | path = eina_module_environment_path_get("HOME", "/.evas/modules"); | ||
49 | evas_module_paths = _evas_module_append(evas_module_paths, path); | ||
50 | |||
51 | /* 2. $(EVAS_MODULE_DIR)/evas/modules/ */ | ||
52 | path = eina_module_environment_path_get("EVAS_MODULES_DIR", "/evas/modules"); | ||
53 | if (eina_list_search_unsorted(evas_module_paths, (Eina_Compare_Cb) strcmp, path)) | ||
54 | free(path); | ||
55 | else | ||
56 | evas_module_paths = _evas_module_append(evas_module_paths, path); | ||
57 | |||
58 | /* 3. libevas.so/../evas/modules/ */ | ||
59 | path = eina_module_symbol_path_get(evas_module_paths_init, "/evas/modules"); | ||
60 | if (eina_list_search_unsorted(evas_module_paths, (Eina_Compare_Cb) strcmp, path)) | ||
61 | free(path); | ||
62 | else | ||
63 | evas_module_paths = _evas_module_append(evas_module_paths, path); | ||
64 | |||
65 | /* 4. PREFIX/evas/modules/ */ | ||
66 | #ifndef _MSC_VER | ||
67 | path = PACKAGE_LIB_DIR "/evas/modules"; | ||
68 | if (!eina_list_search_unsorted(evas_module_paths, (Eina_Compare_Cb) strcmp, path)) | ||
69 | { | ||
70 | path = strdup(path); | ||
71 | if (path) | ||
72 | evas_module_paths = _evas_module_append(evas_module_paths, path); | ||
73 | } | ||
74 | #endif | ||
75 | } | ||
76 | |||
77 | #define EVAS_EINA_STATIC_MODULE_DEFINE(Tn, Name) \ | ||
78 | Eina_Bool evas_##Tn##_##Name##_init(void); \ | ||
79 | void evas_##Tn##_##Name##_shutdown(void); | ||
80 | |||
81 | #define EVAS_EINA_STATIC_MODULE_USE(Tn, Name) \ | ||
82 | { evas_##Tn##_##Name##_init, evas_##Tn##_##Name##_shutdown } | ||
83 | |||
84 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, buffer); | ||
85 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, direct3d); | ||
86 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, directfb); | ||
87 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, fb); | ||
88 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, gl_x11); | ||
89 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, gl_sdl); | ||
90 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, psl1ght); | ||
91 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_16); | ||
92 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_16_ddraw); | ||
93 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_16_sdl); | ||
94 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_16_wince); | ||
95 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_16_x11); | ||
96 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_8); | ||
97 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_8_x11); | ||
98 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_ddraw); | ||
99 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_gdi); | ||
100 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_generic); | ||
101 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_sdl); | ||
102 | EVAS_EINA_STATIC_MODULE_DEFINE(engine, software_x11); | ||
103 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, bmp); | ||
104 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, edb); | ||
105 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, eet); | ||
106 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, generic); | ||
107 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, gif); | ||
108 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, ico); | ||
109 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, jpeg); | ||
110 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, pmaps); | ||
111 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, png); | ||
112 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, psd); | ||
113 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, svg); | ||
114 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, tga); | ||
115 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, tiff); | ||
116 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, wbmp); | ||
117 | EVAS_EINA_STATIC_MODULE_DEFINE(image_loader, xpm); | ||
118 | EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, edb); | ||
119 | EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, eet); | ||
120 | EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, jpeg); | ||
121 | EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, png); | ||
122 | EVAS_EINA_STATIC_MODULE_DEFINE(image_saver, tiff); | ||
123 | |||
124 | static const struct { | ||
125 | Eina_Bool (*init)(void); | ||
126 | void (*shutdown)(void); | ||
127 | } evas_static_module[] = { | ||
128 | #ifdef EVAS_STATIC_BUILD_BUFFER | ||
129 | EVAS_EINA_STATIC_MODULE_USE(engine, buffer), | ||
130 | #endif | ||
131 | #ifdef EVAS_STATIC_BUILD_DIRECT3D | ||
132 | EVAS_EINA_STATIC_MODULE_USE(engine, direct3d), | ||
133 | #endif | ||
134 | #ifdef EVAS_STATIC_BUILD_DIRECTFB | ||
135 | EVAS_EINA_STATIC_MODULE_USE(engine, directfb), | ||
136 | #endif | ||
137 | #ifdef EVAS_STATIC_BUILD_FB | ||
138 | EVAS_EINA_STATIC_MODULE_USE(engine, fb), | ||
139 | #endif | ||
140 | #ifdef EVAS_STATIC_BUILD_GL_X11 | ||
141 | EVAS_EINA_STATIC_MODULE_USE(engine, gl_x11), | ||
142 | #endif | ||
143 | #ifdef EVAS_STATIC_BUILD_GL_SDL | ||
144 | EVAS_EINA_STATIC_MODULE_USE(engine, gl_sdl), | ||
145 | #endif | ||
146 | #ifdef EVAS_STATIC_BUILD_PSL1GHT | ||
147 | EVAS_EINA_STATIC_MODULE_USE(engine, psl1ght), | ||
148 | #endif | ||
149 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16 | ||
150 | EVAS_EINA_STATIC_MODULE_USE(engine, software_16), | ||
151 | #endif | ||
152 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16_DDRAW | ||
153 | EVAS_EINA_STATIC_MODULE_USE(engine, software_16_ddraw), | ||
154 | #endif | ||
155 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16_SDL | ||
156 | EVAS_EINA_STATIC_MODULE_USE(engine, software_16_sdl), | ||
157 | #endif | ||
158 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16_WINCE | ||
159 | EVAS_EINA_STATIC_MODULE_USE(engine, software_16_wince), | ||
160 | #endif | ||
161 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16_X11 | ||
162 | EVAS_EINA_STATIC_MODULE_USE(engine, software_16_x11), | ||
163 | #endif | ||
164 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16_DDRAW | ||
165 | EVAS_EINA_STATIC_MODULE_USE(engine, software_ddraw), | ||
166 | #endif | ||
167 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_16_GDI | ||
168 | EVAS_EINA_STATIC_MODULE_USE(engine, software_gdi), | ||
169 | #endif | ||
170 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_8 | ||
171 | EVAS_EINA_STATIC_MODULE_USE(engine, software_8), | ||
172 | #endif | ||
173 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_8_X11 | ||
174 | EVAS_EINA_STATIC_MODULE_USE(engine, software_8_x11), | ||
175 | #endif | ||
176 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_GENERIC | ||
177 | EVAS_EINA_STATIC_MODULE_USE(engine, software_generic), | ||
178 | #endif | ||
179 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_SDL | ||
180 | EVAS_EINA_STATIC_MODULE_USE(engine, software_sdl), | ||
181 | #endif | ||
182 | #ifdef EVAS_STATIC_BUILD_SOFTWARE_X11 | ||
183 | EVAS_EINA_STATIC_MODULE_USE(engine, software_x11), | ||
184 | #endif | ||
185 | #ifdef EVAS_STATIC_BUILD_BMP | ||
186 | EVAS_EINA_STATIC_MODULE_USE(image_loader, bmp), | ||
187 | #endif | ||
188 | #ifdef EVAS_STATIC_BUILD_EDB | ||
189 | EVAS_EINA_STATIC_MODULE_USE(image_loader, edb), | ||
190 | #endif | ||
191 | #ifdef EVAS_STATIC_BUILD_EET | ||
192 | EVAS_EINA_STATIC_MODULE_USE(image_loader, eet), | ||
193 | #endif | ||
194 | #ifdef EVAS_STATIC_BUILD_GENERIC | ||
195 | EVAS_EINA_STATIC_MODULE_USE(image_loader, generic), | ||
196 | #endif | ||
197 | #ifdef EVAS_STATIC_BUILD_GIF | ||
198 | EVAS_EINA_STATIC_MODULE_USE(image_loader, gif), | ||
199 | #endif | ||
200 | #ifdef EVAS_STATIC_BUILD_ICO | ||
201 | EVAS_EINA_STATIC_MODULE_USE(image_loader, ico), | ||
202 | #endif | ||
203 | #ifdef EVAS_STATIC_BUILD_JPEG | ||
204 | EVAS_EINA_STATIC_MODULE_USE(image_loader, jpeg), | ||
205 | #endif | ||
206 | #ifdef EVAS_STATIC_BUILD_PMAPS | ||
207 | EVAS_EINA_STATIC_MODULE_USE(image_loader, pmaps), | ||
208 | #endif | ||
209 | #ifdef EVAS_STATIC_BUILD_PNG | ||
210 | EVAS_EINA_STATIC_MODULE_USE(image_loader, png), | ||
211 | #endif | ||
212 | #ifdef EVAS_STATIC_BUILD_PSD | ||
213 | EVAS_EINA_STATIC_MODULE_USE(image_loader, psd), | ||
214 | #endif | ||
215 | #ifdef EVAS_STATIC_BUILD_SVG | ||
216 | EVAS_EINA_STATIC_MODULE_USE(image_loader, svg), | ||
217 | #endif | ||
218 | #ifdef EVAS_STATIC_BUILD_TGA | ||
219 | EVAS_EINA_STATIC_MODULE_USE(image_loader, tga), | ||
220 | #endif | ||
221 | #ifdef EVAS_STATIC_BUILD_TIFF | ||
222 | EVAS_EINA_STATIC_MODULE_USE(image_loader, tiff), | ||
223 | #endif | ||
224 | #ifdef EVAS_STATIC_BUILD_WBMP | ||
225 | EVAS_EINA_STATIC_MODULE_USE(image_loader, wbmp), | ||
226 | #endif | ||
227 | #ifdef EVAS_STATIC_BUILD_XPM | ||
228 | EVAS_EINA_STATIC_MODULE_USE(image_loader, xpm), | ||
229 | #endif | ||
230 | #ifdef EVAS_STATIC_BUILD_EDB | ||
231 | EVAS_EINA_STATIC_MODULE_USE(image_saver, edb), | ||
232 | #endif | ||
233 | #ifdef EVAS_STATIC_BUILD_EET | ||
234 | EVAS_EINA_STATIC_MODULE_USE(image_saver, eet), | ||
235 | #endif | ||
236 | #if defined (EVAS_BUILD_SAVER_JPEG) && defined (EVAS_STATIC_BUILD_JPEG) | ||
237 | EVAS_EINA_STATIC_MODULE_USE(image_saver, jpeg), | ||
238 | #endif | ||
239 | #ifdef EVAS_STATIC_BUILD_PNG | ||
240 | EVAS_EINA_STATIC_MODULE_USE(image_saver, png), | ||
241 | #endif | ||
242 | #ifdef EVAS_STATIC_BUILD_TIFF | ||
243 | EVAS_EINA_STATIC_MODULE_USE(image_saver, tiff), | ||
244 | #endif | ||
245 | { NULL, NULL } | ||
246 | }; | ||
247 | |||
248 | /* this will alloc an Evas_Module struct for each module | ||
249 | * it finds on the paths */ | ||
250 | void | ||
251 | evas_module_init(void) | ||
252 | { | ||
253 | int i; | ||
254 | |||
255 | evas_module_paths_init(); | ||
256 | |||
257 | evas_modules[EVAS_MODULE_TYPE_ENGINE] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); | ||
258 | evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); | ||
259 | evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); | ||
260 | evas_modules[EVAS_MODULE_TYPE_OBJECT] = eina_hash_string_small_new(/* FIXME: Add a function to cleanup stuff. */ NULL); | ||
261 | |||
262 | evas_engines = eina_array_new(4); | ||
263 | |||
264 | for (i = 0; evas_static_module[i].init; ++i) | ||
265 | evas_static_module[i].init(); | ||
266 | } | ||
267 | |||
268 | Eina_Bool | ||
269 | evas_module_register(const Evas_Module_Api *module, Evas_Module_Type type) | ||
270 | { | ||
271 | Evas_Module *em; | ||
272 | |||
273 | if ((unsigned int)type > 3) return EINA_FALSE; | ||
274 | if (!module) return EINA_FALSE; | ||
275 | if (module->version != EVAS_MODULE_API_VERSION) return EINA_FALSE; | ||
276 | |||
277 | em = eina_hash_find(evas_modules[type], module->name); | ||
278 | if (em) return EINA_FALSE; | ||
279 | |||
280 | em = calloc(1, sizeof (Evas_Module)); | ||
281 | if (!em) return EINA_FALSE; | ||
282 | |||
283 | em->definition = module; | ||
284 | |||
285 | if (type == EVAS_MODULE_TYPE_ENGINE) | ||
286 | { | ||
287 | eina_array_push(evas_engines, em); | ||
288 | em->id_engine = eina_array_count_get(evas_engines); | ||
289 | } | ||
290 | |||
291 | eina_hash_direct_add(evas_modules[type], module->name, em); | ||
292 | |||
293 | return EINA_TRUE; | ||
294 | } | ||
295 | |||
296 | Eina_List * | ||
297 | evas_module_engine_list(void) | ||
298 | { | ||
299 | Evas_Module *em; | ||
300 | Eina_List *r = NULL; | ||
301 | Eina_Array_Iterator iterator; | ||
302 | unsigned int i; | ||
303 | |||
304 | EINA_ARRAY_ITER_NEXT(evas_engines, i, em, iterator) | ||
305 | r = eina_list_append(r, em->definition->name); | ||
306 | |||
307 | return r; | ||
308 | } | ||
309 | |||
310 | Eina_Bool | ||
311 | evas_module_unregister(const Evas_Module_Api *module, Evas_Module_Type type) | ||
312 | { | ||
313 | Evas_Module *em; | ||
314 | |||
315 | if ((unsigned int)type > 3) return EINA_FALSE; | ||
316 | if (!module) return EINA_FALSE; | ||
317 | |||
318 | em = eina_hash_find(evas_modules[type], module->name); | ||
319 | if (!em || em->definition != module) return EINA_FALSE; | ||
320 | |||
321 | if (type == EVAS_MODULE_TYPE_ENGINE) | ||
322 | eina_array_data_set(evas_engines, em->id_engine, NULL); | ||
323 | |||
324 | eina_hash_del(evas_modules[type], module->name, em); | ||
325 | free(em); | ||
326 | |||
327 | return EINA_TRUE; | ||
328 | } | ||
329 | |||
330 | #if defined(__CEGCC__) || defined(__MINGW32CE__) | ||
331 | # define EVAS_MODULE_NAME_IMAGE_SAVER "saver_%s.dll" | ||
332 | # define EVAS_MODULE_NAME_IMAGE_LOADER "loader_%s.dll" | ||
333 | # define EVAS_MODULE_NAME_ENGINE "engine_%s.dll" | ||
334 | # define EVAS_MODULE_NAME_OBJECT "object_%s.dll" | ||
335 | #elif _WIN32 | ||
336 | # define EVAS_MODULE_NAME_IMAGE_SAVER "module.dll" | ||
337 | # define EVAS_MODULE_NAME_IMAGE_LOADER "module.dll" | ||
338 | # define EVAS_MODULE_NAME_ENGINE "module.dll" | ||
339 | # define EVAS_MODULE_NAME_OBJECT "module.dll" | ||
340 | #else | ||
341 | # define EVAS_MODULE_NAME_IMAGE_SAVER "module.so" | ||
342 | # define EVAS_MODULE_NAME_IMAGE_LOADER "module.so" | ||
343 | # define EVAS_MODULE_NAME_ENGINE "module.so" | ||
344 | # define EVAS_MODULE_NAME_OBJECT "module.so" | ||
345 | #endif | ||
346 | |||
347 | Evas_Module * | ||
348 | evas_module_find_type(Evas_Module_Type type, const char *name) | ||
349 | { | ||
350 | const char *path; | ||
351 | const char *format = NULL; | ||
352 | char buffer[4096]; | ||
353 | Evas_Module *em; | ||
354 | Eina_Module *en; | ||
355 | Eina_List *l; | ||
356 | |||
357 | if ((unsigned int)type > 3) return NULL; | ||
358 | |||
359 | em = eina_hash_find(evas_modules[type], name); | ||
360 | if (em) return em; | ||
361 | |||
362 | EINA_LIST_FOREACH(evas_module_paths, l, path) | ||
363 | { | ||
364 | switch (type) | ||
365 | { | ||
366 | case EVAS_MODULE_TYPE_ENGINE: format = "%s/engines/%s/%s/" EVAS_MODULE_NAME_ENGINE; break; | ||
367 | case EVAS_MODULE_TYPE_IMAGE_LOADER: format = "%s/loaders/%s/%s/" EVAS_MODULE_NAME_IMAGE_LOADER; break; | ||
368 | case EVAS_MODULE_TYPE_IMAGE_SAVER: format = "%s/savers/%s/%s/" EVAS_MODULE_NAME_IMAGE_SAVER; break; | ||
369 | case EVAS_MODULE_TYPE_OBJECT: format = "%s/object/%s/%s/" EVAS_MODULE_NAME_OBJECT; break; | ||
370 | } | ||
371 | |||
372 | snprintf(buffer, sizeof (buffer), format, path, name, MODULE_ARCH, name); | ||
373 | if (!evas_file_path_is_file(buffer)) continue; | ||
374 | |||
375 | en = eina_module_new(buffer); | ||
376 | if (!en) continue; | ||
377 | |||
378 | if (!eina_module_load(en)) | ||
379 | { | ||
380 | eina_module_free(en); | ||
381 | continue; | ||
382 | } | ||
383 | |||
384 | em = eina_hash_find(evas_modules[type], name); | ||
385 | if (em) | ||
386 | { | ||
387 | eina_evas_modules = eina_list_append(eina_evas_modules, en); | ||
388 | return em; | ||
389 | } | ||
390 | |||
391 | eina_module_free(en); | ||
392 | } | ||
393 | |||
394 | return NULL; | ||
395 | } | ||
396 | |||
397 | Evas_Module * | ||
398 | evas_module_engine_get(int render_method) | ||
399 | { | ||
400 | if ((render_method <= 0) || | ||
401 | ((unsigned int)render_method > eina_array_count_get(evas_engines))) | ||
402 | return NULL; | ||
403 | return eina_array_data_get(evas_engines, render_method - 1); | ||
404 | } | ||
405 | |||
406 | void | ||
407 | evas_module_foreach_image_loader(Eina_Hash_Foreach cb, const void *fdata) | ||
408 | { | ||
409 | eina_hash_foreach(evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER], cb, fdata); | ||
410 | } | ||
411 | |||
412 | int | ||
413 | evas_module_load(Evas_Module *em) | ||
414 | { | ||
415 | if (em->loaded) return 1; | ||
416 | if (!em->definition) return 0; | ||
417 | |||
418 | if (!em->definition->func.open(em)) return 0; | ||
419 | em->loaded = 1; | ||
420 | |||
421 | #ifdef BUILD_ASYNC_PRELOAD | ||
422 | LKI(em->lock); | ||
423 | #endif | ||
424 | return 1; | ||
425 | } | ||
426 | |||
427 | void | ||
428 | evas_module_unload(Evas_Module *em) | ||
429 | { | ||
430 | if (!em->loaded) | ||
431 | return; | ||
432 | if (!em->definition) | ||
433 | return ; | ||
434 | |||
435 | // for now lets not unload modules - they may still be in use. | ||
436 | // em->definition->func.close(em); | ||
437 | // em->loaded = 0; | ||
438 | |||
439 | #ifdef BUILD_ASYNC_PRELOAD | ||
440 | LKD(em->lock); | ||
441 | #endif | ||
442 | } | ||
443 | |||
444 | void | ||
445 | evas_module_ref(Evas_Module *em) | ||
446 | { | ||
447 | #ifdef BUILD_ASYNC_PRELOAD | ||
448 | LKL(em->lock); | ||
449 | #endif | ||
450 | em->ref++; | ||
451 | #ifdef BUILD_ASYNC_PRELOAD | ||
452 | LKU(em->lock); | ||
453 | #endif | ||
454 | } | ||
455 | |||
456 | void | ||
457 | evas_module_unref(Evas_Module *em) | ||
458 | { | ||
459 | #ifdef BUILD_ASYNC_PRELOAD | ||
460 | LKL(em->lock); | ||
461 | #endif | ||
462 | em->ref--; | ||
463 | #ifdef BUILD_ASYNC_PRELOAD | ||
464 | LKU(em->lock); | ||
465 | #endif | ||
466 | } | ||
467 | |||
468 | static int use_count = 0; | ||
469 | |||
470 | void | ||
471 | evas_module_use(Evas_Module *em) | ||
472 | { | ||
473 | em->last_used = use_count; | ||
474 | } | ||
475 | |||
476 | void | ||
477 | evas_module_clean(void) | ||
478 | { | ||
479 | static int call_count = 0; | ||
480 | /* int ago; */ | ||
481 | int noclean = -1; | ||
482 | /* Eina_List *l; */ | ||
483 | /* Evas_Module *em; */ | ||
484 | |||
485 | /* only clean modules every 256 calls */ | ||
486 | call_count++; | ||
487 | if (call_count <= 256) return; | ||
488 | call_count = 0; | ||
489 | |||
490 | if (noclean == -1) | ||
491 | { | ||
492 | if (getenv("EVAS_NOCLEAN")) | ||
493 | noclean = 1; | ||
494 | else | ||
495 | noclean = 0; | ||
496 | } | ||
497 | if (noclean == 1) return; | ||
498 | |||
499 | /* disable module cleaning for now - may cause instability with some modules */ | ||
500 | return; | ||
501 | |||
502 | /* FIXME: Don't know what it is supposed to do. */ | ||
503 | /* /\* incriment use counter = 28bits *\/ */ | ||
504 | /* use_count++; */ | ||
505 | /* if (use_count > 0x0fffffff) use_count = 0; */ | ||
506 | |||
507 | /* /\* printf("CLEAN!\n"); *\/ */ | ||
508 | /* /\* go through all modules *\/ */ | ||
509 | /* EINA_LIST_FOREACH(evas_modules, l, em) */ | ||
510 | /* { */ | ||
511 | /* /\* printf("M %s %i %i\n", em->name, em->ref, em->loaded); *\/ */ | ||
512 | /* /\* if the module is refernced - skip *\/ */ | ||
513 | /* if ((em->ref > 0) || (!em->loaded)) continue; */ | ||
514 | /* /\* how many clean cycles ago was this module last used *\/ */ | ||
515 | /* ago = use_count - em->last_used; */ | ||
516 | /* if (em->last_used > use_count) ago += 0x10000000; */ | ||
517 | /* /\* if it was used last more than N clean cycles ago - unload *\/ */ | ||
518 | /* if (ago > 5) */ | ||
519 | /* { */ | ||
520 | /* /\* printf(" UNLOAD %s\n", em->name); *\/ */ | ||
521 | /* evas_module_unload(em); */ | ||
522 | /* } */ | ||
523 | /* } */ | ||
524 | } | ||
525 | |||
526 | /* will dlclose all the modules loaded and free all the structs */ | ||
527 | void | ||
528 | evas_module_shutdown(void) | ||
529 | { | ||
530 | Eina_Module *en; | ||
531 | char *path; | ||
532 | int i; | ||
533 | |||
534 | for (i = 0; evas_static_module[i].shutdown; ++i) | ||
535 | evas_static_module[i].shutdown(); | ||
536 | |||
537 | EINA_LIST_FREE(eina_evas_modules, en) | ||
538 | eina_module_free(en); | ||
539 | |||
540 | eina_hash_free(evas_modules[EVAS_MODULE_TYPE_ENGINE]); | ||
541 | evas_modules[EVAS_MODULE_TYPE_ENGINE] = NULL; | ||
542 | eina_hash_free(evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER]); | ||
543 | evas_modules[EVAS_MODULE_TYPE_IMAGE_LOADER] = NULL; | ||
544 | eina_hash_free(evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER]); | ||
545 | evas_modules[EVAS_MODULE_TYPE_IMAGE_SAVER] = NULL; | ||
546 | eina_hash_free(evas_modules[EVAS_MODULE_TYPE_OBJECT]); | ||
547 | evas_modules[EVAS_MODULE_TYPE_OBJECT] = NULL; | ||
548 | |||
549 | EINA_LIST_FREE(evas_module_paths, path) | ||
550 | free(path); | ||
551 | |||
552 | eina_array_free(evas_engines); | ||
553 | evas_engines = NULL; | ||
554 | } | ||
555 | |||
556 | EAPI int | ||
557 | _evas_module_engine_inherit(Evas_Func *funcs, char *name) | ||
558 | { | ||
559 | Evas_Module *em; | ||
560 | |||
561 | em = evas_module_find_type(EVAS_MODULE_TYPE_ENGINE, name); | ||
562 | if (em) | ||
563 | { | ||
564 | if (evas_module_load(em)) | ||
565 | { | ||
566 | /* FIXME: no way to unref */ | ||
567 | evas_module_ref(em); | ||
568 | evas_module_use(em); | ||
569 | *funcs = *((Evas_Func *)(em->functions)); | ||
570 | return 1; | ||
571 | } | ||
572 | } | ||
573 | return 0; | ||
574 | } | ||
575 | |||
576 | static Eina_Prefix *pfx = NULL; | ||
577 | |||
578 | EAPI const char * | ||
579 | _evas_module_libdir_get(void) | ||
580 | { | ||
581 | if (!pfx) pfx = eina_prefix_new | ||
582 | (NULL, _evas_module_libdir_get, "EVAS", "evas", NULL, | ||
583 | PACKAGE_BIN_DIR, PACKAGE_LIB_DIR, PACKAGE_DATA_DIR, PACKAGE_DATA_DIR); | ||
584 | if (!pfx) return NULL; | ||
585 | return eina_prefix_lib_get(pfx); | ||
586 | } | ||