1 #include "edje_private.h"
3 Eina_Hash *_registered_modules = NULL;
4 Eina_List *_modules_paths = NULL;
6 Eina_List *_modules_found = NULL;
8 #if defined(__CEGCC__) || defined(__MINGW32CE__)
9 # define EDJE_MODULE_NAME "edje_%s.dll"
10 # define EDJE_EXTRA_MODULE_NAME 1
12 # define EDJE_MODULE_NAME "module.dll"
14 # define EDJE_MODULE_NAME "module.so"
18 edje_module_load(const char *module)
20 if (_edje_module_handle_load(module)) return EINA_TRUE;
25 _edje_module_handle_load(const char *module)
29 Eina_Module *em = NULL;
31 EINA_SAFETY_ON_NULL_RETURN_VAL(module, NULL);
33 em = (Eina_Module *)eina_hash_find(_registered_modules, module);
36 EINA_LIST_FOREACH(_modules_paths, l, path)
40 snprintf(tmp, sizeof (tmp), "%s/%s/%s/" EDJE_MODULE_NAME, path, module, MODULE_ARCH
41 #ifdef EDJE_EXTRA_MODULE_NAME
45 em = eina_module_new(tmp);
48 if (!eina_module_load(em))
53 if (eina_hash_add(_registered_modules, module, em))
61 _edje_module_init(void)
63 char *paths[4] = { NULL, NULL, NULL, NULL };
67 _registered_modules = eina_hash_string_small_new(EINA_FREE_CB(eina_module_free));
69 /* 1. ~/.edje/modules/ */
70 paths[0] = eina_module_environment_path_get("HOME", "/.edje/modules");
71 /* 2. $(EDJE_MODULE_DIR)/edje/modules/ */
72 paths[1] = eina_module_environment_path_get("EDJE_MODULES_DIR", "/edje/modules");
73 /* 3. libedje.so/../edje/modules/ */
74 paths[2] = eina_module_symbol_path_get(_edje_module_init, "/edje/modules");
75 /* 4. PREFIX/edje/modules/ */
77 paths[3] = strdup(PACKAGE_LIB_DIR "/edje/modules");
80 for (j = 0; j < ((sizeof (paths) / sizeof (char*)) - 1); ++j)
81 for (i = j + 1; i < sizeof (paths) / sizeof (char*); ++i)
82 if (paths[i] && paths[j] && !strcmp(paths[i], paths[j]))
88 for (i = 0; i < sizeof (paths) / sizeof (char*); ++i)
90 _modules_paths = eina_list_append(_modules_paths, paths[i]);
94 _edje_module_shutdown(void)
98 if (_registered_modules)
100 eina_hash_free(_registered_modules);
101 _registered_modules = NULL;
104 EINA_LIST_FREE(_modules_paths, path)
107 EINA_LIST_FREE(_modules_found, path)
108 eina_stringshare_del(path);
111 EAPI const Eina_List *
112 edje_available_modules_get(void)
114 Eina_File_Direct_Info *info;
118 Eina_List *result = NULL;
120 /* FIXME: Stat each possible dir and check if they did change, before starting a huge round of readdir/stat */
123 EINA_LIST_FREE(_modules_found, path)
124 eina_stringshare_del(path);
127 EINA_LIST_FOREACH(_modules_paths, l, path)
129 it = eina_file_direct_ls(path);
133 EINA_ITERATOR_FOREACH(it, info)
137 snprintf(tmp, sizeof (tmp), "%s/%s/" EDJE_MODULE_NAME, info->path, MODULE_ARCH
138 #ifdef EDJE_EXTRA_MODULE_NAME
139 , info->path + info->name_start
143 if (ecore_file_exists(tmp))
144 result = eina_list_append(result, eina_stringshare_add(info->path + info->name_start));
147 eina_iterator_free(it);
151 _modules_found = result;