forked from fajran/tongseng
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·97 lines (80 loc) · 1.85 KB
/
main.cpp
File metadata and controls
executable file
·97 lines (80 loc) · 1.85 KB
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
#include "tongsengmod.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 = 57120;
static int deviceIndex = 0; //Hopefully, 0 for internal, 1 for external
static void show_help()
{
std::cout << "Usage: tongsengmod [options] [host] [port] [device index]" << std::endl;
std::cout << " -v verbose" << std::endl;
std::cout << " -h show help" << std::endl;
}
static void stop(int param)
{
running = false;
}
static void init(int argc, char** argv)
{
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;
opterr = 0;
while ((c = getopt(argc, argv, "v")) != -1) {
switch (c) {
case 'v':
verbose = true;
break;
case 'h':
show_help();
exit(0);
default:
show_help();
exit(1);
}
}
for (index=optind, c=0; index < argc; index++, c++) {
switch (c) {
case 0:
host = argv[index];
break;
case 1:
port = atoi(argv[index]);
break;
case 2: //last arg is device index. 0 for internal, 1 for external.
deviceIndex = atoi(argv[index]);
break;
default:
break;
}
}
}
int main(int argc, char** argv)
{
init(argc, argv);
std::cout << "Host: " << host << std::endl;
std::cout << "Port: " << port << std::endl;
std::cout << "Verbose: " << verbose << std::endl;
std::cout << "(with external trackpad support)" << std::endl;
signal(SIGINT, stop);
signal(SIGHUP, stop);
signal(SIGQUIT, stop);
signal(SIGTERM, stop);
tongseng_set_hostname_and_port(host.c_str(), port);
tongseng_set_verbose(verbose);
tongseng_start(deviceIndex);
// Loop until the program is stopped.
running = true;
while (running) {
usleep(1000);
};
std::cout << "Cleaning up.." << std::endl;
tongseng_stop();
std::cout << "Tongsengmod stopped." << std::endl;
return 0;
}