summaryrefslogtreecommitdiff
path: root/src/examples/eio/eio_sentry.c
blob: e604e8900ded8648d434772e9ba9d99c84a5f905 (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
#if HAVE_CONFIG_H
#include <config.h>
#endif


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

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

void
sentry_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
    Eio_Sentry_Event *event_info = event->info;

    printf("Event on monitored path %s", event_info->source);
    printf("Created file %s\n", event_info->trigger);

    ecore_main_loop_quit();

    efl_event_callback_stop(event->object);
}

void
monitor_stuff(void *data)
{
    const char *path = data;
    Eio_Sentry *sentry = efl_add_ref(EIO_SENTRY_CLASS, NULL);
    efl_event_callback_add(sentry, EIO_SENTRY_EVENT_FILE_CREATED, (Efl_Event_Cb)&sentry_cb, NULL);

    printf("Starting monitoring path %s\n", path);
    eio_sentry_add(sentry, path);
}

int
main(int argc, char const *argv[])
{
    eio_init();
    ecore_init();

    const char *path = getenv("HOME");

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

    ecore_job_add(&monitor_stuff, path);

    ecore_main_loop_begin();

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