common: event infrastructure overhaul, lifted from core to common.
authorKrisztian Litkey <krisztian.litkey@intel.com>
Tue, 9 Dec 2014 18:38:29 +0000 (20:38 +0200)
committerKrisztian Litkey <krisztian.litkey@intel.com>
Fri, 12 Dec 2014 15:37:22 +0000 (17:37 +0200)
commit2a3322f15bf1779d6599e67c319a92037ccd5bb8
treecbfadc97ee2714df100c09885ef61898178a8c95
parent36d95587b5f2ccadbd0885d0760ce449e7f9e01b
common: event infrastructure overhaul, lifted from core to common.

This patch litfs the original event publish/subscribe code from
core to common and attempts to fix some of its shortcomings.

The patch also introduces events busses to provide an abstraction
for logically grouping related or similar events together. Arbitrary
number of busses can be created dynamically. Subscription and event
delivery (emitting) is always done on a particular bus. There is
a default global (the NULL) bus which is always availablei.
This is the easiest to use for backward-compatibility for code which
used to generate or subscribe to some events but did not have direct
access to the mainloop.

Events can now be delivered both synchronously and asynchronously.
The event mechanism have been put under the mainloop mainly for this
reason (to automatically associate busses with a mainloop) to support
asynchronous delivery. With synchronous delivery, the event have been
delivered to all subscribers by the time the emitting call returns.
With asynchronous delivery the event will be delivered from a deferred
callback once the mainloop is done processing its pending events. The
global NULL bus is not associated with a mainloop and therefore only
supports synchronous delivery.

Data can now be attached to events in different formats. In addition
to the original mrp_msg_t, we now support JSON (mrp_json_t) and custom
pointers. For mrp_msg_t and JSON, the infrastructure takes care of
properly reference-counting the data in case of asychronous delivery.
For custom data this is not done ATM (although that might change), so
the caller has to make sure the event data is valid during delivery
and properly freed afterwards.

Currently it is not possible to delete event busses or unregister
events.
22 files changed:
src/Makefile.am
src/common/mainloop.c
src/common/mainloop.h
src/common/mask.h [new file with mode: 0644]
src/common/tests/Makefile.am
src/common/tests/mask-test.c [new file with mode: 0644]
src/core/context.h
src/core/plugin.c
src/core/plugin.h
src/daemon/daemon.c
src/daemon/daemon.h
src/plugins/domain-control/domain-control.c
src/plugins/plugin-test.c
src/plugins/resource-native/plugin-resource-native.c
src/resolver/events.c
src/resolver/events.h
src/resolver/resolver-types.h
src/resolver/resolver.c
src/resolver/resolver.h
src/resolver/target.c
src/resource/resource-set.c
src/resource/resource-set.h