VirtualBox

Ignore:
Timestamp:
Mar 15, 2012 6:18:49 AM (13 years ago)
Author:
vboxsync
Message:

VBoxManage: use common code in bandwidthctl and showvminfo to list groups, fixed machine readable list (#5582)

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r39576 r40470  
    201201                   ComPtr <IConsole> console = ComPtr<IConsole>());
    202202const char *machineStateToName(MachineState_T machineState, bool fShort);
     203HRESULT showBandwidthGroups(ComPtr<IBandwidthControl> &bwCtrl,
     204                            VMINFO_DETAILS details);
    203205
    204206/* VBoxManageList.cpp */
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageBandwidthControl.cpp

    r40469 r40470  
    187187
    188188/**
    189  * Converts bandwidth group type to a string.
    190  * @returns String representation.
    191  * @param   enmType         Bandwidth control group type.
    192  */
    193 inline const char * typeToString(BandwidthGroupType_T enmType)
    194 {
    195     switch (enmType)
    196     {
    197         case BandwidthGroupType_Disk:    return "Disk";
    198         case BandwidthGroupType_Network: return "Network";
    199     }
    200     return "unknown";
    201 }
    202 
    203 /**
    204189 * Handles the 'bandwidthctl myvm list' sub-command.
    205190 * @returns Exit code.
     
    230215
    231216    /* See showVMInfo. */
     217    if (FAILED(showBandwidthGroups(rptrBWControl, enmDetails)))
     218        return RTEXITCODE_FAILURE;
     219#if 0
    232220    com::SafeIfaceArray<IBandwidthGroup> bwGroups;
    233221    CHECK_ERROR2_RET(rptrBWControl, GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups)), RTEXITCODE_FAILURE);
     
    249237                 cMaxMbPerSec);
    250238    }
     239#endif
    251240
    252241    return RTEXITCODE_SUCCESS;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp

    r40469 r40470  
    230230        RTPrintf("\"\n");
    231231    }
     232}
     233
     234/**
     235 * Converts bandwidth group type to a string.
     236 * @returns String representation.
     237 * @param   enmType         Bandwidth control group type.
     238 */
     239inline const char * bwGroupTypeToString(BandwidthGroupType_T enmType)
     240{
     241    switch (enmType)
     242    {
     243        case BandwidthGroupType_Disk:    return "Disk";
     244        case BandwidthGroupType_Network: return "Network";
     245    }
     246    return "unknown";
     247}
     248
     249HRESULT showBandwidthGroups(ComPtr<IBandwidthControl> &bwCtrl,
     250                            VMINFO_DETAILS details)
     251{
     252    int rc = S_OK;
     253    SafeIfaceArray<IBandwidthGroup> bwGroups;
     254
     255    CHECK_ERROR_RET(bwCtrl, GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups)), rc);
     256
     257    for (size_t i = 0; i < bwGroups.size(); i++)
     258    {
     259        Bstr strName;
     260        ULONG cMaxMbPerSec;
     261        BandwidthGroupType_T enmType;
     262
     263        CHECK_ERROR_RET(bwGroups[i], COMGETTER(Name)(strName.asOutParam()), rc);
     264        CHECK_ERROR_RET(bwGroups[i], COMGETTER(Type)(&enmType), rc);
     265        CHECK_ERROR_RET(bwGroups[i], COMGETTER(MaxMbPerSec)(&cMaxMbPerSec), rc);
     266
     267        const char *pszType = bwGroupTypeToString(enmType);
     268        if (details == VMINFO_MACHINEREADABLE)
     269            RTPrintf("BandwidthGroup%zu=%ls,%s,%d\n", i, strName.raw(), pszType, cMaxMbPerSec);
     270        else
     271            RTPrintf("Name: '%ls', Type: %s, Limit: %d Mbytes/sec\n", strName.raw(), pszType, cMaxMbPerSec);
     272    }
     273    if (details != VMINFO_MACHINEREADABLE && bwGroups.size() != 0)
     274        RTPrintf("\n");
     275
     276    return rc;
    232277}
    233278
     
    18371882    {
    18381883        ComPtr<IBandwidthControl> bwCtrl;
    1839         SafeIfaceArray<IBandwidthGroup> bwGroups;
    1840 
    18411884        CHECK_ERROR_RET(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()), rc);
    18421885
    1843         CHECK_ERROR_RET(bwCtrl, GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups)), rc);
    1844 
    1845         for (size_t i = 0; i < bwGroups.size(); i++)
    1846         {
    1847             Bstr strName;
    1848             ULONG cMaxMbPerSec;
    1849             BandwidthGroupType_T enmType;
    1850 
    1851             CHECK_ERROR_RET(bwGroups[i], COMGETTER(Name)(strName.asOutParam()), rc);
    1852             CHECK_ERROR_RET(bwGroups[i], COMGETTER(Type)(&enmType), rc);
    1853             CHECK_ERROR_RET(bwGroups[i], COMGETTER(MaxMbPerSec)(&cMaxMbPerSec), rc);
    1854 
    1855             const char *pszType = "unknown";
    1856             switch (enmType)
    1857             {
    1858                 case BandwidthGroupType_Disk:    pszType = "disk";    break;
    1859                 case BandwidthGroupType_Network: pszType = "network"; break;
    1860             }
    1861             if (details == VMINFO_MACHINEREADABLE)
    1862                 RTPrintf("BandwidthGroup%zu=%ls,%s,%d\n", strName.raw(), pszType, cMaxMbPerSec);
    1863             else
    1864                 RTPrintf("Name: '%ls', Type: %s, Limit: %d Mbytes/sec\n", strName.raw(), pszType, cMaxMbPerSec);
    1865         }
    1866         if (details != VMINFO_MACHINEREADABLE && bwGroups.size() != 0)
    1867             RTPrintf("\n");
     1886        rc = showBandwidthGroups(bwCtrl, details);
    18681887    }
    18691888
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette