summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorJosé Roberto de Souza <zehortigoza@profusion.mobi>2012-12-03 12:09:53 +0000
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2012-12-03 12:09:53 +0000
commit4ec1d6c4bb1cc3ecf4348d9d778172b7c2a8615b (patch)
tree7a835928fa12c36005b471deb8cc2a97276e95a9 /legacy
parent7c533e08c5d0f5f3c8882cf8024c2e54126ead78 (diff)
edbus: Implement edbus_object_event_callback_add()
Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 80058
Diffstat (limited to 'legacy')
-rw-r--r--legacy/edbus/src/lib/edbus_object.c189
-rw-r--r--legacy/edbus/src/lib/edbus_object.h4
-rw-r--r--legacy/edbus/src/lib/edbus_private_types.h3
3 files changed, 194 insertions, 2 deletions
diff --git a/legacy/edbus/src/lib/edbus_object.c b/legacy/edbus/src/lib/edbus_object.c
index 840e2db329..9f6c704016 100644
--- a/legacy/edbus/src/lib/edbus_object.c
+++ b/legacy/edbus/src/lib/edbus_object.c
@@ -162,6 +162,12 @@ _edbus_object_free(EDBus_Object *obj)
162 eina_list_free(ce->to_delete); 162 eina_list_free(ce->to_delete);
163 } 163 }
164 164
165 if (obj->interfaces_added)
166 edbus_signal_handler_del(obj->interfaces_added);
167 if (obj->interfaces_removed)
168 edbus_signal_handler_del(obj->interfaces_removed);
169 if (obj->properties_changed)
170 edbus_signal_handler_del(obj->properties_changed);
165 eina_stringshare_del(obj->name); 171 eina_stringshare_del(obj->name);
166 eina_stringshare_del(obj->path); 172 eina_stringshare_del(obj->path);
167 EINA_MAGIC_SET(obj, EINA_MAGIC_NONE); 173 EINA_MAGIC_SET(obj, EINA_MAGIC_NONE);
@@ -262,6 +268,110 @@ edbus_object_cb_free_del(EDBus_Object *obj, EDBus_Free_Cb cb, const void *data)
262 obj->cbs_free = edbus_cbs_free_del(obj->cbs_free, cb, data); 268 obj->cbs_free = edbus_cbs_free_del(obj->cbs_free, cb, data);
263} 269}
264 270
271static void
272_cb_interfaces_added(void *data, const EDBus_Message *msg)
273{
274 EDBus_Object *obj = data;
275 const char *obj_path;
276 EDBus_Message_Iter *array_ifaces, *entry_iface;
277
278 if (!edbus_message_arguments_get(msg, "oa{sa{sv}}", &obj_path, &array_ifaces))
279 return;
280
281 while (edbus_message_iter_get_and_next(array_ifaces, 'e', &entry_iface))
282 {
283 const char *iface_name;
284 EDBus_Object_Event_Interface_Added event;
285 EDBus_Proxy *proxy;
286
287 edbus_message_iter_basic_get(entry_iface, &iface_name);
288 proxy = edbus_proxy_get(obj, iface_name);
289 EINA_SAFETY_ON_NULL_RETURN(proxy);
290 event.interface = iface_name;
291 event.proxy = proxy;
292 _edbus_object_event_callback_call(obj, EDBUS_OBJECT_EVENT_IFACE_ADDED,
293 &event);
294 }
295}
296
297static void
298_cb_interfaces_removed(void *data, const EDBus_Message *msg)
299{
300 EDBus_Object *obj = data;
301 const char *obj_path, *iface;
302 EDBus_Message_Iter *array_ifaces;
303
304 if (!edbus_message_arguments_get(msg, "oas", &obj_path, &array_ifaces))
305 return;
306
307 while (edbus_message_iter_get_and_next(array_ifaces, 's', &iface))
308 {
309 EDBus_Object_Event_Interface_Removed event;
310 event.interface = iface;
311 _edbus_object_event_callback_call(obj, EDBUS_OBJECT_EVENT_IFACE_REMOVED,
312 &event);
313 }
314}
315
316static void
317_property_changed_iter(void *data, const void *key, EDBus_Message_Iter *var)
318{
319 EDBus_Proxy *proxy = data;
320 const char *skey = key;
321 Eina_Value *st_value, stack_value;
322 EDBus_Object_Event_Property_Changed event;
323
324 st_value = _message_iter_struct_to_eina_value(var);
325 eina_value_struct_value_get(st_value, "arg0", &stack_value);
326
327 event.interface = edbus_proxy_interface_get(proxy);
328 event.proxy = proxy;
329 event.name = skey;
330 event.value = &stack_value;
331 _edbus_object_event_callback_call(edbus_proxy_object_get(proxy),
332 EDBUS_OBJECT_EVENT_IFACE_REMOVED,
333 &event);
334 eina_value_free(st_value);
335 eina_value_flush(&stack_value);
336}
337
338static void
339_cb_properties_changed(void *data, const EDBus_Message *msg)
340{
341 EDBus_Object *obj = data;
342 EDBus_Proxy *proxy;
343 EDBus_Message_Iter *array, *invalidate;
344 const char *iface;
345 const char *invalidate_prop;
346
347 if (!edbus_message_arguments_get(msg, "sa{sv}as", &iface, &array, &invalidate))
348 {
349 ERR("Error getting data from properties changed signal.");
350 return;
351 }
352
353 proxy = edbus_proxy_get(obj, iface);
354 EINA_SAFETY_ON_NULL_RETURN(proxy);
355
356 if (obj->event_handlers[EDBUS_OBJECT_EVENT_PROPERTY_CHANGED].list)
357 edbus_message_iter_dict_iterate(array, "sv", _property_changed_iter,
358 proxy);
359
360 if (!obj->event_handlers[EDBUS_OBJECT_EVENT_PROPERTY_REMOVED].list)
361 return;
362
363 while (edbus_message_iter_get_and_next(invalidate, 's', &invalidate_prop))
364 {
365 EDBus_Object_Event_Property_Removed event;
366 event.interface = iface;
367 event.name = invalidate_prop;
368 event.proxy = proxy;
369 _edbus_object_event_callback_call(obj,
370 EDBUS_OBJECT_EVENT_PROPERTY_REMOVED,
371 &event);
372 }
373}
374
265EAPI void 375EAPI void
266edbus_object_event_callback_add(EDBus_Object *obj, EDBus_Object_Event_Type type, EDBus_Object_Event_Cb cb, const void *cb_data) 376edbus_object_event_callback_add(EDBus_Object *obj, EDBus_Object_Event_Type type, EDBus_Object_Event_Cb cb, const void *cb_data)
267{ 377{
@@ -281,6 +391,53 @@ edbus_object_event_callback_add(EDBus_Object *obj, EDBus_Object_Event_Type type,
281 ctx->cb_data = cb_data; 391 ctx->cb_data = cb_data;
282 392
283 ce->list = eina_inlist_append(ce->list, EINA_INLIST_GET(ctx)); 393 ce->list = eina_inlist_append(ce->list, EINA_INLIST_GET(ctx));
394
395 switch (type)
396 {
397 case EDBUS_OBJECT_EVENT_IFACE_ADDED:
398 {
399 if (obj->interfaces_added)
400 break;
401 obj->interfaces_added =
402 edbus_signal_handler_add(obj->conn, obj->name, NULL,
403 EDBUS_FDO_INTERFACE_OBJECT_MANAGER,
404 "InterfacesAdded",
405 _cb_interfaces_added, obj);
406 EINA_SAFETY_ON_NULL_RETURN(obj->interfaces_added);
407 edbus_signal_handler_match_extra_set(obj->interfaces_added, "arg0",
408 obj->path, NULL);
409 break;
410 }
411 case EDBUS_OBJECT_EVENT_IFACE_REMOVED:
412 {
413 if (obj->interfaces_removed)
414 break;
415 obj->interfaces_removed =
416 edbus_signal_handler_add(obj->conn, obj->name, NULL,
417 EDBUS_FDO_INTERFACE_OBJECT_MANAGER,
418 "InterfacesRemoved",
419 _cb_interfaces_removed, obj);
420 EINA_SAFETY_ON_NULL_RETURN(obj->interfaces_added);
421 edbus_signal_handler_match_extra_set(obj->interfaces_removed,
422 "arg0", obj->path, NULL);
423 break;
424 }
425 case EDBUS_OBJECT_EVENT_PROPERTY_CHANGED:
426 case EDBUS_OBJECT_EVENT_PROPERTY_REMOVED:
427 {
428 if (obj->properties_changed)
429 break;
430 obj->properties_changed =
431 edbus_object_signal_handler_add(obj,
432 EDBUS_FDO_INTERFACE_PROPERTIES,
433 "PropertiesChanged",
434 _cb_properties_changed, obj);
435 EINA_SAFETY_ON_NULL_RETURN(obj->properties_changed);
436 break;
437 }
438 default:
439 break;
440 }
284} 441}
285 442
286static void 443static void
@@ -322,6 +479,38 @@ edbus_object_event_callback_del(EDBus_Object *obj, EDBus_Object_Event_Type type,
322 } 479 }
323 480
324 _edbus_object_context_event_cb_del(ce, found); 481 _edbus_object_context_event_cb_del(ce, found);
482
483 switch (type)
484 {
485 case EDBUS_OBJECT_EVENT_IFACE_ADDED:
486 {
487 if (obj->event_handlers[EDBUS_OBJECT_EVENT_IFACE_ADDED].list)
488 break;
489 edbus_signal_handler_del(obj->interfaces_added);
490 obj->interfaces_added = NULL;
491 break;
492 }
493 case EDBUS_OBJECT_EVENT_IFACE_REMOVED:
494 {
495 if (obj->event_handlers[EDBUS_OBJECT_EVENT_IFACE_REMOVED].list)
496 break;
497 edbus_signal_handler_del(obj->interfaces_removed);
498 obj->interfaces_removed = NULL;
499 break;
500 }
501 case EDBUS_OBJECT_EVENT_PROPERTY_CHANGED:
502 case EDBUS_OBJECT_EVENT_PROPERTY_REMOVED:
503 {
504 if (obj->event_handlers[EDBUS_OBJECT_EVENT_PROPERTY_CHANGED].list ||
505 obj->event_handlers[EDBUS_OBJECT_EVENT_PROPERTY_REMOVED].list)
506 break;
507 edbus_signal_handler_del(obj->properties_changed);
508 obj->properties_changed = NULL;
509 break;
510 }
511 default:
512 break;
513 }
325} 514}
326 515
327static void 516static void
diff --git a/legacy/edbus/src/lib/edbus_object.h b/legacy/edbus/src/lib/edbus_object.h
index 8e886e7928..2214f935ef 100644
--- a/legacy/edbus/src/lib/edbus_object.h
+++ b/legacy/edbus/src/lib/edbus_object.h
@@ -39,8 +39,8 @@ EAPI void edbus_object_cb_free_del(EDBus_Object *obj, EDBus_Free_Cb cb,
39 39
40typedef enum 40typedef enum
41{ 41{
42 EDBUS_OBJECT_EVENT_IFACE_ADDED = 0, 42 EDBUS_OBJECT_EVENT_IFACE_ADDED = 0, /**< a parent path must have a ObjectManager interface */
43 EDBUS_OBJECT_EVENT_IFACE_REMOVED, 43 EDBUS_OBJECT_EVENT_IFACE_REMOVED, /**< a parent path must have a ObjectManager interface */
44 EDBUS_OBJECT_EVENT_PROPERTY_CHANGED, 44 EDBUS_OBJECT_EVENT_PROPERTY_CHANGED,
45 EDBUS_OBJECT_EVENT_PROPERTY_REMOVED, 45 EDBUS_OBJECT_EVENT_PROPERTY_REMOVED,
46 EDBUS_OBJECT_EVENT_DEL, 46 EDBUS_OBJECT_EVENT_DEL,
diff --git a/legacy/edbus/src/lib/edbus_private_types.h b/legacy/edbus/src/lib/edbus_private_types.h
index be2725eacf..ba810ea097 100644
--- a/legacy/edbus/src/lib/edbus_private_types.h
+++ b/legacy/edbus/src/lib/edbus_private_types.h
@@ -77,6 +77,9 @@ struct _EDBus_Object
77 Eina_List *signal_handlers; 77 Eina_List *signal_handlers;
78 Eina_Inlist *cbs_free; 78 Eina_Inlist *cbs_free;
79 EDBus_Object_Context_Event event_handlers[EDBUS_OBJECT_EVENT_LAST]; 79 EDBus_Object_Context_Event event_handlers[EDBUS_OBJECT_EVENT_LAST];
80 EDBus_Signal_Handler *interfaces_added;
81 EDBus_Signal_Handler *interfaces_removed;
82 EDBus_Signal_Handler *properties_changed;
80}; 83};
81 84
82struct _EDBus_Signal_Handler 85struct _EDBus_Signal_Handler