From 49ea18057b64e2a806d6799bc2aa87b30491634e Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Tue, 26 Jul 2016 23:38:03 +0200 Subject: add '@' command to switch calls using line numbers 1. for a given UA, each call has a unique line number starting from 1 2. the list of calls is sorted in an arbitrary order, but the last list element indicates "current call" 3. the '@' command takes a numeric argument which is the line-number of the wanted call --- src/call.c | 69 ++++++++++++++++++++++++++++++++++++++++++++------------------ src/core.h | 5 +++++ src/ua.c | 24 +++++++++++++++++----- 3 files changed, 73 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/call.c b/src/call.c index 50910dc..e0fec6b 100644 --- a/src/call.c +++ b/src/call.c @@ -439,6 +439,22 @@ static void stream_error_handler(struct stream *strm, int err, void *arg) } +static int assign_linenum(uint32_t *linenum, const struct list *lst) +{ + uint32_t num; + + for (num=CALL_LINENUM_MIN; numvidmode : VIDMODE_OFF; - uint32_t wanted_linenum = 1; bool use_video = true, got_offer = false; int label = 0; int err = 0; @@ -597,27 +612,16 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst, call_enable_rtp_timeout(call, cfg->avt.rtp_timeout*1000); } - for (le = lst->head; le; le = le->next) { - - const struct call *call0 = le->data; - - if (call0->linenum == wanted_linenum) { - /* that linenum was busy, increment */ - ++wanted_linenum; - continue; - } - else if (call0->linenum > wanted_linenum) { - /* wanted linenum is free */ - list_insert_before(lst, le, &call->le, call); - call->linenum = wanted_linenum; - break; - } + err = assign_linenum(&call->linenum, lst); + if (err) { + warning("call: could not assign linenumber\n"); + goto out; } - if (!call->le.list) { - list_append(lst, &call->le, call); - call->linenum = list_count(lst); - } + /* NOTE: The new call must always be added to the tail of list, + * which indicates the current call. + */ + list_append(lst, &call->le, call); out: if (err) @@ -1799,3 +1803,28 @@ uint32_t call_linenum(const struct call *call) { return call ? call->linenum : 0; } + + +struct call *call_find_linenum(const struct list *calls, uint32_t linenum) +{ + struct le *le; + + for (le = list_head(calls); le; le = le->next) { + struct call *call = le->data; + + if (linenum == call->linenum) + return call; + } + + return NULL; +} + + +void call_set_current(struct list *calls, struct call *call) +{ + if (!calls || !call) + return; + + list_unlink(&call->le); + list_append(calls, &call->le, call); +} diff --git a/src/core.h b/src/core.h index dfedf57..27b3b76 100644 --- a/src/core.h +++ b/src/core.h @@ -136,6 +136,11 @@ int bfcp_start(struct bfcp *bfcp); * Call Control */ +enum { + CALL_LINENUM_MIN = 1, + CALL_LINENUM_MAX = 256 +}; + struct call; /** Call parameters */ diff --git a/src/ua.c b/src/ua.c index 35626f7..41a80e7 100644 --- a/src/ua.c +++ b/src/ua.c @@ -1545,21 +1545,35 @@ int ua_print_sip_status(struct re_printf *pf, void *unused) */ int ua_print_calls(struct re_printf *pf, const struct ua *ua) { - struct le *le; + uint32_t n, count=0; + uint32_t linenum; int err = 0; + if (!ua) { err |= re_hprintf(pf, "\n--- No active calls ---\n"); return err; } + n = list_count(&ua->calls); + err |= re_hprintf(pf, "\n--- List of active calls (%u): ---\n", - list_count(&ua->calls)); + n); + + for (linenum=CALL_LINENUM_MIN; linenumcalls.head; le; le = le->next) { + const struct call *call; - const struct call *call = le->data; + call = call_find_linenum(&ua->calls, linenum); + if (call) { + ++count; - err |= re_hprintf(pf, " %H\n", call_info, call); + err |= re_hprintf(pf, " %c %H\n", + call == ua_call(ua) ? '>' : ' ', + call_info, call); + } + + if (count >= n) + break; } err |= re_hprintf(pf, "\n"); -- cgit v1.2.3