summaryrefslogtreecommitdiff
path: root/src/lib/efl_mono
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2019-08-05 10:17:52 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-08-05 10:18:18 -0400
commit40def3eac914138189163a895527705a1ffefcfd (patch)
treee77fc891713de50ca312b080474260d34d7d36df /src/lib/efl_mono
parent7c72f101532d61b00cd483b89ef86830526a82ba (diff)
efl-mono: Add Model manual implementation to C# and MVVM factories
Summary: Depends on D9273, D9270 Test Plan: Run added testcases. Reviewers: cedric, bu5hm4n, zmike, SanghyeonLee, felipealmeida, segfaultxavi Reviewed By: cedric Subscribers: cedric Tags: #expertise_solutions, #efl_language_bindings Differential Revision: https://phab.enlightenment.org/D8080
Diffstat (limited to 'src/lib/efl_mono')
-rw-r--r--src/lib/efl_mono/efl_mono_model_internal.c229
-rw-r--r--src/lib/efl_mono/efl_mono_model_internal.eo19
-rw-r--r--src/lib/efl_mono/efl_mono_model_internal_child.eo10
3 files changed, 258 insertions, 0 deletions
diff --git a/src/lib/efl_mono/efl_mono_model_internal.c b/src/lib/efl_mono/efl_mono_model_internal.c
new file mode 100644
index 0000000000..cda6d66e14
--- /dev/null
+++ b/src/lib/efl_mono/efl_mono_model_internal.c
@@ -0,0 +1,229 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Efl.h"
6#include "Ecore.h"
7#include <Eo.h>
8
9#ifdef EAPI
10# undef EAPI
11#endif
12
13#ifdef _WIN32
14# define EAPI __declspec(dllexport)
15#else
16# ifdef __GNUC__
17# if __GNUC__ >= 4
18# define EAPI __attribute__ ((visibility("default")))
19# else
20# define EAPI
21# endif
22# else
23# define EAPI
24# endif
25#endif /* ! _WIN32 */
26
27
28#include "efl_mono_model_internal.eo.h"
29#include "efl_mono_model_internal_child.eo.h"
30
31#include "assert.h"
32
33typedef struct _Efl_Mono_Model_Internal_Data Efl_Mono_Model_Internal_Data;
34
35typedef struct _Properties_Info Properties_Info;
36struct _Properties_Info
37{
38 const char* name;
39 const Eina_Value_Type* type;
40};
41
42typedef struct _Efl_Mono_Model_Internal_Data
43{
44 Eina_Array *properties_info;
45 Eina_Array *properties_names;
46 Eina_Array *items;
47} _Efl_Mono_Model_Internal_Data;
48
49
50#define MY_CLASS EFL_MONO_MODEL_INTERNAL_CLASS
51
52typedef struct _Efl_Mono_Model_Internal_Child_Data
53{
54 Efl_Mono_Model_Internal_Data* model_pd;
55 size_t index;
56 Eina_Array *values;
57 Eo* child;
58 //Eina_Array *items;
59} Efl_Mono_Model_Internal_Child_Data;
60
61static int _find_property_index (const char* name, Eina_Array* properties_name)
62{
63 int i, size = eina_array_count_get(properties_name);
64 for (i = 0; i != size; ++i)
65 {
66 if (!strcmp(properties_name->data[i], name))
67 {
68 return i;
69 }
70 }
71 return -1;
72}
73
74static Eo *
75_efl_mono_model_internal_efl_object_constructor(Eo *obj, Efl_Mono_Model_Internal_Data *pd)
76{
77 obj = efl_constructor(efl_super(obj, MY_CLASS));
78
79 pd->properties_info = eina_array_new(5);
80 pd->properties_names = eina_array_new(5);
81 pd->items = eina_array_new(5);
82
83 if (!obj) return NULL;
84
85 return obj;
86}
87
88static void
89_efl_mono_model_internal_efl_object_destructor(Eo *obj, Efl_Mono_Model_Internal_Data *pd EINA_UNUSED)
90{
91 efl_destructor(efl_super(obj, MY_CLASS));
92}
93
94static void
95_efl_mono_model_internal_add_property(Eo *obj EINA_UNUSED, Efl_Mono_Model_Internal_Data *pd, const char *name, const Eina_Value_Type *type)
96{
97 Properties_Info* info = malloc(sizeof(Properties_Info));
98 info->name = eina_stringshare_add(name);
99 info->type = type;
100 eina_array_push (pd->properties_info, info);
101 eina_array_push (pd->properties_names, eina_stringshare_add(info->name));
102}
103
104
105static Eina_Iterator *
106_efl_mono_model_internal_efl_model_properties_get(const Eo *obj EINA_UNUSED, Efl_Mono_Model_Internal_Data *pd EINA_UNUSED)
107{
108 return eina_array_iterator_new (NULL);
109}
110
111static Efl_Object*
112_efl_mono_model_internal_efl_model_child_add(Eo *obj, Efl_Mono_Model_Internal_Data *pd)
113{
114 Efl_Mono_Model_Internal_Child* child = efl_add (EFL_MONO_MODEL_INTERNAL_CHILD_CLASS, obj);
115 assert (child != NULL);
116 Efl_Mono_Model_Internal_Child_Data* pcd = efl_data_xref (child, EFL_MONO_MODEL_INTERNAL_CHILD_CLASS, obj);
117 pcd->model_pd = pd;
118 pcd->index = eina_array_count_get(pd->items);
119 pcd->child = child;
120 pcd->values = eina_array_new(5);
121 eina_array_push (pd->items, pcd);
122
123 return child;
124}
125
126static unsigned int
127_efl_mono_model_internal_efl_model_children_count_get(const Eo *obj EINA_UNUSED, Efl_Mono_Model_Internal_Data *pd)
128{
129 return eina_array_count_get(pd->items);
130}
131
132static Eina_Future *
133_efl_mono_model_internal_child_efl_model_property_set(Eo *obj, Efl_Mono_Model_Internal_Child_Data *pd, const char *property, Eina_Value *value)
134{
135 int i = _find_property_index (property, pd->model_pd->properties_names);
136 int j;
137 Eina_Value* old_value;
138 Eina_Value* new_value;
139 Eina_Value tmp_value;
140
141 if (i >= 0)
142 {
143 for (j = i - eina_array_count_get (pd->values); j >= 0; --j)
144 {
145 eina_array_push (pd->values, (void*)1);
146 pd->values->data[pd->values->count-1] = NULL;
147 }
148
149 old_value = eina_array_data_get (pd->values, i);
150 if (old_value)
151 eina_value_free (old_value);
152 new_value = malloc (sizeof(Eina_Value));
153 eina_value_copy (value, new_value);
154 eina_value_copy (value, &tmp_value);
155 eina_array_data_set (pd->values, i, new_value);
156
157
158 return efl_loop_future_resolved(obj, tmp_value);
159 }
160 else
161 {
162 // not found property
163 return efl_loop_future_rejected(obj, EAGAIN);
164 }
165}
166
167static Eina_Value *
168_efl_mono_model_internal_child_efl_model_property_get(const Eo *obj EINA_UNUSED, Efl_Mono_Model_Internal_Child_Data *pd EINA_UNUSED, const char *property EINA_UNUSED)
169{
170 unsigned int i = _find_property_index (property, pd->model_pd->properties_names);
171 if(eina_array_count_get (pd->values) <= i
172 || eina_array_data_get (pd->values, i) == NULL)
173 return eina_value_error_new(EAGAIN);
174 else
175 {
176 Eina_Value* src = eina_array_data_get(pd->values, i);
177 Eina_Value* clone = malloc (sizeof(Eina_Value));
178 eina_value_copy (src, clone);
179 return clone;
180 }
181}
182
183static Eina_Future *
184_efl_mono_model_internal_efl_model_children_slice_get(Eo *obj, Efl_Mono_Model_Internal_Data *pd, unsigned int start, unsigned int count EINA_UNUSED)
185{
186 unsigned int i;
187 Eina_Value array = EINA_VALUE_EMPTY;
188 Efl_Mono_Model_Internal_Child_Data* pcd;
189
190 eina_value_array_setup(&array, EINA_VALUE_TYPE_OBJECT, count % 8);
191
192 for (i = start; i != start + count; ++i)
193 {
194 pcd = eina_array_data_get(pd->items, i);
195 eina_value_array_append (&array, pcd->child);
196 }
197
198 return efl_loop_future_resolved(obj, array);
199}
200
201static Eo *
202_efl_mono_model_internal_child_efl_object_constructor(Eo *obj, Efl_Mono_Model_Internal_Child_Data *pd EINA_UNUSED)
203{
204 obj = efl_constructor(efl_super(obj, EFL_MONO_MODEL_INTERNAL_CHILD_CLASS));
205
206 return obj;
207}
208
209static void
210_efl_mono_model_internal_child_efl_object_destructor(Eo *obj, Efl_Mono_Model_Internal_Child_Data *pd EINA_UNUSED)
211{
212 efl_destructor(efl_super(obj, EFL_MONO_MODEL_INTERNAL_CHILD_CLASS));
213}
214
215static Efl_Object*
216_efl_mono_model_internal_child_efl_model_child_add(Eo *obj EINA_UNUSED, Efl_Mono_Model_Internal_Child_Data *pd EINA_UNUSED)
217{
218 abort();
219 return NULL;
220}
221
222static Eina_Iterator *
223_efl_mono_model_internal_child_efl_model_properties_get(const Eo *obj EINA_UNUSED, Efl_Mono_Model_Internal_Child_Data *pd)
224{
225 return eina_array_iterator_new (pd->model_pd->properties_names);
226}
227
228#include "efl_mono_model_internal.eo.c"
229#include "efl_mono_model_internal_child.eo.c"
diff --git a/src/lib/efl_mono/efl_mono_model_internal.eo b/src/lib/efl_mono/efl_mono_model_internal.eo
new file mode 100644
index 0000000000..3a639defe7
--- /dev/null
+++ b/src/lib/efl_mono/efl_mono_model_internal.eo
@@ -0,0 +1,19 @@
1class @beta Efl.Mono_Model_Internal extends Efl.Loop_Consumer implements Efl.Model
2{
3 methods {
4 add_property {
5 params {
6 @in name: string;
7 @in type: ptr(const(Eina.Value_Type));
8 }
9 }
10 }
11 implements {
12 Efl.Object.constructor;
13 Efl.Object.destructor;
14 Efl.Model.properties { get; }
15 Efl.Model.child_add;
16 Efl.Model.children_count { get; }
17 Efl.Model.children_slice_get;
18 }
19}
diff --git a/src/lib/efl_mono/efl_mono_model_internal_child.eo b/src/lib/efl_mono/efl_mono_model_internal_child.eo
new file mode 100644
index 0000000000..ec8d657ca4
--- /dev/null
+++ b/src/lib/efl_mono/efl_mono_model_internal_child.eo
@@ -0,0 +1,10 @@
1class Efl.Mono_Model_Internal_Child extends Efl.Loop_Consumer implements Efl.Model
2{
3 implements {
4 Efl.Object.constructor;
5 Efl.Object.destructor;
6 Efl.Model.properties { get; }
7 Efl.Model.property { get; set; }
8 Efl.Model.child_add;
9 }
10}