summaryrefslogtreecommitdiff
path: root/src/examples/eio/eio_job_open.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_open.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_open.c')
-rw-r--r--src/examples/eio/eio_job_open.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/examples/eio/eio_job_open.c b/src/examples/eio/eio_job_open.c
new file mode 100644
index 0000000..fb235c2
--- /dev/null
+++ b/src/examples/eio/eio_job_open.c
@@ -0,0 +1,80 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include <Eina.h>
9#include <Eio.h>
10#include <Ecore.h>
11
12void error_cb(void *data, Eina_Error *error)
13{
14 EINA_SAFETY_ON_NULL_RETURN(error);
15 EINA_SAFETY_ON_NULL_RETURN(data);
16
17 const char *msg = eina_error_msg_get(*error);
18 EINA_LOG_ERR("error: %s", msg);
19
20 ecore_main_loop_quit();
21}
22
23void done_closing_cb(int *result EINA_UNUSED)
24{
25 printf("%s closed file.\n", __FUNCTION__);
26
27 ecore_main_loop_quit();
28}
29
30void closing_job(Eio_Job *job, Eina_File *file)
31{
32 Eina_Promise *promise = NULL;
33 printf("%s Will close the file...\n", __FUNCTION__);
34 eio_job_file_close(job, file, &promise);
35 eina_promise_then(promise, (Eina_Promise_Cb)&done_closing_cb, (Eina_Promise_Error_Cb)&error_cb, job);
36}
37
38void done_open_cb(void *data, Eina_File **file)
39{
40 EINA_SAFETY_ON_NULL_RETURN(data);
41 EINA_SAFETY_ON_NULL_RETURN(file);
42 EINA_SAFETY_ON_NULL_RETURN(*file);
43
44 Eio_Job *job = data;
45
46 const char *name = eina_file_filename_get(*file);
47 printf("%s opened file %s\n", __FUNCTION__, name);
48
49 closing_job(job, *file);
50}
51
52void open_file(const char *path)
53{
54 Eina_Promise *promise;
55
56 Eio_Job *job = eo_add(EIO_JOB_CLASS, NULL);
57 eio_job_file_open(job, path, EINA_FALSE, &promise);
58 eina_promise_then(promise, (Eina_Promise_Cb)&done_open_cb, (Eina_Promise_Error_Cb)&error_cb, job);
59
60 eo_unref(job);
61}
62
63int main(int argc, char const *argv[])
64{
65 eio_init();
66 ecore_init();
67
68 const char *path = getenv("HOME");
69
70 if (argc > 1)
71 path = argv[1];
72
73 open_file(path);
74
75 ecore_main_loop_begin();
76
77 ecore_shutdown();
78 eio_shutdown();
79 return 0;
80}