blob: 21373aa46b9d9a738a308b5195ae225f2909315a [file] [log] [blame]
Eddie James9d7ff842018-12-11 12:54:35 -06001#include "ikvm_args.hpp"
2
3#include <getopt.h>
4#include <rfb/rfb.h>
5#include <stdio.h>
6#include <stdlib.h>
7
8namespace ikvm
9{
10
Paul Fertser2d2f3da2021-06-18 11:16:43 +000011Args::Args(int argc, char* argv[]) : frameRate(30), calcFrameCRC{false},
12 commandLine(argc, argv)
Eddie James9d7ff842018-12-11 12:54:35 -060013{
14 int option;
Paul Fertser2d2f3da2021-06-18 11:16:43 +000015 const char* opts = "f:h:k:p:v:c";
Eddie James9d7ff842018-12-11 12:54:35 -060016 struct option lopts[] = {{"frameRate", 1, 0, 'f'},
17 {"help", 0, 0, 'h'},
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080018 {"keyboard", 1, 0, 'k'},
19 {"mouse", 1, 0, 'p'},
Eddie James9d7ff842018-12-11 12:54:35 -060020 {"videoDevice", 1, 0, 'v'},
Paul Fertser2d2f3da2021-06-18 11:16:43 +000021 {"calcCRC", 0, 0, 'c'},
Eddie James9d7ff842018-12-11 12:54:35 -060022 {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 Yoo7dfac9f2019-01-15 10:14:59 -080036 case 'k':
37 keyboardPath = std::string(optarg);
38 break;
39 case 'p':
40 pointerPath = std::string(optarg);
Eddie James9d7ff842018-12-11 12:54:35 -060041 break;
42 case 'v':
43 videoPath = std::string(optarg);
44 break;
Paul Fertser2d2f3da2021-06-18 11:16:43 +000045 case 'c':
46 calcFrameCRC = true;
47 break;
Eddie James9d7ff842018-12-11 12:54:35 -060048 }
49 }
50}
51
52void 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 Yoo7dfac9f2019-01-15 10:14:59 -080059 fprintf(stderr, "-k device HID keyboard gadget device\n");
60 fprintf(stderr, "-p device HID mouse gadget device\n");
Eddie James9d7ff842018-12-11 12:54:35 -060061 fprintf(stderr, "-v device V4L2 device\n");
Paul Fertser2d2f3da2021-06-18 11:16:43 +000062 fprintf(stderr, "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
Eddie James9d7ff842018-12-11 12:54:35 -060063 rfbUsage();
64}
65
66} // namespace ikvm