summaryrefslogtreecommitdiff
path: root/src/modules/ecordova/linux/ecordova_file.c
blob: a7c2dec2acac8ca83ac9928875deeb2577310023 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "ecordova_file_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_FILE_CLASS
#define MY_CLASS_NAME "Ecordova_File"

static Eo_Base *
_ecordova_file_eo_base_constructor(Eo *obj, Ecordova_File_Data *pd)
{
   DBG("(%p)", obj);

   pd->obj = obj;

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

static void
_ecordova_file_constructor(Eo *obj,
                           Ecordova_File_Data *pd,
                           const char *name,
                           const char *url,
                           const char *type,
                           time_t last_modified_date,
                           long size)
{
   DBG("(%p)", obj);
   pd->name = name ? strdup(name) : strdup("");
   pd->url = url ? strdup(url) : NULL;
   pd->type = type ? strdup(type) : NULL;
   pd->modified_date = last_modified_date;
   pd->size = size;

   pd->start = 0;
   pd->end = pd->size;
}

static void
_ecordova_file_eo_base_destructor(Eo *obj, Ecordova_File_Data *pd)
{
   DBG("(%p)", obj);

   free(pd->name);
   free(pd->url);
   free(pd->type);

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

static Ecordova_File *
_ecordova_file_slice(Eo *obj EINA_UNUSED,
                     Ecordova_File_Data *pd,
                     long start,
                     long end)
{
   DBG("(%p) start=%ld end=%ld", obj, start, end);
   long size = pd->end - pd->start;
   long new_start = 0;
   long new_end = size;

   if (start < 0)
     new_start = MAX(size + start, 0);
   else
     new_start = MIN(size, start);

   if (end < 0)
     new_end = MAX(size + end, 0);
   else
     new_end = MIN(end, size);

   if (new_start > new_end)
     {
        long aux = new_start;
        new_start = new_end;
        new_end = aux;
     }

   Ecordova_File *new_file = eo_add(MY_CLASS, NULL,
     ecordova_file_constructor(pd->name,
                               pd->url,
                               pd->type,
                               pd->modified_date,
                               pd->size));
   EINA_SAFETY_ON_NULL_RETURN_VAL(new_file, NULL);

   Ecordova_File_Data *new_file_pd = eo_data_scope_get(new_file, MY_CLASS);
   EINA_SAFETY_ON_NULL_GOTO(new_file_pd, on_error);

   new_file_pd->start = pd->start + new_start;
   new_file_pd->end = pd->start + new_end;
   return new_file;

on_error:
   eo_unref(new_file);
   return NULL;
}

static const char *
_ecordova_file_name_get(Eo *obj EINA_UNUSED, Ecordova_File_Data *pd)
{
   DBG("(%p)", obj);
   return pd->name;
}

static const char *
_ecordova_file_url_get(Eo *obj EINA_UNUSED, Ecordova_File_Data *pd)
{
   DBG("(%p)", obj);
   return pd->url;
}

static long
_ecordova_file_start_get(Eo *obj EINA_UNUSED, Ecordova_File_Data *pd)
{
   DBG("(%p)", obj);
   return pd->start;
}

static long
_ecordova_file_end_get(Eo *obj EINA_UNUSED, Ecordova_File_Data *pd)
{
   DBG("(%p)", obj);
   return pd->end;
}

#undef EOAPI
#define EOAPI EAPI

#include "undefs.h"

#define ecordova_file_class_get ecordova_file_impl_class_get

#include "ecordova_file.eo.c"