vici: Raise events with an optional identifier for specific connections
This commit is contained in:
@@ -55,7 +55,7 @@ START_TEST(test_event)
|
|||||||
ck_assert(vici_register(conn, "test", event_cb, &count) == 0);
|
ck_assert(vici_register(conn, "test", event_cb, &count) == 0);
|
||||||
ck_assert(vici_register(conn, "nonexistent", 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_KEY_VALUE, "key1", chunk_from_str("value1"),
|
||||||
VICI_END));
|
VICI_END));
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ START_TEST(test_stress)
|
|||||||
/* do some event re/deregistration in between */
|
/* do some event re/deregistration in between */
|
||||||
ck_assert(vici_register(conn, "dummy", event_cb, NULL) == 0);
|
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_message_create_from_args(
|
||||||
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
|
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
|
||||||
VICI_END));
|
VICI_END));
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ START_TEST(test_stress)
|
|||||||
{
|
{
|
||||||
/* do some event management in between */
|
/* do some event management in between */
|
||||||
ck_assert(vici_register(conn, "dummy", event_cb, &events) == 0);
|
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_message_create_from_args(
|
||||||
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
|
VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
|
||||||
VICI_END));
|
VICI_END));
|
||||||
|
|||||||
@@ -382,11 +382,12 @@ METHOD(vici_dispatcher_t, manage_event, void,
|
|||||||
}
|
}
|
||||||
|
|
||||||
METHOD(vici_dispatcher_t, raise_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;
|
enumerator_t *enumerator;
|
||||||
event_t *event;
|
event_t *event;
|
||||||
u_int *id;
|
u_int *current;
|
||||||
|
|
||||||
this->mutex->lock(this->mutex);
|
this->mutex->lock(this->mutex);
|
||||||
event = this->events->get(this->events, name);
|
event = this->events->get(this->events, name);
|
||||||
@@ -397,9 +398,12 @@ METHOD(vici_dispatcher_t, raise_event, void,
|
|||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
|
|
||||||
enumerator = array_create_enumerator(event->clients);
|
enumerator = array_create_enumerator(event->clients);
|
||||||
while (enumerator->enumerate(enumerator, &id))
|
while (enumerator->enumerate(enumerator, ¤t))
|
||||||
{
|
{
|
||||||
send_op(this, *id, VICI_EVENT, name, message);
|
if (id == 0 || id == *current)
|
||||||
|
{
|
||||||
|
send_op(this, *current, VICI_EVENT, name, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
|
|
||||||
|
|||||||
@@ -92,12 +92,13 @@ struct vici_dispatcher_t {
|
|||||||
void (*manage_event)(vici_dispatcher_t *this, char *name, bool reg);
|
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 name event name to raise
|
||||||
|
* @param id client connection ID, 0 for all
|
||||||
* @param message event message to send, gets destroyed
|
* @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);
|
vici_message_t *message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user