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