Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 1 | #include "ikvm_args.hpp" |
| 2 | |
| 3 | #include <getopt.h> |
| 4 | #include <rfb/rfb.h> |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | |
| 8 | namespace ikvm |
| 9 | { |
George Liu | f79f6f5 | 2022-07-06 09:32:35 +0800 | [diff] [blame] | 10 | Args::Args(int argc, char* argv[]) : |
| 11 | frameRate(30), subsampling(0), calcFrameCRC{false}, commandLine(argc, argv) |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 12 | { |
| 13 | int option; |
Marvin Lin | fe685fb | 2022-10-25 16:20:08 +0800 | [diff] [blame] | 14 | const char* opts = "f:s:h:k:p:u:v:c"; |
Patrick Williams | 94f5f42 | 2024-08-16 15:22:08 -0400 | [diff] [blame] | 15 | struct option lopts[] = { |
| 16 | {"frameRate", 1, 0, 'f'}, |
| 17 | {"subsampling", 1, 0, 's'}, |
| 18 | {"help", 0, 0, 'h'}, |
| 19 | {"keyboard", 1, 0, 'k'}, |
| 20 | {"mouse", 1, 0, 'p'}, |
| 21 | {"udcName", 1, 0, 'u'}, |
| 22 | {"videoDevice", 1, 0, 'v'}, |
| 23 | {"calcCRC", 0, 0, 'c'}, |
| 24 | {0, 0, 0, 0}}; |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 25 | |
| 26 | while ((option = getopt_long(argc, argv, opts, lopts, NULL)) != -1) |
| 27 | { |
| 28 | switch (option) |
| 29 | { |
| 30 | case 'f': |
| 31 | frameRate = (int)strtol(optarg, NULL, 0); |
| 32 | if (frameRate < 0 || frameRate > 60) |
| 33 | frameRate = 30; |
| 34 | break; |
Jammy Huang | a4f63b3 | 2022-02-14 14:43:21 +0800 | [diff] [blame] | 35 | case 's': |
| 36 | subsampling = (int)strtol(optarg, NULL, 0); |
| 37 | if (subsampling < 0 || subsampling > 1) |
| 38 | subsampling = 0; |
| 39 | break; |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 40 | case 'h': |
| 41 | printUsage(); |
| 42 | exit(0); |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 43 | case 'k': |
| 44 | keyboardPath = std::string(optarg); |
| 45 | break; |
| 46 | case 'p': |
| 47 | pointerPath = std::string(optarg); |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 48 | break; |
Marvin Lin | fe685fb | 2022-10-25 16:20:08 +0800 | [diff] [blame] | 49 | case 'u': |
| 50 | udcName = std::string(optarg); |
| 51 | break; |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 52 | case 'v': |
| 53 | videoPath = std::string(optarg); |
| 54 | break; |
Paul Fertser | 2d2f3da | 2021-06-18 11:16:43 +0000 | [diff] [blame] | 55 | case 'c': |
| 56 | calcFrameCRC = true; |
| 57 | break; |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void Args::printUsage() |
| 63 | { |
| 64 | // use fprintf(stderr to match rfbUsage() |
| 65 | fprintf(stderr, "OpenBMC IKVM daemon\n"); |
| 66 | fprintf(stderr, "Usage: obmc-ikvm [options]\n"); |
| 67 | fprintf(stderr, "-f frame rate try this frame rate\n"); |
Jammy Huang | a4f63b3 | 2022-02-14 14:43:21 +0800 | [diff] [blame] | 68 | fprintf(stderr, "-s subsampling try this subsampling\n"); |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 69 | fprintf(stderr, "-h, --help show this message and exit\n"); |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 70 | fprintf(stderr, "-k device HID keyboard gadget device\n"); |
| 71 | fprintf(stderr, "-p device HID mouse gadget device\n"); |
Marvin Lin | fe685fb | 2022-10-25 16:20:08 +0800 | [diff] [blame] | 72 | fprintf(stderr, |
| 73 | "-u udc name UDC that HID gadget will connect to\n"); |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 74 | fprintf(stderr, "-v device V4L2 device\n"); |
George Liu | f79f6f5 | 2022-07-06 09:32:35 +0800 | [diff] [blame] | 75 | fprintf( |
| 76 | stderr, |
| 77 | "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n"); |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 78 | rfbUsage(); |
| 79 | } |
| 80 | |
| 81 | } // namespace ikvm |