FreeCalypso > hg > themwi-system-sw
annotate mtctest/main.c @ 184:f8c40090a0a8
librtpalloc: new library for talking to themwi-rtp-mgr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Mar 2023 23:48:14 -0800 |
parents | c8e9b295e88f |
children |
rev | line source |
---|---|
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Main module for ThemWi test MT call generator. |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
159
c8e9b295e88f
mtctest: add time reporting for DTMF events
Mychaela Falconia <falcon@freecalypso.org>
parents:
37
diff
changeset
|
6 #include <sys/time.h> |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/errno.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <syslog.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <unistd.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int mtc_socket; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int disconnect_mode; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
159
c8e9b295e88f
mtctest: add time reporting for DTMF events
Mychaela Falconia <falcon@freecalypso.org>
parents:
37
diff
changeset
|
17 struct timeval cur_event_time; |
c8e9b295e88f
mtctest: add time reporting for DTMF events
Mychaela Falconia <falcon@freecalypso.org>
parents:
37
diff
changeset
|
18 |
37
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
19 static void |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
20 drain_stdin() |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
21 { |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
22 char buf[256]; |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
23 |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
24 read(0, buf, sizeof buf); |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
25 } |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
26 |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 main(argc, argv) |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 char **argv; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 extern int optind; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 extern char *optarg; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 char *from; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fd_set fds; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 int c; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 from = 0; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 while ((c = getopt(argc, argv, "f:")) != EOF) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 switch (c) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case 'f': |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 from = optarg; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 continue; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 default: |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 usage: |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fprintf(stderr, |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 "usage: %s [-f from-number] to-number\n", |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 argv[0]); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (argc != optind + 1) |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 goto usage; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 openlog("themwi-test-mtc", 0, LOG_LOCAL5); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 init_setup_msg(from, argv[optind]); |
36
e8e82a4bf12b
themwi-test-mtc: implement dummy RTP via themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
54 obtain_dummy_rtp(); |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 connect_mtc_socket(); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 send_setup_msg(); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 /* main select loop */ |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 for (;;) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 FD_ZERO(&fds); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 FD_SET(mtc_socket, &fds); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (!disconnect_mode) |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 FD_SET(0, &fds); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 c = select(mtc_socket+1, &fds, 0, 0, 0); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (c < 0) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (errno == EINTR) |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 continue; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 perror("select"); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(1); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
159
c8e9b295e88f
mtctest: add time reporting for DTMF events
Mychaela Falconia <falcon@freecalypso.org>
parents:
37
diff
changeset
|
70 gettimeofday(&cur_event_time, 0); |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (FD_ISSET(mtc_socket, &fds)) |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 mtc_socket_select(); |
37
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
73 if (!disconnect_mode && FD_ISSET(0, &fds)) { |
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
74 drain_stdin(); |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 send_disconnect_req(); |
37
a065b4a62a8a
themwi-test-mtc: drain stdin when we receive input
Mychaela Falconia <falcon@freecalypso.org>
parents:
36
diff
changeset
|
76 } |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |