Re: [E-devel] eio Example for eio_file_stat_ls
On 21/09/2012 17:37, Leandro Dorileo wrote: Hi Guillaume, On Fri, Sep 21, 2012 at 01:55:54PM +0200, Guillaume Friloux wrote: Hello e people, I have written a little example app for eio_file_stat_ls() that could have its place under trunk/eio/src/examples/ or trunk/EXAMPLES/eio/. I think this could help people that needs to use it. It also warns about the filter_cb being called in eio's thread. A trap i stepped on by badly reading the doc (totally my fault). Example file is attached to this mail. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; Eina_List *l_filters; unsigned int count_filtered, count_passed, jobs; Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file); void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file); void _list_cb_done(void *data, Eio_File *handler); void _list_cb_error(void *data, Eio_File *handler, int error); You don't need these prototypes, reorder your functions. void _free_cb(void *data) { return; } void _filter_add(const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); l_filters = eina_list_append(l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Filter *obj_filter; Eina_List *l; last_slash = strrchr(file-path, '/'); if (file-type==EINA_FILE_DIR) return EINA_TRUE; EINA_LIST_FOREACH(l_filters, l, obj_filter) { if (!regexec((obj_filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, obj_filter, _free_cb); return EINA_TRUE; } } count_filtered++; return EINA_FALSE; } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Filter *obj; if (file-type==EINA_FILE_DIR) { jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, NULL); return; } count_passed++; obj = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, obj-name); } void _list_cb_done(void *data, Eio_File *handler) { if (!--jobs) ecore_main_loop_quit(); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } eina_init(); ecore_init(); eio_init(); Check for initializations. l_filters = NULL; count_filtered = 0; count_passed = 0; jobs = 1; You could use a struct do describe your status data and pass it to eio_file_stat_ls and appropriately handle it. _filter_add(^[0-9]+$); _filter_add(^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, NULL); ecore_main_loop_begin(); printf(Stats :\tFiltered = %d\tPassed = %d\n, count_filtered, count_passed); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } Regards I made the changes : http://slexy.org/view/s204s5bbvk attachment: guillaume_friloux.vcf-- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] eio Example for eio_file_stat_ls
Added a mutex to not get crappy values when multiple calls to filter_cb are done (eio can launch multiple threads it seems) /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; struct _Data { unsigned int count_filtered, count_passed, count_total, jobs; Eina_List *l_filters; Eina_Lock mutex; }; void _free_cb(void *data) { return; } void _filter_add(struct _Data *data, const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); data-l_filters = eina_list_append(data-l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Data *obj = data; struct _Filter *filter; Eina_List *l; last_slash = strrchr(file-path, '/'); obj-count_total++; //printf(%s\n, file-path); if (file-type==EINA_FILE_DIR) return EINA_TRUE; eina_lock_take(obj-mutex); EINA_LIST_FOREACH(obj-l_filters, l, filter) { if (!regexec((filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, filter, _free_cb); eina_lock_release(obj-mutex); return EINA_TRUE; } } obj-count_filtered++; eina_lock_release(obj-mutex); return EINA_FALSE; } void _list_cb_done(void *data, Eio_File *handler) { struct _Data *obj = data; eina_lock_take(obj-mutex); if (!--obj-jobs) ecore_main_loop_quit(); eina_lock_release(obj-mutex); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Data *obj = data; struct _Filter *filter; eina_lock_take(obj-mutex); if (file-type==EINA_FILE_DIR) { obj-jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); eina_lock_release(obj-mutex); return; } obj-count_passed++; filter = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, filter-name); eina_lock_release(obj-mutex); } int main(int argc, char **argv) { struct _Data *data; struct _Filter *filter; if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } if (!eina_init()) return 1; if (!ecore_init()) return 1; if (!eio_init()) return 1; data = calloc(1, sizeof(struct _Data)); data-jobs = 1; eina_lock_new(data-mutex); eina_lock_debug(data-mutex); _filter_add(data, ^[0-9]+$); _filter_add(data, ^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); ecore_main_loop_begin(); printf(Stats :\tTotal = %d\tFiltered = %d\tPassed = %d\n, data-count_total, data-count_filtered, data-count_passed); EINA_LIST_FREE(data-l_filters, filter) { eina_stringshare_del(filter-name); regfree(filter-preg); free(filter); } eina_lock_free(data-mutex); free(data); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } attachment: guillaume_friloux.vcf-- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] eio Example for eio_file_stat_ls
On 24/09/2012 13:40, Guillaume Friloux wrote: Added a mutex to not get crappy values when multiple calls to filter_cb are done (eio can launch multiple threads it seems) Fuck me i suck. This version is better. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; struct _Data { unsigned int count_filtered, count_passed, count_total, jobs; Eina_List *l_filters; Eina_Lock mutex; }; void _free_cb(void *data) { return; } void _filter_add(struct _Data *data, const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); data-l_filters = eina_list_append(data-l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Data *obj = data; struct _Filter *filter; Eina_List *l; last_slash = strrchr(file-path, '/'); eina_lock_take(obj-mutex); obj-count_total++; if (file-type==EINA_FILE_DIR) { eina_lock_release(obj-mutex); return EINA_TRUE; } EINA_LIST_FOREACH(obj-l_filters, l, filter) { if (!regexec((filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, filter, _free_cb); eina_lock_release(obj-mutex); return EINA_TRUE; } } obj-count_filtered++; eina_lock_release(obj-mutex); return EINA_FALSE; } void _list_cb_done(void *data, Eio_File *handler) { struct _Data *obj = data; eina_lock_take(obj-mutex); if (!--obj-jobs) ecore_main_loop_quit(); eina_lock_release(obj-mutex); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Data *obj = data; struct _Filter *filter; eina_lock_take(obj-mutex); if (file-type==EINA_FILE_DIR) { obj-jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); eina_lock_release(obj-mutex); return; } obj-count_passed++; filter = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, filter-name); eina_lock_release(obj-mutex); } int main(int argc, char **argv) { struct _Data *data; struct _Filter *filter; if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } if (!eina_init()) return 1; if (!ecore_init()) return 1; if (!eio_init()) return 1; data = calloc(1, sizeof(struct _Data)); data-jobs = 1; eina_lock_new(data-mutex); eina_lock_debug(data-mutex); _filter_add(data, ^[0-9]+$); _filter_add(data, ^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); ecore_main_loop_begin(); printf(Stats :\tTotal = %d\tFiltered = %d\tPassed = %d\n, data-count_total, data-count_filtered, data-count_passed); EINA_LIST_FREE(data-l_filters, filter) { eina_stringshare_del(filter-name); regfree(filter-preg); free(filter); } eina_lock_free(data-mutex); free(data); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } attachment: guillaume_friloux.vcf-- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] eio Example for eio_file_stat_ls
On Mon, 24 Sep 2012 13:54:45 +0200 Guillaume Friloux guillaume.fril...@asp64.com wrote: Fuck me i suck. This version is better. Nope, you are not my type, and I don't care how well you suck. :-P -- A big old stinking pile of genius that no one wants coz there are too many silver coated monkeys in the world. signature.asc Description: PGP signature -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] eio Example for eio_file_stat_ls
Hi Guillaume, On Mon, Sep 24, 2012 at 01:54:45PM +0200, Guillaume Friloux wrote: On 24/09/2012 13:40, Guillaume Friloux wrote: Added a mutex to not get crappy values when multiple calls to filter_cb are done (eio can launch multiple threads it seems) Fuck me i suck. This version is better. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; struct _Data { unsigned int count_filtered, count_passed, count_total, jobs; Eina_List *l_filters; Eina_Lock mutex; }; void _free_cb(void *data) { return; } You don't need this callback. void _filter_add(struct _Data *data, const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); data-l_filters = eina_list_append(data-l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Data *obj = data; struct _Filter *filter; Eina_List *l; last_slash = strrchr(file-path, '/'); eina_lock_take(obj-mutex); obj-count_total++; if (file-type==EINA_FILE_DIR) { eina_lock_release(obj-mutex); return EINA_TRUE; } EINA_LIST_FOREACH(obj-l_filters, l, filter) { if (!regexec((filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, filter, _free_cb); Like I said, you don't need _free_cb, pass NULL here. eina_lock_release(obj-mutex); return EINA_TRUE; } } obj-count_filtered++; eina_lock_release(obj-mutex); return EINA_FALSE; } void _list_cb_done(void *data, Eio_File *handler) { struct _Data *obj = data; eina_lock_take(obj-mutex); if (!--obj-jobs) ecore_main_loop_quit(); eina_lock_release(obj-mutex); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Data *obj = data; struct _Filter *filter; eina_lock_take(obj-mutex); if (file-type==EINA_FILE_DIR) { obj-jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); eina_lock_release(obj-mutex); return; } obj-count_passed++; filter = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, filter-name); eina_lock_release(obj-mutex); } int main(int argc, char **argv) { struct _Data *data; struct _Filter *filter; if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } if (!eina_init()) return 1; if (!ecore_init()) return 1; if (!eio_init()) return 1; I'm not sure if the sequence here matter too much but I would register ecore first. And, just returning is not enough, you should shutdown what succeed before. In the sequence we have here, if eina_init has succeed and ecore_init has failed eina still needs to be finished. Labels down in the end of your main to handle this scenarios would fit very well. :-) data = calloc(1, sizeof(struct _Data)); data-jobs = 1; eina_lock_new(data-mutex); eina_lock_debug(data-mutex); _filter_add(data, ^[0-9]+$); _filter_add(data, ^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); ecore_main_loop_begin(); printf(Stats :\tTotal = %d\tFiltered = %d\tPassed = %d\n, data-count_total, data-count_filtered, data-count_passed); EINA_LIST_FREE(data-l_filters, filter) { eina_stringshare_del(filter-name); regfree(filter-preg); free(filter); } eina_lock_free(data-mutex); free(data); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } Thank you -- Leandro Dorileo ProFUSION embedded
Re: [E-devel] eio Example for eio_file_stat_ls
On Mon, Sep 24, 2012 at 10:48 AM, Leandro Dorileo dori...@profusion.mobi wrote: Hi Guillaume, On Mon, Sep 24, 2012 at 01:54:45PM +0200, Guillaume Friloux wrote: On 24/09/2012 13:40, Guillaume Friloux wrote: Added a mutex to not get crappy values when multiple calls to filter_cb are done (eio can launch multiple threads it seems) Fuck me i suck. This version is better. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; struct _Data { unsigned int count_filtered, count_passed, count_total, jobs; Eina_List *l_filters; Eina_Lock mutex; }; void _free_cb(void *data) { return; } You don't need this callback. If he doesn't want to see his data freed, actually he needs it. Take a look at eio_file_associate_add docs. If no callback is passed, free will be called. Regards void _filter_add(struct _Data *data, const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); data-l_filters = eina_list_append(data-l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Data *obj = data; struct _Filter *filter; Eina_List *l; last_slash = strrchr(file-path, '/'); eina_lock_take(obj-mutex); obj-count_total++; if (file-type==EINA_FILE_DIR) { eina_lock_release(obj-mutex); return EINA_TRUE; } EINA_LIST_FOREACH(obj-l_filters, l, filter) { if (!regexec((filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, filter, _free_cb); Like I said, you don't need _free_cb, pass NULL here. eina_lock_release(obj-mutex); return EINA_TRUE; } } obj-count_filtered++; eina_lock_release(obj-mutex); return EINA_FALSE; } void _list_cb_done(void *data, Eio_File *handler) { struct _Data *obj = data; eina_lock_take(obj-mutex); if (!--obj-jobs) ecore_main_loop_quit(); eina_lock_release(obj-mutex); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Data *obj = data; struct _Filter *filter; eina_lock_take(obj-mutex); if (file-type==EINA_FILE_DIR) { obj-jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); eina_lock_release(obj-mutex); return; } obj-count_passed++; filter = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, filter-name); eina_lock_release(obj-mutex); } int main(int argc, char **argv) { struct _Data *data; struct _Filter *filter; if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } if (!eina_init()) return 1; if (!ecore_init()) return 1; if (!eio_init()) return 1; I'm not sure if the sequence here matter too much but I would register ecore first. And, just returning is not enough, you should shutdown what succeed before. In the sequence we have here, if eina_init has succeed and ecore_init has failed eina still needs to be finished. Labels down in the end of your main to handle this scenarios would fit very well. :-) data = calloc(1, sizeof(struct _Data)); data-jobs = 1; eina_lock_new(data-mutex); eina_lock_debug(data-mutex); _filter_add(data, ^[0-9]+$); _filter_add(data, ^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); ecore_main_loop_begin(); printf(Stats :\tTotal = %d\tFiltered = %d\tPassed = %d\n, data-count_total, data-count_filtered, data-count_passed); EINA_LIST_FREE(data-l_filters, filter) { eina_stringshare_del(filter-name);
Re: [E-devel] eio Example for eio_file_stat_ls
Hi Dilly, On Mon, Sep 24, 2012 at 11:21:42AM -0300, Bruno Dilly wrote: On Mon, Sep 24, 2012 at 10:48 AM, Leandro Dorileo dori...@profusion.mobi wrote: Hi Guillaume, On Mon, Sep 24, 2012 at 01:54:45PM +0200, Guillaume Friloux wrote: On 24/09/2012 13:40, Guillaume Friloux wrote: Added a mutex to not get crappy values when multiple calls to filter_cb are done (eio can launch multiple threads it seems) Fuck me i suck. This version is better. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; struct _Data { unsigned int count_filtered, count_passed, count_total, jobs; Eina_List *l_filters; Eina_Lock mutex; }; void _free_cb(void *data) { return; } You don't need this callback. If he doesn't want to see his data freed, actually he needs it. Take a look at eio_file_associate_add docs. If no callback is passed, free will be called. Actually he doesn't. His filter data is being freed at the end of main(), I took the time to make sure the suggestion I did wasn't introducing any leak, I changed his implementation ad ran it with valgrind and saw the eio docs and implementation as well. Regards void _filter_add(struct _Data *data, const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); data-l_filters = eina_list_append(data-l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Data *obj = data; struct _Filter *filter; Eina_List *l; last_slash = strrchr(file-path, '/'); eina_lock_take(obj-mutex); obj-count_total++; if (file-type==EINA_FILE_DIR) { eina_lock_release(obj-mutex); return EINA_TRUE; } EINA_LIST_FOREACH(obj-l_filters, l, filter) { if (!regexec((filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, filter, _free_cb); Like I said, you don't need _free_cb, pass NULL here. eina_lock_release(obj-mutex); return EINA_TRUE; } } obj-count_filtered++; eina_lock_release(obj-mutex); return EINA_FALSE; } void _list_cb_done(void *data, Eio_File *handler) { struct _Data *obj = data; eina_lock_take(obj-mutex); if (!--obj-jobs) ecore_main_loop_quit(); eina_lock_release(obj-mutex); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Data *obj = data; struct _Filter *filter; eina_lock_take(obj-mutex); if (file-type==EINA_FILE_DIR) { obj-jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); eina_lock_release(obj-mutex); return; } obj-count_passed++; filter = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, filter-name); eina_lock_release(obj-mutex); } int main(int argc, char **argv) { struct _Data *data; struct _Filter *filter; if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } if (!eina_init()) return 1; if (!ecore_init()) return 1; if (!eio_init()) return 1; I'm not sure if the sequence here matter too much but I would register ecore first. And, just returning is not enough, you should shutdown what succeed before. In the sequence we have here, if eina_init has succeed and ecore_init has failed eina still needs to be finished. Labels down in the end of your main to handle this scenarios would fit very well. :-) data = calloc(1, sizeof(struct _Data)); data-jobs = 1; eina_lock_new(data-mutex); eina_lock_debug(data-mutex);
Re: [E-devel] eio Example for eio_file_stat_ls
So, another version with your remarks /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; struct _Data { unsigned int count_filtered, count_passed, count_total, jobs; Eina_List *l_filters; Eina_Lock mutex; }; void _filter_add(struct _Data *data, const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); data-l_filters = eina_list_append(data-l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Data *obj = data; struct _Filter *filter; Eina_List *l; last_slash = strrchr(file-path, '/'); eina_lock_take(obj-mutex); obj-count_total++; if (file-type==EINA_FILE_DIR) { eina_lock_release(obj-mutex); return EINA_TRUE; } EINA_LIST_FOREACH(obj-l_filters, l, filter) { if (!regexec((filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, filter, NULL); eina_lock_release(obj-mutex); return EINA_TRUE; } } obj-count_filtered++; eina_lock_release(obj-mutex); return EINA_FALSE; } void _list_cb_done(void *data, Eio_File *handler) { struct _Data *obj = data; eina_lock_take(obj-mutex); if (!--obj-jobs) ecore_main_loop_quit(); eina_lock_release(obj-mutex); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Data *obj = data; struct _Filter *filter; eina_lock_take(obj-mutex); if (file-type==EINA_FILE_DIR) { obj-jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); eina_lock_release(obj-mutex); return; } obj-count_passed++; filter = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, filter-name); eina_lock_release(obj-mutex); } int main(int argc, char **argv) { struct _Data *data; struct _Filter *filter; if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } if (!eina_init()) return 1; if (!ecore_init()) { eina_shutdown(); return 1; } if (!eio_init()) { eina_shutdown(); ecore_shutdown(); return 1; } data = calloc(1, sizeof(struct _Data)); data-jobs = 1; eina_lock_new(data-mutex); eina_lock_debug(data-mutex); _filter_add(data, ^[0-9]+$); _filter_add(data, ^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, data); ecore_main_loop_begin(); printf(Stats :\tTotal = %d\tFiltered = %d\tPassed = %d\n, data-count_total, data-count_filtered, data-count_passed); EINA_LIST_FREE(data-l_filters, filter) { eina_stringshare_del(filter-name); regfree(filter-preg); free(filter); } eina_lock_free(data-mutex); free(data); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } attachment: guillaume_friloux.vcf-- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] eio Example for eio_file_stat_ls
if (!eio_init()) { eina_shutdown(); ecore_shutdown(); return 1; } the shutdown should be in the reverse order Vincent On Mon, Sep 24, 2012 at 4:59 PM, Guillaume Friloux guillaume.fril...@asp64.com wrote: So, another version with your remarks -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel -- Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ ___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
[E-devel] eio Example for eio_file_stat_ls
Hello e people, I have written a little example app for eio_file_stat_ls() that could have its place under trunk/eio/src/examples/ or trunk/EXAMPLES/eio/. I think this could help people that needs to use it. It also warns about the filter_cb being called in eio's thread. A trap i stepped on by badly reading the doc (totally my fault). Example file is attached to this mail. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; Eina_List *l_filters; unsigned int count_filtered, count_passed, jobs; Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file); void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file); void _list_cb_done(void *data, Eio_File *handler); void _list_cb_error(void *data, Eio_File *handler, int error); void _free_cb(void *data) { return; } void _filter_add(const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); l_filters = eina_list_append(l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Filter *obj_filter; Eina_List *l; last_slash = strrchr(file-path, '/'); if (file-type==EINA_FILE_DIR) return EINA_TRUE; EINA_LIST_FOREACH(l_filters, l, obj_filter) { if (!regexec((obj_filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, obj_filter, _free_cb); return EINA_TRUE; } } count_filtered++; return EINA_FALSE; } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Filter *obj; if (file-type==EINA_FILE_DIR) { jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, NULL); return; } count_passed++; obj = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, obj-name); } void _list_cb_done(void *data, Eio_File *handler) { if (!--jobs) ecore_main_loop_quit(); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } eina_init(); ecore_init(); eio_init(); l_filters = NULL; count_filtered = 0; count_passed = 0; jobs = 1; _filter_add(^[0-9]+$); _filter_add(^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, NULL); ecore_main_loop_begin(); printf(Stats :\tFiltered = %d\tPassed = %d\n, count_filtered, count_passed); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } attachment: guillaume_friloux.vcf-- Got visibility? Most devs has no idea what their production app looks like. Find out how fast your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219671;13503038;y? http://info.appdynamics.com/FreeJavaPerformanceDownload.html___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
Re: [E-devel] eio Example for eio_file_stat_ls
Hi Guillaume, On Fri, Sep 21, 2012 at 01:55:54PM +0200, Guillaume Friloux wrote: Hello e people, I have written a little example app for eio_file_stat_ls() that could have its place under trunk/eio/src/examples/ or trunk/EXAMPLES/eio/. I think this could help people that needs to use it. It also warns about the filter_cb being called in eio's thread. A trap i stepped on by badly reading the doc (totally my fault). Example file is attached to this mail. /* * Compile : * gcc -g -o eio_file_stat_ls eio_file_stat_ls.c `pkg-config --cflags --libs eina ecore eio` * * Prepare : * mkdir test * touch test/456 * touch test/excluded * touch test/backuped * * Run : * ./eio_file_stat_ls test */ #include Eio.h #include regex.h struct _Filter { const char *name; regex_t preg; }; Eina_List *l_filters; unsigned int count_filtered, count_passed, jobs; Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file); void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file); void _list_cb_done(void *data, Eio_File *handler); void _list_cb_error(void *data, Eio_File *handler, int error); You don't need these prototypes, reorder your functions. void _free_cb(void *data) { return; } void _filter_add(const char *name) { struct _Filter *obj; obj = calloc(1, sizeof(struct _Filter)); if (!obj) return; if (regcomp((obj-preg), name, REG_EXTENDED)) { fprintf(stderr, Failed to compile regex for \%s\\n, name); free(obj); return; } obj-name = eina_stringshare_add(name); l_filters = eina_list_append(l_filters, obj); } /* * This function is called inside eio's thread, so dont use anything not * thread-safe inside! */ Eina_Bool _list_cb_filter(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { char *last_slash; struct _Filter *obj_filter; Eina_List *l; last_slash = strrchr(file-path, '/'); if (file-type==EINA_FILE_DIR) return EINA_TRUE; EINA_LIST_FOREACH(l_filters, l, obj_filter) { if (!regexec((obj_filter-preg), last_slash + 1, 0, 0, 0)) { eio_file_associate_add(handler, file-path, obj_filter, _free_cb); return EINA_TRUE; } } count_filtered++; return EINA_FALSE; } void _list_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *file) { struct _Filter *obj; if (file-type==EINA_FILE_DIR) { jobs++; eio_file_stat_ls(file-path, _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, NULL); return; } count_passed++; obj = eio_file_associate_find(handler, file-path); printf(File %s matched %s\n, file-path, obj-name); } void _list_cb_done(void *data, Eio_File *handler) { if (!--jobs) ecore_main_loop_quit(); } void _list_cb_error(void *data, Eio_File *handler, int error) { fprintf(stderr, An error occured : %s\n, strerror(error)); } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, Usage ./eio_file_stat_ls testdir\n); return 1; } eina_init(); ecore_init(); eio_init(); Check for initializations. l_filters = NULL; count_filtered = 0; count_passed = 0; jobs = 1; You could use a struct do describe your status data and pass it to eio_file_stat_ls and appropriately handle it. _filter_add(^[0-9]+$); _filter_add(^back.*); eio_file_stat_ls(argv[1], _list_cb_filter, _list_cb, _list_cb_done, _list_cb_error, NULL); ecore_main_loop_begin(); printf(Stats :\tFiltered = %d\tPassed = %d\n, count_filtered, count_passed); eio_shutdown(); ecore_shutdown(); eina_shutdown(); return 0; } Regards -- Leandro Dorileo ProFUSION embedded systems http://profusion.mobi -- Got visibility? Most devs has no idea what their production app looks like. Find out how fast your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219671;13503038;y? http://info.appdynamics.com/FreeJavaPerformanceDownload.html ___ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel