summaryrefslogtreecommitdiff
path: root/src/lib/efl/interfaces/efl_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/efl/interfaces/efl_file.c')
-rw-r--r--src/lib/efl/interfaces/efl_file.c208
1 files changed, 181 insertions, 27 deletions
diff --git a/src/lib/efl/interfaces/efl_file.c b/src/lib/efl/interfaces/efl_file.c
index d1c86ee..6761903 100644
--- a/src/lib/efl/interfaces/efl_file.c
+++ b/src/lib/efl/interfaces/efl_file.c
@@ -7,56 +7,210 @@
7typedef struct _Efl_File_Data Efl_File_Data; 7typedef struct _Efl_File_Data Efl_File_Data;
8struct _Efl_File_Data 8struct _Efl_File_Data
9{ 9{
10 Efl_Gfx_Image_Load_Error error; 10 Eina_Stringshare *vpath; /* efl_file_set */
11 Eina_Stringshare *key; /* efl_file_key_set */
12 Eina_File *file; /* efl_file_mmap_set */
13 Eina_Bool file_opened : 1; /* if `file` was opened implicitly during load */
14 Eina_Bool setting : 1; /* set when this file is internally calling methods to avoid infinite recursion */
15 Eina_Bool loaded : 1; /* whether the currently set file properties have been loaded */
11}; 16};
12 17
13static Eina_Bool 18EOLIAN static void
14_efl_file_file_set(Eo *obj, Efl_File_Data *pd, const char *file, const char *key) 19_efl_file_unload(Eo *obj, Efl_File_Data *pd)
15{ 20{
16 char *tmp = NULL; 21 if (!pd->loaded) return;
17 Eina_File *f = NULL; 22 if (!pd->file) return;
18 Eina_Bool r = EINA_FALSE; 23 if (!pd->file_opened) return;
24 pd->setting = 1;
25 eina_file_close(pd->file);
26 efl_file_mmap_set(obj, NULL);
27 pd->setting = 0;
28 pd->loaded = pd->file_opened = EINA_FALSE;
29}
19 30
20 pd->error = EFL_GFX_IMAGE_LOAD_ERROR_DOES_NOT_EXIST; 31EOLIAN static Eina_Error
32_efl_file_load(Eo *obj, Efl_File_Data *pd)
33{
34 Eina_Error ret = 0;
21 35
22 tmp = (char*)(file); 36 if (pd->loaded) return 0;
23 if (tmp) 37 EINA_SAFETY_ON_NULL_RETURN_VAL(pd->vpath, ENOENT);
38 errno = 0;
39 if (!pd->file)
24 { 40 {
25 tmp = eina_vpath_resolve(tmp); 41 Eina_File *f;
42 f = eina_file_open(pd->vpath, EINA_FALSE);
43 if (!f) return errno ?: ENOENT;
44 pd->file_opened = EINA_TRUE;
45 pd->setting = 1;
46 ret = efl_file_mmap_set(obj, f);
47 pd->setting = 0;
48 if (ret) pd->file_opened = EINA_FALSE;
49 eina_file_close(f);
26 } 50 }
51 pd->loaded = !ret;
52 return ret;
53}
27 54
28 if (tmp) 55EOLIAN static Eina_Error
56_efl_file_mmap_set(Eo *obj, Efl_File_Data *pd, const Eina_File *f)
57{
58 Eina_Error err = 0;
59 Eina_File *file = NULL;
60
61 if (f == pd->file) return 0;
62 if (f)
63 {
64 file = eina_file_dup(f);
65 if (!file) return errno;
66 }
67 if (pd->file) eina_file_close(pd->file);
68 pd->file = file;
69 pd->loaded = EINA_FALSE;
70
71 if (!pd->setting)
29 { 72 {
30 f = eina_file_open(tmp, EINA_FALSE); 73 /* avoid infinite recursion */
31 if (!f) goto on_error; 74 pd->setting = 1;
75 err = efl_file_set(obj, eina_file_filename_get(pd->file));
76 pd->setting = 0;
32 } 77 }
78 return err;
79}
33 80
34 pd->error = EFL_GFX_IMAGE_LOAD_ERROR_NONE; 81EOLIAN static const Eina_File *
82_efl_file_mmap_get(const Eo *obj EINA_UNUSED, Efl_File_Data *pd)
83{
84 return pd->file;
85}
35 86
36 r = efl_file_mmap_set(obj, f, key); 87EOLIAN static Eina_Error
37 if (f) eina_file_close(f); 88_efl_file_file_set(Eo *obj, Efl_File_Data *pd, const char *file)
89{
90 char *tmp;
91 Eina_Error err = 0;
92 Eina_Bool same;
38 93
39 on_error: 94 tmp = (char*)(file);
95 if (tmp)
96 tmp = eina_vpath_resolve(tmp);
40 97
98 same = !eina_stringshare_replace(&pd->vpath, tmp ?: file);
41 free(tmp); 99 free(tmp);
42 return r; 100 if (same) return err;
101 pd->loaded = EINA_FALSE;
102 if (!pd->setting)
103 {
104 pd->setting = 1;
105 err = efl_file_mmap_set(obj, NULL);
106 pd->setting = 0;
107 }
108 return err;
43} 109}
44 110
45static void 111EOLIAN static Eina_Stringshare *
46_efl_file_file_get(const Eo *obj, Efl_File_Data *pd EINA_UNUSED, const char **file, const char **key) 112_efl_file_file_get(const Eo *obj EINA_UNUSED, Efl_File_Data *pd)
47{ 113{
48 const Eina_File *f = NULL; 114 return pd->vpath;
115}
49 116
50 efl_file_mmap_get(obj, &f, key); 117EOLIAN static void
118_efl_file_key_set(Eo *obj EINA_UNUSED, Efl_File_Data *pd, const char *key)
119{
120 if (eina_stringshare_replace(&pd->key, key))
121 pd->loaded = 0;
122}
51 123
52 if (f && file) *file = eina_file_filename_get(f); 124EOLIAN static Eina_Stringshare *
53 else if (file) *file = NULL; 125_efl_file_key_get(const Eo *obj EINA_UNUSED, Efl_File_Data *pd)
126{
127 return pd->key;
128}
129
130EOLIAN static Eina_Bool
131_efl_file_loaded_get(const Eo *obj EINA_UNUSED, Efl_File_Data *pd)
132{
133 return pd->loaded;
134}
135
136EOLIAN static void
137_efl_file_efl_object_destructor(Eo *obj, Efl_File_Data *pd)
138{
139 eina_stringshare_del(pd->vpath);
140 eina_stringshare_del(pd->key);
141 eina_file_close(pd->file);
142 efl_destructor(efl_super(obj, EFL_FILE_MIXIN));
143}
144
145EOLIAN static Eo *
146_efl_file_efl_object_finalize(Eo *obj, Efl_File_Data *pd)
147{
148 obj = efl_finalize(efl_super(obj, EFL_FILE_MIXIN));
149 if (!obj) return NULL;
150 if (pd->file || pd->vpath) efl_file_load(obj);
151 return obj;
152}
153
154////////////////////////////////////////////////////////////////////////////
155
156EAPI Eina_Bool
157efl_file_simple_load(Eo *obj, const char *file, const char *key)
158{
159 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
160 efl_ref(obj);
161 EINA_SAFETY_ON_TRUE_GOTO(efl_file_set(obj, file), fail);
162 efl_file_key_set(obj, key);
163 if (file)
164 {
165 if (efl_file_load(obj)) goto fail;
166 efl_unref(obj);
167 return EINA_TRUE;
168 }
169 efl_file_unload(obj);
170 efl_unref(obj);
171 return EINA_TRUE;
172fail:
173 efl_unref(obj);
174 return EINA_FALSE;
175}
176
177EAPI Eina_Bool
178efl_file_simple_mmap_load(Eo *obj, const Eina_File *file, const char *key)
179{
180 EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
181 efl_ref(obj);
182 EINA_SAFETY_ON_TRUE_GOTO(efl_file_mmap_set(obj, file), fail);
183 efl_file_key_set(obj, key);
184 if (file)
185 {
186 if (efl_file_load(obj)) goto fail;
187 efl_unref(obj);
188 return EINA_TRUE;
189 }
190 efl_file_unload(obj);
191 efl_unref(obj);
192 return EINA_TRUE;
193fail:
194 efl_unref(obj);
195 return EINA_FALSE;
196}
197
198EAPI void
199efl_file_simple_get(const Eo *obj, const char **file, const char **key)
200{
201 efl_ref((Eo*)obj);
202 if (file) *file = efl_file_get(obj);
203 if (key) *key = efl_file_key_get(obj);
204 efl_unref((Eo*)obj);
54} 205}
55 206
56static Efl_Gfx_Image_Load_Error 207EAPI void
57_efl_file_load_error_get(const Eo *obj EINA_UNUSED, Efl_File_Data *pd) 208efl_file_simple_mmap_get(const Eo *obj, const Eina_File **file, const char **key)
58{ 209{
59 return pd->error; 210 efl_ref((Eo*)obj);
211 if (file) *file = efl_file_mmap_get(obj);
212 if (key) *key = efl_file_key_get(obj);
213 efl_unref((Eo*)obj);
60} 214}
61 215
62#include "interfaces/efl_file.eo.c" 216#include "interfaces/efl_file.eo.c"