2010-06-26 12:41:41 -07:00
|
|
|
#include "edje_private.h"
|
2009-11-23 07:03:19 -08:00
|
|
|
|
|
|
|
Eina_Hash *_registered_modules = NULL;
|
2010-08-18 09:57:19 -07:00
|
|
|
Eina_List *_modules_paths = NULL;
|
2009-11-23 07:03:19 -08:00
|
|
|
|
2010-08-18 09:57:19 -07:00
|
|
|
Eina_List *_modules_found = NULL;
|
|
|
|
|
2013-01-04 09:19:43 -08:00
|
|
|
#if _WIN32
|
2010-08-18 09:57:19 -07:00
|
|
|
# define EDJE_MODULE_NAME "module.dll"
|
|
|
|
#else
|
|
|
|
# define EDJE_MODULE_NAME "module.so"
|
|
|
|
#endif
|
2009-11-23 07:03:19 -08:00
|
|
|
|
2011-11-04 16:19:14 -07:00
|
|
|
EAPI Eina_Bool
|
2009-11-23 07:03:19 -08:00
|
|
|
edje_module_load(const char *module)
|
2011-11-04 16:19:14 -07:00
|
|
|
{
|
|
|
|
if (_edje_module_handle_load(module)) return EINA_TRUE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Module *
|
|
|
|
_edje_module_handle_load(const char *module)
|
2009-11-23 07:03:19 -08:00
|
|
|
{
|
2010-08-18 09:57:19 -07:00
|
|
|
const char *path;
|
|
|
|
Eina_List *l;
|
2011-11-04 05:18:13 -07:00
|
|
|
Eina_Module *em = NULL;
|
2013-01-04 09:19:43 -08:00
|
|
|
Eina_Bool run_in_tree;
|
2009-11-23 07:03:19 -08:00
|
|
|
|
2011-11-04 05:18:13 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(module, NULL);
|
2009-11-23 10:47:31 -08:00
|
|
|
|
2011-11-04 05:18:13 -07:00
|
|
|
em = (Eina_Module *)eina_hash_find(_registered_modules, module);
|
|
|
|
if (em) return em;
|
2009-11-23 10:47:31 -08:00
|
|
|
|
2013-01-04 09:19:43 -08:00
|
|
|
run_in_tree = !!getenv("EFL_RUN_IN_TREE");
|
|
|
|
|
2010-08-18 09:57:19 -07:00
|
|
|
EINA_LIST_FOREACH(_modules_paths, l, path)
|
2009-11-23 07:03:19 -08:00
|
|
|
{
|
2013-01-04 09:19:43 -08:00
|
|
|
char tmp[PATH_MAX] = "";
|
|
|
|
|
2014-01-08 05:06:41 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() == geteuid())
|
|
|
|
#endif
|
2013-01-04 09:19:43 -08:00
|
|
|
{
|
2014-01-08 02:46:23 -08:00
|
|
|
if (run_in_tree)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%s/.libs/%s",
|
|
|
|
path, module, EDJE_MODULE_NAME);
|
|
|
|
if (stat(tmp, &st) != 0)
|
|
|
|
tmp[0] = '\0';
|
|
|
|
}
|
2013-01-04 09:19:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp[0] == '\0')
|
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%s/%s/%s",
|
|
|
|
path, module, MODULE_ARCH, EDJE_MODULE_NAME);
|
2009-11-23 07:03:19 -08:00
|
|
|
|
2011-11-04 05:18:13 -07:00
|
|
|
em = eina_module_new(tmp);
|
|
|
|
if (!em) continue;
|
2010-08-18 09:57:19 -07:00
|
|
|
|
2011-11-04 05:18:13 -07:00
|
|
|
if (!eina_module_load(em))
|
|
|
|
{
|
|
|
|
eina_module_free(em);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (eina_hash_add(_registered_modules, module, em))
|
|
|
|
return em;
|
2009-11-23 07:03:19 -08:00
|
|
|
}
|
|
|
|
|
2011-11-04 05:18:13 -07:00
|
|
|
return NULL;
|
2009-11-23 07:03:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_edje_module_init(void)
|
|
|
|
{
|
2014-01-08 02:46:23 -08:00
|
|
|
char *paths[2] = { NULL, NULL };
|
2010-08-17 06:29:23 -07:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int j;
|
2009-11-23 11:50:54 -08:00
|
|
|
|
2010-08-18 09:57:19 -07:00
|
|
|
_registered_modules = eina_hash_string_small_new(EINA_FREE_CB(eina_module_free));
|
2010-08-17 06:29:23 -07:00
|
|
|
|
2014-01-08 05:06:41 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() == geteuid())
|
|
|
|
#endif
|
2013-01-04 09:19:43 -08:00
|
|
|
{
|
2014-01-08 02:46:23 -08:00
|
|
|
if (getenv("EFL_RUN_IN_TREE"))
|
2013-01-04 09:19:43 -08:00
|
|
|
{
|
2014-01-08 02:46:23 -08:00
|
|
|
struct stat st;
|
|
|
|
const char mp[] = PACKAGE_BUILD_DIR"/src/modules/edje";
|
|
|
|
if (stat(mp, &st) == 0)
|
|
|
|
{
|
|
|
|
_modules_paths = eina_list_append(_modules_paths, strdup(mp));
|
|
|
|
return;
|
|
|
|
}
|
2013-01-04 09:19:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 02:46:23 -08:00
|
|
|
/* 1. libedje.so/../edje/modules/ */
|
|
|
|
paths[0] = eina_module_symbol_path_get(_edje_module_init, "/edje/modules");
|
|
|
|
/* 2. PREFIX/edje/modules/ */
|
2010-08-17 06:29:23 -07:00
|
|
|
#ifndef _MSC_VER
|
2014-01-08 02:46:23 -08:00
|
|
|
paths[1] = strdup(PACKAGE_LIB_DIR "/edje/modules");
|
2010-08-17 06:29:23 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (j = 0; j < ((sizeof (paths) / sizeof (char*)) - 1); ++j)
|
|
|
|
for (i = j + 1; i < sizeof (paths) / sizeof (char*); ++i)
|
|
|
|
if (paths[i] && paths[j] && !strcmp(paths[i], paths[j]))
|
2010-08-18 09:57:19 -07:00
|
|
|
{
|
|
|
|
free(paths[i]);
|
|
|
|
paths[i] = NULL;
|
|
|
|
}
|
2010-08-17 06:29:23 -07:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof (paths) / sizeof (char*); ++i)
|
|
|
|
if (paths[i])
|
2010-08-18 09:57:19 -07:00
|
|
|
_modules_paths = eina_list_append(_modules_paths, paths[i]);
|
2009-11-23 07:03:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_edje_module_shutdown(void)
|
|
|
|
{
|
2010-08-18 09:57:19 -07:00
|
|
|
char *path;
|
2009-11-23 07:03:19 -08:00
|
|
|
|
|
|
|
if (_registered_modules)
|
|
|
|
{
|
|
|
|
eina_hash_free(_registered_modules);
|
|
|
|
_registered_modules = NULL;
|
|
|
|
}
|
|
|
|
|
2010-08-18 09:57:19 -07:00
|
|
|
EINA_LIST_FREE(_modules_paths, path)
|
|
|
|
free(path);
|
2010-07-23 19:28:24 -07:00
|
|
|
|
2010-08-18 09:57:19 -07:00
|
|
|
EINA_LIST_FREE(_modules_found, path)
|
|
|
|
eina_stringshare_del(path);
|
2009-11-23 07:03:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI const Eina_List *
|
|
|
|
edje_available_modules_get(void)
|
|
|
|
{
|
2010-08-18 09:57:19 -07:00
|
|
|
Eina_File_Direct_Info *info;
|
|
|
|
Eina_Iterator *it;
|
|
|
|
Eina_List *l;
|
|
|
|
const char *path;
|
|
|
|
Eina_List *result = NULL;
|
|
|
|
|
|
|
|
/* FIXME: Stat each possible dir and check if they did change, before starting a huge round of readdir/stat */
|
|
|
|
if (_modules_found)
|
|
|
|
{
|
|
|
|
EINA_LIST_FREE(_modules_found, path)
|
|
|
|
eina_stringshare_del(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(_modules_paths, l, path)
|
|
|
|
{
|
|
|
|
it = eina_file_direct_ls(path);
|
|
|
|
|
|
|
|
if (it)
|
|
|
|
{
|
|
|
|
EINA_ITERATOR_FOREACH(it, info)
|
|
|
|
{
|
|
|
|
char tmp[PATH_MAX];
|
|
|
|
|
2010-09-18 20:04:17 -07:00
|
|
|
snprintf(tmp, sizeof (tmp), "%s/%s/" EDJE_MODULE_NAME, info->path, MODULE_ARCH
|
2011-05-20 09:41:16 -07:00
|
|
|
#ifdef EDJE_EXTRA_MODULE_NAME
|
2012-01-18 16:35:36 -08:00
|
|
|
, info->path + info->name_start
|
2010-09-18 20:04:17 -07:00
|
|
|
#endif
|
|
|
|
);
|
2010-08-18 09:57:19 -07:00
|
|
|
|
|
|
|
if (ecore_file_exists(tmp))
|
2012-01-18 16:35:36 -08:00
|
|
|
result = eina_list_append(result, eina_stringshare_add(info->path + info->name_start));
|
2010-08-18 09:57:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
eina_iterator_free(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_modules_found = result;
|
|
|
|
|
|
|
|
return result;
|
2009-11-23 07:03:19 -08:00
|
|
|
}
|