Changeset 32201 in vbox for trunk/src/VBox
- Timestamp:
- Sep 2, 2010 1:56:03 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp
r32198 r32201 24 24 #include <iprt/initterm.h> 25 25 #include <iprt/mem.h> 26 #include <iprt/message.h> 26 27 #include <iprt/path.h> 27 28 #include <iprt/string.h> … … 513 514 } 514 515 515 inthandleSetVideoMode(int argc, char *argv[])516 static RTEXITCODE handleSetVideoMode(int argc, char *argv[]) 516 517 { 517 518 if (argc != 3 && argc != 4) 518 519 { 519 520 usage(SET_VIDEO_MODE); 520 return 1;521 return RTEXITCODE_FAILURE; 521 522 } 522 523 … … 550 551 RTPrintf("done.\n"); 551 552 } 552 else VBoxControlError("Error retrieving API for display change!"); 553 } 554 else VBoxControlError("Error retrieving handle to user32.dll!"); 555 556 return 0; 553 else 554 VBoxControlError("Error retrieving API for display change!"); 555 } 556 else 557 VBoxControlError("Error retrieving handle to user32.dll!"); 558 559 return RTEXITCODE_SUCCESS; 557 560 } 558 561 … … 593 596 } 594 597 595 inthandleGetVideoAcceleration(int argc, char *argv[])598 static RTEXITCODE handleGetVideoAcceleration(int argc, char *argv[]) 596 599 { 597 600 ULONG status; … … 611 614 RegCloseKey(hkeyVideo); 612 615 } 613 return 0;614 } 615 616 inthandleSetVideoAcceleration(int argc, char *argv[])616 return RTEXITCODE_SUCCESS; 617 } 618 619 static RTEXITCODE handleSetVideoAcceleration(int argc, char *argv[]) 617 620 { 618 621 ULONG status; … … 625 628 { 626 629 usage(SET_VIDEO_ACCEL); 627 return 1;630 return RTEXITCODE_FAILURE; 628 631 } 629 632 … … 643 646 RegCloseKey(hkeyVideo); 644 647 } 645 return 0;648 return RTEXITCODE_SUCCESS; 646 649 } 647 650 … … 755 758 } 756 759 757 inthandleListCustomModes(int argc, char *argv[])760 static RTEXITCODE handleListCustomModes(int argc, char *argv[]) 758 761 { 759 762 if (argc != 0) 760 763 { 761 764 usage(LIST_CUST_MODES); 762 return 1;765 return RTEXITCODE_FAILURE; 763 766 } 764 767 … … 780 783 RegCloseKey(hkeyVideo); 781 784 } 782 return 0;783 } 784 785 inthandleAddCustomMode(int argc, char *argv[])785 return RTEXITCODE_SUCCESS; 786 } 787 788 static RTEXITCODE handleAddCustomMode(int argc, char *argv[]) 786 789 { 787 790 if (argc != 3) 788 791 { 789 792 usage(ADD_CUST_MODE); 790 return 1;793 return RTEXITCODE_FAILURE; 791 794 } 792 795 … … 803 806 { 804 807 VBoxControlError("Error: invalid mode specified!\n"); 805 return 1;808 return RTEXITCODE_FAILURE; 806 809 } 807 810 … … 841 844 RegCloseKey(hkeyVideo); 842 845 } 843 return 0;844 } 845 846 inthandleRemoveCustomMode(int argc, char *argv[])846 return RTEXITCODE_SUCCESS; 847 } 848 849 static RTEXITCODE handleRemoveCustomMode(int argc, char *argv[]) 847 850 { 848 851 if (argc != 3) 849 852 { 850 853 usage(REMOVE_CUST_MODE); 851 return 1;854 return RTEXITCODE_FAILURE; 852 855 } 853 856 … … 877 880 } 878 881 879 return 0;882 return RTEXITCODE_SUCCESS; 880 883 } 881 884 … … 887 890 * This is accessed through the "VBoxGuestPropSvc" HGCM service. 888 891 * 889 * @returns 0 on success, 1 on failure892 * @returns Command exit code. 890 893 * @note see the command line API description for parameters 891 894 */ 892 intgetGuestProperty(int argc, char **argv)895 static RTEXITCODE getGuestProperty(int argc, char **argv) 893 896 { 894 897 using namespace guestProp; … … 903 906 { 904 907 usage(GUEST_PROP); 905 return 1;908 return RTEXITCODE_FAILURE; 906 909 } 907 910 … … 976 979 VbglR3GuestPropDisconnect(u32ClientId); 977 980 RTMemFree(pvBuf); 978 return RT_SUCCESS(rc) ? 0 : 1;981 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 979 982 } 980 983 … … 984 987 * This is accessed through the "VBoxGuestPropSvc" HGCM service. 985 988 * 986 * @returns 0 on success, 1 on failure989 * @returns Command exit code. 987 990 * @note see the command line API description for parameters 988 991 */ 989 static intsetGuestProperty(int argc, char *argv[])992 static RTEXITCODE setGuestProperty(int argc, char *argv[]) 990 993 { 991 994 /* … … 1016 1019 { 1017 1020 usage(GUEST_PROP); 1018 return 1;1021 return RTEXITCODE_FAILURE; 1019 1022 } 1020 1023 /* This is always needed. */ … … 1041 1044 if (u32ClientId != 0) 1042 1045 VbglR3GuestPropDisconnect(u32ClientId); 1043 return RT_SUCCESS(rc) ? 0 : 1;1046 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1044 1047 } 1045 1048 … … 1049 1052 * This is accessed through the "VBoxGuestPropSvc" HGCM service. 1050 1053 * 1051 * @returns 0 on success, 1 on failure1054 * @returns Command exit code. 1052 1055 * @note see the command line API description for parameters 1053 1056 */ 1054 static intenumGuestProperty(int argc, char *argv[])1057 static RTEXITCODE enumGuestProperty(int argc, char *argv[]) 1055 1058 { 1056 1059 /* … … 1070 1073 { 1071 1074 usage(GUEST_PROP); 1072 return 1;1075 return RTEXITCODE_FAILURE; 1073 1076 } 1074 1077 … … 1108 1111 else 1109 1112 VBoxControlError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 1110 return RT_SUCCESS(rc) ? 0 : 1;1113 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1111 1114 } 1112 1115 … … 1116 1119 * This is accessed through the "VBoxGuestPropSvc" HGCM service. 1117 1120 * 1118 * @returns 0 on success, 1 on failure1121 * @returns Command exit code. 1119 1122 * @note see the command line API description for parameters 1120 1123 */ 1121 intwaitGuestProperty(int argc, char **argv)1124 static RTEXITCODE waitGuestProperty(int argc, char **argv) 1122 1125 { 1123 1126 using namespace guestProp; … … 1163 1166 { 1164 1167 usage(GUEST_PROP); 1165 return 1;1168 return RTEXITCODE_FAILURE; 1166 1169 } 1167 1170 … … 1243 1246 VbglR3GuestPropDisconnect(u32ClientId); 1244 1247 RTMemFree(pvBuf); 1245 return RT_SUCCESS(rc) ? 0 : 1;1248 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1246 1249 } 1247 1250 … … 1254 1257 * @note see the command line API description for parameters 1255 1258 */ 1256 static inthandleGuestProperty(int argc, char *argv[])1259 static RTEXITCODE handleGuestProperty(int argc, char *argv[]) 1257 1260 { 1258 1261 if (0 == argc) 1259 1262 { 1260 1263 usage(GUEST_PROP); 1261 return 1;1262 } 1263 if ( 0 ==strcmp(argv[0], "get"))1264 return RTEXITCODE_FAILURE; 1265 } 1266 if (!strcmp(argv[0], "get")) 1264 1267 return getGuestProperty(argc - 1, argv + 1); 1265 else if ( 0 ==strcmp(argv[0], "set"))1268 else if (!strcmp(argv[0], "set")) 1266 1269 return setGuestProperty(argc - 1, argv + 1); 1267 else if ( 0 ==strcmp(argv[0], "enumerate"))1270 else if (!strcmp(argv[0], "enumerate")) 1268 1271 return enumGuestProperty(argc - 1, argv + 1); 1269 else if ( 0 ==strcmp(argv[0], "wait"))1272 else if (!strcmp(argv[0], "wait")) 1270 1273 return waitGuestProperty(argc - 1, argv + 1); 1271 1274 /* else */ 1272 1275 usage(GUEST_PROP); 1273 return 1;1276 return RTEXITCODE_FAILURE; 1274 1277 } 1275 1278 #endif … … 1279 1282 * Lists the Shared Folders provided by the host. 1280 1283 */ 1281 intlistSharedFolders(int argc, char **argv)1284 static RTEXITCODE listSharedFolders(int argc, char **argv) 1282 1285 { 1283 1286 bool usageOK = true; … … 1285 1288 if (argc == 1) 1286 1289 { 1287 if ( strcmp(argv[0], "-automount") == 0 1288 || strcmp(argv[0], "--automount") == 0 1289 ) 1290 { 1290 if ( !strcmp(argv[0], "-automount") 1291 || !strcmp(argv[0], "--automount")) 1291 1292 fOnlyShowAutoMount = true; 1292 }1293 1293 else 1294 1294 usageOK = false; … … 1300 1300 { 1301 1301 usage(GUEST_SHAREDFOLDERS); 1302 return 1;1302 return RTEXITCODE_FAILURE; 1303 1303 } 1304 1304 … … 1341 1341 VbglR3SharedFolderDisconnect(u32ClientId); 1342 1342 } 1343 return RT_SUCCESS(rc) ? 0 : 1;1343 return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1344 1344 } 1345 1345 … … 1350 1350 * @note see the command line API description for parameters 1351 1351 */ 1352 static inthandleSharedFolder(int argc, char *argv[])1352 static RTEXITCODE handleSharedFolder(int argc, char *argv[]) 1353 1353 { 1354 1354 if (0 == argc) 1355 1355 { 1356 1356 usage(GUEST_SHAREDFOLDERS); 1357 return 1;1358 } 1359 if ( 0 ==strcmp(argv[0], "list"))1357 return RTEXITCODE_FAILURE; 1358 } 1359 if (!strcmp(argv[0], "list")) 1360 1360 return listSharedFolders(argc - 1, argv + 1); 1361 1361 /* else */ 1362 1362 usage(GUEST_SHAREDFOLDERS); 1363 return 1;1363 return RTEXITCODE_FAILURE; 1364 1364 } 1365 1365 #endif 1366 1366 1367 1367 /** command handler type */ 1368 typedef DECLCALLBACK( int) FNHANDLER(int argc, char *argv[]);1368 typedef DECLCALLBACK(RTEXITCODE) FNHANDLER(int argc, char *argv[]); 1369 1369 typedef FNHANDLER *PFNHANDLER; 1370 1370 … … 1372 1372 struct COMMANDHANDLER 1373 1373 { 1374 const char * command;1375 PFNHANDLER handler;1376 } g_ commandHandlers[] =1374 const char *pszCommand; 1375 PFNHANDLER pfnHandler; 1376 } g_aCommandHandlers[] = 1377 1377 { 1378 1378 #if defined(RT_OS_WINDOWS) && !defined(VBOX_CONTROL_TEST) 1379 { "getvideoacceleration", handleGetVideoAcceleration },1380 { "setvideoacceleration", handleSetVideoAcceleration },1381 { "listcustommodes", handleListCustomModes },1382 { "addcustommode", handleAddCustomMode },1383 { "removecustommode", handleRemoveCustomMode },1384 { "setvideomode", handleSetVideoMode },1379 { "getvideoacceleration", handleGetVideoAcceleration }, 1380 { "setvideoacceleration", handleSetVideoAcceleration }, 1381 { "listcustommodes", handleListCustomModes }, 1382 { "addcustommode", handleAddCustomMode }, 1383 { "removecustommode", handleRemoveCustomMode }, 1384 { "setvideomode", handleSetVideoMode }, 1385 1385 #endif 1386 1386 #ifdef VBOX_WITH_GUEST_PROPS 1387 { "guestproperty", handleGuestProperty },1387 { "guestproperty", handleGuestProperty }, 1388 1388 #endif 1389 1389 #ifdef VBOX_WITH_SHARED_FOLDERS 1390 { "sharedfolder", handleSharedFolder },1390 { "sharedfolder", handleSharedFolder }, 1391 1391 #endif 1392 { NULL, NULL } /* terminator*/1392 { NULL, NULL } /* unnecessary terminator entry */ 1393 1393 }; 1394 1394 … … 1397 1397 { 1398 1398 /** The application's global return code */ 1399 int rc = 0;1399 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 1400 1400 /** An IPRT return code for local use */ 1401 1401 int rrc = VINF_SUCCESS; … … 1409 1409 bool fOnlyInfo = false; 1410 1410 1411 rrc = RTR3Init(); 1412 if (RT_FAILURE(rrc)) 1413 return RTMsgInitFailure(rrc); 1414 1411 1415 /* 1412 1416 * Start by handling command line switches 1413 1417 */ 1414 1415 /** Are we finished with handling switches? */ 1416 bool done = false; 1418 /** @todo RTGetOpt conversion of the whole file. */ 1419 bool done = false; /**< Are we finished with handling switches? */ 1417 1420 while (!done && (iArg < argc)) 1418 1421 { 1419 if ( 0 ==strcmp(argv[iArg], "-V")1420 || 0 ==strcmp(argv[iArg], "-v")1421 || 0 ==strcmp(argv[iArg], "--version")1422 || 0 ==strcmp(argv[iArg], "-version")1423 || 0 ==strcmp(argv[iArg], "getversion")1422 if ( !strcmp(argv[iArg], "-V") 1423 || !strcmp(argv[iArg], "-v") 1424 || !strcmp(argv[iArg], "--version") 1425 || !strcmp(argv[iArg], "-version") 1426 || !strcmp(argv[iArg], "getversion") 1424 1427 ) 1425 1428 { … … 1430 1433 done = true; 1431 1434 } 1432 else if ( 0 ==strcmp(argv[iArg], "-nologo")1433 || 0 ==strcmp(argv[iArg], "--nologo"))1435 else if ( !strcmp(argv[iArg], "-nologo") 1436 || !strcmp(argv[iArg], "--nologo")) 1434 1437 fShowLogo = false; 1435 else if ( 0 ==strcmp(argv[iArg], "-help")1436 || 0 ==strcmp(argv[iArg], "--help"))1438 else if ( !strcmp(argv[iArg], "-help") 1439 || !strcmp(argv[iArg], "--help")) 1437 1440 { 1438 1441 fOnlyInfo = true; … … 1452 1455 * and show the usage if the user asked us to 1453 1456 */ 1454 1455 1457 g_pszProgName = RTPathFilename(argv[0]); 1456 1458 if (fShowLogo) … … 1465 1467 * Do global initialisation for the programme if we will be handling a command 1466 1468 */ 1467 1468 1469 if (!fOnlyInfo) 1469 1470 { 1470 rrc = RTR3Init(); /** @todo r=bird: This ALWAYS goes first, the only exception is when you have to parse args to figure out which to call! */ 1471 if (!RT_SUCCESS(rrc)) 1472 { 1473 VBoxControlError("Failed to initialise the VirtualBox runtime - error %Rrc\n", rrc); 1474 rc = 1; 1475 } 1476 if (0 == rc) 1477 { 1478 if (!RT_SUCCESS(VbglR3Init())) 1479 { 1480 VBoxControlError("Could not contact the host system. Make sure that you are running this\n" 1481 "application inside a VirtualBox guest system, and that you have sufficient\n" 1482 "user permissions.\n"); 1483 rc = 1; 1484 } 1471 rrc = VbglR3Init(); 1472 if (RT_FAILURE(rrc)) 1473 { 1474 VBoxControlError("Could not contact the host system. Make sure that you are running this\n" 1475 "application inside a VirtualBox guest system, and that you have sufficient\n" 1476 "user permissions.\n"); 1477 rcExit = RTEXITCODE_FAILURE; 1485 1478 } 1486 1479 } … … 1490 1483 */ 1491 1484 1492 if (!fOnlyInfo && (0 == rc))1485 if (!fOnlyInfo && rcExit == RTEXITCODE_SUCCESS) 1493 1486 { 1494 1487 /* … … 1497 1490 * here. 1498 1491 */ 1492 /** @todo this must be done before we start checking for --help and 1493 * stuff above. */ 1499 1494 for (int i = iArg; i < argc; i++) 1500 1495 { 1501 char * converted;1502 RTStrCurrentCPToUtf8(& converted, argv[i]);1503 argv[i] = converted;1496 char *pszConverted; 1497 RTStrCurrentCPToUtf8(&pszConverted, argv[i]); 1498 argv[i] = pszConverted; 1504 1499 } 1505 1500 … … 1510 1505 /** And if so, what is its position in the table? */ 1511 1506 unsigned index = 0; 1512 while ( index < RT_ELEMENTS(g_ commandHandlers)1507 while ( index < RT_ELEMENTS(g_aCommandHandlers) 1513 1508 && !found 1514 && (g_ commandHandlers[index].command != NULL))1509 && (g_aCommandHandlers[index].pszCommand != NULL)) 1515 1510 { 1516 if ( 0 == strcmp(argv[iArg], g_commandHandlers[index].command))1511 if (!strcmp(argv[iArg], g_aCommandHandlers[index].pszCommand)) 1517 1512 found = true; 1518 1513 else … … 1520 1515 } 1521 1516 if (found) 1522 rc = g_commandHandlers[index].handler(argc - iArg - 1, argv + iArg + 1);1517 rcExit = g_aCommandHandlers[index].pfnHandler(argc - iArg - 1, argv + iArg + 1); 1523 1518 else 1524 1519 { 1525 rc = 1;1520 rcExit = RTEXITCODE_FAILURE; 1526 1521 usage(); 1527 1522 } … … 1530 1525 { 1531 1526 /* The user didn't specify a command. */ 1532 rc = 1;1527 rcExit = RTEXITCODE_FAILURE; 1533 1528 usage(); 1534 1529 } … … 1539 1534 for (int i = iArg; i < argc; i++) 1540 1535 RTStrFree(argv[i]); 1541 1542 1536 } 1543 1537 … … 1545 1539 * And exit, returning the status 1546 1540 */ 1547 1548 return rc; 1549 } 1550 1541 return rcExit; 1542 } 1543
Note:
See TracChangeset
for help on using the changeset viewer.