1 #include "ikvm_args.hpp" 2 3 #include <getopt.h> 4 #include <rfb/rfb.h> 5 #include <stdio.h> 6 #include <stdlib.h> 7 8 namespace ikvm 9 { 10 Args::Args(int argc, char* argv[]) : 11 frameRate(30), subsampling(0), calcFrameCRC{false}, commandLine(argc, argv) 12 { 13 int option; 14 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}}; 24 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; 34 case 's': 35 subsampling = (int)strtol(optarg, NULL, 0); 36 if (subsampling < 0 || subsampling > 1) 37 subsampling = 0; 38 break; 39 case 'h': 40 printUsage(); 41 exit(0); 42 case 'k': 43 keyboardPath = std::string(optarg); 44 break; 45 case 'p': 46 pointerPath = std::string(optarg); 47 break; 48 case 'u': 49 udcName = std::string(optarg); 50 break; 51 case 'v': 52 videoPath = std::string(optarg); 53 break; 54 case 'c': 55 calcFrameCRC = true; 56 break; 57 } 58 } 59 } 60 61 void 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"); 67 fprintf(stderr, "-s subsampling try this subsampling\n"); 68 fprintf(stderr, "-h, --help show this message and exit\n"); 69 fprintf(stderr, "-k device HID keyboard gadget device\n"); 70 fprintf(stderr, "-p device HID mouse gadget device\n"); 71 fprintf(stderr, 72 "-u udc name UDC that HID gadget will connect to\n"); 73 fprintf(stderr, "-v device V4L2 device\n"); 74 fprintf( 75 stderr, 76 "-c, --calcCRC Calculate CRC for each frame to save bandwidth\n"); 77 rfbUsage(); 78 } 79 80 } // namespace ikvm 81