blob: 7070848e0156e4382df36d4ec5bfb480dcd7e338 [file] [log] [blame]
Jorge E. Moreiraccd57452017-09-29 15:19:07 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jorge E. Moreira24307012017-09-22 14:35:21 -070016
Greg Hartmana4ff2482017-10-03 16:35:00 -070017#include <getopt.h>
Jorge E. Moreira24307012017-09-22 14:35:21 -070018#include <algorithm>
Greg Hartman70753782017-09-28 16:12:43 -070019#include <string>
Jorge E. Moreira24307012017-09-22 14:35:21 -070020
Jorge E. Moreiraccd57452017-09-29 15:19:07 -070021#include "host/frontend/vnc_server/vnc_server.h"
22
Greg Hartmana4ff2482017-10-03 16:35:00 -070023bool FLAGS_agressive = false;
24bool FLAGS_debug = false;
25std::string FLAGS_input_socket("/tmp/android-cuttlefish-1-input");
26
27bool FLAGS_port = 6444;
28
29static struct option opts[] = {
30 {"agressive", no_argument, NULL, 'a'},
31 {"debug", no_argument, NULL, 'd'},
32 {"input_socket", required_argument, NULL, 'i'},
33 {"port", required_argument, NULL, 'p'},
34 {0, 0, 0, 0}
35};
Jorge E. Moreira24307012017-09-22 14:35:21 -070036
37int main(int argc, char* argv[]) {
Greg Hartmana4ff2482017-10-03 16:35:00 -070038 using ::android::base::ERROR;
39 ::android::base::InitLogging(argv, android::base::StderrLogger);
40 long port = -1;
41 char *endp = NULL;
42 bool error = false;
43 char c;
44 while ((c = getopt_long(argc, argv, "", opts, nullptr)) != -1) {
45 switch(c) {
46 case 'a':
47 FLAGS_agressive = true;
48 break;
49 case 'd':
50 FLAGS_debug = true;
51 break;
52 case 'i':
53 FLAGS_input_socket = optarg;
54 break;
55 case 'p':
56 port = strtol(optarg, &endp, 10);
57 if (*endp || (port <= 0) || (port > 65536)) {
58 LOG(ERROR) << "Port must be an integer > 0 and < 65536";
59 error = true;
60 }
61 FLAGS_port = port;
62 break;
63 }
64 }
65 if (error) {
66 exit(2);
67 }
Greg Hartmanca7fb192017-09-28 16:14:12 -070068 avd::vnc::VncServer vnc_server(FLAGS_port, FLAGS_agressive);
Jorge E. Moreira24307012017-09-22 14:35:21 -070069 vnc_server.MainLoop();
70}