blob: 7e824dc9cf448cdb6d266d8e9e17937dda93c544 [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";
Patrick Williams94f5f422024-08-16 15:22:08 -040015 struct option lopts[] = {
16 {"frameRate", 1, 0, 'f'},
17 {"subsampling", 1, 0, 's'},
18 {"help", 0, 0, 'h'},
19 {"keyboard", 1, 0, 'k'},
20 {"mouse", 1, 0, 'p'},
21 {"udcName", 1, 0, 'u'},
22 {"videoDevice", 1, 0, 'v'},
23 {"calcCRC", 0, 0, 'c'},
24 {0, 0, 0, 0}};
Eddie James9d7ff842018-12-11 12:54:35 -060025
26 while ((option = getopt_long(argc, argv, opts, lopts, NULL)) != -1)
27 {
28 switch (option)
29 {
30 case 'f':
31 frameRate = (int)strtol(optarg, NULL, 0);
32 if (frameRate < 0 || frameRate > 60)
33 frameRate = 30;
34 break;
Jammy Huanga4f63b32022-02-14 14:43:21 +080035 case 's':
36 subsampling = (int)strtol(optarg, NULL, 0);
37 if (subsampling < 0 || subsampling > 1)
38 subsampling = 0;
39 break;
Eddie James9d7ff842018-12-11 12:54:35 -060040 case 'h':
41 printUsage();
42 exit(0);
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080043 case 'k':
44 keyboardPath = std::string(optarg);
45 break;
46 case 'p':
47 pointerPath = std::string(optarg);
Eddie James9d7ff842018-12-11 12:54:35 -060048 break;
Marvin Linfe685fb2022-10-25 16:20:08 +080049 case 'u':
50 udcName = std::string(optarg);
51 break;
Eddie James9d7ff842018-12-11 12:54:35 -060052 case 'v':
53 videoPath = std::string(optarg);
54 break;
Paul Fertser2d2f3da2021-06-18 11:16:43 +000055 case 'c':
56 calcFrameCRC = true;
57 break;
Eddie James9d7ff842018-12-11 12:54:35 -060058 }
59 }
60}
61
62void Args::printUsage()
63{
64 // use fprintf(stderr to match rfbUsage()
65 fprintf(stderr, "OpenBMC IKVM daemon\n");
66 fprintf(stderr, "Usage: obmc-ikvm [options]\n");
67 fprintf(stderr, "-f frame rate try this frame rate\n");
Jammy Huanga4f63b32022-02-14 14:43:21 +080068 fprintf(stderr, "-s subsampling try this subsampling\n");
Eddie James9d7ff842018-12-11 12:54:35 -060069 fprintf(stderr, "-h, --help show this message and exit\n");
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080070 fprintf(stderr, "-k device HID keyboard gadget device\n");
71 fprintf(stderr, "-p device HID mouse gadget device\n");
Marvin Linfe685fb2022-10-25 16:20:08 +080072 fprintf(stderr,
73 "-u udc name UDC that HID gadget will connect to\n");
Eddie James9d7ff842018-12-11 12:54:35 -060074 fprintf(stderr, "-v device V4L2 device\n");
George Liuf79f6f52022-07-06 09:32:35 +080075 fprintf(
76 stderr,
77 "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
Eddie James9d7ff842018-12-11 12:54:35 -060078 rfbUsage();
79}
80
81} // namespace ikvm