2008-01-25 22:01:00 -08:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
# define _GNU_SOURCE
|
2006-01-14 04:13:38 -08:00
|
|
|
#endif
|
|
|
|
|
2006-01-14 12:03:42 -08:00
|
|
|
#include <dirent.h> /* DIR, dirent */
|
2008-03-14 09:49:49 -07:00
|
|
|
#include <dlfcn.h> /* dlopen,dlclose,etc */
|
2006-01-14 04:13:38 -08:00
|
|
|
|
|
|
|
#include <evas_common.h>
|
|
|
|
#include <evas_private.h>
|
|
|
|
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *evas_modules = NULL;
|
|
|
|
static Eina_List *evas_module_paths = NULL;
|
2006-01-14 04:13:38 -08:00
|
|
|
|
|
|
|
static void
|
2007-05-06 04:29:37 -07:00
|
|
|
_evas_module_path_append(Evas_Module_Type type, char *path, const char *subdir)
|
2006-01-14 04:13:38 -08:00
|
|
|
{
|
|
|
|
Evas_Module_Path *mp;
|
|
|
|
char *buf;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
buf = evas_file_path_join(path, subdir);
|
|
|
|
if (!buf) return;
|
|
|
|
if (evas_file_path_exists(buf))
|
|
|
|
{
|
|
|
|
mp = malloc(sizeof(Evas_Module_Path));
|
|
|
|
mp->type = type;
|
|
|
|
mp->path = buf;
|
2008-10-21 09:31:05 -07:00
|
|
|
evas_module_paths = eina_list_append(evas_module_paths, mp);
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* this will alloc a list of paths to search for the modules */
|
|
|
|
/* by now these are: */
|
|
|
|
/* 1. ~/.evas/modules/ */
|
2007-10-17 02:29:18 -07:00
|
|
|
/* 2. $(EVAS_MODULE_DIR)/evas/modules/ */
|
2006-01-14 04:13:38 -08:00
|
|
|
/* 3. dladdr/evas/modules/ */
|
2007-10-17 02:29:18 -07:00
|
|
|
/* 4. PREFIX/evas/modules/ */
|
2006-01-14 04:13:38 -08:00
|
|
|
void
|
|
|
|
evas_module_paths_init(void)
|
|
|
|
{
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
char *prefix;
|
|
|
|
char *path;
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *paths = NULL;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
/* 1. ~/.evas/modules/ */
|
|
|
|
prefix = getenv("HOME");
|
2006-01-31 22:19:38 -08:00
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
path = malloc(strlen(prefix) + 1 + strlen("/.evas/modules"));
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
path[0] = 0;
|
|
|
|
strcpy(path, prefix);
|
|
|
|
strcat(path, "/.evas/modules");
|
|
|
|
if (evas_file_path_exists(path))
|
2008-10-21 09:31:05 -07:00
|
|
|
paths = eina_list_append(paths, path);
|
2006-01-31 22:19:38 -08:00
|
|
|
else
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
}
|
2006-01-14 04:36:25 -08:00
|
|
|
|
2007-10-17 02:29:18 -07:00
|
|
|
/* 2. $(EVAS_MODULE_DIR)/evas/modules/ */
|
|
|
|
prefix = getenv("EVAS_MODULES_DIR");
|
|
|
|
if (prefix)
|
|
|
|
{
|
|
|
|
path = malloc(strlen(prefix) + 1 + strlen("/evas/modules"));
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
path[0] = 0;
|
|
|
|
strcpy(path, prefix);
|
|
|
|
strcat(path, "/evas/modules");
|
|
|
|
if (evas_file_path_exists(path))
|
2008-10-21 09:31:05 -07:00
|
|
|
paths = eina_list_append(paths, path);
|
2007-10-17 02:29:18 -07:00
|
|
|
else
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
#ifdef HAVE_DLADDR
|
|
|
|
{
|
2006-01-14 04:36:25 -08:00
|
|
|
Dl_info evas_dl;
|
|
|
|
/* 3. libevas.so/../evas/modules/ */
|
|
|
|
if (dladdr(evas_module_paths_init, &evas_dl))
|
|
|
|
{
|
|
|
|
int length;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:36:25 -08:00
|
|
|
if (strrchr(evas_dl.dli_fname, '/'))
|
|
|
|
{
|
|
|
|
length = strlen(strrchr(evas_dl.dli_fname, '/'));
|
2007-08-13 05:13:03 -07:00
|
|
|
path = malloc(strlen(evas_dl.dli_fname) - length +
|
2006-01-14 04:36:25 -08:00
|
|
|
strlen("/evas/modules") + 1);
|
|
|
|
if (path)
|
|
|
|
{
|
2007-08-13 05:13:03 -07:00
|
|
|
strncpy(path, evas_dl.dli_fname,
|
2006-01-14 04:36:25 -08:00
|
|
|
strlen(evas_dl.dli_fname) - length);
|
|
|
|
path[strlen(evas_dl.dli_fname) - length] = 0;
|
|
|
|
strcat(path, "/evas/modules");
|
|
|
|
if (evas_file_path_exists(path))
|
2008-10-21 09:31:05 -07:00
|
|
|
paths = eina_list_append(paths, path);
|
2006-01-14 04:36:25 -08:00
|
|
|
else
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
#else
|
2007-10-17 02:29:18 -07:00
|
|
|
/* 4. PREFIX/evas/modules/ */
|
2007-08-13 05:13:03 -07:00
|
|
|
prefix = PACKAGE_LIB_DIR;
|
2006-01-14 04:13:38 -08:00
|
|
|
path = malloc(strlen(prefix) + 1 + strlen("/evas/modules"));
|
2006-01-31 22:19:38 -08:00
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
strcpy(path, prefix);
|
|
|
|
strcat(path, "/evas/modules");
|
|
|
|
if (evas_file_path_exists(path))
|
2008-10-21 09:31:05 -07:00
|
|
|
paths = eina_list_append(paths, path);
|
2006-01-31 22:19:38 -08:00
|
|
|
else
|
|
|
|
free(path);
|
|
|
|
}
|
2006-01-14 04:13:38 -08:00
|
|
|
#endif
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
/* append all the module types subdirs */
|
|
|
|
while (paths)
|
|
|
|
{
|
|
|
|
/* here must be added all the types of modules and their subdirectory */
|
|
|
|
/* do this on a separate function */
|
|
|
|
/* 1. engines */
|
|
|
|
_evas_module_path_append(EVAS_MODULE_TYPE_ENGINE, paths->data, "engines");
|
2006-01-14 12:03:42 -08:00
|
|
|
_evas_module_path_append(EVAS_MODULE_TYPE_IMAGE_LOADER, paths->data, "loaders");
|
2006-01-15 02:35:02 -08:00
|
|
|
_evas_module_path_append(EVAS_MODULE_TYPE_IMAGE_SAVER, paths->data, "savers");
|
2006-01-14 04:13:38 -08:00
|
|
|
_evas_module_path_append(EVAS_MODULE_TYPE_OBJECT, paths->data, "objects");
|
|
|
|
free(paths->data);
|
2008-10-21 09:31:05 -07:00
|
|
|
paths = eina_list_remove_list(paths, paths);
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 05:13:03 -07:00
|
|
|
/* this will alloc an Evas_Module struct for each module
|
2006-01-14 04:13:38 -08:00
|
|
|
* it finds on the paths */
|
|
|
|
void
|
|
|
|
evas_module_init(void)
|
|
|
|
{
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Evas_Module_Path *mp;
|
2006-01-14 12:03:42 -08:00
|
|
|
int new_id_engine = 1;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-15 02:35:02 -08:00
|
|
|
/* printf("[init modules]\n"); */
|
2006-01-14 04:13:38 -08:00
|
|
|
evas_module_paths_init();
|
2008-10-21 09:31:05 -07:00
|
|
|
EINA_LIST_FOREACH(evas_module_paths, l, mp)
|
2006-01-14 04:13:38 -08:00
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
if (!(dir = opendir(mp->path))) break;
|
2008-11-05 09:21:04 -08:00
|
|
|
/* printf("[evas module] searching modules on %s\n", mp->path); */
|
2006-01-14 07:58:01 -08:00
|
|
|
while ((de = readdir(dir)))
|
2006-01-14 04:13:38 -08:00
|
|
|
{
|
|
|
|
char *buf;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
if ((!strcmp(de->d_name, ".")) || (!strcmp(de->d_name, "..")))
|
|
|
|
continue;
|
|
|
|
buf = malloc(strlen(mp->path) + 1 + strlen(de->d_name) + 1);
|
2006-01-31 22:19:38 -08:00
|
|
|
sprintf(buf, "%s/%s", mp->path, de->d_name);
|
2006-01-14 04:13:38 -08:00
|
|
|
if (evas_file_path_is_dir(buf))
|
|
|
|
{
|
|
|
|
Evas_Module *em;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-09-18 02:40:29 -07:00
|
|
|
em = calloc(1, sizeof(Evas_Module));
|
2006-01-14 04:13:38 -08:00
|
|
|
if (!em) continue;
|
|
|
|
em->name = strdup(de->d_name);
|
|
|
|
em->path = strdup(mp->path);
|
|
|
|
em->type = mp->type;
|
|
|
|
em->handle = NULL;
|
|
|
|
em->data = NULL;
|
2006-01-14 15:36:52 -08:00
|
|
|
em->loaded = 0;
|
2009-03-13 02:32:42 -07:00
|
|
|
#ifdef BUILD_ASYNC_PRELOAD
|
|
|
|
LKI(em->lock);
|
|
|
|
#endif
|
|
|
|
//#if defined(BUILD_PTHREAD) && defined(BUILD_ASYNC_PRELOAD)
|
|
|
|
// pthread_mutex_init(&em->lock, NULL);
|
|
|
|
//#endif
|
2006-01-14 04:13:38 -08:00
|
|
|
if (em->type == EVAS_MODULE_TYPE_ENGINE)
|
|
|
|
{
|
|
|
|
Evas_Module_Engine *eme;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
eme = malloc(sizeof(Evas_Module_Engine));
|
|
|
|
if (eme)
|
|
|
|
{
|
2006-01-14 12:03:42 -08:00
|
|
|
eme->id = new_id_engine;
|
2006-01-14 04:13:38 -08:00
|
|
|
em->data = eme;
|
2006-01-14 12:03:42 -08:00
|
|
|
new_id_engine++;
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
}
|
2006-01-14 12:03:42 -08:00
|
|
|
else if (em->type == EVAS_MODULE_TYPE_IMAGE_LOADER)
|
|
|
|
{
|
|
|
|
}
|
2006-01-15 02:35:02 -08:00
|
|
|
else if (em->type == EVAS_MODULE_TYPE_IMAGE_SAVER)
|
|
|
|
{
|
|
|
|
}
|
2008-11-05 09:21:04 -08:00
|
|
|
/* printf("[evas module] including module path %s/%s of type %d\n",em->path, em->name, em->type); */
|
2008-10-21 09:31:05 -07:00
|
|
|
evas_modules = eina_list_append(evas_modules, em);
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
2006-01-15 19:37:34 -08:00
|
|
|
closedir(dir);
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Evas_Module *
|
|
|
|
evas_module_find_type(Evas_Module_Type type, const char *name)
|
|
|
|
{
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Evas_Module *em;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2008-10-21 09:31:05 -07:00
|
|
|
EINA_LIST_FOREACH(evas_modules, l, em)
|
2006-01-14 04:13:38 -08:00
|
|
|
{
|
|
|
|
if ((type == em->type) && (!strcmp(name,em->name)))
|
2006-01-14 21:04:32 -08:00
|
|
|
{
|
|
|
|
if (evas_modules != l)
|
|
|
|
{
|
2008-10-21 09:31:05 -07:00
|
|
|
evas_modules = eina_list_promote_list(evas_modules, l);
|
2006-01-14 21:04:32 -08:00
|
|
|
}
|
|
|
|
return em;
|
|
|
|
}
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
evas_module_load(Evas_Module *em)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
void *handle;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 15:36:52 -08:00
|
|
|
if (em->loaded) return 1;
|
|
|
|
|
2007-08-13 05:13:03 -07:00
|
|
|
/* printf("LOAD %s\n", em->name); */
|
2008-03-14 09:49:49 -07:00
|
|
|
#if defined(__CEGCC__) || defined(__MINGW32CE__)
|
|
|
|
switch (em->type) {
|
|
|
|
case EVAS_MODULE_TYPE_IMAGE_SAVER:
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s/saver_%s.dll", em->path, em->name, MODULE_ARCH, em->name);
|
|
|
|
break;
|
|
|
|
case EVAS_MODULE_TYPE_IMAGE_LOADER:
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s/loader_%s.dll", em->path, em->name, MODULE_ARCH, em->name);
|
|
|
|
break;
|
|
|
|
case EVAS_MODULE_TYPE_ENGINE:
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s/engine_%s.dll", em->path, em->name, MODULE_ARCH, em->name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s/object_%s.dll", em->path, em->name, MODULE_ARCH, em->name);
|
|
|
|
}
|
|
|
|
#elif _WIN32
|
2007-05-26 23:43:23 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s/module.dll", em->path, em->name, MODULE_ARCH);
|
|
|
|
#else
|
2006-01-15 02:04:39 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s/%s/module.so", em->path, em->name, MODULE_ARCH);
|
2007-05-26 23:43:23 -07:00
|
|
|
#endif
|
2006-01-14 04:13:38 -08:00
|
|
|
if (!evas_file_path_exists(buf))
|
|
|
|
{
|
|
|
|
printf("[evas module] error loading the module %s. It doesnt exists\n", buf);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
handle = dlopen(buf, RTLD_LAZY);
|
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
em->handle = handle;
|
|
|
|
em->func.open = dlsym(em->handle, "module_open");
|
|
|
|
em->func.close = dlsym(em->handle, "module_close");
|
|
|
|
em->api = dlsym(em->handle, "evas_modapi");
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
if ((!em->func.open) || (!em->api) || (!em->func.close))
|
|
|
|
goto error_dl;
|
|
|
|
/* check the api */
|
|
|
|
if (em->api->version != EVAS_MODULE_API_VERSION)
|
|
|
|
{
|
|
|
|
printf("[evas module] error loading the modules %s. The version doesnt match\n", buf);
|
2006-01-15 02:04:39 -08:00
|
|
|
goto error_dl;
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
em->func.open(em);
|
|
|
|
em->loaded = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
2007-08-13 05:13:03 -07:00
|
|
|
error_dl:
|
2006-01-14 04:13:38 -08:00
|
|
|
{
|
2007-06-27 03:57:54 -07:00
|
|
|
const char *err;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-14 04:13:38 -08:00
|
|
|
err = dlerror();
|
|
|
|
printf("[evas module] error loading the module %s. %s\n", buf, err);
|
2007-02-03 01:33:26 -08:00
|
|
|
if (handle)
|
|
|
|
dlclose(handle);
|
2006-01-14 04:13:38 -08:00
|
|
|
em->handle = NULL;
|
2006-01-15 02:04:39 -08:00
|
|
|
em->func.open = NULL;
|
|
|
|
em->func.close = NULL;
|
|
|
|
em->api = NULL;
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
2006-01-15 02:04:39 -08:00
|
|
|
return 0;
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_module_unload(Evas_Module *em)
|
|
|
|
{
|
|
|
|
if (!em->loaded)
|
|
|
|
return;
|
|
|
|
if (em->handle)
|
|
|
|
{
|
|
|
|
em->func.close(em);
|
|
|
|
dlclose(em->handle);
|
|
|
|
}
|
2006-01-15 02:04:39 -08:00
|
|
|
em->handle = NULL;
|
|
|
|
em->func.open = NULL;
|
|
|
|
em->func.close = NULL;
|
|
|
|
em->api = NULL;
|
|
|
|
em->loaded = 0;
|
2009-03-13 02:32:42 -07:00
|
|
|
#ifdef BUILD_ASYNC_PRELOAD
|
|
|
|
LKD(em->lock);
|
2008-12-23 13:20:43 -08:00
|
|
|
#endif
|
2009-03-13 02:32:42 -07:00
|
|
|
//#if defined(BUILD_PTHREAD) && defined(BUILD_ASYNC_PRELOAD)
|
|
|
|
// pthread_mutex_destroy(&em->lock);
|
|
|
|
//#endif
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
|
|
|
|
2006-09-18 02:40:29 -07:00
|
|
|
void
|
|
|
|
evas_module_ref(Evas_Module *em)
|
|
|
|
{
|
2009-03-13 02:32:42 -07:00
|
|
|
#ifdef BUILD_ASYNC_PRELOAD
|
|
|
|
LKL(em->lock);
|
|
|
|
#endif
|
|
|
|
//#if defined(BUILD_PTHREAD) && defined(BUILD_ASYNC_PRELOAD)
|
|
|
|
// pthread_mutex_lock(&em->lock);
|
|
|
|
//#endif
|
2006-09-18 02:40:29 -07:00
|
|
|
em->ref++;
|
2007-08-13 05:13:03 -07:00
|
|
|
/* printf("M: %s ref++ = %i\n", em->name, em->ref); */
|
2009-03-13 02:32:42 -07:00
|
|
|
#ifdef BUILD_ASYNC_PRELOAD
|
|
|
|
LKU(em->lock);
|
2008-12-23 13:20:43 -08:00
|
|
|
#endif
|
2009-03-13 02:32:42 -07:00
|
|
|
//#if defined(BUILD_PTHREAD) && defined(BUILD_ASYNC_PRELOAD)
|
|
|
|
// pthread_mutex_unlock(&em->lock);
|
|
|
|
//#endif
|
2006-09-18 02:40:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_module_unref(Evas_Module *em)
|
|
|
|
{
|
2009-03-13 02:32:42 -07:00
|
|
|
#ifdef BUILD_ASYNC_PRELOAD
|
|
|
|
LKL(em->lock);
|
|
|
|
#endif
|
|
|
|
//#if defined(BUILD_PTHREAD) && defined(BUILD_ASYNC_PRELOAD)
|
|
|
|
// pthread_mutex_lock(&em->lock);
|
|
|
|
//#endif
|
2006-09-18 02:40:29 -07:00
|
|
|
em->ref--;
|
2007-08-13 05:13:03 -07:00
|
|
|
/* printf("M: %s ref-- = %i\n", em->name, em->ref); */
|
2009-03-13 02:32:42 -07:00
|
|
|
#ifdef BUILD_ASYNC_PRELOAD
|
|
|
|
LKU(em->lock);
|
2008-12-23 13:20:43 -08:00
|
|
|
#endif
|
2009-03-13 02:32:42 -07:00
|
|
|
//#if defined(BUILD_PTHREAD) && defined(BUILD_ASYNC_PRELOAD)
|
|
|
|
// pthread_mutex_unlock(&em->lock);
|
|
|
|
//#endif
|
2006-09-18 02:40:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int use_count = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_module_use(Evas_Module *em)
|
|
|
|
{
|
|
|
|
em->last_used = use_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_module_clean(void)
|
|
|
|
{
|
|
|
|
static int call_count = 0;
|
|
|
|
int ago;
|
|
|
|
int noclean = -1;
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *l;
|
2006-09-18 02:40:29 -07:00
|
|
|
Evas_Module *em;
|
|
|
|
|
2006-09-18 02:47:34 -07:00
|
|
|
/* only clean modules every 256 calls */
|
2006-09-18 02:40:29 -07:00
|
|
|
call_count++;
|
2006-09-18 02:47:34 -07:00
|
|
|
if (call_count <= 256) return;
|
2006-09-18 02:40:29 -07:00
|
|
|
call_count = 0;
|
|
|
|
|
|
|
|
if (noclean == -1)
|
|
|
|
{
|
|
|
|
if (getenv("EVAS_NOCLEAN"))
|
|
|
|
{
|
|
|
|
noclean = 1;
|
|
|
|
}
|
|
|
|
noclean = 0;
|
|
|
|
}
|
|
|
|
if (noclean == 1) return;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2007-05-04 01:18:07 -07:00
|
|
|
/* disable module cleaning for now - may cause instability with some modules */
|
|
|
|
return;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-09-18 02:40:29 -07:00
|
|
|
/* incriment use counter = 28bits */
|
|
|
|
use_count++;
|
|
|
|
if (use_count > 0x0fffffff) use_count = 0;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
|
|
|
/* printf("CLEAN!\n"); */
|
2006-09-18 02:40:29 -07:00
|
|
|
/* go through all modules */
|
2008-10-21 09:31:05 -07:00
|
|
|
EINA_LIST_FOREACH(evas_modules, l, em)
|
2006-09-18 02:40:29 -07:00
|
|
|
{
|
2007-08-13 05:13:03 -07:00
|
|
|
/* printf("M %s %i %i\n", em->name, em->ref, em->loaded); */
|
2006-09-18 02:40:29 -07:00
|
|
|
/* if the module is refernced - skip */
|
|
|
|
if ((em->ref > 0) || (!em->loaded)) continue;
|
|
|
|
/* how many clean cycles ago was this module last used */
|
|
|
|
ago = use_count - em->last_used;
|
|
|
|
if (em->last_used > use_count) ago += 0x10000000;
|
|
|
|
/* if it was used last more than N clean cycles ago - unload */
|
2006-09-18 02:47:34 -07:00
|
|
|
if (ago > 5)
|
2006-09-18 02:40:29 -07:00
|
|
|
{
|
2007-08-13 05:13:03 -07:00
|
|
|
/* printf(" UNLOAD %s\n", em->name); */
|
2006-09-18 02:40:29 -07:00
|
|
|
evas_module_unload(em);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-14 07:43:05 -08:00
|
|
|
/* will dlclose all the modules loaded and free all the structs */
|
2006-01-14 04:13:38 -08:00
|
|
|
void
|
|
|
|
evas_module_shutdown(void)
|
|
|
|
{
|
|
|
|
Evas_Module *em;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-01-15 02:35:02 -08:00
|
|
|
/* printf("[shutdown modules]\n"); */
|
2006-01-14 04:13:38 -08:00
|
|
|
while (evas_modules)
|
|
|
|
{
|
|
|
|
em = (Evas_Module *)evas_modules->data;
|
|
|
|
evas_module_unload(em);
|
|
|
|
if (em->name) free(em->name);
|
|
|
|
if (em->path) free(em->path);
|
2006-01-14 21:04:32 -08:00
|
|
|
if (em->type == EVAS_MODULE_TYPE_ENGINE)
|
|
|
|
{
|
|
|
|
if (em->data) free(em->data);
|
|
|
|
}
|
|
|
|
else if (em->type == EVAS_MODULE_TYPE_IMAGE_LOADER)
|
|
|
|
{
|
|
|
|
}
|
2006-01-15 02:35:02 -08:00
|
|
|
else if (em->type == EVAS_MODULE_TYPE_IMAGE_SAVER)
|
|
|
|
{
|
|
|
|
}
|
2006-01-14 04:13:38 -08:00
|
|
|
free(evas_modules->data);
|
2008-10-21 09:31:05 -07:00
|
|
|
evas_modules = eina_list_remove_list(evas_modules, evas_modules);
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
2006-01-15 02:24:37 -08:00
|
|
|
while (evas_module_paths)
|
|
|
|
{
|
|
|
|
Evas_Module_Path *mp;
|
|
|
|
|
|
|
|
mp = evas_module_paths->data;
|
2008-10-21 09:31:05 -07:00
|
|
|
evas_module_paths = eina_list_remove_list(evas_module_paths, evas_module_paths);
|
2006-01-15 02:24:37 -08:00
|
|
|
free(mp->path);
|
|
|
|
free(mp);
|
|
|
|
}
|
2006-01-14 04:13:38 -08:00
|
|
|
}
|
2006-03-02 00:06:10 -08:00
|
|
|
|
2006-09-06 00:33:40 -07:00
|
|
|
EAPI int
|
2006-03-02 00:06:10 -08:00
|
|
|
_evas_module_engine_inherit(Evas_Func *funcs, char *name)
|
|
|
|
{
|
|
|
|
Evas_Module *em;
|
2007-08-13 05:13:03 -07:00
|
|
|
|
2006-03-02 00:06:10 -08:00
|
|
|
em = evas_module_find_type(EVAS_MODULE_TYPE_ENGINE, name);
|
|
|
|
if (em)
|
|
|
|
{
|
|
|
|
if (evas_module_load(em))
|
|
|
|
{
|
2006-09-18 02:40:29 -07:00
|
|
|
/* FIXME: no way to unref */
|
|
|
|
evas_module_ref(em);
|
|
|
|
evas_module_use(em);
|
2006-03-02 00:06:10 -08:00
|
|
|
*funcs = *((Evas_Func *)(em->functions));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2006-04-23 08:38:23 -07:00
|
|
|
}
|