summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-graphics/obmc-ikvm/obmc-ikvm/ikvm_args.cpp
blob: 2723187dd003a91b1e4ef494f425f1a9f6096634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "ikvm_args.hpp"

#include <getopt.h>
#include <rfb/rfb.h>
#include <stdio.h>
#include <stdlib.h>

namespace ikvm
{

Args::Args(int argc, char* argv[]) : frameRate(30), commandLine(argc, argv)
{
    int option;
    const char* opts = "f:h:k:p:v:";
    struct option lopts[] = {{"frameRate", 1, 0, 'f'},   {"help", 0, 0, 'h'},
                             {"keyboard", 1, 0, 'k'},    {"mouse", 1, 0, 'p'},
                             {"videoDevice", 1, 0, 'v'}, {0, 0, 0, 0}};

    while ((option = getopt_long(argc, argv, opts, lopts, NULL)) != -1)
    {
        switch (option)
        {
            case 'f':
                frameRate = (int)strtol(optarg, NULL, 0);
                if (frameRate < 0 || frameRate > 60)
                    frameRate = 30;
                break;
            case 'h':
                printUsage();
                exit(0);
            case 'k':
                keyboardPath = std::string(optarg);
                break;
            case 'p':
                pointerPath = std::string(optarg);
                break;
            case 'v':
                videoPath = std::string(optarg);
                break;
        }
    }
}

void Args::printUsage()
{
    // use fprintf(stderr to match rfbUsage()
    fprintf(stderr, "OpenBMC IKVM daemon\n");
    fprintf(stderr, "Usage: obmc-ikvm [options]\n");
    fprintf(stderr, "-f frame rate          try this frame rate\n");
    fprintf(stderr, "-h, --help             show this message and exit\n");
    fprintf(stderr, "-k device              HID keyboard gadget device\n");
    fprintf(stderr, "-p device              HID mouse gadget device\n");
    fprintf(stderr, "-v device              V4L2 device\n");
    rfbUsage();
}

} // namespace ikvm