Skip to content

Commit

Permalink
event: put stop flag to bevent instead of return value
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed May 6, 2024
1 parent af28d46 commit a363273
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ enum answer_method {
/** Defines the User-Agent event handler */
typedef void (ua_event_h)(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg);
typedef bool (bevent_h)(struct bevent *event, void *arg);
typedef void (bevent_h)(struct bevent *event, void *arg);
typedef void (options_resp_h)(int err, const struct sip_msg *msg, void *arg);
typedef void (refer_resp_h)(int err, const struct sip_msg *msg, void *arg);

Expand Down
9 changes: 4 additions & 5 deletions modules/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static void process_module_event(struct call *call, const char *prm)
}


static bool event_handler(struct bevent *event, void *arg)
static void event_handler(struct bevent *event, void *arg)
{
struct call *call2 = NULL;
int32_t adelay = -1;
Expand Down Expand Up @@ -684,11 +684,11 @@ static bool event_handler(struct bevent *event, void *arg)
case UA_EVENT_CALL_INCOMING:

if (call_state(call) != CALL_STATE_INCOMING)
return false;
return;

if (account_answermode(acc) == ANSWERMODE_AUTO) {
if (!menu_autoanwser_call(call))
return false;
return;
}

/* the new incoming call should not change the current call */
Expand Down Expand Up @@ -902,7 +902,7 @@ static bool event_handler(struct bevent *event, void *arg)
break;

case UA_EVENT_UNREGISTERING:
return false;
return;

case UA_EVENT_MWI_NOTIFY:
info("----- MWI for %s -----\n", account_aor(acc));
Expand All @@ -924,7 +924,6 @@ static bool event_handler(struct bevent *event, void *arg)
incall = ev == UA_EVENT_CALL_CLOSED ? count > 1 : count;
menu_set_incall(incall);
menu_update_callstatus(incall);
return false;
}


Expand Down
23 changes: 12 additions & 11 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct bevent {
enum ua_event ev;
const char *txt;
int err;
bool stop;
union {
struct ua *ua;
struct call *call;
Expand Down Expand Up @@ -55,7 +56,7 @@ struct ehe {
static struct list ehel; /**< Event handlers (struct ehe) */


static bool bevent_emit_base(struct bevent *event);
static void bevent_emit_base(struct bevent *event);


static void ehe_destructor(void *arg)
Expand Down Expand Up @@ -624,7 +625,7 @@ void ua_event(struct ua *ua, enum ua_event ev, struct call *call,
warning("Used deprecated ua_event() for %s. "
"Use one of event_xxx_emit() instead!\n",
uag_event_str(ev));
struct bevent event = {ev, buf, 0, { 0 } };
struct bevent event = {ev, buf, 0, false, { 0 } };

if (bevent_class(ev) == BEVENT_CLASS_CALL)
event.u.call = call;
Expand Down Expand Up @@ -680,27 +681,27 @@ void module_event(const char *module, const char *event, struct ua *ua,
eh->h(ua, UA_EVENT_MODULE, call, buf, eh->arg);
}

struct bevent bevent = {UA_EVENT_MODULE, buf, 0, { 0 } };
(void)bevent_emit_base(&bevent);
struct bevent bevent = {UA_EVENT_MODULE, buf, 0, false, { 0 } };
bevent_emit_base(&bevent);

out:
mem_deref(buf);
}


static bool bevent_emit_base(struct bevent *event)
static void bevent_emit_base(struct bevent *event)
{
struct le *le;
le = ehel.head;
while (le) {
struct ehe *ehe = le->data;
le = le->next;

if (ehe->h(event, ehe->arg))
return true;
}
ehe->h(event, ehe->arg);

return false;
if (event->stop)
return;
}
}


Expand All @@ -720,14 +721,14 @@ static int bevent_emit(struct bevent *event, const char *fmt, va_list ap)

event->txt = buf;
event->err = 0;
bool stop = bevent_emit_base(event);
bevent_emit_base(event);
if (event->err) {
err = event->err;
goto out;
}

/* backwards compatibility */
if (stop)
if (event->stop)
goto out;

ua_event_private(ua, event->ev, call, event->txt);
Expand Down
8 changes: 4 additions & 4 deletions test/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ static void process_rules(struct agent *ag, enum ua_event ev, const char *prm)
}


static bool event_handler(struct bevent *event, void *arg)
static void event_handler(struct bevent *event, void *arg)
{
struct fixture *f = arg;
struct call *call2 = NULL;
Expand Down Expand Up @@ -627,7 +627,7 @@ static bool event_handler(struct bevent *event, void *arg)
else if (ua == f->c.ua)
ag = &f->c;
else {
return false;
return;
}

switch (ev) {
Expand Down Expand Up @@ -861,7 +861,7 @@ static bool event_handler(struct bevent *event, void *arg)
if (ag->failed && ag->peer->failed) {
info("test: re_cancel on call failed\n");
re_cancel();
return false;
return;
}

process_rules(ag, ev, prm);
Expand All @@ -872,7 +872,7 @@ static bool event_handler(struct bevent *event, void *arg)
fixture_abort(f, err);
}

return false;
return;
}


Expand Down
6 changes: 2 additions & 4 deletions test/ua.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void test_abort(struct test *t, int err)
}


static bool event_handler(struct bevent *event, void *arg)
static void event_handler(struct bevent *event, void *arg)
{
struct test *t = arg;
size_t i;
Expand All @@ -71,7 +71,7 @@ static bool event_handler(struct bevent *event, void *arg)
ASSERT_TRUE(t != NULL);

if (ua != t->ua)
return false;
return;

if (ev == UA_EVENT_REGISTER_OK) {

Expand Down Expand Up @@ -103,8 +103,6 @@ static bool event_handler(struct bevent *event, void *arg)
warning("selftest: event handler error: %m\n", err);
t->err = err;
}

return false;
}


Expand Down

0 comments on commit a363273

Please sign in to comment.