blob: 681a9f8e26b42fd28d3d4df35b75d91e1271b62e [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{
George Liuf79f6f52022-07-06 09:32:35 +080010Args::Args(int argc, char* argv[]) :
11 frameRate(30), subsampling(0), calcFrameCRC{false}, commandLine(argc, argv)
Eddie James9d7ff842018-12-11 12:54:35 -060012{
13 int option;
Marvin Linfe685fb2022-10-25 16:20:08 +080014 const char* opts = "f:s:h:k:p:u:v:c";
15 struct option lopts[] = {{"frameRate", 1, 0, 'f'},
16 {"subsampling", 1, 0, 's'},
17 {"help", 0, 0, 'h'},
18 {"keyboard", 1, 0, 'k'},
19 {"mouse", 1, 0, 'p'},
20 {"udcName", 1, 0, 'u'},
21 {"videoDevice", 1, 0, 'v'},
22 {"calcCRC", 0, 0, 'c'},
23 {0, 0, 0, 0}};
Eddie James9d7ff842018-12-11 12:54:35 -060024
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;
Marvin Linfe685fb2022-10-25 16:20:08 +080048 case 'u':
49 udcName = std::string(optarg);
50 break;
Eddie James9d7ff842018-12-11 12:54:35 -060051 case 'v':
52 videoPath = std::string(optarg);
53 break;
Paul Fertser2d2f3da2021-06-18 11:16:43 +000054 case 'c':
55 calcFrameCRC = true;
56 break;
Eddie James9d7ff842018-12-11 12:54:35 -060057 }
58 }
59}
60
61void Args::printUsage()
62{
63 // use fprintf(stderr to match rfbUsage()
64 fprintf(stderr, "OpenBMC IKVM daemon\n");
65 fprintf(stderr, "Usage: obmc-ikvm [options]\n");
66 fprintf(stderr, "-f frame rate try this frame rate\n");
Jammy Huanga4f63b32022-02-14 14:43:21 +080067 fprintf(stderr, "-s subsampling try this subsampling\n");
Eddie James9d7ff842018-12-11 12:54:35 -060068 fprintf(stderr, "-h, --help show this message and exit\n");
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080069 fprintf(stderr, "-k device HID keyboard gadget device\n");
70 fprintf(stderr, "-p device HID mouse gadget device\n");
Marvin Linfe685fb2022-10-25 16:20:08 +080071 fprintf(stderr,
72 "-u udc name UDC that HID gadget will connect to\n");
Eddie James9d7ff842018-12-11 12:54:35 -060073 fprintf(stderr, "-v device V4L2 device\n");
George Liuf79f6f52022-07-06 09:32:35 +080074 fprintf(
75 stderr,
76 "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
Eddie James9d7ff842018-12-11 12:54:35 -060077 rfbUsage();
78}
79
80} // namespace ikvm