2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
15 #include <ecore_private.h>
17 #include "Ecore_IMF.h"
18 #include "ecore_imf_private.h"
20 static void _ecore_imf_module_free(Ecore_IMF_Module *module);
21 static int _ecore_imf_modules_exists(const char *ctx_id);
23 typedef struct _Ecore_IMF_Selector
29 static Eina_Hash *modules = NULL;
30 static Eina_Array *module_list = NULL;
33 ecore_imf_module_init(void)
37 module_list = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/ecore/immodules", 0, NULL, NULL);
38 homedir = eina_module_environment_path_get("HOME", "/.ecore/immodules");
41 module_list = eina_module_list_get(module_list, homedir, 0, NULL, NULL);
44 eina_module_list_load(module_list);
48 ecore_imf_module_shutdown(void)
52 eina_hash_free(modules);
57 eina_module_list_free(module_list);
63 _hash_module_available_get(const Eina_Hash *hash __UNUSED__, int *data, void *list)
65 *(Eina_List**)list = eina_list_append(*(Eina_List**)list, data);
70 ecore_imf_module_available_get(void)
72 Eina_List *values = NULL;
73 Eina_Iterator *it = NULL;
75 if (!modules) return NULL;
77 it = eina_hash_iterator_data_new(modules);
81 eina_iterator_foreach(it, EINA_EACH(_hash_module_available_get), &values);
82 eina_iterator_free(it);
88 ecore_imf_module_get(const char *ctx_id)
90 if (!modules) return NULL;
91 return eina_hash_find(modules, ctx_id);
95 ecore_imf_module_context_create(const char *ctx_id)
97 Ecore_IMF_Module *module;
98 Ecore_IMF_Context *ctx = NULL;
100 if (!modules) return NULL;
101 module = eina_hash_find(modules, ctx_id);
104 ctx = module->create();
105 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
107 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
108 "ecore_imf_module_context_create");
111 ctx->module = module;
117 _hash_ids_get(const Eina_Hash *hash __UNUSED__, const char *key, void *list)
119 *(Eina_List**)list = eina_list_append(*(Eina_List**)list, key);
124 ecore_imf_module_context_ids_get(void)
127 Eina_Iterator *it = NULL;
129 if (!modules) return NULL;
131 it = eina_hash_iterator_key_new(modules);
135 eina_iterator_foreach(it, EINA_EACH(_hash_ids_get), &l);
136 eina_iterator_free(it);
142 _hash_ids_by_canvas_type_get(const Eina_Hash *hash __UNUSED__, void *data, void *fdata)
144 Ecore_IMF_Module *module = data;
145 Ecore_IMF_Selector *selector = fdata;
147 if (!strcmp(module->info->canvas_type, selector->toselect))
148 selector->selected = eina_list_append(selector->selected, (void *)module->info->id);
154 ecore_imf_module_context_ids_by_canvas_type_get(const char *canvas_type)
156 Ecore_IMF_Selector selector;
157 Eina_List *values = NULL;
158 Eina_Iterator *it = NULL;
160 if (!modules) return NULL;
163 return ecore_imf_module_context_ids_get();
165 it = eina_hash_iterator_data_new(modules);
169 selector.toselect = canvas_type;
170 selector.selected = values;
171 eina_iterator_foreach(it, EINA_EACH(_hash_ids_by_canvas_type_get), &selector);
172 eina_iterator_free(it);
178 ecore_imf_module_register(const Ecore_IMF_Context_Info *info,
179 Ecore_IMF_Context *(*imf_module_create)(void),
180 Ecore_IMF_Context *(*imf_module_exit)(void))
182 Ecore_IMF_Module *module;
184 if (_ecore_imf_modules_exists(info->id)) return;
187 modules = eina_hash_string_superfast_new(EINA_FREE_CB(_ecore_imf_module_free));
189 module = malloc(sizeof(Ecore_IMF_Module));
191 /* cache imf_module_create as it may be used several times */
192 module->create = imf_module_create;
193 module->exit = imf_module_exit;
195 eina_hash_add(modules, info->id, module);
199 _ecore_imf_module_free(Ecore_IMF_Module *module)
201 if (module->exit) module->exit();
206 _ecore_imf_modules_exists(const char *ctx_id)
208 if (!modules) return 0;
209 if (!ctx_id) return 0;
211 if (eina_hash_find(modules, ctx_id))