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