11 #include <ecore_private.h>
13 #include "Ecore_IMF.h"
14 #include "ecore_imf_private.h"
16 static void _ecore_imf_module_free(Ecore_IMF_Module *module);
17 static int _ecore_imf_modules_exists(const char *ctx_id);
19 typedef struct _Ecore_IMF_Selector
25 static Eina_Hash *modules = NULL;
26 static Eina_Array *module_list = NULL;
29 ecore_imf_module_init(void)
33 module_list = eina_module_list_get(NULL, PACKAGE_LIB_DIR "/ecore/immodules", 0, NULL, NULL);
34 homedir = eina_module_environment_path_get("HOME", "/.ecore/immodules");
37 module_list = eina_module_list_get(module_list, homedir, 0, NULL, NULL);
40 eina_module_list_load(module_list);
44 ecore_imf_module_shutdown(void)
48 eina_hash_free(modules);
53 eina_module_list_free(module_list);
54 eina_array_free(module_list);
60 _hash_module_available_get(const Eina_Hash *hash __UNUSED__, int *data, void *list)
62 *(Eina_List**)list = eina_list_append(*(Eina_List**)list, data);
67 ecore_imf_module_available_get(void)
69 Eina_List *values = NULL;
70 Eina_Iterator *it = NULL;
72 if (!modules) return NULL;
74 it = eina_hash_iterator_data_new(modules);
78 eina_iterator_foreach(it, EINA_EACH_CB(_hash_module_available_get), &values);
79 eina_iterator_free(it);
85 ecore_imf_module_get(const char *ctx_id)
87 if (!modules) return NULL;
88 return eina_hash_find(modules, ctx_id);
92 ecore_imf_module_context_create(const char *ctx_id)
94 Ecore_IMF_Module *module;
95 Ecore_IMF_Context *ctx = NULL;
97 if (!modules) return NULL;
98 module = eina_hash_find(modules, ctx_id);
101 ctx = module->create();
102 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
104 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
105 "ecore_imf_module_context_create");
108 ctx->module = module;
114 _hash_ids_get(const Eina_Hash *hash __UNUSED__, const char *key, void *list)
116 *(Eina_List**)list = eina_list_append(*(Eina_List**)list, key);
121 ecore_imf_module_context_ids_get(void)
124 Eina_Iterator *it = NULL;
126 if (!modules) return NULL;
128 it = eina_hash_iterator_key_new(modules);
132 eina_iterator_foreach(it, EINA_EACH_CB(_hash_ids_get), &l);
133 eina_iterator_free(it);
139 _hash_ids_by_canvas_type_get(const Eina_Hash *hash __UNUSED__, void *data, void *fdata)
141 Ecore_IMF_Module *module = data;
142 Ecore_IMF_Selector *selector = fdata;
144 if (!strcmp(module->info->canvas_type, selector->toselect))
145 selector->selected = eina_list_append(selector->selected, (void *)module->info->id);
151 ecore_imf_module_context_ids_by_canvas_type_get(const char *canvas_type)
153 Ecore_IMF_Selector selector;
154 Eina_List *values = NULL;
155 Eina_Iterator *it = NULL;
157 if (!modules) return NULL;
160 return ecore_imf_module_context_ids_get();
162 it = eina_hash_iterator_data_new(modules);
166 selector.toselect = canvas_type;
167 selector.selected = values;
168 eina_iterator_foreach(it, EINA_EACH_CB(_hash_ids_by_canvas_type_get), &selector);
169 eina_iterator_free(it);
175 ecore_imf_module_register(const Ecore_IMF_Context_Info *info,
176 Ecore_IMF_Context *(*imf_module_create)(void),
177 Ecore_IMF_Context *(*imf_module_exit)(void))
179 Ecore_IMF_Module *module;
181 if (_ecore_imf_modules_exists(info->id)) return;
184 modules = eina_hash_string_superfast_new(EINA_FREE_CB(_ecore_imf_module_free));
186 module = malloc(sizeof(Ecore_IMF_Module));
188 /* cache imf_module_create as it may be used several times */
189 module->create = imf_module_create;
190 module->exit = imf_module_exit;
192 eina_hash_add(modules, info->id, module);
196 _ecore_imf_module_free(Ecore_IMF_Module *module)
198 if (module->exit) module->exit();
203 _ecore_imf_modules_exists(const char *ctx_id)
205 if (!modules) return 0;
206 if (!ctx_id) return 0;
208 if (eina_hash_find(modules, ctx_id))