2
* @page eio_examples Eio Examples
4
* Here is a page with some Eio examples explained:
6
* @li @ref eio_file_ls.c
9
* @li @ref tutorial_dir_copy
10
* @li @ref tutorial_dir_stat_ls
11
* @li @ref tutorial_file_ls
12
* @li @ref tutorial_dir_direct_ls
13
* @li @ref tutorial_monitor_add
15
* @example eio_file_ls.c
19
* @page tutorial_dir_copy eio_dir_copy() tutorial
21
* To use eio_dir_copy(), you basically need the source and
22
* destination files (or directories), and set three callbacks:
24
* @li The notification callback, which allows you to know if a file or
25
* a directory is copied, and the progress of the copy.
26
* @li The end callback, which is called when the copy is finished.
27
* @li The error callback, which is called if an error occurred. You
28
* can then retrieve the error type as an errno error.
30
* @warning It is the user's duty to provide the "right target". It
31
* means that copying to '.' will copy the content directly inside '.'
32
* and not in a subdirectory.
34
* Here is a simple example:
41
* _test_notify_cb(void *data, Eio_File *handler, const Eio_Progress *info)
46
* printf("[%s] %f%%\n", info->dest, info->percent);
49
* printf("global [%li/%li] %f%%\n", info->current, info->max, info->percent);
55
* _test_done_cb(void *data, Eio_File *handler)
57
* printf("copy done\n");
58
* ecore_main_loop_quit();
62
* _test_error_cb(int error, Eio_File *handler, void *data)
64
* fprintf(stderr, "error: [%s]\n", strerror(error));
65
* ecore_main_loop_quit();
69
* main(int argc, char **argv)
75
* fprintf(stderr, "eio_cp source_file destination_file\n");
82
* cp = eio_dir_copy(argv[1], argv[2],
88
* ecore_main_loop_begin();
99
* @page tutorial_dir_stat_ls eio_dir_stat_ls() tutorial
101
* @li The filter callback, which allow or not a file to be seen
102
* by the main loop handler. This callback run in a separated thread.
103
* @li The main callback, which receive in the main loop all the file
104
* that are allowed by the filter. If you are updating a user interface
105
* it make sense to delay the insertion a little, so you get a chance
106
* to update the canvas for a bunch of file instead of one by one.
107
* @li The end callback, which is called in the main loop when the
108
* content of the directory has been correctly scanned and all the
109
* file notified to the main loop.
110
* @li The error callback, which is called if an error occurred or
111
* if the listing was cancelled during it's run. You can then retrieve
112
* the error type as an errno error.
114
* Here is a simple example that implement a stupidly simple replacement for find:
121
* _test_filter_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info)
123
* fprintf(stderr, "ACCEPTING: %s\n", info->path);
128
* _test_main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info)
130
* fprintf(stderr, "PROCESS: %s\n", info->path);
134
* _test_done_cb(void *data, Eio_File *handler)
136
* printf("ls done\n");
137
* ecore_main_loop_quit();
141
* _test_error_cb(void *data, Eio_File *handler, int error)
143
* fprintf(stderr, "error: [%s]\n", strerror(error));
144
* ecore_main_loop_quit();
148
* main(int argc, char **argv)
154
* fprintf(stderr, "eio_ls directory\n");
161
* cp = eio_dir_stat_ls(argv[1],
168
* ecore_main_loop_begin();
180
* @page tutorial_file_ls eio_file_ls() tutorial
182
* To use eio_file_ls(), you just need to define four callbacks:
184
* @li The filter callback, which allows a file to be seen (or not)
185
* by the main loop handler. This callback runs in a separate thread.
186
* @li The main callback, which receive in the main loop all the file
187
* that are allowed by the filter. If you are updating a user interface
188
* it makes sense to delay the insertion a little, so you get a chance
189
* to update the canvas for a bunch of files instead of one by one.
190
* @li The end callback, which is called in the main loop when the
191
* content of the directory has been correctly scanned and all the
192
* file notified to the main loop.
193
* @li The error callback, which is called if an error occurred or
194
* if the listing was cancelled during its run. You can then retrieve
195
* the error type as an errno error.
197
* Here is a simple example:
204
* _test_filter_cb(void *data, Eio_File *handler, const char *file)
206
* fprintf(stderr, "ACCEPTING: %s\n", file);
211
* _test_main_cb(void *data, Eio_File *handler, const char *file)
213
* fprintf(stderr, "PROCESS: %s\n", file);
217
* _test_done_cb(void *data, Eio_File *handler)
219
* printf("ls done\n");
220
* ecore_main_loop_quit();
224
* _test_error_cb(void *data, Eio_File *handler, int error)
226
* fprintf(stderr, "error: [%s]\n", strerror(error));
227
* ecore_main_loop_quit();
231
* main(int argc, char **argv)
237
* fprintf(stderr, "eio_ls directory\n");
244
* cp = eio_file_ls(argv[1],
251
* ecore_main_loop_begin();
263
* @page tutorial_monitor_add eio_monitor_add() tutorial
265
* To use eio_monitor_add(), you have to define callbacks
266
* for events declared by eio.
267
* Available events are :
268
* - EIO_MONITOR_FILE_CREATED
269
* - EIO_MONITOR_FILE_DELETED
270
* - EIO_MONITOR_FILE_MODIFIED
271
* - EIO_MONITOR_FILE_CLOSED
272
* - EIO_MONITOR_DIRECTORY_CREATED
273
* - EIO_MONITOR_DIRECTORY_DELETED
274
* - EIO_MONITOR_DIRECTORY_CLOSED
275
* - EIO_MONITOR_SELF_RENAME
276
* - EIO_MONITOR_SELF_DELETED
278
* As nothing is worth an example, here it is :
284
* void file_modified(void *data, int type, void *event)
286
* const char *filename = (const char *)data;
287
* printf("file %s ", filename);
288
* if( type == EIO_MONITOR_FILE_MODIFIED )
289
* printf("is being modified");
290
* else if( type == EIO_MONITOR_FILE_CLOSED )
291
* printf("is no longer being modified");
292
* else printf("got unexpected changes");
296
* int main(int argc, char **argv) {
297
* Eio_Monitor *monitor = NULL,
300
* const char *filename = eina_stringshare_add("/tmp/eio_notify_testfile");
302
* monitor = eio_monitor_add(filename);
303
* ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, (Ecore_Event_Handler_Cb)file_modified, filename);
304
* ecore_event_handler_add(EIO_MONITOR_FILE_CLOSED, (Ecore_Event_Handler_Cb)file_modified, filename);
306
* ecore_main_loop_begin();
308
* eina_stringshare_del(filename);
311
* Build the example doing :
312
* @verbatim gcc -o tutorial_monitor_add tutorial_monitor_add.c `pkg-config --libs --cflags eio ecore ecore-file eina`
313
* then create the file /tmp/eio_notify_testfile :
314
* touch /tmp/eio_notify_testfile
315
* and launch tutorial_monitor_add, and in another terminal, write into /tmp/eio_notify_testfile, doing for example :
316
* echo "test" >> /tmp/eio_notify_testfile
321
* @page tutorial_dir_direct_ls eio_dir_direct_ls() tutorial
323
* @li The filter callback, which allow or not a file to be seen
324
* by the main loop handler. This callback run in a separated thread.
325
* It also take care of getting a stat buffer needed by the main callback
326
* to display the file size.
327
* @li The main callback, which receive in the main loop all the file
328
* that are allowed by the filter. If you are updating a user interface
329
* it make sense to delay the insertion a little, so you get a chance
330
* to update the canvas for a bunch of file instead of one by one.
331
* @li The end callback, which is called in the main loop when the
332
* content of the directory has been correctly scanned and all the
333
* file notified to the main loop.
334
* @li The error callback, which is called if an error occurred or
335
* if the listing was cancelled during it's run. You can then retrieve
336
* the error type as an errno error.
338
* Here is a simple example that implement a stupidly simple recursive ls that display file size:
346
* _test_filter_cb(void *data, Eio_File *handler, Eina_File_Direct_Info *info)
351
* isdir = info->type == EINA_FILE_DIR;
353
* buffer = malloc(sizeof (Eina_Stat));
354
* if (eina_file_statat(eio_file_container_get(handler), info, buffer))
360
* if (!isdir && info->type == EINA_FILE_DIR)
363
* if (lstat(info->path, &st) == 0)
365
* if (S_ISLNK(st.st_mode))
366
* info->type = EINA_FILE_LNK;
370
* eio_file_associate_direct_add(handler, "stat", buffer, free);
371
* fprintf(stdout, "ACCEPTING: %s\n", info->path);
376
* _test_main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info)
378
* struct stat *buffer;
380
* buffer = eio_file_associate_find(handler, "stat");
381
* fprintf(stdout, "PROCESS: %s of size %li\n", info->path, buffer->st_size);
385
* _test_done_cb(void *data, Eio_File *handler)
387
* printf("ls done\n");
388
* ecore_main_loop_quit();
392
* _test_error_cb(void *data, Eio_File *handler, int error)
394
* fprintf(stdout, "error: [%s]\n", strerror(error));
395
* ecore_main_loop_quit();
399
* main(int argc, char **argv)
405
* fprintf(stdout, "eio_ls directory\n");
412
* cp = eio_dir_direct_ls(argv[1],
419
* ecore_main_loop_begin();