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 | |
| 11 | Args::Args(int argc, char* argv[]) : frameRate(30), commandLine(argc, argv) |
| 12 | { |
| 13 | int option; |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 14 | const char* opts = "f:h:k:p:v:"; |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 15 | struct option lopts[] = {{"frameRate", 1, 0, 'f'}, |
| 16 | {"help", 0, 0, 'h'}, |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 17 | {"keyboard", 1, 0, 'k'}, |
| 18 | {"mouse", 1, 0, 'p'}, |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 19 | {"videoDevice", 1, 0, 'v'}, |
| 20 | {0, 0, 0, 0}}; |
| 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; |
| 31 | case 'h': |
| 32 | printUsage(); |
| 33 | exit(0); |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 34 | case 'k': |
| 35 | keyboardPath = std::string(optarg); |
| 36 | break; |
| 37 | case 'p': |
| 38 | pointerPath = std::string(optarg); |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 39 | break; |
| 40 | case 'v': |
| 41 | videoPath = std::string(optarg); |
| 42 | break; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void Args::printUsage() |
| 48 | { |
| 49 | // use fprintf(stderr to match rfbUsage() |
| 50 | fprintf(stderr, "OpenBMC IKVM daemon\n"); |
| 51 | fprintf(stderr, "Usage: obmc-ikvm [options]\n"); |
| 52 | fprintf(stderr, "-f frame rate try this frame rate\n"); |
| 53 | fprintf(stderr, "-h, --help show this message and exit\n"); |
Jae Hyun Yoo | 7dfac9f | 2019-01-15 10:14:59 -0800 | [diff] [blame] | 54 | fprintf(stderr, "-k device HID keyboard gadget device\n"); |
| 55 | fprintf(stderr, "-p device HID mouse gadget device\n"); |
Eddie James | 9d7ff84 | 2018-12-11 12:54:35 -0600 | [diff] [blame] | 56 | fprintf(stderr, "-v device V4L2 device\n"); |
| 57 | rfbUsage(); |
| 58 | } |
| 59 | |
| 60 | } // namespace ikvm |