blob: ad5b4f79ab7a548fb493b90321a400ddf83b3fdd [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
11Args::Args(int argc, char* argv[]) : frameRate(30), commandLine(argc, argv)
12{
13 int option;
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080014 const char* opts = "f:h:k:p:v:";
Eddie James9d7ff842018-12-11 12:54:35 -060015 struct option lopts[] = {{"frameRate", 1, 0, 'f'},
16 {"help", 0, 0, 'h'},
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080017 {"keyboard", 1, 0, 'k'},
18 {"mouse", 1, 0, 'p'},
Eddie James9d7ff842018-12-11 12:54:35 -060019 {"videoDevice", 1, 0, 'v'},
20 {0, 0, 0, 0}};
21
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;
31 case 'h':
32 printUsage();
33 exit(0);
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080034 case 'k':
35 keyboardPath = std::string(optarg);
36 break;
37 case 'p':
38 pointerPath = std::string(optarg);
Eddie James9d7ff842018-12-11 12:54:35 -060039 break;
40 case 'v':
41 videoPath = std::string(optarg);
42 break;
43 }
44 }
45}
46
47void Args::printUsage()
48{
49 // use fprintf(stderr to match rfbUsage()
50 fprintf(stderr, "OpenBMC IKVM daemon\n");
51 fprintf(stderr, "Usage: obmc-ikvm [options]\n");
52 fprintf(stderr, "-f frame rate try this frame rate\n");
53 fprintf(stderr, "-h, --help show this message and exit\n");
Jae Hyun Yoo7dfac9f2019-01-15 10:14:59 -080054 fprintf(stderr, "-k device HID keyboard gadget device\n");
55 fprintf(stderr, "-p device HID mouse gadget device\n");
Eddie James9d7ff842018-12-11 12:54:35 -060056 fprintf(stderr, "-v device V4L2 device\n");
57 rfbUsage();
58}
59
60} // namespace ikvm