aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_evas/ecore_evas_module.c
diff options
context:
space:
mode:
authorFlavio Vinicius Alvares Ceolin <flavio.ceolin@profusion.mobi>2012-12-05 21:15:42 +0000
committerFlavio Vinicius Alvares Ceolin <flavio.ceolin@profusion.mobi>2012-12-05 21:15:42 +0000
commitad7579c1294222d0647673499f062b137d30d270 (patch)
tree9c2c8e693ee3e74ff3d9a05ef69a0645a541533a /src/lib/ecore_evas/ecore_evas_module.c
parentedje: support applying impulse via script (diff)
downloadefl-ad7579c1294222d0647673499f062b137d30d270.tar.gz
ecore_evas: Make the engines loadable modules
Implementing support for loadables modules. It makes the engines been loaded when they are needed. It not breakes the api, so each engine still has its own api. The implementation basically is: * Functions that creates Ecore_Evas, for example ecore_evas_software_x11_new, request to load its module and then get the module's function to create the Ecore_Evas. * The other functions such as \(.*\)_window_get from the Ecore_Evas its interface and then call the appropriate method. * As there is no unified interface to communicate with the engines (not break api problem), all interfaces were declared in ecore_evas_private.h * Now the data necessary for each module is not declared in the Ecore_Evas_Engine structure, instead of this, the struct has a void pointer that is used by the modules. * In this first moment engines as software_x11 and gl_x11 were put together in the same module, but obviously exporting all the things necessary. SVN revision: 80280
Diffstat (limited to 'src/lib/ecore_evas/ecore_evas_module.c')
-rw-r--r--src/lib/ecore_evas/ecore_evas_module.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/ecore_evas/ecore_evas_module.c b/src/lib/ecore_evas/ecore_evas_module.c
new file mode 100644
index 0000000000..1e399b07d6
--- /dev/null
+++ b/src/lib/ecore_evas/ecore_evas_module.c
@@ -0,0 +1,96 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "Ecore_Evas.h"
+#include "ecore_evas_private.h"
+
+Eina_Hash *_registered_engines = NULL;
+Eina_List *_engines_paths = NULL;
+
+#if defined(__CEGCC__) || defined(__MINGW32CE__) || defined(_WIN32)
+# define ECORE_EVAS_ENGINE_NAME "module.dll"
+#else
+# define ECORE_EVAS_ENGINE_NAME "module.so"
+#endif
+
+
+Eina_Module *
+_ecore_evas_engine_load(const char *engine)
+{
+ const char *path;
+ Eina_List *l;
+ Eina_Module *em = NULL;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(engine, NULL);
+
+ em = (Eina_Module *)eina_hash_find(_registered_engines, engine);
+ if (em) return em;
+
+ EINA_LIST_FOREACH(_engines_paths, l, path)
+ {
+ char tmp[PATH_MAX];
+
+ snprintf(tmp, sizeof (tmp), "%s/%s/%s/"ECORE_EVAS_ENGINE_NAME, path, engine, MODULE_ARCH);
+ em = eina_module_new(tmp);
+ if (!em) continue;
+
+ if (!eina_module_load(em))
+ {
+ eina_module_free(em);
+ continue;
+ }
+ if (eina_hash_add(_registered_engines, engine, em))
+ return em;
+ }
+
+ return NULL;
+}
+
+void
+_ecore_evas_engine_init(void)
+{
+ char *paths[4] = { NULL, NULL, NULL, NULL };
+ unsigned int i;
+ unsigned int j;
+
+ _registered_engines = eina_hash_string_small_new(EINA_FREE_CB(eina_module_free));
+
+ /* 1. ~/.ecore_evas/modules/ */
+ paths[0] = eina_module_environment_path_get("HOME", "/.ecore_evas/engines");
+ /* 2. $(ECORE_ENGINE_DIR)/ecore_evas/modules/ */
+ paths[1] = eina_module_environment_path_get("ECORE_EVAS_ENGINES_DIR", "/ecore_evas/engines");
+ /* 3. libecore_evas.so/../ecore_evas/engines/ */
+ paths[2] = eina_module_symbol_path_get(_ecore_evas_engine_init, "/ecore_evas/engines");
+ /* 4. PREFIX/ecore_evas/engines/ */
+#ifndef _MSC_VER
+ paths[3] = strdup(PACKAGE_LIB_DIR "/ecore_evas/engines");
+#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]))
+ {
+ free(paths[i]);
+ paths[i] = NULL;
+ }
+
+ for (i = 0; i < sizeof (paths) / sizeof (char*); ++i)
+ if (paths[i])
+ _engines_paths = eina_list_append(_engines_paths, paths[i]);
+}
+
+void
+_ecore_evas_engine_shutdown(void)
+{
+ char *path;
+
+ if (_registered_engines)
+ {
+ eina_hash_free(_registered_engines);
+ _registered_engines = NULL;
+ }
+
+ EINA_LIST_FREE(_engines_paths, path)
+ free(path);
+}