Jorge E. Moreira | ccd5745 | 2017-09-29 15:19:07 -0700 | [diff] [blame] | 1 | /* |
| 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. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 16 | |
Greg Hartman | a4ff248 | 2017-10-03 16:35:00 -0700 | [diff] [blame^] | 17 | #include <getopt.h> |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 18 | #include <algorithm> |
Greg Hartman | 7075378 | 2017-09-28 16:12:43 -0700 | [diff] [blame] | 19 | #include <string> |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 20 | |
Jorge E. Moreira | ccd5745 | 2017-09-29 15:19:07 -0700 | [diff] [blame] | 21 | #include "host/frontend/vnc_server/vnc_server.h" |
| 22 | |
Greg Hartman | a4ff248 | 2017-10-03 16:35:00 -0700 | [diff] [blame^] | 23 | bool FLAGS_agressive = false; |
| 24 | bool FLAGS_debug = false; |
| 25 | std::string FLAGS_input_socket("/tmp/android-cuttlefish-1-input"); |
| 26 | |
| 27 | bool FLAGS_port = 6444; |
| 28 | |
| 29 | static 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. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 36 | |
| 37 | int main(int argc, char* argv[]) { |
Greg Hartman | a4ff248 | 2017-10-03 16:35:00 -0700 | [diff] [blame^] | 38 | 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 Hartman | ca7fb19 | 2017-09-28 16:14:12 -0700 | [diff] [blame] | 68 | avd::vnc::VncServer vnc_server(FLAGS_port, FLAGS_agressive); |
Jorge E. Moreira | 2430701 | 2017-09-22 14:35:21 -0700 | [diff] [blame] | 69 | vnc_server.MainLoop(); |
| 70 | } |