vici: Raise events with an optional identifier for specific connections

This commit is contained in:
Martin Willi 2014-02-10 17:09:01 +01:00
parent 293431269b
commit b40a12a96f
4 changed files with 14 additions and 9 deletions

View File

@ -55,7 +55,7 @@ START_TEST(test_event)
ck_assert(vici_register(conn, "test", event_cb, &count) == 0);
ck_assert(vici_register(conn, "nonexistent", event_cb, &count) != 0);
dispatcher->raise_event(dispatcher, "test", vici_message_create_from_args(
dispatcher->raise_event(dispatcher, "test", 0, vici_message_create_from_args(
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
VICI_END));
@ -100,7 +100,7 @@ START_TEST(test_stress)
/* do some event re/deregistration in between */
ck_assert(vici_register(conn, "dummy", event_cb, NULL) == 0);
dispatcher->raise_event(dispatcher, "test",
dispatcher->raise_event(dispatcher, "test", 0,
vici_message_create_from_args(
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
VICI_END));

View File

@ -188,7 +188,7 @@ START_TEST(test_stress)
{
/* do some event management in between */
ck_assert(vici_register(conn, "dummy", event_cb, &events) == 0);
dispatcher->raise_event(dispatcher, "dummy",
dispatcher->raise_event(dispatcher, "dummy", 0,
vici_message_create_from_args(
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
VICI_END));

View File

@ -382,11 +382,12 @@ METHOD(vici_dispatcher_t, manage_event, void,
}
METHOD(vici_dispatcher_t, raise_event, void,
private_vici_dispatcher_t *this, char *name, vici_message_t *message)
private_vici_dispatcher_t *this, char *name, u_int id,
vici_message_t *message)
{
enumerator_t *enumerator;
event_t *event;
u_int *id;
u_int *current;
this->mutex->lock(this->mutex);
event = this->events->get(this->events, name);
@ -397,9 +398,12 @@ METHOD(vici_dispatcher_t, raise_event, void,
this->mutex->unlock(this->mutex);
enumerator = array_create_enumerator(event->clients);
while (enumerator->enumerate(enumerator, &id))
while (enumerator->enumerate(enumerator, &current))
{
send_op(this, *id, VICI_EVENT, name, message);
if (id == 0 || id == *current)
{
send_op(this, *current, VICI_EVENT, name, message);
}
}
enumerator->destroy(enumerator);

View File

@ -92,12 +92,13 @@ struct vici_dispatcher_t {
void (*manage_event)(vici_dispatcher_t *this, char *name, bool reg);
/**
* Raise an event to all clients registered to that event.
* Raise an event to a specific or all clients registered to that event.
*
* @param name event name to raise
* @param id client connection ID, 0 for all
* @param message event message to send, gets destroyed
*/
void (*raise_event)(vici_dispatcher_t *this, char *name,
void (*raise_event)(vici_dispatcher_t *this, char *name, u_int id,
vici_message_t *message);
/**