blob: f9401acb3f62d3e66e24089b5454892e6cdc5176 [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
George Liuf79f6f52022-07-06 09:32:35 +080011Args::Args(int argc, char* argv[]) :
12 frameRate(30), subsampling(0), calcFrameCRC{false}, 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";
George Liuf79f6f52022-07-06 09:32:35 +080016 struct option lopts[] = {
17 {"frameRate", 1, 0, 'f'}, {"subsampling", 1, 0, 's'},
18 {"help", 0, 0, 'h'}, {"keyboard", 1, 0, 'k'},
19 {"mouse", 1, 0, 'p'}, {"videoDevice", 1, 0, 'v'},
20 {"calcCRC", 0, 0, 'c'}, {0, 0, 0, 0}};
Eddie James9d7ff842018-12-11 12:54:35 -060021
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;
Jammy Huanga4f63b32022-02-14 14:43:21 +080031 case 's':
32 subsampling = (int)strtol(optarg, NULL, 0);
33 if (subsampling < 0 || subsampling > 1)
34 subsampling = 0;
35 break;
Eddie James9d7ff842018-12-11 12:54:35 -060036 case 'h':
37 printUsage();
38 exit(0);
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080039 case 'k':
40 keyboardPath = std::string(optarg);
41 break;
42 case 'p':
43 pointerPath = std::string(optarg);
Eddie James9d7ff842018-12-11 12:54:35 -060044 break;
45 case 'v':
46 videoPath = std::string(optarg);
47 break;
Paul Fertser2d2f3da2021-06-18 11:16:43 +000048 case 'c':
49 calcFrameCRC = true;
50 break;
Eddie James9d7ff842018-12-11 12:54:35 -060051 }
52 }
53}
54
55void Args::printUsage()
56{
57 // use fprintf(stderr to match rfbUsage()
58 fprintf(stderr, "OpenBMC IKVM daemon\n");
59 fprintf(stderr, "Usage: obmc-ikvm [options]\n");
60 fprintf(stderr, "-f frame rate try this frame rate\n");
Jammy Huanga4f63b32022-02-14 14:43:21 +080061 fprintf(stderr, "-s subsampling try this subsampling\n");
Eddie James9d7ff842018-12-11 12:54:35 -060062 fprintf(stderr, "-h, --help show this message and exit\n");
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080063 fprintf(stderr, "-k device HID keyboard gadget device\n");
64 fprintf(stderr, "-p device HID mouse gadget device\n");
Eddie James9d7ff842018-12-11 12:54:35 -060065 fprintf(stderr, "-v device V4L2 device\n");
George Liuf79f6f52022-07-06 09:32:35 +080066 fprintf(
67 stderr,
68 "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n");
Eddie James9d7ff842018-12-11 12:54:35 -060069 rfbUsage();
70}
71
72} // namespace ikvm