summaryrefslogtreecommitdiff
path: root/src/lib/eldbus
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2018-11-23 16:25:19 +0000
committerCedric BAIL <cedric@osg.samsung.com>2018-11-23 10:13:58 -0800
commitd4d44d76f3efef4d61edb4cce7152284915a12d2 (patch)
tree502779c9047c6a8e02c8466f81ddc8616887fa50 /src/lib/eldbus
parentaac7d099a17d69f5989481f8999a43d4173005bd (diff)
efl: make Efl.Model.properties_get return an Iterator<string>.
Reviewed-by: Vitor Sousa da Silva <vitorsousa@expertisesolutions.com.br> Differential Revision: https://phab.enlightenment.org/D7289
Diffstat (limited to 'src/lib/eldbus')
-rw-r--r--src/lib/eldbus/eldbus_model.c9
-rw-r--r--src/lib/eldbus/eldbus_model_arguments.c71
-rw-r--r--src/lib/eldbus/eldbus_model_arguments_private.h5
-rw-r--r--src/lib/eldbus/eldbus_model_method.c7
-rw-r--r--src/lib/eldbus/eldbus_model_proxy.c15
5 files changed, 35 insertions, 72 deletions
diff --git a/src/lib/eldbus/eldbus_model.c b/src/lib/eldbus/eldbus_model.c
index 28faa0f..3a2115e 100644
--- a/src/lib/eldbus/eldbus_model.c
+++ b/src/lib/eldbus/eldbus_model.c
@@ -152,16 +152,13 @@ _eldbus_model_efl_model_property_get(const Eo *obj,
152 return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND); 152 return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND);
153} 153}
154 154
155static Eina_Array * 155static Eina_Iterator *
156_eldbus_model_efl_model_properties_get(const Eo *obj EINA_UNUSED, 156_eldbus_model_efl_model_properties_get(const Eo *obj EINA_UNUSED,
157 Eldbus_Model_Data *pd EINA_UNUSED) 157 Eldbus_Model_Data *pd EINA_UNUSED)
158{ 158{
159 Eina_Array *r; 159 char *unique[] = { UNIQUE_NAME_PROPERTY };
160 160
161 r = eina_array_new(1); 161 return EINA_C_ARRAY_ITERATOR_NEW(unique);
162 eina_array_push(r, eina_stringshare_add(UNIQUE_NAME_PROPERTY));
163
164 return r;
165} 162}
166 163
167static Efl_Object * 164static Efl_Object *
diff --git a/src/lib/eldbus/eldbus_model_arguments.c b/src/lib/eldbus/eldbus_model_arguments.c
index 1d22903..4c60930 100644
--- a/src/lib/eldbus/eldbus_model_arguments.c
+++ b/src/lib/eldbus/eldbus_model_arguments.c
@@ -12,8 +12,6 @@
12#define MY_CLASS ELDBUS_MODEL_ARGUMENTS_CLASS 12#define MY_CLASS ELDBUS_MODEL_ARGUMENTS_CLASS
13#define MY_CLASS_NAME "Eldbus_Model_Arguments" 13#define MY_CLASS_NAME "Eldbus_Model_Arguments"
14 14
15#define ARGUMENT_FORMAT "arg%u"
16
17static void _eldbus_model_arguments_properties_load(Eldbus_Model_Arguments_Data *); 15static void _eldbus_model_arguments_properties_load(Eldbus_Model_Arguments_Data *);
18static void _eldbus_model_arguments_unload(Eldbus_Model_Arguments_Data *); 16static void _eldbus_model_arguments_unload(Eldbus_Model_Arguments_Data *);
19static Eina_Bool _eldbus_model_arguments_is_input_argument(Eldbus_Model_Arguments_Data *, const char *); 17static Eina_Bool _eldbus_model_arguments_is_input_argument(Eldbus_Model_Arguments_Data *, const char *);
@@ -31,8 +29,8 @@ static Efl_Object*
31_eldbus_model_arguments_efl_object_constructor(Eo *obj, Eldbus_Model_Arguments_Data *pd) 29_eldbus_model_arguments_efl_object_constructor(Eo *obj, Eldbus_Model_Arguments_Data *pd)
32{ 30{
33 pd->obj = obj; 31 pd->obj = obj;
34 pd->properties_array = NULL; 32 // We do keep strings here as some of our API are looking for arg%u as a key instead of just indexes.
35 pd->properties_hash = eina_hash_string_superfast_new(EINA_FREE_CB(_eldbus_model_arguments_hash_free)); 33 pd->properties = eina_hash_string_superfast_new(EINA_FREE_CB(_eldbus_model_arguments_hash_free));
36 pd->pending_list = NULL; 34 pd->pending_list = NULL;
37 pd->proxy = NULL; 35 pd->proxy = NULL;
38 pd->arguments = NULL; 36 pd->arguments = NULL;
@@ -72,7 +70,7 @@ _eldbus_model_arguments_efl_object_destructor(Eo *obj, Eldbus_Model_Arguments_Da
72{ 70{
73 _eldbus_model_arguments_unload(pd); 71 _eldbus_model_arguments_unload(pd);
74 72
75 eina_hash_free(pd->properties_hash); 73 eina_hash_free(pd->properties);
76 74
77 eina_stringshare_del(pd->name); 75 eina_stringshare_del(pd->name);
78 eldbus_proxy_unref(pd->proxy); 76 eldbus_proxy_unref(pd->proxy);
@@ -80,14 +78,14 @@ _eldbus_model_arguments_efl_object_destructor(Eo *obj, Eldbus_Model_Arguments_Da
80 efl_destructor(efl_super(obj, MY_CLASS)); 78 efl_destructor(efl_super(obj, MY_CLASS));
81} 79}
82 80
83static Eina_Array * 81static Eina_Iterator *
84_eldbus_model_arguments_efl_model_properties_get(const Eo *obj EINA_UNUSED, 82_eldbus_model_arguments_efl_model_properties_get(const Eo *obj EINA_UNUSED,
85 Eldbus_Model_Arguments_Data *pd) 83 Eldbus_Model_Arguments_Data *pd)
86{ 84{
87 EINA_SAFETY_ON_NULL_RETURN_VAL(pd, NULL); 85 EINA_SAFETY_ON_NULL_RETURN_VAL(pd, NULL);
88 86
89 _eldbus_model_arguments_properties_load(pd); 87 _eldbus_model_arguments_properties_load(pd);
90 return pd->properties_array; 88 return eina_hash_iterator_key_new(pd->properties);
91} 89}
92 90
93static void 91static void
@@ -96,30 +94,25 @@ _eldbus_model_arguments_properties_load(Eldbus_Model_Arguments_Data *pd)
96 unsigned int arguments_count; 94 unsigned int arguments_count;
97 unsigned int i; 95 unsigned int i;
98 96
99 if (pd->properties_array) 97 if (eina_hash_population(pd->properties) > 0)
100 return; 98 return ;
101 99
102 arguments_count = eina_list_count(pd->arguments); 100 arguments_count = eina_list_count(pd->arguments);
103 101
104 pd->properties_array = eina_array_new(arguments_count);
105 EINA_SAFETY_ON_NULL_RETURN(pd->properties_array);
106
107 for (i = 0; i < arguments_count; ++i) 102 for (i = 0; i < arguments_count; ++i)
108 { 103 {
109 Eldbus_Introspection_Argument *arg; 104 Eldbus_Introspection_Argument *arg;
110 const Eina_Value_Type *type; 105 const Eina_Value_Type *type;
111 Eina_Stringshare *name; 106 Eina_Slstr *name;
112 Eina_Value *value; 107 Eina_Value *value;
113 108
114 name = eina_stringshare_printf(ARGUMENT_FORMAT, i); 109 name = eina_slstr_printf(ARGUMENT_FORMAT, i);
115 if (!name) continue; 110 if (!name) continue;
116 111
117 eina_array_push(pd->properties_array, name);
118
119 arg = eina_list_nth(pd->arguments, i); 112 arg = eina_list_nth(pd->arguments, i);
120 type = _dbus_type_to_eina_value_type(arg->type[0]); 113 type = _dbus_type_to_eina_value_type(arg->type[0]);
121 value = eina_value_new(type); 114 value = eina_value_new(type);
122 eina_hash_add(pd->properties_hash, name, value); 115 eina_hash_add(pd->properties, name, value);
123 } 116 }
124} 117}
125 118
@@ -144,7 +137,7 @@ _eldbus_model_arguments_efl_model_property_set(Eo *obj,
144 if (!ret) goto on_error; 137 if (!ret) goto on_error;
145 138
146 err = EFL_MODEL_ERROR_NOT_FOUND; 139 err = EFL_MODEL_ERROR_NOT_FOUND;
147 prop_value = eina_hash_find(pd->properties_hash, property); 140 prop_value = eina_hash_find(pd->properties, property);
148 if (!prop_value) goto on_error; 141 if (!prop_value) goto on_error;
149 142
150 eina_value_flush(prop_value); 143 eina_value_flush(prop_value);
@@ -168,7 +161,7 @@ _eldbus_model_arguments_efl_model_property_get(const Eo *obj, Eldbus_Model_Argum
168 161
169 _eldbus_model_arguments_properties_load(pd); 162 _eldbus_model_arguments_properties_load(pd);
170 163
171 value = eina_hash_find(pd->properties_hash, property); 164 value = eina_hash_find(pd->properties, property);
172 if (!value) return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND); 165 if (!value) return eina_value_error_new(EFL_MODEL_ERROR_NOT_FOUND);
173 166
174 ret = _eldbus_model_arguments_is_output_argument(pd, property); 167 ret = _eldbus_model_arguments_is_output_argument(pd, property);
@@ -193,19 +186,7 @@ _eldbus_model_arguments_unload(Eldbus_Model_Arguments_Data *pd)
193 EINA_LIST_FREE(pd->pending_list, pending) 186 EINA_LIST_FREE(pd->pending_list, pending)
194 eldbus_pending_cancel(pending); 187 eldbus_pending_cancel(pending);
195 188
196 if (pd->properties_array) 189 eina_hash_free_buckets(pd->properties);
197 {
198 Eina_Stringshare *property;
199 Eina_Array_Iterator it;
200 unsigned int i;
201
202 EINA_ARRAY_ITER_NEXT(pd->properties_array, i, property, it)
203 eina_stringshare_del(property);
204 eina_array_free(pd->properties_array);
205 pd->properties_array = NULL;
206 }
207
208 eina_hash_free_buckets(pd->properties_hash);
209} 190}
210 191
211Eina_Bool 192Eina_Bool
@@ -219,6 +200,7 @@ eldbus_model_arguments_process_arguments(Eldbus_Model_Arguments_Data *pd,
219 Eina_Value *value_struct; 200 Eina_Value *value_struct;
220 Eina_Array *changed_properties; 201 Eina_Array *changed_properties;
221 unsigned int i = 0; 202 unsigned int i = 0;
203 Eina_Stringshare *property;
222 Eina_Bool result = EINA_FALSE; 204 Eina_Bool result = EINA_FALSE;
223 205
224 _eldbus_model_arguments_properties_load(pd); 206 _eldbus_model_arguments_properties_load(pd);
@@ -244,16 +226,14 @@ eldbus_model_arguments_process_arguments(Eldbus_Model_Arguments_Data *pd,
244 { 226 {
245 if (ELDBUS_INTROSPECTION_ARGUMENT_DIRECTION_IN != argument->direction) 227 if (ELDBUS_INTROSPECTION_ARGUMENT_DIRECTION_IN != argument->direction)
246 { 228 {
247 Eina_Stringshare *property;
248 Eina_Bool ret; 229 Eina_Bool ret;
249 230
250 property = eina_array_data_get(pd->properties_array, i); 231 property = eina_stringshare_printf(ARGUMENT_FORMAT, i);
251 EINA_SAFETY_ON_NULL_GOTO(property, on_error);
252 232
253 ret = _eldbus_model_arguments_property_set(pd, value_struct, property); 233 ret = eina_array_push(changed_properties, property);
254 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error); 234 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
255 235
256 ret = eina_array_push(changed_properties, property); 236 ret = _eldbus_model_arguments_property_set(pd, value_struct, property);
257 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error); 237 EINA_SAFETY_ON_FALSE_GOTO(ret, on_error);
258 } 238 }
259 239
@@ -269,6 +249,8 @@ eldbus_model_arguments_process_arguments(Eldbus_Model_Arguments_Data *pd,
269 result = EINA_TRUE; 249 result = EINA_TRUE;
270 250
271on_error: 251on_error:
252 while (property = eina_array_pop(changed_properties))
253 eina_stringshare_del(property);
272 eina_array_free(changed_properties); 254 eina_array_free(changed_properties);
273 eina_value_free(value_struct); 255 eina_value_free(value_struct);
274 256
@@ -286,7 +268,7 @@ _eldbus_model_arguments_property_set(Eldbus_Model_Arguments_Data *pd,
286 268
287 _eldbus_model_arguments_properties_load(pd); 269 _eldbus_model_arguments_properties_load(pd);
288 270
289 prop_value = eina_hash_find(pd->properties_hash, property); 271 prop_value = eina_hash_find(pd->properties, property);
290 EINA_SAFETY_ON_NULL_RETURN_VAL(prop_value, EINA_FALSE); 272 EINA_SAFETY_ON_NULL_RETURN_VAL(prop_value, EINA_FALSE);
291 273
292 ret = eina_value_struct_value_get(value_struct, "arg0", &value); 274 ret = eina_value_struct_value_get(value_struct, "arg0", &value);
@@ -311,7 +293,7 @@ _eldbus_model_arguments_is(Eldbus_Model_Arguments_Data *pd,
311 _eldbus_model_arguments_properties_load(pd); 293 _eldbus_model_arguments_properties_load(pd);
312 294
313 i = _eldbus_model_arguments_argument_index_get(pd, argument); 295 i = _eldbus_model_arguments_argument_index_get(pd, argument);
314 if (i >= eina_array_count(pd->properties_array)) 296 if (i >= eina_hash_population(pd->properties))
315 { 297 {
316 WRN("Argument not found: %s", argument); 298 WRN("Argument not found: %s", argument);
317 return false; 299 return false;
@@ -342,15 +324,10 @@ _eldbus_model_arguments_argument_index_get(Eldbus_Model_Arguments_Data *pd, cons
342 Eina_Stringshare *name; 324 Eina_Stringshare *name;
343 Eina_Array_Iterator it; 325 Eina_Array_Iterator it;
344 unsigned int i = 0; 326 unsigned int i = 0;
345 _eldbus_model_arguments_properties_load(pd);
346
347 EINA_ARRAY_ITER_NEXT(pd->properties_array, i, name, it)
348 {
349 if (strcmp(name, argument) == 0)
350 return i;
351 }
352 327
353 return ++i; 328 if (sscanf(argument, ARGUMENT_FORMAT, &i) > 0)
329 return i;
330 return eina_hash_population(pd->properties);
354} 331}
355 332
356#include "eldbus_model_arguments.eo.c" 333#include "eldbus_model_arguments.eo.c"
diff --git a/src/lib/eldbus/eldbus_model_arguments_private.h b/src/lib/eldbus/eldbus_model_arguments_private.h
index 06aa1ae..83d55dd 100644
--- a/src/lib/eldbus/eldbus_model_arguments_private.h
+++ b/src/lib/eldbus/eldbus_model_arguments_private.h
@@ -14,8 +14,7 @@ struct _Eldbus_Model_Arguments_Data
14{ 14{
15 Eo *obj; 15 Eo *obj;
16 Eldbus_Proxy *proxy; 16 Eldbus_Proxy *proxy;
17 Eina_Array *properties_array; 17 Eina_Hash *properties;
18 Eina_Hash *properties_hash;
19 Eina_Stringshare *name; 18 Eina_Stringshare *name;
20 Eina_List *pending_list; 19 Eina_List *pending_list;
21 const Eina_List *arguments; 20 const Eina_List *arguments;
@@ -24,4 +23,6 @@ struct _Eldbus_Model_Arguments_Data
24 23
25Eina_Bool eldbus_model_arguments_process_arguments(Eldbus_Model_Arguments_Data *, const Eldbus_Message *, Eldbus_Pending *); 24Eina_Bool eldbus_model_arguments_process_arguments(Eldbus_Model_Arguments_Data *, const Eldbus_Message *, Eldbus_Pending *);
26 25
26#define ARGUMENT_FORMAT "arg%u"
27
27#endif 28#endif
diff --git a/src/lib/eldbus/eldbus_model_method.c b/src/lib/eldbus/eldbus_model_method.c
index 8e7e87b..dbdbdde 100644
--- a/src/lib/eldbus/eldbus_model_method.c
+++ b/src/lib/eldbus/eldbus_model_method.c
@@ -69,7 +69,7 @@ _eldbus_model_method_call(Eo *obj EINA_UNUSED, Eldbus_Model_Method_Data *pd EINA
69 69
70 EINA_LIST_FOREACH(data->arguments, it, argument) 70 EINA_LIST_FOREACH(data->arguments, it, argument)
71 { 71 {
72 Eina_Stringshare *name; 72 Eina_Slstr *name;
73 const Eina_Value *value; 73 const Eina_Value *value;
74 const char *signature; 74 const char *signature;
75 Eina_Bool ret; 75 Eina_Bool ret;
@@ -77,11 +77,10 @@ _eldbus_model_method_call(Eo *obj EINA_UNUSED, Eldbus_Model_Method_Data *pd EINA
77 if (ELDBUS_INTROSPECTION_ARGUMENT_DIRECTION_IN != argument->direction) 77 if (ELDBUS_INTROSPECTION_ARGUMENT_DIRECTION_IN != argument->direction)
78 continue; 78 continue;
79 79
80 name = eina_array_data_get(data->properties_array, i); 80 name = eina_slstr_printf(ARGUMENT_FORMAT, i);
81 if (!name) continue;
82 EINA_SAFETY_ON_NULL_GOTO(name, on_error); 81 EINA_SAFETY_ON_NULL_GOTO(name, on_error);
83 82
84 value = eina_hash_find(data->properties_hash, name); 83 value = eina_hash_find(data->properties, name);
85 EINA_SAFETY_ON_NULL_GOTO(value, on_error); 84 EINA_SAFETY_ON_NULL_GOTO(value, on_error);
86 85
87 signature = argument->type; 86 signature = argument->type;
diff --git a/src/lib/eldbus/eldbus_model_proxy.c b/src/lib/eldbus/eldbus_model_proxy.c
index c1ab3b2..a159ecd 100644
--- a/src/lib/eldbus/eldbus_model_proxy.c
+++ b/src/lib/eldbus/eldbus_model_proxy.c
@@ -190,22 +190,11 @@ _eldbus_model_proxy_efl_object_destructor(Eo *obj, Eldbus_Model_Proxy_Data *pd)
190 efl_destructor(efl_super(obj, MY_CLASS)); 190 efl_destructor(efl_super(obj, MY_CLASS));
191} 191}
192 192
193static Eina_Array * 193static Eina_Iterator *
194_eldbus_model_proxy_efl_model_properties_get(const Eo *obj EINA_UNUSED, 194_eldbus_model_proxy_efl_model_properties_get(const Eo *obj EINA_UNUSED,
195 Eldbus_Model_Proxy_Data *pd) 195 Eldbus_Model_Proxy_Data *pd)
196{ 196{
197 Eina_Iterator *it; 197 return eina_hash_iterator_key_new(pd->properties);
198 Eina_Array *r;
199 Eina_Stringshare *property;
200
201 r = eina_array_new(4);
202
203 it = eina_hash_iterator_key_new(pd->properties);
204 EINA_ITERATOR_FOREACH(it, property)
205 eina_array_push(r, property);
206 eina_iterator_free(it);
207
208 return r;
209} 198}
210 199
211#define PROPERTY_EXIST 1 200#define PROPERTY_EXIST 1