Enlightenment CVS committal Author : moom Project : e17 Module : libs/etk
Dir : e17/libs/etk/src/lib Modified Files: etk_cache.c etk_cache.h Log Message: * [Cache] Add etk_cache_free_callback_set() =================================================================== RCS file: /cvs/e/e17/libs/etk/src/lib/etk_cache.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- etk_cache.c 6 Jan 2007 19:23:09 -0000 1.10 +++ etk_cache.c 7 Jan 2007 03:46:05 -0000 1.11 @@ -68,6 +68,9 @@ while (cache->cached_objects) { item = cache->cached_objects->data; + + if (cache->free_cb) + cache->free_cb(item->object, cache->free_cb_data); evas_object_del(item->object); free(item->filename); free(item->key); @@ -78,6 +81,23 @@ } /** + * @brief Sets the callback to call when a cached object is deleted (because it is too old, or because the cache is + * cleared) + * @param cache a cache system + * @param free_cb the function to call when a cached object is deleted. @a object is the object that will be deleted, + * and @a data is the user data you gave (see the next param) + * @param data a data pointer that will be passed to the callback when it is called + */ +void etk_cache_free_callback_set(Etk_Cache *cache, void (*free_cb)(Evas_Object *object, void *data), void *data) +{ + if (!cache) + return; + + cache->free_cb = free_cb; + cache->free_cb_data = data; +} + +/** * @brief Sets the max number of objects that the cache system can contain. If the new size is smaller than current * number of objects in the cache, the oldest objects that can't fit in the new cache size will be destroyed * @param cache the cache system to resize @@ -98,6 +118,9 @@ while (cache->cached_objects && num_objects > cache->size) { item = cache->cached_objects->data; + + if (cache->free_cb) + cache->free_cb(item->object, cache->free_cb_data); evas_object_del(item->object); free(item->filename); free(item->key); @@ -149,8 +172,12 @@ if (!cache || !object || cache->size <= 0 || !filename) { - if (object) + if (cache && object) + { + if (cache->free_cb) + cache->free_cb(object, cache->free_cb_data); evas_object_del(object); + } return; } @@ -161,6 +188,8 @@ { item = cache->cached_objects->data; + if (cache->free_cb) + cache->free_cb(item->object, cache->free_cb_data); evas_object_del(item->object); free(item->filename); free(item->key); =================================================================== RCS file: /cvs/e/e17/libs/etk/src/lib/etk_cache.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- etk_cache.h 5 Jan 2007 22:25:12 -0000 1.5 +++ etk_cache.h 7 Jan 2007 03:46:05 -0000 1.6 @@ -20,12 +20,16 @@ /* private: */ Evas_List *cached_objects; int size; + + void (*free_cb)(Evas_Object *object, void *data); + void *free_cb_data; }; Etk_Cache *etk_cache_new(int size); void etk_cache_destroy(Etk_Cache *cache); void etk_cache_clear(Etk_Cache *cache); +void etk_cache_free_callback_set(Etk_Cache *cache, void (*free_cb)(Evas_Object *object, void *data), void *data); void etk_cache_size_set(Etk_Cache *cache, int size); int etk_cache_size_get(Etk_Cache *cache); int etk_cache_num_objects_get(Etk_Cache *cache); ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs