FreeCalypso > hg > themwi-interim
changeset 8:a902ccbf6bbc
mtctest: introduce general user command structure
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 09 Jun 2024 02:48:55 +0000 |
parents | d0b86b144577 |
children | 0ec938ed530b |
files | mtctest/Makefile mtctest/disconnect.c mtctest/main.c mtctest/user_cmd.c |
diffstat | 4 files changed, 49 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mtctest/Makefile Sun Jun 09 01:56:27 2024 +0000 +++ b/mtctest/Makefile Sun Jun 09 02:48:55 2024 +0000 @@ -1,6 +1,7 @@ CPPFLAGS=-I${includedir} PROG= themwi-test-mtc -OBJS= disconnect.o main.o rtp_sink.o setup.o sig_handler.o sock_conn.o +OBJS= disconnect.o main.o rtp_sink.o setup.o sig_handler.o sock_conn.o \ + user_cmd.o LIBUTIL=../libutil/libutil.a include ../config.defs
--- a/mtctest/disconnect.c Sun Jun 09 01:56:27 2024 +0000 +++ b/mtctest/disconnect.c Sun Jun 09 02:48:55 2024 +0000 @@ -18,6 +18,7 @@ int disconnect_mode; +void send_disconnect_req() { struct gsm_mncc msg; @@ -31,3 +32,13 @@ send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc)); disconnect_mode = 1; } + +void +disconnect_command() +{ + if (disconnect_mode) { + printf("Already in disconnect mode, command ignored\n"); + return; + } + send_disconnect_req(); +}
--- a/mtctest/main.c Sun Jun 09 01:56:27 2024 +0000 +++ b/mtctest/main.c Sun Jun 09 02:48:55 2024 +0000 @@ -13,19 +13,10 @@ #include <themwi/rtp/rtp_alloc_simple.h> extern int mtc_socket; -extern int disconnect_mode; extern struct rtp_alloc_simple rtp_info; struct timeval cur_event_time; -static void -drain_stdin() -{ - char buf[256]; - - read(0, buf, sizeof buf); -} - main(argc, argv) char **argv; { @@ -64,11 +55,10 @@ max_fd = rtp_info.gsm_rtcp_fd; for (;;) { FD_ZERO(&fds); + FD_SET(0, &fds); FD_SET(mtc_socket, &fds); FD_SET(rtp_info.gsm_rtp_fd, &fds); FD_SET(rtp_info.gsm_rtcp_fd, &fds); - if (!disconnect_mode) - FD_SET(0, &fds); c = select(max_fd+1, &fds, 0, 0, 0); if (c < 0) { if (errno == EINTR) @@ -77,12 +67,10 @@ exit(1); } gettimeofday(&cur_event_time, 0); + if (FD_ISSET(0, &fds)) + select_stdin(); if (FD_ISSET(mtc_socket, &fds)) mtc_socket_select(); - if (!disconnect_mode && FD_ISSET(0, &fds)) { - drain_stdin(); - send_disconnect_req(); - } if (FD_ISSET(rtp_info.gsm_rtp_fd, &fds)) rtp_rx_select(); if (FD_ISSET(rtp_info.gsm_rtcp_fd, &fds))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mtctest/user_cmd.c Sun Jun 09 02:48:55 2024 +0000 @@ -0,0 +1,33 @@ +/* + * In this module we implement stdin command handling: we start with + * 'disc' command for caller-initiated disconnect, and then we'll add + * play commands for RTP output. + */ + +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +void +select_stdin() +{ + char buf[256], *cp; + + fgets(buf, sizeof buf, stdin); + cp = index(buf, '\n'); + if (cp) { + while (cp > buf && isspace(cp[-1])) + cp--; + *cp = '\0'; + } + for (cp = buf; isspace(*cp); cp++) + ; + if (!*cp) + return; + if (!strcmp(cp, "disc")) + disconnect_command(); + else + fprintf(stderr, "error: non-understood stdin command\n"); +}