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