annotate mtctest/main.c @ 8:a902ccbf6bbc

mtctest: introduce general user command structure
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 02:48:55 +0000
parents 33d8b3177540
children 395c56969bc4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Main module for ThemWi test MT call generator.
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/time.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/errno.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <syslog.h>
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <unistd.h>
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
13 #include <themwi/rtp/rtp_alloc_simple.h>
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int mtc_socket;
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
16 extern struct rtp_alloc_simple rtp_info;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 struct timeval cur_event_time;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 main(argc, argv)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char **argv;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int optind;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern char *optarg;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char *from;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 fd_set fds;
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
27 int c, max_fd;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 from = 0;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 while ((c = getopt(argc, argv, "f:")) != EOF) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 switch (c) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case 'f':
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 from = optarg;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 continue;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 default:
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 usage:
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fprintf(stderr,
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 "usage: %s [-f from-number] to-number\n",
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 argv[0]);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 exit(1);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (argc != optind + 1)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 goto usage;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 openlog("themwi-test-mtc", 0, LOG_LOCAL5);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 init_setup_msg(from, argv[optind]);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
47 obtain_rtp_endp();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 connect_mtc_socket();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 send_setup_msg();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 /* main select loop */
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
51 max_fd = mtc_socket;
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
52 if (rtp_info.gsm_rtp_fd > mtc_socket)
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
53 max_fd = rtp_info.gsm_rtp_fd;
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
54 if (rtp_info.gsm_rtcp_fd > mtc_socket)
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
55 max_fd = rtp_info.gsm_rtcp_fd;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 for (;;) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 FD_ZERO(&fds);
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
58 FD_SET(0, &fds);
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 FD_SET(mtc_socket, &fds);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
60 FD_SET(rtp_info.gsm_rtp_fd, &fds);
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
61 FD_SET(rtp_info.gsm_rtcp_fd, &fds);
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
62 c = select(max_fd+1, &fds, 0, 0, 0);
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (c < 0) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (errno == EINTR)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 continue;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 perror("select");
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 exit(1);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 gettimeofday(&cur_event_time, 0);
8
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
70 if (FD_ISSET(0, &fds))
a902ccbf6bbc mtctest: introduce general user command structure
Mychaela Falconia <falcon@freecalypso.org>
parents: 6
diff changeset
71 select_stdin();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (FD_ISSET(mtc_socket, &fds))
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 mtc_socket_select();
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
74 if (FD_ISSET(rtp_info.gsm_rtp_fd, &fds))
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
75 rtp_rx_select();
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
76 if (FD_ISSET(rtp_info.gsm_rtcp_fd, &fds))
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
77 rtcp_rx_select();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }