summaryrefslogtreecommitdiff
path: root/src/examples/eio/efl_io_manager_ls.c
blob: b73e4544ef0dea9168861b4579bdd84de84f6d1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>

#include <Eina.h>
#include <Eio.h>
#include <Ecore.h>

static Eina_Value
done_cb(void *data EINA_UNUSED,
        const Eina_Value file,
        const Eina_Future *dead EINA_UNUSED)
{
   if (file.type == EINA_VALUE_TYPE_ERROR)
     {
        Eina_Error err;

        eina_value_get(&file, &err);
        fprintf(stderr, "Something has gone wrong: %s\n", eina_error_msg_get(err));
        abort();
     }
   if (file.type == EINA_VALUE_TYPE_UINT64)
     {
        uint64_t value;

        eina_value_get(&file, &value);

        printf("%s done listing files %"PRIu64".\n", __FUNCTION__, value);
     }

   ecore_main_loop_quit();

   return file;
}

// Progress used to be the "Eio_Main_Cb" family of callbacks in the legacy API.
static void
progress_cb(void *data EINA_UNUSED, Eina_Accessor *access)
{
   const char *filename;
   unsigned int count;

   EINA_ACCESSOR_FOREACH(access, count, filename)
     printf("%s listing filename: %s\n", __FUNCTION__, filename);
}

void list_files(void *data)
{
   Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, efl_app_main_loop_get(efl_app_get()));
   const char *path = data;

   eina_future_then(efl_io_manager_ls(job, path, NULL, progress_cb, NULL), done_cb, NULL);
}

int main(int argc, char const *argv[])
{
   const char *path;
   Ecore_Job *job;

   eio_init();
   ecore_init();

   path = getenv("HOME");

   if (argc > 1)
     path = argv[1];

   job = ecore_job_add(&list_files, path);

   ecore_main_loop_begin();

   ecore_shutdown();
   eio_shutdown();
   return 0;
}