# HG changeset patch # User Mychaela Falconia # Date 1717901335 0 # Node ID a902ccbf6bbc5e4c9fca6abefb297a8b2b8d3e30 # Parent d0b86b1445770bbb5eedfbc7b8146b4aedc387e6 mtctest: introduce general user command structure diff -r d0b86b144577 -r a902ccbf6bbc mtctest/Makefile --- 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 diff -r d0b86b144577 -r a902ccbf6bbc mtctest/disconnect.c --- 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(); +} diff -r d0b86b144577 -r a902ccbf6bbc mtctest/main.c --- 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 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)) diff -r d0b86b144577 -r a902ccbf6bbc mtctest/user_cmd.c --- /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 +#include +#include +#include +#include + +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"); +}