mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Enhance console command to allow multiple concurrent calls
This commit is contained in:
parent
23cb4600e2
commit
14be44d211
100
tests/vomp
100
tests/vomp
@ -73,7 +73,7 @@ test_nophone() {
|
||||
set_instance +A
|
||||
init_console
|
||||
send_cmd "call $SIDB $DIDA $DIDB" "$A_IN"
|
||||
wait_until grep "^Call ended$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$A_OUT"
|
||||
send_cmd "quit" "$A_IN"
|
||||
fork_wait_all
|
||||
tfw_cat "$A_OUT"
|
||||
@ -83,14 +83,14 @@ doc_hangup="Hangup instead of answering"
|
||||
test_hangup() {
|
||||
foreach_instance +A +B init_console
|
||||
send_cmd "call $SIDA $DIDB $DIDA" "$B_IN"
|
||||
wait_until grep "^Dialling$" "$B_OUT"
|
||||
wait_until grep "^Incoming call" "$A_OUT"
|
||||
wait_until grep "^Codec list" "$A_OUT"
|
||||
wait_until grep "^Codec list" "$B_OUT"
|
||||
wait_until grep "^Ringing$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Dialling$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Incoming call" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Ringing$" "$B_OUT"
|
||||
send_cmd "hangup" "$A_IN"
|
||||
wait_until grep "^Call ended$" "$A_OUT"
|
||||
wait_until grep "^Call ended$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$B_OUT"
|
||||
send_cmd "quit" "$A_IN"
|
||||
send_cmd "quit" "$B_IN"
|
||||
fork_wait_all
|
||||
@ -101,20 +101,20 @@ doc_timeout="Call timeout"
|
||||
test_timeout() {
|
||||
foreach_instance +A +B init_console
|
||||
send_cmd "call $SIDA $DIDB $DIDA" "$B_IN"
|
||||
wait_until grep "^Dialling$" "$B_OUT"
|
||||
wait_until grep "^Incoming call" "$A_OUT"
|
||||
wait_until grep "^Codec list" "$A_OUT"
|
||||
wait_until grep "^Codec list" "$B_OUT"
|
||||
wait_until grep "^Ringing$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Dialling$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Incoming call" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Ringing$" "$B_OUT"
|
||||
send_cmd "answer" "$A_IN"
|
||||
wait_until grep "^Picked up$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Picked up$" "$B_OUT"
|
||||
send_cmd "say hello" "$A_IN"
|
||||
send_cmd "say hi there" "$B_IN"
|
||||
wait_until grep "^hello$" "$B_OUT"
|
||||
wait_until grep "^hi there$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^hello$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^hi there$" "$A_OUT"
|
||||
stop_servald_server +B
|
||||
# B's console should just quit
|
||||
wait_until --timeout=20 grep "^Call ended$" "$A_OUT"
|
||||
wait_until --timeout=10 --timeout=20 grep "^Call ended$" "$A_OUT"
|
||||
send_cmd "quit" "$A_IN"
|
||||
fork_wait_all
|
||||
tfw_cat "$A_OUT" "$B_OUT"
|
||||
@ -124,24 +124,70 @@ doc_call_lifecycle="Successful call lifecycle"
|
||||
test_call_lifecycle() {
|
||||
foreach_instance +A +B init_console
|
||||
send_cmd "call $SIDA $DIDB $DIDA" "$B_IN"
|
||||
wait_until grep "^Dialling$" "$B_OUT"
|
||||
wait_until grep "^Incoming call" "$A_OUT"
|
||||
wait_until grep "^Codec list" "$A_OUT"
|
||||
wait_until grep "^Codec list" "$B_OUT"
|
||||
wait_until grep "^Ringing$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Dialling$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Incoming call" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Ringing$" "$B_OUT"
|
||||
send_cmd "answer" "$A_IN"
|
||||
wait_until grep "^Picked up$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Picked up$" "$B_OUT"
|
||||
send_cmd "say hello" "$A_IN"
|
||||
send_cmd "say hi there" "$B_IN"
|
||||
wait_until grep "^hello$" "$B_OUT"
|
||||
wait_until grep "^hi there$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^hello$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^hi there$" "$A_OUT"
|
||||
send_cmd "hangup" "$B_IN"
|
||||
wait_until grep "^Call ended$" "$A_OUT"
|
||||
wait_until grep "^Call ended$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$B_OUT"
|
||||
send_cmd "quit" "$A_IN"
|
||||
send_cmd "quit" "$B_IN"
|
||||
fork_wait_all
|
||||
tfw_cat "$A_OUT" "$B_OUT"
|
||||
}
|
||||
|
||||
doc_concurrent="Multiple calls at once"
|
||||
setup_concurrent() {
|
||||
setup_servald
|
||||
assert_no_servald_processes
|
||||
start_servald_instances +A +B +C +D +E
|
||||
}
|
||||
test_concurrent() {
|
||||
foreach_instance +A +B +C +D +E init_console
|
||||
send_cmd "call $SIDB $DIDA $DIDB" "$A_IN"
|
||||
send_cmd "call $SIDC $DIDA $DIDC" "$A_IN"
|
||||
send_cmd "call $SIDA $DIDD $DIDA" "$D_IN"
|
||||
send_cmd "call $SIDA $DIDE $DIDA" "$E_IN"
|
||||
wait_until --timeout=10 grep "^Incoming call" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Incoming call" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Incoming call" "$C_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$C_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$D_OUT"
|
||||
wait_until --timeout=10 grep "^Codec list" "$E_OUT"
|
||||
wait_until --timeout=10 grep "^Ringing$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Ringing$" "$D_OUT"
|
||||
wait_until --timeout=10 grep "^Ringing$" "$E_OUT"
|
||||
send_cmd "answer" "$A_IN"
|
||||
send_cmd "answer" "$A_IN"
|
||||
send_cmd "answer" "$B_IN"
|
||||
send_cmd "hangup" "$C_IN"
|
||||
wait_until --timeout=10 grep "^Picked up$" "$A_OUT"
|
||||
wait_until --timeout=10 grep "^Picked up$" "$D_OUT"
|
||||
wait_until --timeout=10 grep "^Picked up$" "$E_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$C_OUT"
|
||||
send_cmd "hangup" "$B_IN"
|
||||
send_cmd "hangup" "$D_IN"
|
||||
send_cmd "hangup" "$E_IN"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$B_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$D_OUT"
|
||||
wait_until --timeout=10 grep "^Call ended$" "$E_OUT"
|
||||
send_cmd "quit" "$A_IN"
|
||||
send_cmd "quit" "$B_IN"
|
||||
send_cmd "quit" "$C_IN"
|
||||
send_cmd "quit" "$D_IN"
|
||||
send_cmd "quit" "$E_IN"
|
||||
fork_wait_all
|
||||
tfw_cat "$A_OUT" "$B_OUT" "$C_OUT" "$D_OUT" "$E_OUT"
|
||||
}
|
||||
|
||||
runTests "$@"
|
||||
|
109
vomp_console.c
109
vomp_console.c
@ -113,8 +113,14 @@ struct sched_ent monitor_alarm={
|
||||
.stats=&monitor_profile,
|
||||
};
|
||||
|
||||
int call_token=-1;
|
||||
int seen_audio=0;
|
||||
struct call{
|
||||
struct call *_next;
|
||||
int token;
|
||||
char ring_in;
|
||||
};
|
||||
|
||||
struct call *calls=NULL;
|
||||
|
||||
struct monitor_state *monitor_state;
|
||||
|
||||
static void send_hangup(int session_id){
|
||||
@ -133,21 +139,26 @@ static void send_audio(int session_id, unsigned char *buffer, int len, int codec
|
||||
monitor_client_writeline_and_data(monitor_alarm.poll.fd, buffer, len, "audio %06x %d\n", session_id, codec);
|
||||
}
|
||||
|
||||
static struct call* find_call(int token){
|
||||
struct call *call = calls;
|
||||
while(call){
|
||||
if (call->token==token)
|
||||
return call;
|
||||
call=call->_next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int remote_call(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
|
||||
if (call_token != -1){
|
||||
send_hangup(token);
|
||||
printf("Rejected incoming call, already busy\n");
|
||||
fflush(stdout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
call_token = token;
|
||||
seen_audio = 0;
|
||||
printf("Incoming call for %s (%s) from %s (%s)\n", argv[1], argv[2], argv[3], argv[4]);
|
||||
fflush(stdout);
|
||||
struct call *call = emalloc_zero(sizeof(struct call));
|
||||
call->_next = calls;
|
||||
calls=call;
|
||||
call->token = token;
|
||||
call->ring_in = 1;
|
||||
send_ringing(token);
|
||||
return 1;
|
||||
}
|
||||
@ -155,7 +166,8 @@ static int remote_call(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigne
|
||||
static int remote_ringing(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
struct call *call=find_call(token);
|
||||
if (call){
|
||||
printf("Ringing\n");
|
||||
fflush(stdout);
|
||||
}else
|
||||
@ -166,7 +178,8 @@ static int remote_ringing(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsi
|
||||
static int remote_pickup(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
struct call *call=find_call(token);
|
||||
if (call){
|
||||
printf("Picked up\n");
|
||||
fflush(stdout);
|
||||
}else
|
||||
@ -177,23 +190,30 @@ static int remote_pickup(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsig
|
||||
static int remote_dialing(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == -1){
|
||||
call_token=token;
|
||||
seen_audio=0;
|
||||
printf("Dialling\n");
|
||||
fflush(stdout);
|
||||
}else
|
||||
send_hangup(token);
|
||||
struct call *call=emalloc_zero(sizeof(struct call));
|
||||
call->token = token;
|
||||
call->_next = calls;
|
||||
calls = call;
|
||||
printf("Dialling\n");
|
||||
fflush(stdout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_hangup(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
printf("Call ended\n");
|
||||
fflush(stdout);
|
||||
call_token=-1;
|
||||
|
||||
struct call **call=&calls;
|
||||
while(*call){
|
||||
if ((*call)->token == token){
|
||||
printf("Call ended\n");
|
||||
fflush(stdout);
|
||||
struct call *p=*call;
|
||||
call = &p->_next;
|
||||
free(p);
|
||||
}else{
|
||||
call = &(*call)->_next;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -201,7 +221,9 @@ static int remote_hangup(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsig
|
||||
static int remote_audio(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
|
||||
struct call *call=find_call(token);
|
||||
if (call){
|
||||
int codec = strtol(argv[1], NULL, 10);
|
||||
// int start_time = strtol(argv[2], NULL, 10);
|
||||
// int sequence = strtol(argv[3], NULL, 10);
|
||||
@ -223,7 +245,8 @@ static int remote_audio(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsign
|
||||
static int remote_codecs(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
struct call *call=find_call(token);
|
||||
if (call){
|
||||
int i;
|
||||
printf("Codec list");
|
||||
for (i=1;i<argc;i++)
|
||||
@ -272,11 +295,6 @@ struct monitor_command_handler console_handlers[]={
|
||||
|
||||
static int console_dial(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token!=-1){
|
||||
printf("Already in a call\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
const char *sid = parsed->args[1];
|
||||
const char *local = parsed->argc >= 3 ? parsed->args[2] : "";
|
||||
const char *remote = parsed->argc >= 4 ? parsed->args[3] : "";
|
||||
@ -286,21 +304,28 @@ static int console_dial(const struct cli_parsed *parsed, struct cli_context *UNU
|
||||
|
||||
static int console_answer(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token==-1){
|
||||
printf("No active call to answer\n");
|
||||
fflush(stdout);
|
||||
}else
|
||||
send_pickup(call_token);
|
||||
struct call *call = calls;
|
||||
while(call){
|
||||
if (call->ring_in){
|
||||
send_pickup(call->token);
|
||||
call->ring_in = 0;
|
||||
return 0;
|
||||
}
|
||||
call = call->_next;
|
||||
}
|
||||
printf("No ringing call to answer\n");
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int console_hangup(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token==-1){
|
||||
if (calls){
|
||||
send_hangup(calls->token);
|
||||
}else{
|
||||
printf("No call to hangup\n");
|
||||
fflush(stdout);
|
||||
}else
|
||||
send_hangup(call_token);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -318,7 +343,7 @@ static int console_quit(const struct cli_parsed *UNUSED(parsed), struct cli_cont
|
||||
|
||||
static int console_audio(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token==-1){
|
||||
if (!calls){
|
||||
printf("No active call\n");
|
||||
fflush(stdout);
|
||||
}else{
|
||||
@ -335,7 +360,7 @@ static int console_audio(const struct cli_parsed *parsed, struct cli_context *UN
|
||||
strbuf_puts(&str_buf, "NULL");
|
||||
}
|
||||
|
||||
send_audio(call_token, (unsigned char *)strbuf_str(&str_buf), strbuf_len(&str_buf), VOMP_CODEC_TEXT);
|
||||
send_audio(calls->token, (unsigned char *)strbuf_str(&str_buf), strbuf_len(&str_buf), VOMP_CODEC_TEXT);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user