-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.cpp
105 lines (90 loc) · 2.58 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "tongseng.h"
#include <iostream>
#include <signal.h>
#include <unistd.h>
static bool running = false;
static bool verbose = false;
static std::string host("localhost");
static int port = 3333;
static int device = 0;
static void show_help()
{
std::cout << "Usage: tongseng -t [transport] -p [port] -d [device]" << std::endl;
std::cout << " -t [hostname] for remote TUIO/UDP client" << std::endl;
std::cout << " -t TCP for TUIO/TCP" << std::endl;
std::cout << " -t WEB for TUIO/WEB" << std::endl;
std::cout << " -p [port] for alternative port number" << std::endl;
std::cout << " -l list available devices" << std::endl;
std::cout << " -v verbose output" << std::endl;
std::cout << " -h show this help" << std::endl;
}
static void stop(int param)
{
running = false;
}
static void init(int argc, char** argv)
{
char c;
while ((c = getopt(argc, argv, "t:p:d:lvh")) != -1) {
switch (c) {
case 't':
host = std::string(optarg);
break;
case 'p':
port = atoi(optarg);
break;
case 'd':
device = atoi(optarg);
break;
case 'v':
verbose = true;
break;
case 'l':
tongseng_list_devices();
exit(0);
case 'h':
show_help();
exit(0);
/*case '?':
if (optopt == 'n')
fprintf (stderr, "Option -n requires a host name.\n");
if (optopt == 'p')
fprintf (stderr, "Option -p requires a port number.\n");
if (optopt == 'd')
fprintf (stderr, "Option -d requires a device number.\n");
else if (isprint (optopt)) fprintf (stderr, "Unknown option '-%c'.\n", optopt);
else fprintf (stderr, "Unknown option character '\\x%x'.\n", optopt);*/
default:
show_help();
exit(1);
}
}
}
int main(int argc, char** argv)
{
init(argc, argv);
std::cout << "Host: " << host << std::endl;
std::cout << "Port: " << port << std::endl;
std::cout << "Device: " << device << std::endl;
std::cout << "Verbose: " << verbose << std::endl;
std::cout << "Press Ctrl+C to end this program." << std::endl;
signal(SIGINT, stop);
signal(SIGHUP, stop);
signal(SIGQUIT, stop);
signal(SIGTERM, stop);
tongseng_set_hostname_and_port(host.c_str(), port);
if ((host=="TCP") || (host=="tcp")) tongseng_set_protocol(TUIO_TCP);
else if ((host=="WEB") || (host=="web")) tongseng_set_protocol(TUIO_WEB);
tongseng_set_verbose(verbose);
tongseng_set_device(device);
tongseng_start();
// Loop until the program is stopped.
running = true;
while (running) {
usleep(1000);
};
std::cout << "Cleaning up.." << std::endl;
tongseng_stop();
std::cout << "Program stopped." << std::endl;
return 0;
}