diff options
author | Alfred E. Heggestad <aeh@db.org> | 2016-07-26 23:38:03 +0200 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2016-07-26 23:38:03 +0200 |
commit | 49ea18057b64e2a806d6799bc2aa87b30491634e (patch) | |
tree | 6b407138e2f94c2a14eedd6dc97b2f184ab82c38 /src | |
parent | ff3961ad2920ba674272b4f842f4456ed685a4a7 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/call.c | 69 | ||||
-rw-r--r-- | src/core.h | 5 | ||||
-rw-r--r-- | src/ua.c | 24 |
3 files changed, 73 insertions, 25 deletions
@@ -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; num<CALL_LINENUM_MAX; num++) { + + if (!call_find_linenum(lst, num)) { + *linenum = num; + return 0; + } + } + + return ENOENT; +} + + /** * Allocate a new Call state object * @@ -466,7 +482,6 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst, struct call *call; struct le *le; enum vidmode vidmode = prm ? prm->vidmode : 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); +} @@ -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 */ @@ -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; linenum<CALL_LINENUM_MAX; linenum++) { - for (le = ua->calls.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"); |