summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-20 18:50:38 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-06-20 20:25:26 -0300
commit65f21ff2f76601303f1a99b54b6fd5c309994edf (patch)
tree5f8f54a4b5d204fd0f0a3b776da1d55b9d0f2a00
parent72ef91c8ca7db2391163d360cc33b7249b07573b (diff)
efl: Composite model for boolean properties (WIP)devs/felipealmeida/boolean-model
-rw-r--r--src/lib/efl/Efl_Model_Common.h1
-rw-r--r--src/lib/efl/interfaces/efl_model_composite_boolean.c326
-rw-r--r--src/lib/efl/interfaces/efl_model_composite_boolean.eo23
-rw-r--r--src/lib/efl/interfaces/efl_model_composite_boolean_children.eo12
-rw-r--r--src/tests/efl/efl_suite.c51
-rw-r--r--src/tests/efl/efl_suite.h26
-rw-r--r--src/tests/efl/efl_test_model_composite_boolean.c42
7 files changed, 481 insertions, 0 deletions
diff --git a/src/lib/efl/Efl_Model_Common.h b/src/lib/efl/Efl_Model_Common.h
index 68de92a0a1..372144da6a 100644
--- a/src/lib/efl/Efl_Model_Common.h
+++ b/src/lib/efl/Efl_Model_Common.h
@@ -38,6 +38,7 @@ struct _Efl_Model_Children_Event
38typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event; 38typedef struct _Efl_Model_Children_Event Efl_Model_Children_Event;
39 39
40#include "interfaces/efl_model.eo.h" 40#include "interfaces/efl_model.eo.h"
41#include "interfaces/efl_model_composite_boolean.eo.h"
41 42
42EAPI int efl_model_init(void); 43EAPI int efl_model_init(void);
43 44
diff --git a/src/lib/efl/interfaces/efl_model_composite_boolean.c b/src/lib/efl/interfaces/efl_model_composite_boolean.c
new file mode 100644
index 0000000000..3a2944614a
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_model_composite_boolean.c
@@ -0,0 +1,326 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eina.h"
6#include "Efl.h"
7
8#include "interfaces/efl_model_composite_boolean_children.eo.h"
9
10typedef struct _Efl_Model_Hash_Value
11{
12 unsigned char* buffer;
13 unsigned int bits_count;
14 Eina_Bool default_value : 1;
15} Efl_Model_Hash_Value;
16
17typedef struct _Efl_Model_Composite_Boolean_Data
18{
19 Efl_Model* composite_model;
20 Eina_Array* empty_properties;
21 Eina_Hash* values; // [property_name, Efl_Model_Hash_Value*]
22} Efl_Model_Composite_Boolean_Data;
23
24typedef struct _Efl_Model_Composite_Boolean_Children_Data
25{
26 Efl_Model_Composite_Boolean_Data* parent_pd;
27 Efl_Model* composite_children;
28 Eina_Array* properties_names;
29 unsigned int index;
30} Efl_Model_Composite_Boolean_Children_Data;
31
32typedef struct _Efl_Model_Iterator_Slice
33{
34 Eina_Iterator vtable;
35 Eina_Iterator* composite_iterator;
36 Efl_Model* parent;
37 Efl_Model_Composite_Boolean_Data* parent_pd;
38 Eina_Promise_Owner* promise;
39 unsigned int index;
40} Efl_Model_Iterator_Slice;
41
42/**************** efl_mmodel_composite_boolean_children **************/
43
44static const Eina_Array*
45_efl_model_composite_boolean_children_efl_model_properties_get(Eo *obj EINA_UNUSED,
46 Efl_Model_Composite_Boolean_Children_Data *pd)
47{
48 Eina_Array const* composite_properties;
49 unsigned int i;
50
51 if(pd->properties_names) return pd->properties_names;
52 else
53 {
54 composite_properties = efl_model_properties_get(pd->parent_pd->composite_model);
55 unsigned int composite_count = eina_array_count_get(composite_properties),
56 self_count = eina_hash_population(pd->parent_pd->values);
57 pd->properties_names = eina_array_new(composite_count + self_count);
58 for(i = 0; i != composite_count; ++i)
59 {
60 const char* name = strdup(eina_array_data_get(composite_properties, i));
61 eina_array_push(pd->properties_names, name);
62 }
63 return pd->properties_names;
64 }
65}
66
67static Eina_Promise*
68_efl_model_composite_boolean_children_efl_model_property_get(Eo *obj EINA_UNUSED,
69 Efl_Model_Composite_Boolean_Children_Data *pd, const char *property)
70{
71 Efl_Model_Hash_Value* value = eina_hash_find(pd->parent_pd->values, property);
72 if(value)
73 {
74 Eina_Promise_Owner* promise = eina_promise_add();
75 Eina_Value* eina_value = eina_value_new(EINA_VALUE_TYPE_UCHAR);
76 if(value->bits_count <= pd->index)
77 {
78 unsigned char f = value->default_value;
79 eina_value_set(eina_value, f);
80 }
81 else
82 {
83 eina_value_set(eina_value, (value->buffer[pd->index / 8] >> (pd->index % 8))&1);
84 }
85 eina_promise_owner_value_set(promise, eina_value, (Eina_Promise_Free_Cb)eina_value_free);
86 return eina_promise_owner_promise_get(promise);
87 }
88 else if(pd->composite_children)
89 return efl_model_property_get(pd->composite_children, property);
90 else
91 {
92 Eina_Promise_Owner* promise = eina_promise_add();
93 eina_promise_owner_error_set(promise, EFL_MODEL_ERROR_NOT_FOUND);
94 return eina_promise_owner_promise_get(promise);
95 }
96}
97
98static void
99_efl_model_composite_boolean_children_efl_model_property_set(Eo *obj EINA_UNUSED,
100 Efl_Model_Composite_Boolean_Children_Data *pd, const char *property, const Eina_Value *value, Eina_Promise_Owner *promise)
101{
102
103}
104
105static Eina_Promise*
106_efl_model_composite_boolean_children_efl_model_children_slice_get(Eo *obj EINA_UNUSED,
107 Efl_Model_Composite_Boolean_Children_Data *pd, unsigned int start, unsigned int count)
108{
109 return efl_model_children_slice_get(pd->composite_children, start, count);
110}
111
112static Eina_Promise*
113_efl_model_composite_boolean_children_efl_model_children_count_get(Eo *obj EINA_UNUSED,
114 Efl_Model_Composite_Boolean_Children_Data *pd)
115{
116 return efl_model_children_count_get(pd->composite_children);
117}
118
119static Eo_Base*
120_efl_model_composite_boolean_children_efl_model_child_add(Eo *obj EINA_UNUSED,
121 Efl_Model_Composite_Boolean_Children_Data *pd)
122{
123 return efl_model_child_add(pd->composite_children);
124}
125
126static void
127_efl_model_composite_boolean_children_efl_model_child_del(Eo *obj EINA_UNUSED,
128 Efl_Model_Composite_Boolean_Children_Data *pd, Eo_Base *child)
129{
130 return efl_model_child_del(pd->composite_children, child);
131}
132
133/**************** efl_mmodel_iterator_slice **************/
134
135static Eina_Bool
136efl_model_iterator_slice_next(Efl_Model_Iterator_Slice* iterator, void** data)
137{
138 Efl_Model* child;
139 if(eina_iterator_next(iterator->composite_iterator, (void**)&child))
140 {
141 Efl_Model* model = eo_add(EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS, iterator->parent);
142 Efl_Model_Composite_Boolean_Children_Data* pd =
143 eo_data_scope_get(model, EFL_MODEL_COMPOSITE_BOOLEAN_CHILDREN_CLASS);
144 pd->parent_pd = iterator->parent_pd;
145 pd->composite_children = eo_ref(child);
146 pd->index = iterator->index++;
147 eo_data_ref(iterator->parent, EFL_MODEL_COMPOSITE_BOOLEAN_CLASS);
148 eo_data_unref(model, pd);
149 *data = model;
150 return EINA_TRUE;
151 }
152 else
153 return EINA_FALSE;
154}
155
156static void*
157efl_model_iterator_slice_container(Efl_Model_Iterator_Slice* iterator)
158{
159 return iterator->composite_iterator;
160}
161
162static void
163efl_model_iterator_slice_free(Efl_Model_Iterator_Slice* iterator)
164{
165 eina_iterator_free(iterator->composite_iterator);
166 free(iterator);
167}
168
169static Eina_Bool
170efl_model_iterator_slice_lock(Efl_Model_Iterator_Slice* iterator EINA_UNUSED)
171{
172 return EINA_FALSE;
173}
174
175static void
176efl_model_iterator_slice_setup(Efl_Model_Iterator_Slice* iterator,
177 Efl_Model* parent, Efl_Model_Composite_Boolean_Data* parent_pd, Eina_Promise_Owner* promise)
178{
179 iterator->vtable.version = EINA_ITERATOR_VERSION;
180 iterator->vtable.next = FUNC_ITERATOR_NEXT(efl_model_iterator_slice_next);
181 iterator->vtable.get_container = FUNC_ITERATOR_GET_CONTAINER(efl_model_iterator_slice_container);
182 iterator->vtable.free = FUNC_ITERATOR_FREE(efl_model_iterator_slice_free);
183 iterator->vtable.lock = FUNC_ITERATOR_LOCK(efl_model_iterator_slice_lock);
184 EINA_MAGIC_SET(&iterator->vtable, EINA_MAGIC_ITERATOR);
185 iterator->parent = eo_ref(parent);
186 iterator->parent_pd = parent_pd;
187 iterator->promise = promise;
188}
189
190static void
191_efl_model_composite_boolean_slice_then_cb(void* data, void* value)
192{
193 Efl_Model_Iterator_Slice* slice_iterator = data;
194 Eina_Iterator* iterator = value;
195
196 slice_iterator->composite_iterator = eina_iterator_clone(iterator);
197 if(slice_iiterator->composite_iterator)
198 eina_promise_owner_value_set(slice_iterator->promise, slice_iterator, (Eina_Promise_Free_Cb)&eina_iterator_free);
199 else
200 {
201 eina_promise_owner_error_set(slice_iterator->promise, EFL_MODEL_ERROR_NOT_SUPPORTED);
202 free(slice_iterator);
203 }
204}
205
206static void
207_efl_model_composite_boolean_slice_error_cb(void* data, Eina_Error error)
208{
209 Efl_Model_Iterator_Slice* slice_iterator = data;
210 eina_promise_owner_error_set(slice_iterator->promise, error);
211 free(slice_iterator);
212}
213
214static void efl_model_hash_value_free(void* p)
215{
216 Efl_Model_Hash_Value* value = p;
217 if(value)
218 {
219 free(value->buffer);
220 free(value);
221 }
222}
223
224/**************** efl_mmodel_composite_boolean **************/
225
226static const Eina_Array *
227_efl_model_composite_boolean_efl_model_properties_get(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd)
228{
229 if(pd->composite_model)
230 return efl_model_properties_get(pd->composite_model);
231 else if(pd->empty_properties)
232 return pd->empty_properties;
233 else
234 return pd->empty_properties = eina_array_new(1);
235
236}
237
238static void
239_efl_model_composite_boolean_property_add(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd,
240 const char *name, Eina_Bool initial_value)
241{
242 if(!pd->values)
243 pd->values = eina_hash_string_small_new(&efl_model_hash_value_free);
244 Efl_Model_Hash_Value* value = calloc(sizeof(Efl_Model_Hash_Value), 1);
245 value->default_value = initial_value;
246 eina_hash_add(pd->values, name, value);
247}
248
249static Eina_Promise *
250_efl_model_composite_boolean_efl_model_property_get(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd EINA_UNUSED, const char *property EINA_UNUSED)
251{
252 if(pd->composite_model)
253 return efl_model_property_get(pd->composite_model, property);
254 else
255 {
256 Eina_Promise_Owner* promise = eina_promise_add();
257 eina_promise_owner_error_set(promise, EFL_MODEL_ERROR_NOT_FOUND);
258 return eina_promise_owner_promise_get(promise);
259 }
260}
261
262static void
263_efl_model_composite_boolean_efl_model_property_set(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd EINA_UNUSED, const char *property EINA_UNUSED, const Eina_Value *value EINA_UNUSED, Eina_Promise_Owner *promise EINA_UNUSED)
264{
265
266}
267
268static Eina_Promise*
269_efl_model_composite_boolean_efl_model_children_slice_get(Eo *obj, Efl_Model_Composite_Boolean_Data *pd, unsigned int start, unsigned int count)
270{
271 Eina_Promise_Owner* promise = eina_promise_add();
272 if(pd->composite_model)
273 {
274 Eina_Promise* composite_promise = efl_model_children_slice_get(pd->composite_model, start, count);
275 Efl_Model_Iterator_Slice* iterator = calloc(sizeof(*iterator), 1);
276 efl_model_iterator_slice_setup(iterator, obj, pd, promise);
277 eina_promise_then(composite_promise, &_efl_model_composite_boolean_slice_then_cb,
278 &_efl_model_composite_boolean_slice_error_cb, iterator);
279 }
280 else
281 {
282 eina_promise_owner_error_set(promise, EFL_MODEL_ERROR_NOT_SUPPORTED);
283 }
284 return eina_promise_owner_promise_get(promise);
285}
286
287static Eina_Promise*
288_efl_model_composite_boolean_efl_model_children_count_get(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd)
289{
290 if(pd->composite_model)
291 return efl_model_children_count_get(pd->composite_model);
292 else
293 {
294 Eina_Promise_Owner* promise = eina_promise_add();
295 unsigned int* count = malloc(sizeof(unsigned int));
296 *count = eina_hash_population(pd->values);
297 eina_promise_owner_value_set(promise, count, free);
298 return eina_promise_owner_promise_get(promise);
299 }
300}
301
302static Eo_Base*
303_efl_model_composite_boolean_efl_model_child_add(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd)
304{
305 if(pd->composite_model)
306 return efl_model_child_add(pd->composite_model);
307 else
308 {
309 eina_error_set(EFL_MODEL_ERROR_NOT_SUPPORTED);
310 return NULL;
311 }
312}
313
314static void
315_efl_model_composite_boolean_efl_model_child_del(Eo *obj EINA_UNUSED, Efl_Model_Composite_Boolean_Data *pd, Eo_Base *child)
316{
317 if(pd->composite_model)
318 return efl_model_child_del(pd->composite_model, child);
319 else
320 {
321 eina_error_set(EFL_MODEL_ERROR_NOT_SUPPORTED);
322 }
323}
324
325#include "interfaces/efl_model_composite_boolean.eo.c"
326#include "interfaces/efl_model_composite_boolean_children.eo.c"
diff --git a/src/lib/efl/interfaces/efl_model_composite_boolean.eo b/src/lib/efl/interfaces/efl_model_composite_boolean.eo
new file mode 100644
index 0000000000..9302051a31
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_model_composite_boolean.eo
@@ -0,0 +1,23 @@
1class Efl.Model.Composite.Boolean (Eo.Base, Efl.Model)
2{
3 methods {
4 property_add {
5 params {
6 @in name: string;
7 @in initial_value: bool;
8 }
9 }
10 }
11 implements {
12 Efl.Model.properties.get;
13 Efl.Model.property_get;
14 Efl.Model.property_set;
15 Efl.Model.children_slice_get;
16 Efl.Model.children_count_get;
17 Efl.Model.child_add;
18 Efl.Model.child_del;
19 }
20 constructors {
21 .property_add;
22 }
23}
diff --git a/src/lib/efl/interfaces/efl_model_composite_boolean_children.eo b/src/lib/efl/interfaces/efl_model_composite_boolean_children.eo
new file mode 100644
index 0000000000..8044a0e474
--- /dev/null
+++ b/src/lib/efl/interfaces/efl_model_composite_boolean_children.eo
@@ -0,0 +1,12 @@
1class Efl.Model.Composite.Boolean.Children (Eo.Base, Efl.Model)
2{
3 implements {
4 Efl.Model.properties.get;
5 Efl.Model.property_get;
6 Efl.Model.property_set;
7 Efl.Model.children_slice_get;
8 Efl.Model.children_count_get;
9 Efl.Model.child_add;
10 Efl.Model.child_del;
11 }
12}
diff --git a/src/tests/efl/efl_suite.c b/src/tests/efl/efl_suite.c
new file mode 100644
index 0000000000..a76fb7bbf7
--- /dev/null
+++ b/src/tests/efl/efl_suite.c
@@ -0,0 +1,51 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <Eina.h>
24
25#include "efl_suite.h"
26#include "../efl_check.h"
27
28static const Efl_Test_Case etc[] = {
29 { "Efl_Model_Composite_Boolean ", efl_test_model_composite_boolean },
30 { NULL, NULL }
31};
32
33int
34main(int argc, char **argv)
35{
36 int failed_count;
37
38 if (!_efl_test_option_disp(argc, argv, etc))
39 return 0;
40
41 putenv("EFL_RUN_IN_TREE=1");
42
43 eina_init();
44
45 failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1,
46 "Efl", etc);
47
48 eina_shutdown();
49
50 return (failed_count == 0) ? 0 : 255;
51}
diff --git a/src/tests/efl/efl_suite.h b/src/tests/efl/efl_suite.h
new file mode 100644
index 0000000000..b41766508a
--- /dev/null
+++ b/src/tests/efl/efl_suite.h
@@ -0,0 +1,26 @@
1/* EFL - EFL library
2 * Copyright (C) 2008 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef EFL_SUITE_H_
20#define EFL_SUITE_H_
21
22#include <check.h>
23
24void efl_test_model_composite_boolean(TCase *tc);
25
26#endif /* EFL_SUITE_H_ */
diff --git a/src/tests/efl/efl_test_model_composite_boolean.c b/src/tests/efl/efl_test_model_composite_boolean.c
new file mode 100644
index 0000000000..2d4dbe9456
--- /dev/null
+++ b/src/tests/efl/efl_test_model_composite_boolean.c
@@ -0,0 +1,42 @@
1/* EFL - EFL library
2 * Copyright (C) 2013 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include "efl_suite.h"
24
25#include <Efl.h>
26
27START_TEST(efl_model_composite_boolean)
28{
29 eo_init();
30
31 Efl_Model_Composite_Boolean* model
32 = eo_add(EFL_MODEL_COMPOSITE_BOOLEAN_CLASS, NULL);
33
34 eo_shutdown();
35}
36END_TEST
37
38void
39efl_test_model_composite_boolean(TCase *tc)
40{
41 tcase_add_test(tc, efl_model_composite_boolean);
42}