annotate mtctest/main.c @ 6:33d8b3177540

mtctest compiles in the new environment
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 01:55:28 +0000
parents e7b192a5dee5
children a902ccbf6bbc
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;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern int disconnect_mode;
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
17 extern struct rtp_alloc_simple rtp_info;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct timeval cur_event_time;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static void
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 drain_stdin()
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 char buf[256];
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 read(0, buf, sizeof buf);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
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 main(argc, argv)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char **argv;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 extern int optind;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 extern char *optarg;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char *from;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fd_set fds;
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
36 int c, max_fd;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 from = 0;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 while ((c = getopt(argc, argv, "f:")) != EOF) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 switch (c) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 case 'f':
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 from = optarg;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 continue;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 default:
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 usage:
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr,
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 "usage: %s [-f from-number] to-number\n",
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 argv[0]);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (argc != optind + 1)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 goto usage;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 openlog("themwi-test-mtc", 0, LOG_LOCAL5);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 init_setup_msg(from, argv[optind]);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
56 obtain_rtp_endp();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 connect_mtc_socket();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 send_setup_msg();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* main select loop */
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
60 max_fd = mtc_socket;
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
61 if (rtp_info.gsm_rtp_fd > mtc_socket)
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
62 max_fd = rtp_info.gsm_rtp_fd;
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
63 if (rtp_info.gsm_rtcp_fd > mtc_socket)
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
64 max_fd = rtp_info.gsm_rtcp_fd;
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 for (;;) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 FD_ZERO(&fds);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 FD_SET(mtc_socket, &fds);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
68 FD_SET(rtp_info.gsm_rtp_fd, &fds);
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
69 FD_SET(rtp_info.gsm_rtcp_fd, &fds);
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!disconnect_mode)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 FD_SET(0, &fds);
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
72 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
73 if (c < 0) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (errno == EINTR)
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 continue;
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 perror("select");
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 exit(1);
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 gettimeofday(&cur_event_time, 0);
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (FD_ISSET(mtc_socket, &fds))
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 mtc_socket_select();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (!disconnect_mode && FD_ISSET(0, &fds)) {
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 drain_stdin();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 send_disconnect_req();
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
6
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
86 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
87 rtp_rx_select();
33d8b3177540 mtctest compiles in the new environment
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
88 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
89 rtcp_rx_select();
5
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
e7b192a5dee5 mtctest: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }