Skip to content

Commit

Permalink
core: refactor events
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Aug 12, 2024
1 parent 0a753af commit b51459a
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 96 deletions.
12 changes: 7 additions & 5 deletions modules/menu/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,17 +652,19 @@ static void process_module_event(struct call *call, const char *prm)
}


static void ua_event_handler(struct ua *ua, enum ua_event ev,
struct call *call, const char *prm, void *arg)
static void event_handler(enum ua_event ev, struct bevent *event, void *arg)
{
struct call *call2 = NULL;
struct account *acc = ua_account(ua);
int32_t adelay = -1;
bool incall;
enum sdp_dir ardir, vrdir;
uint32_t count;
struct pl val;
char * uri;
const char *prm = bevent_get_text(event);
struct call *call = bevent_get_call(event);
struct ua *ua = bevent_get_ua(event);
struct account *acc = ua_account(bevent_get_ua(event));
int err;
(void)arg;

Expand Down Expand Up @@ -1179,7 +1181,7 @@ static int module_init(void)
if (err)
return err;

err = uag_event_register(ua_event_handler, NULL);
err = bevent_register(event_handler, NULL);
if (err)
return err;

Expand All @@ -1199,7 +1201,7 @@ static int module_close(void)

message_unlisten(baresip_message(), message_handler);

uag_event_unregister(ua_event_handler);
bevent_unregister(event_handler);
static_menu_unregister();
dial_menu_unregister();
dynamic_menu_unregister();
Expand Down
3 changes: 1 addition & 2 deletions src/bevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,8 @@ 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 = ev, .txt = buf};

struct bevent event = {.ev = ev, .txt = buf};
if (bevent_class(ev) == BEVENT_CLASS_CALL)
event.u.call = call;
else if (bevent_class(ev) == BEVENT_CLASS_UA)
Expand Down Expand Up @@ -781,7 +781,6 @@ void module_event(const char *module, const char *event, struct ua *ua,
}

struct bevent bevent = {.ev = UA_EVENT_MODULE, .txt = buf};

if (call)
bevent.u.call = call;

Expand Down
47 changes: 24 additions & 23 deletions src/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ static int update_media(struct call *call)
{
debug("call: update media\n");

ua_event(call->ua, UA_EVENT_CALL_REMOTE_SDP, call,
call->got_offer ? "offer" : "answer");
bevent_call_emit(UA_EVENT_CALL_REMOTE_SDP, call,
call->got_offer ? "offer" : "answer");

return call_update_media(call);
}
Expand Down Expand Up @@ -384,8 +384,8 @@ static void audio_level_handler(bool tx, double lvl, void *arg)
struct call *call = arg;
MAGIC_CHECK(call);

ua_event(call->ua, tx ? UA_EVENT_VU_TX : UA_EVENT_VU_RX,
call, "%.2f", lvl);
bevent_call_emit(tx ? UA_EVENT_VU_TX : UA_EVENT_VU_RX, call,
"%.2f", lvl);
}


Expand All @@ -397,14 +397,15 @@ static void audio_error_handler(int err, const char *str, void *arg)
if (err) {
warning("call: audio device error: %m (%s)\n", err, str);

ua_event(call->ua, UA_EVENT_AUDIO_ERROR, call, "%d,%s",
err, str);
bevent_call_emit(UA_EVENT_AUDIO_ERROR, call,
"%d,%s", err, str);

call_stream_stop(call);
call_event_handler(call, CALL_EVENT_CLOSED,
"%s", str);
}
else
ua_event(call->ua, UA_EVENT_END_OF_FILE, call, "");
bevent_call_emit(UA_EVENT_END_OF_FILE, call, "");
}


Expand Down Expand Up @@ -525,8 +526,8 @@ static void stream_rtpestab_handler(struct stream *strm, void *arg)
struct call *call = arg;
MAGIC_CHECK(call);

ua_event(call->ua, UA_EVENT_CALL_RTPESTAB, call,
"%s", sdp_media_name(stream_sdpmedia(strm)));
bevent_call_emit(UA_EVENT_CALL_RTPESTAB, call,
"%s", sdp_media_name(stream_sdpmedia(strm)));
}


Expand All @@ -543,13 +544,13 @@ static void stream_rtcp_handler(struct stream *strm,
if (call->config_avt.rtp_stats)
call_set_xrtpstat(call);

ua_event(call->ua, UA_EVENT_CALL_RTCP, call,
"%s", sdp_media_name(stream_sdpmedia(strm)));
bevent_call_emit(UA_EVENT_CALL_RTCP, call,
"%s", sdp_media_name(stream_sdpmedia(strm)));
break;

case RTCP_APP:
ua_event(call->ua, UA_EVENT_CALL_RTCP, call,
"%s", sdp_media_name(stream_sdpmedia(strm)));
bevent_call_emit(UA_EVENT_CALL_RTCP, call,
"%s", sdp_media_name(stream_sdpmedia(strm)));
break;
}
}
Expand Down Expand Up @@ -1092,8 +1093,8 @@ int call_modify(struct call *call)
if (call_refresh_allowed(call)) {
err = call_sdp_get(call, &desc, true);
if (!err) {
ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call,
"offer");
bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call,
"offer");

err = sipsess_modify(call->sess, desc);
if (err)
Expand Down Expand Up @@ -1226,7 +1227,7 @@ int call_progress_dir(struct call *call, enum sdp_dir adir, enum sdp_dir vdir)
goto out;

if (call->got_offer) {
ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call, "answer");
bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call, "answer");
err = call_update_media(call);
}

Expand Down Expand Up @@ -1294,8 +1295,8 @@ int call_answer(struct call *call, uint16_t scode, enum vidmode vmode)
if (call->got_offer)
err = call_apply_sdp(call);

ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call,
"%s", !call->got_offer ? "offer" : "answer");
bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call,
"%s", !call->got_offer ? "offer" : "answer");

err = sdp_encode(&desc, call->sdp, !call->got_offer);
if (err)
Expand Down Expand Up @@ -1749,9 +1750,9 @@ static int sipsess_offer_handler(struct mbuf **descp,
}

if (aurx && !(sdp_media_dir(m) & SDP_SENDONLY))
ua_event(call->ua, UA_EVENT_CALL_HOLD, call, "");
bevent_call_emit(UA_EVENT_CALL_HOLD, call, "");
else if (!aurx && sdp_media_dir(m) & SDP_SENDONLY)
ua_event(call->ua, UA_EVENT_CALL_RESUME, call, "");
bevent_call_emit(UA_EVENT_CALL_RESUME, call, "");

err = update_media(call);
if (err) {
Expand Down Expand Up @@ -2337,8 +2338,8 @@ static void redirect_handler(const struct sip_msg *msg, const char *uri,
struct call *call = arg;

info("call: redirect to %s\n", uri);
ua_event(call->ua, UA_EVENT_CALL_REDIRECT, call,
"%d,%s", msg->scode, uri);
bevent_call_emit(UA_EVENT_CALL_REDIRECT, call,
"%d,%s", msg->scode, uri);
return;
}

Expand Down Expand Up @@ -2434,7 +2435,7 @@ static int send_invite(struct call *call)
/* save call setup timer */
call->time_conn = time(NULL);

ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call, "offer");
bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call, "offer");

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions src/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void register_handler(int err, const struct sip_msg *msg, void *arg)

reg->scode = 999;

ua_event(reg->ua, evfail, NULL, "%m", err);
bevent_ua_emit(evfail, reg->ua, "%m", err);
return;
}

Expand Down Expand Up @@ -162,8 +162,8 @@ static void register_handler(int err, const struct sip_msg *msg, void *arg)
}
}

ua_event(reg->ua, evok, NULL, "%u %r",
msg->scode, &msg->reason);
bevent_ua_emit(evok, reg->ua,
"%u %r", msg->scode, &msg->reason);
}
else if (msg->scode >= 300) {

Expand All @@ -172,8 +172,8 @@ static void register_handler(int err, const struct sip_msg *msg, void *arg)

reg->scode = msg->scode;

ua_event(reg->ua, evfail, NULL, "%u %r",
msg->scode, &msg->reason);
bevent_ua_emit(evfail, reg->ua,
"%u %r", msg->scode, &msg->reason);
}
}

Expand Down
Loading

0 comments on commit b51459a

Please sign in to comment.