summaryrefslogtreecommitdiff
path: root/src/examples/eio/eio_job_ls.c
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2016-04-12 16:00:23 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-25 21:32:03 -0300
commit7241b7375de1eb4327f5bca21dcfc5a889b9eb72 (patch)
treececbe8991d1b38db8f8c67965ae2a5e6cf2aa503 /src/examples/eio/eio_job_ls.c
parentde9be13d458f2739a536e5863aa8caddd3f7f715 (diff)
eio: Adds Eo-based Eio API
The legacy Eio_File factory functions are replaced by an Eo object called Eo_Job that return promises wrapping the async file operations. With this commit, the legacy Eio callbacks are replaced by the following Eo/Promises counterparts : * Done_Cb -> Promise then success callback * Error_Cb -> Promise then error callback * Main_Cb -> Promise progress callback * Filter_Cb -> Job object event (more below) Events are used to deliver and get the filter data. To differentiate between the named and direct versions, they come in "filter,direct" and "filter,name" versions. Monitors were wrapped inside a new class Eo_Sentry. The user creates a sentry object and adds monitoring targets to it, listening to events on it. The sentry event info is composed of two strings. The source string is the path being monitored, i.e. the one passed to eio_sentry_add, and the trigger string is the path that actually triggered the event, e.g. a new file created in a monitored directory.
Diffstat (limited to 'src/examples/eio/eio_job_ls.c')
-rw-r--r--src/examples/eio/eio_job_ls.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/examples/eio/eio_job_ls.c b/src/examples/eio/eio_job_ls.c
new file mode 100644
index 0000000..354325e
--- /dev/null
+++ b/src/examples/eio/eio_job_ls.c
@@ -0,0 +1,79 @@
1#if HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5
6#include <stdlib.h>
7#include <stdio.h>
8
9#include <Eina.h>
10#include <Eio.h>
11#include <Ecore.h>
12
13void done_cb(void *data, void *value EINA_UNUSED)
14{
15 Eio_Job *job = data;
16 printf("%s done listing files.\n", __FUNCTION__);
17 ecore_main_loop_quit();
18 eo_unref(job);
19}
20
21void error_cb(void *data, Eina_Error *error)
22{
23 Eio_Job *job = data;
24 EINA_SAFETY_ON_NULL_RETURN(error);
25 const char *msg = eina_error_msg_get(*error);
26 printf("%s error: %s\n", __FUNCTION__, msg);
27 ecore_main_loop_quit();
28
29 eo_unref(job);
30}
31
32void filter_cb(void *data, const Eo_Event *event)
33{
34 Eio_Filter_Name_Data *event_info = event->info;
35 static Eina_Bool should_filter = EINA_FALSE;
36
37 printf("Filtering file %s\n", event_info->file);
38
39 should_filter = !should_filter;
40 event_info->filter = should_filter;
41}
42
43// Progress used to be the "Eio_Main_Cb" family of callbacks in the legacy API.
44void progress_cb(void *data, const char *filename)
45{
46 EINA_SAFETY_ON_NULL_RETURN(filename);
47 printf("%s listing filename: %s\n", __FUNCTION__, filename);
48}
49
50void list_files(void *data)
51{
52 Eina_Promise *promise;
53 const char *path = data;
54
55 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
56 eo_event_callback_add(job, EIO_JOB_EVENT_FILTER_NAME, (Eo_Event_Cb)&filter_cb, NULL);
57 eio_job_file_ls(job, path, &promise);
58 eina_promise_progress_cb_add(promise, (Eina_Promise_Progress_Cb)&progress_cb, NULL, NULL);
59 eina_promise_then(promise, (Eina_Promise_Cb)&done_cb, (Eina_Promise_Error_Cb)&error_cb, job);
60}
61
62int main(int argc, char const *argv[])
63{
64 eio_init();
65 ecore_init();
66
67 const char *path = getenv("HOME");
68
69 if (argc > 1)
70 path = argv[1];
71
72 Ecore_Job *job = ecore_job_add(&list_files, path);
73
74 ecore_main_loop_begin();
75
76 ecore_shutdown();
77 eio_shutdown();
78 return 0;
79}