summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorJosé Roberto de Souza <zehortigoza@profusion.mobi>2012-10-09 15:23:25 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-10-09 15:23:25 +0000
commitfe34dc2b72f683adbc89239365fe0683cb2b29ff (patch)
tree12138fa93ef2598a92966137786f69ed01d18292 /legacy
parent90ee430ce5c095760d1818f113fbc0b7a8d6f96e (diff)
edbus: Remove edbus_real_method
Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 77656
Diffstat (limited to 'legacy')
-rw-r--r--legacy/edbus/src/lib/edbus_private_types.h6
-rw-r--r--legacy/edbus/src/lib/edbus_service.c95
2 files changed, 32 insertions, 69 deletions
diff --git a/legacy/edbus/src/lib/edbus_private_types.h b/legacy/edbus/src/lib/edbus_private_types.h
index 74ca939412..a6c818fc78 100644
--- a/legacy/edbus/src/lib/edbus_private_types.h
+++ b/legacy/edbus/src/lib/edbus_private_types.h
@@ -159,10 +159,4 @@ typedef struct _Signal_Argument
159 const char *value; 159 const char *value;
160} Signal_Argument; 160} Signal_Argument;
161 161
162typedef struct _EDBus_Real_Method
163{
164 const EDBus_Method *method;
165 const char *in;
166} EDBus_Real_Method;
167
168#endif 162#endif
diff --git a/legacy/edbus/src/lib/edbus_service.c b/legacy/edbus/src/lib/edbus_service.c
index bbc8c0a907..c0bb94fa8b 100644
--- a/legacy/edbus/src/lib/edbus_service.c
+++ b/legacy/edbus/src/lib/edbus_service.c
@@ -121,7 +121,7 @@ _introspect_append_method(Eina_Strbuf *buf, const EDBus_Method *method)
121static void 121static void
122_introspect_append_interface(Eina_Strbuf *buf, EDBus_Service_Interface *iface) 122_introspect_append_interface(Eina_Strbuf *buf, EDBus_Service_Interface *iface)
123{ 123{
124 EDBus_Real_Method *method; 124 EDBus_Method *method;
125 Eina_Iterator *iterator; 125 Eina_Iterator *iterator;
126 unsigned short i; 126 unsigned short i;
127 unsigned int size; 127 unsigned int size;
@@ -129,7 +129,7 @@ _introspect_append_interface(Eina_Strbuf *buf, EDBus_Service_Interface *iface)
129 eina_strbuf_append_printf(buf, "<interface name=\"%s\">", iface->name); 129 eina_strbuf_append_printf(buf, "<interface name=\"%s\">", iface->name);
130 iterator = eina_hash_iterator_data_new(iface->methods); 130 iterator = eina_hash_iterator_data_new(iface->methods);
131 EINA_ITERATOR_FOREACH(iterator, method) 131 EINA_ITERATOR_FOREACH(iterator, method)
132 _introspect_append_method(buf, method->method); 132 _introspect_append_method(buf, method);
133 eina_iterator_free(iterator); 133 eina_iterator_free(iterator);
134 134
135 size = eina_array_count(iface->sign_of_signals); 135 size = eina_array_count(iface->sign_of_signals);
@@ -180,30 +180,20 @@ static const EDBus_Method instrospect = { "Introspect", EDBUS_ARGS({ "", "" }),
180static void 180static void
181_introspectable_create(void) 181_introspectable_create(void)
182{ 182{
183 EDBus_Real_Method *r_instrospect;
184 introspectable = calloc(1, sizeof(EDBus_Service_Interface)); 183 introspectable = calloc(1, sizeof(EDBus_Service_Interface));
185 EINA_SAFETY_ON_NULL_RETURN(introspectable); 184 EINA_SAFETY_ON_NULL_RETURN(introspectable);
186 185
187 r_instrospect = malloc(sizeof(EDBus_Real_Method));
188 EINA_SAFETY_ON_NULL_RETURN(r_instrospect);
189 r_instrospect->in = "";
190 r_instrospect->method = &instrospect;
191
192 EINA_MAGIC_SET(introspectable, EDBUS_SERVICE_INTERFACE_MAGIC); 186 EINA_MAGIC_SET(introspectable, EDBUS_SERVICE_INTERFACE_MAGIC);
193 introspectable->sign_of_signals = eina_array_new(1); 187 introspectable->sign_of_signals = eina_array_new(1);
194 introspectable->name = eina_stringshare_add("org.freedesktop.DBus.Introspectable"); 188 introspectable->name = eina_stringshare_add("org.freedesktop.DBus.Introspectable");
195 introspectable->methods = eina_hash_string_small_new(NULL); 189 introspectable->methods = eina_hash_string_small_new(NULL);
196 190
197 eina_hash_add(introspectable->methods, instrospect.member, r_instrospect); 191 eina_hash_add(introspectable->methods, instrospect.member, &instrospect);
198} 192}
199 193
200static void 194static void
201_instrospectable_free(void) 195_instrospectable_free(void)
202{ 196{
203 EDBus_Real_Method *method;
204 method = eina_hash_find(introspectable->methods, instrospect.member);
205 eina_stringshare_del(method->in);
206 free(method);
207 eina_hash_free(introspectable->methods); 197 eina_hash_free(introspectable->methods);
208 eina_stringshare_del(introspectable->name); 198 eina_stringshare_del(introspectable->name);
209 eina_array_free(introspectable->sign_of_signals); 199 eina_array_free(introspectable->sign_of_signals);
@@ -270,47 +260,37 @@ _edbus_service_interface_add(EDBus_Service_Object *obj, const char *interface)
270} 260}
271 261
272static Eina_Bool 262static Eina_Bool
263_have_signature(const EDBus_Arg_Info *args, EDBus_Message *msg)
264{
265 const char *sig = dbus_message_get_signature(msg->dbus_msg);
266 const char *p = NULL;
267
268 for (; args->signature && *args->signature && *sig; args++)
269 {
270 p = args->signature;
271 for (; *sig && *p; sig++, p++)
272 {
273 if (*p != *sig)
274 return EINA_FALSE;
275 }
276 }
277
278 if (*sig || (p && *p) || (args->signature && *args->signature))
279 return EINA_FALSE;
280
281 return EINA_TRUE;
282}
283
284static Eina_Bool
273_edbus_service_method_add(EDBus_Service_Interface *interface, EDBus_Method *method) 285_edbus_service_method_add(EDBus_Service_Interface *interface, EDBus_Method *method)
274{ 286{
275 EDBus_Real_Method *rm;
276 Eina_Strbuf *buf;
277 int z;
278 EINA_SAFETY_ON_TRUE_RETURN_VAL(!!eina_hash_find(interface->methods, 287 EINA_SAFETY_ON_TRUE_RETURN_VAL(!!eina_hash_find(interface->methods,
279 method->member), EINA_FALSE); 288 method->member), EINA_FALSE);
280 EINA_SAFETY_ON_NULL_RETURN_VAL(method->member, EINA_FALSE); 289 EINA_SAFETY_ON_NULL_RETURN_VAL(method->member, EINA_FALSE);
281 EINA_SAFETY_ON_NULL_RETURN_VAL(method->cb, EINA_FALSE); 290 EINA_SAFETY_ON_NULL_RETURN_VAL(method->cb, EINA_FALSE);
282 291
283 buf = eina_strbuf_new(); 292 eina_hash_add(interface->methods, method->member, method);
284 for (z = 0; &method->in[z] && method->in[z].signature; z++)
285 eina_strbuf_append(buf, method->in[z].signature);
286 EINA_SAFETY_ON_FALSE_GOTO(
287 dbus_signature_validate(eina_strbuf_string_get(buf), NULL),
288 error);
289
290 rm = malloc(sizeof(EDBus_Real_Method));
291 EINA_SAFETY_ON_NULL_GOTO(rm, error);
292 rm->method = method;
293 rm->in = eina_stringshare_add(eina_strbuf_string_get(buf));
294 eina_strbuf_free(buf);
295
296 //check if out is valid
297 buf = eina_strbuf_new();
298 for (z = 0; &method->out[z] && method->out[z].signature; z++)
299 eina_strbuf_append(buf, method->out[z].signature);
300 EINA_SAFETY_ON_FALSE_GOTO(
301 dbus_signature_validate(eina_strbuf_string_get(buf), NULL),
302 invalid_out);
303
304 eina_strbuf_free(buf);
305 eina_hash_add(interface->methods, method->member, rm);
306 return EINA_TRUE; 293 return EINA_TRUE;
307
308invalid_out:
309 eina_stringshare_del(rm->in);
310 free(rm);
311error:
312 eina_strbuf_free(buf);
313 return EINA_FALSE;
314} 294}
315 295
316EAPI EDBus_Service_Interface * 296EAPI EDBus_Service_Interface *
@@ -377,17 +357,8 @@ static void
377_interface_free(EDBus_Service_Interface *interface) 357_interface_free(EDBus_Service_Interface *interface)
378{ 358{
379 unsigned size, i; 359 unsigned size, i;
380 Eina_Iterator *iterator;
381 EDBus_Real_Method *method;
382 if (interface == introspectable) return; 360 if (interface == introspectable) return;
383 361
384 iterator = eina_hash_iterator_data_new(interface->methods);
385 EINA_ITERATOR_FOREACH(iterator, method)
386 {
387 eina_stringshare_del(method->in);
388 free(method);
389 }
390 eina_iterator_free(iterator);
391 eina_hash_free(interface->methods); 362 eina_hash_free(interface->methods);
392 eina_stringshare_del(interface->name); 363 eina_stringshare_del(interface->name);
393 size = eina_array_count(interface->sign_of_signals); 364 size = eina_array_count(interface->sign_of_signals);
@@ -458,7 +429,7 @@ _object_handler(DBusConnection *conn, DBusMessage *msg, void *user_data)
458{ 429{
459 EDBus_Service_Object *obj; 430 EDBus_Service_Object *obj;
460 EDBus_Service_Interface *iface; 431 EDBus_Service_Interface *iface;
461 EDBus_Real_Method *method; 432 EDBus_Method *method;
462 EDBus_Message *edbus_msg; 433 EDBus_Message *edbus_msg;
463 EDBus_Message *reply; 434 EDBus_Message *reply;
464 435
@@ -488,18 +459,16 @@ _object_handler(DBusConnection *conn, DBusMessage *msg, void *user_data)
488 edbus_msg->dbus_msg = msg; 459 edbus_msg->dbus_msg = msg;
489 dbus_message_iter_init(edbus_msg->dbus_msg, &edbus_msg->iterator->dbus_iterator); 460 dbus_message_iter_init(edbus_msg->dbus_msg, &edbus_msg->iterator->dbus_iterator);
490 461
491 if (method->in && !dbus_message_has_signature(msg, method->in)) 462 if (!_have_signature(method->in, edbus_msg))
492 { 463 {
493 char buf[DBUS_MAXIMUM_SIGNATURE_LENGTH +
494 sizeof("Expected signature: ")];
495 snprintf(buf, sizeof(buf), "Expected signature: %s", method->in);
496 reply = edbus_message_error_new(edbus_msg, 464 reply = edbus_message_error_new(edbus_msg,
497 DBUS_ERROR_INVALID_SIGNATURE, buf); 465 DBUS_ERROR_INVALID_SIGNATURE,
466 "See introspectable to know the expected signature");
498 } 467 }
499 else 468 else
500 { 469 {
501 if (iface->obj) 470 if (iface->obj)
502 reply = method->method->cb(iface, edbus_msg); 471 reply = method->cb(iface, edbus_msg);
503 else 472 else
504 { 473 {
505 //if iface does have obj it is some of FreeDesktop interfaces: 474 //if iface does have obj it is some of FreeDesktop interfaces:
@@ -513,7 +482,7 @@ _object_handler(DBusConnection *conn, DBusMessage *msg, void *user_data)
513 return DBUS_HANDLER_RESULT_NEED_MEMORY; 482 return DBUS_HANDLER_RESULT_NEED_MEMORY;
514 } 483 }
515 cpy->obj = obj; 484 cpy->obj = obj;
516 reply = method->method->cb(cpy, edbus_msg); 485 reply = method->cb(cpy, edbus_msg);
517 free(cpy); 486 free(cpy);
518 } 487 }
519 } 488 }