summaryrefslogtreecommitdiff
path: root/src/modules/ecordova/linux/ecordova_fileentry.c
blob: 273c28dac32c93b1af7ec693c8a9a7262c15a8f3 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "ecordova_fileentry_private.h"
#include "ecordova_entry_private.h"

#ifdef EAPI
# undef EAPI
#endif

#ifdef _WIN32
# ifdef DLL_EXPORT
#  define EAPI __declspec(dllexport)
# else
#  define EAPI
# endif /* ! DLL_EXPORT */
#else
# ifdef __GNUC__
#  if __GNUC__ >= 4
#   define EAPI __attribute__ ((visibility("default")))
#  else
#   define EAPI
#  endif
# else
#  define EAPI
# endif
#endif /* ! _WIN32 */

/* logging support */
extern int _ecordova_log_dom;

#define CRI(...) EINA_LOG_DOM_CRIT(_ecordova_log_dom, __VA_ARGS__)
#define ERR(...) EINA_LOG_DOM_ERR(_ecordova_log_dom, __VA_ARGS__)
#define WRN(...) EINA_LOG_DOM_WARN(_ecordova_log_dom, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(_ecordova_log_dom, __VA_ARGS__)
#define DBG(...) EINA_LOG_DOM_DBG(_ecordova_log_dom, __VA_ARGS__)

#define MY_CLASS ECORDOVA_FILEENTRY_CLASS
#define MY_CLASS_NAME "Ecordova_FileEntry"

static void _file_notify(Eo *, void *);
static void _writer_create(Eo *, void *);

static Eo_Base *
_ecordova_fileentry_eo_base_constructor(Eo *obj, Ecordova_FileEntry_Data *pd)
{
   DBG("(%p)", obj);

   pd->obj = obj;

   return eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
}

static void
_ecordova_fileentry_constructor(Eo *obj,
                                Ecordova_FileEntry_Data *pd EINA_UNUSED,
                                const char *name,
                                const char *path,
                                Ecordova_FileSystem *file_system,
                                const char *url)
{
   DBG("(%p)", obj);
   eo_do_super(obj, MY_CLASS, ecordova_entry_constructor(EINA_TRUE,
                                                         EINA_FALSE,
                                                         name,
                                                         path,
                                                         file_system,
                                                         url));
}

static void
_ecordova_fileentry_eo_base_destructor(Eo *obj,
                                       Ecordova_FileEntry_Data *pd EINA_UNUSED)
{
   DBG("(%p)", obj);

   eo_do_super(obj, MY_CLASS, eo_destructor());
}

static void
_ecordova_fileentry_writer_create(Eo *obj,
                                  Ecordova_FileEntry_Data *pd EINA_UNUSED)
{
   Ecordova_Entry_Data *super = eo_data_scope_get(obj, ECORDOVA_ENTRY_CLASS);
   EINA_SAFETY_ON_NULL_RETURN(super);

   _metadata_get(super, _writer_create, _error_notify);
}

static void
_ecordova_fileentry_file(Eo *obj, Ecordova_FileEntry_Data *pd EINA_UNUSED)
{
   Ecordova_Entry_Data *super = eo_data_scope_get(obj, ECORDOVA_ENTRY_CLASS);
   EINA_SAFETY_ON_NULL_RETURN(super);

   _metadata_get(super, _file_notify, _error_notify);
}

static Ecordova_File *
_create_file(Eo *obj, const Ecordova_Metadata *metadata)
{
   Ecordova_Entry_Data *super = eo_data_scope_get(obj, ECORDOVA_ENTRY_CLASS);
   EINA_SAFETY_ON_NULL_RETURN_VAL(super, NULL);

   return eo_add(ECORDOVA_FILE_CLASS, NULL,
     ecordova_file_constructor(super->name,
                              super->native,
                              NULL, //< TODO: mime-type?
                              metadata->modification_date,
                              metadata->size));
}

static void
_file_notify(Eo *obj, void *data)
{
   const Ecordova_Metadata *metadata = data;

   Ecordova_File *file = _create_file(obj, metadata);

   eo_do(obj, eo_event_callback_call(ECORDOVA_FILEENTRY_EVENT_FILE, file));
   eo_unref(file);
}

static void
_writer_create(Eo *obj, void *data)
{
   const Ecordova_Metadata *metadata = data;
   Ecordova_File *file = _create_file(obj, metadata);
   Ecordova_FileWriter *writer = eo_add(ECORDOVA_FILEWRITER_CLASS, NULL,
     ecordova_filewriter_constructor(file));

   eo_do(obj,
         eo_event_callback_call(ECORDOVA_FILEENTRY_EVENT_CREATE_WRITER, writer));

   eo_unref(writer);
   eo_unref(file);
}

#undef EOAPI
#define EOAPI EAPI

#include "undefs.h"

#define ecordova_fileentry_class_get ecordova_fileentry_impl_class_get

#include "ecordova_fileentry.eo.c"