summaryrefslogtreecommitdiff
path: root/src/lib/ethumb
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-12 05:21:36 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-12 05:21:36 +0000
commita4e4c3041ee4eafee168f51348d2399cede29ff6 (patch)
treeca2f1ec94f9c4733b25250d0365c7cd7e620357c /src/lib/ethumb
parent8e9303e1a422bcf12eb8a406cd3f808b8a9695f0 (diff)
ethumb: improve plugin handling.
be more like emotion, delay plugin load and change the api to register/unregister, more future-proof. SVN revision: 82681
Diffstat (limited to 'src/lib/ethumb')
-rw-r--r--src/lib/ethumb/Ethumb_Plugin.h6
-rw-r--r--src/lib/ethumb/ethumb.c131
2 files changed, 106 insertions, 31 deletions
diff --git a/src/lib/ethumb/Ethumb_Plugin.h b/src/lib/ethumb/Ethumb_Plugin.h
index 3eb6f020cd..483399d212 100644
--- a/src/lib/ethumb/Ethumb_Plugin.h
+++ b/src/lib/ethumb/Ethumb_Plugin.h
@@ -9,11 +9,17 @@ typedef struct _Ethumb_Plugin Ethumb_Plugin;
9 9
10struct _Ethumb_Plugin 10struct _Ethumb_Plugin
11{ 11{
12#define ETHUMB_PLUGIN_API_VERSION (1U)
13 unsigned int version;
14 const char *name;
12 const char **extensions; 15 const char **extensions;
13 void *(*thumb_generate)(Ethumb *); 16 void *(*thumb_generate)(Ethumb *);
14 void (*thumb_cancel)(Ethumb *, void *); 17 void (*thumb_cancel)(Ethumb *, void *);
15}; 18};
16 19
20EAPI Eina_Bool ethumb_plugin_register(const Ethumb_Plugin *plugin);
21EAPI Eina_Bool ethumb_plugin_unregister(const Ethumb_Plugin *plugin);
22
17EAPI void ethumb_calculate_aspect_from_ratio(Ethumb *e, float ia, int *w, int *h); 23EAPI void ethumb_calculate_aspect_from_ratio(Ethumb *e, float ia, int *w, int *h);
18EAPI void ethumb_calculate_aspect(Ethumb *e, int iw, int ih, int *w, int *h); 24EAPI void ethumb_calculate_aspect(Ethumb *e, int iw, int ih, int *w, int *h);
19EAPI void ethumb_calculate_fill_from_ratio(Ethumb *e, float ia, int *fx, int *fy, int *fw, int *fh); 25EAPI void ethumb_calculate_fill_from_ratio(Ethumb *e, float ia, int *fx, int *fy, int *fw, int *fh);
diff --git a/src/lib/ethumb/ethumb.c b/src/lib/ethumb/ethumb.c
index 8178c78578..1f2cfb6ee8 100644
--- a/src/lib/ethumb/ethumb.c
+++ b/src/lib/ethumb/ethumb.c
@@ -83,6 +83,7 @@ static int _log_dom = -1;
83#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__) 83#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__)
84 84
85static int initcount = 0; 85static int initcount = 0;
86static Eina_Bool _plugins_loaded = EINA_FALSE;
86static const char *_home_thumb_dir = NULL; 87static const char *_home_thumb_dir = NULL;
87static const char *_thumb_category_normal = NULL; 88static const char *_thumb_category_normal = NULL;
88static const char *_thumb_category_large = NULL; 89static const char *_thumb_category_large = NULL;
@@ -94,71 +95,131 @@ static Eina_Hash *_plugins_ext = NULL;
94static Eina_Array *_plugins = NULL; 95static Eina_Array *_plugins = NULL;
95static Eina_Prefix *_pfx = NULL; 96static Eina_Prefix *_pfx = NULL;
96 97
97static Eina_Bool 98EAPI Eina_Bool
98_ethumb_plugin_list_cb(Eina_Module *m, void *data EINA_UNUSED) 99ethumb_plugin_register(const Ethumb_Plugin *plugin)
99{ 100{
100 const char *file; 101 const char * const *ext;
101 const char **ext;
102 Ethumb_Plugin *plugin;
103 Ethumb_Plugin *(*plugin_get)(void);
104 102
105 file = eina_module_file_get(m); 103 EINA_SAFETY_ON_NULL_RETURN_VAL(plugin, EINA_FALSE);
106 if (!eina_module_load(m)) 104
105 if (plugin->version != ETHUMB_PLUGIN_API_VERSION)
107 { 106 {
108 ERR("could not load module \"%s\": %s", 107 ERR("Plugin '%p' uses api version=%u while %u was expected",
109 file, eina_error_msg_get(eina_error_get())); 108 plugin, plugin->version, ETHUMB_PLUGIN_API_VERSION);
110 return EINA_FALSE; 109 return EINA_FALSE;
111 } 110 }
112 111
113 plugin_get = eina_module_symbol_get(m, "ethumb_plugin_get"); 112 EINA_SAFETY_ON_NULL_RETURN_VAL(plugin->name, EINA_FALSE);
114 if (!plugin_get) 113 EINA_SAFETY_ON_NULL_RETURN_VAL(plugin->extensions, EINA_FALSE);
114
115 DBG("registered plugin '%s' (%p) with extensions:", plugin->name, plugin);
116 for (ext = plugin->extensions; *ext; ext++)
115 { 117 {
116 ERR("could not find ethumb_plugin_get() in module \"%s\": %s", 118 Eina_Bool r = eina_hash_add(_plugins_ext, *ext, plugin);
117 file, eina_error_msg_get(eina_error_get())); 119 DBG(" extension \"%s\": %hhu", *ext, r);
118 eina_module_unload(m);
119 return EINA_FALSE;
120 } 120 }
121 121
122 plugin = plugin_get(); 122 return EINA_TRUE;
123 if (!plugin) 123}
124
125EAPI Eina_Bool
126ethumb_plugin_unregister(const Ethumb_Plugin *plugin)
127{
128 const char * const *ext;
129
130 EINA_SAFETY_ON_NULL_RETURN_VAL(plugin, EINA_FALSE);
131
132 if (plugin->version != ETHUMB_PLUGIN_API_VERSION)
124 { 133 {
125 ERR("plugin \"%s\" failed to init.", file); 134 ERR("Plugin '%p' uses api version=%u while %u was expected",
126 eina_module_unload(m); 135 plugin, plugin->version, ETHUMB_PLUGIN_API_VERSION);
127 return EINA_FALSE; 136 return EINA_FALSE;
128 } 137 }
129 138
130 DBG("loaded plugin \"%s\" (%p) with extensions:", file, plugin); 139 EINA_SAFETY_ON_NULL_RETURN_VAL(plugin->name, EINA_FALSE);
140 EINA_SAFETY_ON_NULL_RETURN_VAL(plugin->extensions, EINA_FALSE);
141
142 DBG("unregister plugin '%s' (%p) with extensions:", plugin->name, plugin);
131 for (ext = plugin->extensions; *ext; ext++) 143 for (ext = plugin->extensions; *ext; ext++)
132 { 144 {
133 DBG(" extension \"%s\"", *ext); 145 Eina_Bool r = eina_hash_del(_plugins_ext, *ext, plugin);
134 eina_hash_add(_plugins_ext, *ext, plugin); 146 DBG(" extension \"%s\": %hhu", *ext, r);
135 } 147 }
136 148
137 return EINA_TRUE; 149 return EINA_TRUE;
138} 150}
139 151
152
140static void 153static void
141_ethumb_plugins_load(void) 154_ethumb_plugins_load(void)
142{ 155{
143 char buf[PATH_MAX]; 156 char buf[PATH_MAX];
157 char *path;
144 158
145 _plugins_ext = eina_hash_string_small_new(NULL); 159 if (_plugins_loaded) return;
146 EINA_SAFETY_ON_NULL_RETURN(_plugins_ext); 160 _plugins_loaded = EINA_TRUE;
161
162 if (getenv("EFL_RUN_IN_TREE"))
163 {
164 struct stat st;
165 snprintf(buf, sizeof(buf), "%s/src/modules/ethumb",
166 PACKAGE_BUILD_DIR);
167 if (stat(buf, &st) == 0)
168 {
169 const char *built_modules[] = {
170 "emotion",
171 NULL
172 };
173 const char **itr;
174 for (itr = built_modules; *itr != NULL; itr++)
175 {
176 snprintf(buf, sizeof(buf),
177 "%s/src/modules/ethumb/%s/.libs",
178 PACKAGE_BUILD_DIR, *itr);
179 _plugins = eina_module_list_get(_plugins, buf,
180 EINA_FALSE, NULL, NULL);
181 }
182 goto load;
183 }
184 }
185
186 path = eina_module_environment_path_get("ETHUMB_MODULES_DIR",
187 "/ethumb/modules");
188 if (path)
189 {
190 _plugins = eina_module_arch_list_get(_plugins, path, MODULE_ARCH);
191 free(path);
192 }
193
194 path = eina_module_environment_path_get("HOME", "/.ethumb");
195 if (path)
196 {
197 _plugins = eina_module_arch_list_get(_plugins, path, MODULE_ARCH);
198 free(path);
199 }
147 200
148 snprintf(buf, sizeof(buf), "%s/ethumb/modules", eina_prefix_lib_get(_pfx)); 201 snprintf(buf, sizeof(buf), "%s/ethumb/modules", eina_prefix_lib_get(_pfx));
149 _plugins = eina_module_list_get(_plugins, buf, 1, 202 _plugins = eina_module_arch_list_get(_plugins, buf, MODULE_ARCH);
150 &_ethumb_plugin_list_cb, NULL); 203
204 load:
205 if (_plugins)
206 eina_module_list_load(_plugins);
207
208 if (!eina_hash_population(_plugins_ext))
209 ERR("Couldn't find any ethumb plugin.");
151} 210}
152 211
153static void 212static void
154_ethumb_plugins_unload(void) 213_ethumb_plugins_unload(void)
155{ 214{
156 eina_hash_free(_plugins_ext);
157 _plugins_ext = NULL;
158 eina_module_list_unload(_plugins);
159 eina_module_list_free(_plugins); 215 eina_module_list_free(_plugins);
160 eina_array_free(_plugins); 216 eina_array_free(_plugins);
161 _plugins = NULL; 217 _plugins = NULL;
218
219 eina_hash_free(_plugins_ext);
220 _plugins_ext = NULL;
221
222 _plugins_loaded = EINA_FALSE;
162} 223}
163 224
164EAPI int 225EAPI int
@@ -192,6 +253,9 @@ ethumb_init(void)
192 goto error_pfx; 253 goto error_pfx;
193 } 254 }
194 255
256 _plugins_ext = eina_hash_string_small_new(NULL);
257 EINA_SAFETY_ON_NULL_GOTO(_plugins_ext, error_plugins_ext);
258
195 evas_init(); 259 evas_init();
196 ecore_init(); 260 ecore_init();
197 ecore_evas_init(); 261 ecore_evas_init();
@@ -204,9 +268,12 @@ ethumb_init(void)
204 _thumb_category_normal = eina_stringshare_add("normal"); 268 _thumb_category_normal = eina_stringshare_add("normal");
205 _thumb_category_large = eina_stringshare_add("large"); 269 _thumb_category_large = eina_stringshare_add("large");
206 270
207 _ethumb_plugins_load();
208 return ++initcount; 271 return ++initcount;
209 272
273 error_plugins_ext:
274 eina_prefix_free(_pfx);
275 _pfx = NULL;
276
210 error_pfx: 277 error_pfx:
211 eina_log_domain_unregister(_log_dom); 278 eina_log_domain_unregister(_log_dom);
212 _log_dom = -1; 279 _log_dom = -1;
@@ -1211,6 +1278,8 @@ _ethumb_plugin_generate(Ethumb *e)
1211 for (i = 0; extp[i] != '\0'; i++) 1278 for (i = 0; extp[i] != '\0'; i++)
1212 ext[i] = tolower(extp[i + 1]); 1279 ext[i] = tolower(extp[i + 1]);
1213 1280
1281 _ethumb_plugins_load();
1282
1214 plugin = eina_hash_find(_plugins_ext, ext); 1283 plugin = eina_hash_find(_plugins_ext, ext);
1215 if (!plugin) 1284 if (!plugin)
1216 { 1285 {