summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@samsung.com>2013-11-01 10:58:33 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-11-01 11:01:18 +0900
commitcf452cc419b5c4449d0538a9638f79b898f10025 (patch)
treea64da8df69eed2a96e9684c944df43ce078918e3 /src/lib
parent8447e652c7db74c14b26486e5f222c420337cd2f (diff)
edje: make it possible for all upper layer function to query the exact same file.
With Eina_File we now can pass an efficient handler accross library boundary. Edje and all underlayer already use it to avoid race condition when setting an Edje object. Elementary and Enlightenment are still exposed to some potential race condition when an Edje file is modified underneath there feet. With the following set of function it should now be possible to avoid those race condition to: edje_mmap_data_get edje_mmap_collection_list edje_mmap_collection_list_free edje_mmap_group_exists
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/edje/Edje_Common.h53
-rw-r--r--src/lib/edje/edje_load.c100
2 files changed, 123 insertions, 30 deletions
diff --git a/src/lib/edje/Edje_Common.h b/src/lib/edje/Edje_Common.h
index 8e72b753f5..dc5a01dfc2 100644
--- a/src/lib/edje/Edje_Common.h
+++ b/src/lib/edje/Edje_Common.h
@@ -119,6 +119,25 @@ EAPI int edje_shutdown (void);
119EAPI void edje_fontset_append_set (const char *fonts); 119EAPI void edje_fontset_append_set (const char *fonts);
120 120
121/** 121/**
122 * Get data from the file level data block of an edje mapped file
123 * @param file The mapped edje file
124 * @param key The data key
125 * @return The string value of the data or NULL if no key is found.
126 * Must be freed by the user when no longer needed.
127 *
128 * If an edje file test.edj is built from the following edc:
129 *
130 * data {
131 * item: "key1" "value1";
132 * item: "key2" "value2";
133 * }
134 * collections { ... }
135 *
136 * Then, edje_file_data_get("test.edj", "key1") will return "value1"
137 */
138EAPI char *edje_mmap_data_get(Eina_File *f, const char *key);
139
140/**
122 * Get data from the file level data block of an edje file 141 * Get data from the file level data block of an edje file
123 * @param file The path to the .edj file 142 * @param file The path to the .edj file
124 * @param key The data key 143 * @param key The data key
@@ -134,6 +153,8 @@ EAPI void edje_fontset_append_set (const char *fonts);
134 * collections { ... } 153 * collections { ... }
135 * 154 *
136 * Then, edje_file_data_get("test.edj", "key1") will return "value1" 155 * Then, edje_file_data_get("test.edj", "key1") will return "value1"
156 *
157 * @see edje_mmap_data_get()
137 */ 158 */
138EAPI char *edje_file_data_get (const char *file, const char *key); 159EAPI char *edje_file_data_get (const char *file, const char *key);
139 160
@@ -1553,14 +1574,46 @@ typedef enum _Edje_Load_Error
1553 EDJE_LOAD_ERROR_RECURSIVE_REFERENCE = 9 /**< The group/collection set to load from had <b>recursive references</b> on its components */ 1574 EDJE_LOAD_ERROR_RECURSIVE_REFERENCE = 9 /**< The group/collection set to load from had <b>recursive references</b> on its components */
1554} Edje_Load_Error; /**< Edje file loading error codes one can get - see edje_load_error_str() too. */ 1575} Edje_Load_Error; /**< Edje file loading error codes one can get - see edje_load_error_str() too. */
1555 1576
1577
1578/**
1579 * Get a list of groups in an edje mapped file
1580 * @param file The mapped file
1581 *
1582 * @return The Eina_List of group names (char *)
1583 *
1584 * Note: the list must be freed using edje_mmap_collection_list_free()
1585 * when you are done with it.
1586 */
1587EAPI Eina_List *edje_mmap_collection_list(Eina_File *f);
1588
1589/**
1590 * Free file collection list
1591 * @param lst The Eina_List of groups
1592 *
1593 * Frees the list returned by edje_mmap_collection_list().
1594 */
1595EAPI void edje_mmap_collection_list_free(Eina_List *lst);
1596
1597/**
1598 * Determine whether a group matching glob exists in an edje mapped file.
1599 * @param file The mapped file
1600 * @param glob A glob to match on
1601 *
1602 * @return 1 if a match is found, 0 otherwise
1603 */
1604EAPI Eina_Bool edje_mmap_group_exists(Eina_File *f, const char *glob);
1605
1556/** 1606/**
1557 * Get a list of groups in an edje file 1607 * Get a list of groups in an edje file
1558 * @param file The path to the edje file 1608 * @param file The path to the edje file
1559 * 1609 *
1560 * @return The Eina_List of group names (char *) 1610 * @return The Eina_List of group names (char *)
1611 * @see edje_mmap_collection_list()
1561 * 1612 *
1562 * Note: the list must be freed using edje_file_collection_list_free() 1613 * Note: the list must be freed using edje_file_collection_list_free()
1563 * when you are done with it. 1614 * when you are done with it.
1615 *
1616 * @see edje_mmap_group_exists()
1564 */ 1617 */
1565EAPI Eina_List *edje_file_collection_list (const char *file); 1618EAPI Eina_List *edje_file_collection_list (const char *file);
1566 1619
diff --git a/src/lib/edje/edje_load.c b/src/lib/edje/edje_load.c
index f69b59e829..d78fa68ad7 100644
--- a/src/lib/edje/edje_load.c
+++ b/src/lib/edje/edje_load.c
@@ -156,17 +156,13 @@ edje_load_error_str(Edje_Load_Error error)
156 } 156 }
157} 157}
158 158
159
160EAPI Eina_List * 159EAPI Eina_List *
161edje_file_collection_list(const char *file) 160edje_mmap_collection_list(Eina_File *f)
162{ 161{
163 Eina_List *lst = NULL; 162 Eina_List *lst = NULL;
164 Eina_File *f;
165 Edje_File *edf; 163 Edje_File *edf;
166 int error_ret = 0; 164 int error_ret = 0;
167 165
168 if ((!file) || (!*file)) return NULL;
169 f = eina_file_open(file, EINA_FALSE);
170 if (!f) return NULL; 166 if (!f) return NULL;
171 edf = _edje_cache_file_coll_open(f, NULL, &error_ret, NULL, NULL); 167 edf = _edje_cache_file_coll_open(f, NULL, &error_ret, NULL, NULL);
172 if (edf) 168 if (edf)
@@ -183,6 +179,21 @@ edje_file_collection_list(const char *file)
183 179
184 _edje_cache_file_unref(edf); 180 _edje_cache_file_unref(edf);
185 } 181 }
182
183 return lst;
184}
185
186EAPI Eina_List *
187edje_file_collection_list(const char *file)
188{
189 Eina_File *f;
190 Eina_List *lst;
191
192 if ((!file) || (!*file)) return NULL;
193 f = eina_file_open(file, EINA_FALSE);
194
195 lst = edje_mmap_collection_list(f);
196
186 eina_file_close(f); 197 eina_file_close(f);
187 return lst; 198 return lst;
188} 199}
@@ -197,24 +208,26 @@ edje_file_collection_list_free(Eina_List *lst)
197 } 208 }
198} 209}
199 210
211EAPI void
212edje_mmap_collection_list_free(Eina_List *lst)
213{
214 edje_file_collection_list_free(lst);
215}
216
200EAPI Eina_Bool 217EAPI Eina_Bool
201edje_file_group_exists(const char *file, const char *glob) 218edje_mmap_group_exists(Eina_File *f, const char *glob)
202{ 219{
203 Edje_File *edf; 220 Edje_File *edf;
204 Eina_File *f;
205 int error_ret = 0; 221 int error_ret = 0;
206 Eina_Bool succeed = EINA_FALSE; 222 Eina_Bool succeed = EINA_FALSE;
207 Eina_Bool is_glob = EINA_FALSE; 223 Eina_Bool is_glob = EINA_FALSE;
208 const char *p; 224 const char *p;
209 225
210 if ((!file) || (!*file) || (!glob)) 226 if ((!f) || (!glob))
211 return EINA_FALSE; 227 return EINA_FALSE;
212 228
213 f = eina_file_open(file, EINA_FALSE);
214 if (!f) return EINA_FALSE;
215
216 edf = _edje_cache_file_coll_open(f, NULL, &error_ret, NULL, NULL); 229 edf = _edje_cache_file_coll_open(f, NULL, &error_ret, NULL, NULL);
217 if (!edf) goto on_error; 230 if (!edf) return EINA_FALSE;
218 231
219 for (p = glob; *p; p++) 232 for (p = glob; *p; p++)
220 { 233 {
@@ -257,39 +270,66 @@ edje_file_group_exists(const char *file, const char *glob)
257 } 270 }
258 _edje_cache_file_unref(edf); 271 _edje_cache_file_unref(edf);
259 272
260 DBG("edje_file_group_exists: '%s', '%s': %i.", file, glob, succeed); 273 DBG("edje_file_group_exists: '%s', '%s': %i.", eina_file_filename_get(f), glob, succeed);
261 274
262 on_error:
263 eina_file_close(f);
264 return succeed; 275 return succeed;
265} 276}
266 277
278EAPI Eina_Bool
279edje_file_group_exists(const char *file, const char *glob)
280{
281 Eina_File *f;
282 Eina_Bool result;
283
284 if ((!file) || (!*file) || (!glob))
285 return EINA_FALSE;
286
287 f = eina_file_open(file, EINA_FALSE);
288 if (!f) return EINA_FALSE;
289
290 result = edje_mmap_group_exists(f, glob);
291
292 eina_file_close(f);
293
294 return result;
295}
267 296
268EAPI char * 297EAPI char *
269edje_file_data_get(const char *file, const char *key) 298edje_mmap_data_get(Eina_File *f, const char *key)
270{ 299{
271 Edje_File *edf; 300 Edje_File *edf;
272 Eina_File *f;
273 char *str = NULL; 301 char *str = NULL;
274 int error_ret = 0; 302 int error_ret = 0;
275 303
276 if (key) 304 if (!key) return NULL;
305
306 edf = _edje_cache_file_coll_open(f, NULL, &error_ret, NULL, NULL);
307 if (edf)
277 { 308 {
278 f = eina_file_open(file, EINA_FALSE); 309 str = (char*) edje_string_get(eina_hash_find(edf->data, key));
279 if (!f) return NULL;
280 310
281 edf = _edje_cache_file_coll_open(f, NULL, &error_ret, NULL, NULL); 311 if (str) str = strdup(str);
282 if (edf)
283 {
284 str = (char*) edje_string_get(eina_hash_find(edf->data, key));
285 312
286 if (str) str = strdup(str); 313 _edje_cache_file_unref(edf);
314 }
315 return str;
316}
287 317
288 _edje_cache_file_unref(edf); 318EAPI char *
289 } 319edje_file_data_get(const char *file, const char *key)
320{
321 Eina_File *f;
322 char *str;
323
324 if (!key) return NULL;
325
326 f = eina_file_open(file, EINA_FALSE);
327 if (!f) return NULL;
328
329 str = edje_mmap_data_get(f, key);
330
331 eina_file_close(f);
290 332
291 eina_file_close(f);
292 }
293 return str; 333 return str;
294} 334}
295 335