blob: 19642af9a9bdb721097ef3c0678654b30c7f8476 [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
Jammy Huanga4f63b32022-02-14 14:43:21 +080011Args::Args(int argc, char* argv[]) : frameRate(30), subsampling(0), calcFrameCRC{false},
Paul Fertser2d2f3da2021-06-18 11:16:43 +000012 commandLine(argc, argv)
Eddie James9d7ff842018-12-11 12:54:35 -060013{
14 int option;
Jammy Huanga4f63b32022-02-14 14:43:21 +080015 const char* opts = "f:s:h:k:p:v:c";
Eddie James9d7ff842018-12-11 12:54:35 -060016 struct option lopts[] = {{"frameRate", 1, 0, 'f'},
Jammy Huanga4f63b32022-02-14 14:43:21 +080017 {"subsampling", 1, 0, 's'},
Eddie James9d7ff842018-12-11 12:54:35 -060018 {"help", 0, 0, 'h'},
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080019 {"keyboard", 1, 0, 'k'},
20 {"mouse", 1, 0, 'p'},
Eddie James9d7ff842018-12-11 12:54:35 -060021 {"videoDevice", 1, 0, 'v'},
Paul Fertser2d2f3da2021-06-18 11:16:43 +000022 {"calcCRC", 0, 0, 'c'},
Eddie James9d7ff842018-12-11 12:54:35 -060023 {0, 0, 0, 0}};
24
25 while ((option = getopt_long(argc, argv, opts, lopts, NULL)) != -1)
26 {
27 switch (option)
28 {
29 case 'f':
30 frameRate = (int)strtol(optarg, NULL, 0);
31 if (frameRate < 0 || frameRate > 60)
32 frameRate = 30;
33 break;
Jammy Huanga4f63b32022-02-14 14:43:21 +080034 case 's':
35 subsampling = (int)strtol(optarg, NULL, 0);
36 if (subsampling < 0 || subsampling > 1)
37 subsampling = 0;
38 break;
Eddie James9d7ff842018-12-11 12:54:35 -060039 case 'h':
40 printUsage();
41 exit(0);
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080042 case 'k':
43 keyboardPath = std::string(optarg);
44 break;
45 case 'p':
46 pointerPath = std::string(optarg);
Eddie James9d7ff842018-12-11 12:54:35 -060047 break;
48 case 'v':
49 videoPath = std::string(optarg);
50 break;
Paul Fertser2d2f3da2021-06-18 11:16:43 +000051 case 'c':
52 calcFrameCRC = true;
53 break;
Eddie James9d7ff842018-12-11 12:54:35 -060054 }
55 }
56}
57
58void Args::printUsage()
59{
60 // use fprintf(stderr to match rfbUsage()
61 fprintf(stderr, "OpenBMC IKVM daemon\n");
62 fprintf(stderr, "Usage: obmc-ikvm [options]\n");
63 fprintf(stderr, "-f frame rate try this frame rate\n");
Jammy Huanga4f63b32022-02-14 14:43:21 +080064 fprintf(stderr, "-s subsampling try this subsampling\n");
Eddie James9d7ff842018-12-11 12:54:35 -060065 fprintf(stderr, "-h, --help show this message and exit\n");
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080066 fprintf(stderr, "-k device HID keyboard gadget device\n");
67 fprintf(stderr, "-p device HID mouse gadget device\n");
Eddie James9d7ff842018-12-11 12:54:35 -060068 fprintf(stderr, "-v device V4L2 device\n");
Paul Fertser2d2f3da2021-06-18 11:16:43 +000069 fprintf(stderr, "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
Eddie James9d7ff842018-12-11 12:54:35 -060070 rfbUsage();
71}
72
73} // namespace ikvm