Changeset 93627 in vbox for trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
- Timestamp:
- Feb 6, 2022 11:35:13 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r93561 r93627 495 495 * @param pszValue The value. 496 496 * @param fQuoteName Whether to unconditionally quote the name or not. 497 * @param fNewline Whether to automatically add a newline after the value. 497 498 */ 498 void outputMachineReadableString(const char *pszName, const char *pszValue, bool fQuoteName /*=false*/ )499 void outputMachineReadableString(const char *pszName, const char *pszValue, bool fQuoteName /*=false*/, bool fNewline /*=true*/) 499 500 { 500 501 if (!fQuoteName) … … 503 504 bool const fEscapeValue = doesMachineReadableStringNeedEscaping(pszValue); 504 505 if (!fEscapeName && !fEscapeValue) 505 RTPrintf(!fQuoteName ? "%s=\"%s\"\n" : "\"%s\"=\"%s\"\n", pszName, pszValue); 506 { 507 if (fNewline) 508 RTPrintf(!fQuoteName ? "%s=\"%s\"\n" : "\"%s\"=\"%s\"\n", pszName, pszValue); 509 else 510 RTPrintf(!fQuoteName ? "%s=\"%s\"" : "\"%s\"=\"%s\"", pszName, pszValue); 511 } 506 512 else 507 513 { … … 522 528 /* the value and the closing quotation */ 523 529 outputMachineReadableStringWorker(pszValue); 524 RTStrmWrite(g_pStdOut, RT_STR_TUPLE("\"\n")); 530 if (fNewline) 531 RTStrmWrite(g_pStdOut, RT_STR_TUPLE("\"\n")); 532 else 533 RTStrmWrite(g_pStdOut, RT_STR_TUPLE("\"")); 525 534 } 526 535 } … … 534 543 * @param pbstrValue The value. 535 544 * @param fQuoteName Whether to unconditionally quote the name or not. 545 * @param fNewline Whether to automatically add a newline after the value. 536 546 */ 537 void outputMachineReadableString(const char *pszName, Bstr const *pbstrValue, bool fQuoteName /*=false*/ )547 void outputMachineReadableString(const char *pszName, Bstr const *pbstrValue, bool fQuoteName /*=false*/, bool fNewline /*=true*/) 538 548 { 539 549 com::Utf8Str strValue(*pbstrValue); 540 outputMachineReadableString(pszName, strValue.c_str(), fQuoteName );550 outputMachineReadableString(pszName, strValue.c_str(), fQuoteName, fNewline); 541 551 } 542 552 … … 695 705 VMINFO_DETAILS details) 696 706 { 697 int rc = S_OK;698 707 SafeIfaceArray<IBandwidthGroup> bwGroups; 699 700 CHECK_ERROR_RET(bwCtrl, GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups)), rc); 701 702 if (bwGroups.size() && details != VMINFO_MACHINEREADABLE) 703 RTPrintf("\n\n"); 708 CHECK_ERROR2I_RET(bwCtrl, GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups)), hrcCheck); 709 710 if (details != VMINFO_MACHINEREADABLE) 711 RTPrintf(bwGroups.size() != 0 ? "\n" : Info::tr("<none>\n")); 704 712 for (size_t i = 0; i < bwGroups.size(); i++) 705 713 { 706 714 Bstr strName; 707 LONG64 cMaxBytesPerSec;715 CHECK_ERROR2I_RET(bwGroups[i], COMGETTER(Name)(strName.asOutParam()), hrcCheck); 708 716 BandwidthGroupType_T enmType; 709 710 CHECK_ERROR_RET(bwGroups[i], COMGETTER(Name)(strName.asOutParam()), rc); 711 CHECK_ERROR_RET(bwGroups[i], COMGETTER(Type)(&enmType), rc); 712 CHECK_ERROR_RET(bwGroups[i], COMGETTER(MaxBytesPerSec)(&cMaxBytesPerSec), rc); 717 CHECK_ERROR2I_RET(bwGroups[i], COMGETTER(Type)(&enmType), hrcCheck); 718 LONG64 cbMaxPerSec; 719 CHECK_ERROR2I_RET(bwGroups[i], COMGETTER(MaxBytesPerSec)(&cbMaxPerSec), hrcCheck); 713 720 714 721 const char *pszType = bwGroupTypeToString(enmType); 715 722 if (details == VMINFO_MACHINEREADABLE) 716 RTPrintf("BandwidthGroup%zu=%ls,%s,%lld\n", i, strName.raw(), pszType, cMaxBytesPerSec); 723 { 724 /* Complicated condensed format. */ 725 char szName[64]; 726 RTStrPrintf(szName, sizeof(szName), "BandwidthGroup%zu", i); 727 outputMachineReadableString(szName, &strName, false /*fQuoteName*/, false /*fNewline*/); 728 RTPrintf(",%s,%RI64\n", pszType, cbMaxPerSec); 729 } 717 730 else 718 731 { 719 const char *pszUnits = ""; 720 LONG64 cBytes = cMaxBytesPerSec; 721 if (cBytes == 0) 722 { 723 RTPrintf(Info::tr("Name: '%ls', Type: %s, Limit: none (disabled)\n"), strName.raw(), pszType); 732 if (cbMaxPerSec == 0) 733 { 734 RTPrintf(Info::tr("#%zu: Name: '%ls', Type: %s, Limit: none (disabled)\n"), i, strName.raw(), pszType); 724 735 continue; 725 736 } 726 else if (!(cBytes % _1G)) 727 { 728 pszUnits = "G"; 729 cBytes /= _1G; 730 } 731 else if (!(cBytes % _1M)) 732 { 733 pszUnits = "M"; 734 cBytes /= _1M; 735 } 736 else if (!(cBytes % _1K)) 737 { 738 pszUnits = "K"; 739 cBytes /= _1K; 740 } 741 const char *pszNetUnits = NULL; 742 if (enmType == BandwidthGroupType_Network) 743 { 744 /* 745 * We want to report network rate limit in bits/s, not bytes. 746 * Only if it cannot be express it in kilobits we will fall 747 * back to reporting it in bytes. 748 */ 749 LONG64 cBits = cMaxBytesPerSec; 750 if (!(cBits % 125)) 737 738 /* translate to human readable units.*/ 739 const char *pszUnit; 740 LONG64 cUnits; 741 if (!(cbMaxPerSec % _1G)) 742 { 743 cUnits = cbMaxPerSec / _1G; 744 pszUnit = "GiB/s"; 745 } 746 else if (!(cbMaxPerSec % _1M)) 747 { 748 cUnits = cbMaxPerSec / _1M; 749 pszUnit = "MiB/s"; 750 } 751 else if (!(cbMaxPerSec % _1K)) 752 { 753 cUnits = cbMaxPerSec / _1K; 754 pszUnit = "KiB/s"; 755 } 756 else 757 { 758 cUnits = cbMaxPerSec; 759 pszUnit = "bytes/s"; 760 } 761 762 /* 763 * We want to report network rate limit in bits/s, not bytes. 764 * Only if it cannot be express it in kilobits we will fall 765 * back to reporting it in bytes. 766 */ 767 if ( enmType == BandwidthGroupType_Network 768 && !(cbMaxPerSec % 125) ) 769 { 770 LONG64 cNetUnits = cbMaxPerSec / 125; 771 const char *pszNetUnit = "kbps"; 772 if (!(cNetUnits % 1000000)) 751 773 { 752 cBits /= 125; 753 pszNetUnits = "k"; 754 if (!(cBits % 1000000)) 755 { 756 cBits /= 1000000; 757 pszNetUnits = "g"; 758 } 759 else if (!(cBits % 1000)) 760 { 761 cBits /= 1000; 762 pszNetUnits = "m"; 763 } 764 RTPrintf(Info::tr("Name: '%ls', Type: %s, Limit: %lld %sbits/sec (%lld %sbytes/sec)\n"), 765 strName.raw(), pszType, cBits, pszNetUnits, cBytes, pszUnits); 774 cNetUnits /= 1000000; 775 pszNetUnit = "Gbps"; 766 776 } 767 } 768 if (!pszNetUnits) 769 RTPrintf(Info::tr("Name: '%ls', Type: %s, Limit: %lld %sbytes/sec\n"), strName.raw(), pszType, cBytes, pszUnits); 770 } 771 } 772 if (details != VMINFO_MACHINEREADABLE) 773 RTPrintf(bwGroups.size() != 0 ? "\n" : Info::tr("<none>\n")); 774 775 return rc; 777 else if (!(cNetUnits % 1000)) 778 { 779 cNetUnits /= 1000; 780 pszNetUnit = "Mbps"; 781 } 782 RTPrintf(Info::tr("#%zu: Name: '%ls', Type: %s, Limit: %RI64 %s (%RI64 %s)\n"), 783 i, strName.raw(), pszType, cNetUnits, pszNetUnit, cUnits, pszUnit); 784 } 785 else 786 RTPrintf(Info::tr("#%zu: Name: '%ls', Type: %s, Limit: %RI64 %s\n"), i, strName.raw(), pszType, cUnits, pszUnit); 787 } 788 } 789 790 return VINF_SUCCESS; 776 791 } 777 792
Note:
See TracChangeset
for help on using the changeset viewer.