VirtualBox

Changeset 103598 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 28, 2024 5:17:55 PM (12 months ago)
Author:
vboxsync
Message:

FE/VBoxManage: Removed listing the supported guest OS types when listing the system properties and instead revamped the "list ostypes" command. This (sub) command now also supports filtering by platform architecture (--platform-arch), long output mode and sorting (by guest type ID).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp

    r102167 r103598  
    760760}
    761761
     762/**
     763 * Returns the platform architecture for a given string.
     764 *
     765 * @return Platform architecture, or PlatformArchitecture_None if not found.
     766 * @param  pszPlatform           Platform architecture to convert.
     767 */
     768static PlatformArchitecture_T platformArchitectureToStr(const char *pszPlatform)
     769{
     770    if (   !RTStrICmp(pszPlatform, "x86")
     771        || !RTStrICmp(pszPlatform, "x86_64")
     772        || !RTStrICmp(pszPlatform, "ia32")
     773        || !RTStrICmp(pszPlatform, "amd64")
     774        || !RTStrICmp(pszPlatform, "intel"))
     775        return PlatformArchitecture_x86;
     776    else if (   !RTStrICmp(pszPlatform, "arm")
     777             || !RTStrICmp(pszPlatform, "armv8"))
     778        return PlatformArchitecture_ARM;
     779    return PlatformArchitecture_None;
     780}
     781
    762782/** @todo r=andy Make use of SHOW_ULONG_PROP and friends like in VBoxManageInfo to have a more uniform / prettier output.
    763783 *               Use nesting (as padding / tabs). */
     
    797817
    798818/**
     819 * Shows a single guest OS type.
     820 *
     821 * @returns HRESULT
     822 * @param   ptrGuestOS          Guest OS type to show.
     823 * @param   fLong               Set to @true to show the guest OS type information in a not-so-compact mode.
     824 */
     825static HRESULT showGuestOSType(ComPtr<IGuestOSType> ptrGuestOS, bool fLong)
     826{
     827    PlatformArchitecture_T enmPlatformArch = (PlatformArchitecture_T)PlatformArchitecture_None;
     828    ptrGuestOS->COMGETTER(PlatformArchitecture)(&enmPlatformArch);
     829    Bstr guestId;
     830    Bstr guestDescription;
     831    ptrGuestOS->COMGETTER(Description)(guestDescription.asOutParam());
     832    ptrGuestOS->COMGETTER(Id)(guestId.asOutParam());
     833    Bstr familyId;
     834    Bstr familyDescription;
     835    ptrGuestOS->COMGETTER(FamilyId)(familyId.asOutParam());
     836    ptrGuestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
     837    Bstr guestOSSubtype;
     838    ptrGuestOS->COMGETTER(Subtype)(guestOSSubtype.asOutParam());
     839    BOOL fIs64Bit;
     840    ptrGuestOS->COMGETTER(Is64Bit)(&fIs64Bit);
     841
     842    if (fLong)
     843    {
     844        RTPrintf(         "ID:               %ls\n", guestId.raw());
     845        RTPrintf(List::tr("Description:      %ls\n"), guestDescription.raw());
     846        RTPrintf(List::tr("Family ID:        %ls\n"), familyId.raw());
     847        RTPrintf(List::tr("Family Desc:      %ls\n"), familyDescription.raw());
     848        if (guestOSSubtype.isNotEmpty())
     849            RTPrintf(List::tr("OS Subtype:       %ls\n"), guestOSSubtype.raw());
     850        RTPrintf(List::tr("Architecture:     %s\n"), platformArchitectureToStr(enmPlatformArch));
     851        RTPrintf(List::tr("64 bit:           %RTbool\n"), fIs64Bit);
     852    }
     853    else
     854    {
     855        RTPrintf(         "ID / Description: %ls -- %ls\n", guestId.raw(), guestDescription.raw());
     856        if (guestOSSubtype.isNotEmpty())
     857            RTPrintf(List::tr("Family:           %ls / %ls (%ls)\n"),
     858                     familyId.raw(), guestOSSubtype.raw(), familyDescription.raw());
     859        else
     860            RTPrintf(List::tr("Family:           %ls (%ls)\n"), familyId.raw(), familyDescription.raw());
     861        RTPrintf(List::tr("Architecture:     %s%s\n"), platformArchitectureToStr(enmPlatformArch),
     862                                                      fIs64Bit ? " (64-bit)" : "");
     863    }
     864    RTPrintf("\n");
     865
     866    return S_OK;
     867}
     868
     869/**
    799870 * Lists guest OS types.
    800871 *
    801872 * @returns HRESULT
    802  * @param   aGuestOSTypes       Reference to guest OS types to list.
    803  */
    804 static HRESULT listGuestOSTypes(const com::SafeIfaceArray<IGuestOSType> &aGuestOSTypes)
    805 {
    806     /*
    807      * Iterate through the collection.
    808      */
    809     for (size_t i = 0; i < aGuestOSTypes.size(); ++i)
    810     {
    811         ComPtr<IGuestOSType> guestOS;
    812         guestOS = aGuestOSTypes[i];
    813         Bstr guestId;
    814         guestOS->COMGETTER(Id)(guestId.asOutParam());
    815         RTPrintf(         "ID:              %ls\n", guestId.raw());
    816         Bstr guestDescription;
    817         guestOS->COMGETTER(Description)(guestDescription.asOutParam());
    818         RTPrintf(List::tr("Description:     %ls\n"), guestDescription.raw());
    819         Bstr familyId;
    820         guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
    821         RTPrintf(List::tr("Family ID:       %ls\n"), familyId.raw());
    822         Bstr familyDescription;
    823         guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
    824         RTPrintf(List::tr("Family Desc:     %ls\n"), familyDescription.raw());
    825         Bstr guestOSSubtype;
    826         guestOS->COMGETTER(Subtype)(guestOSSubtype.asOutParam());
    827         if (guestOSSubtype.isNotEmpty())
    828             RTPrintf(List::tr("OS Subtype:      %ls\n"), guestOSSubtype.raw());
    829         PlatformArchitecture_T enmPlatformArch = (PlatformArchitecture_T)PlatformArchitecture_None;
    830         guestOS->COMGETTER(PlatformArchitecture)(&enmPlatformArch);
    831         RTPrintf(List::tr("Platform Arch.:  %s\n"), platformArchitectureToStr(enmPlatformArch));
    832         BOOL is64Bit;
    833         guestOS->COMGETTER(Is64Bit)(&is64Bit);
    834         RTPrintf(List::tr("64 bit:          %RTbool\n"), is64Bit);
    835         RTPrintf("\n");
    836     }
     873 * @param   aGuestOSTypes           Reference to guest OS types to list.
     874 * @param   fLong                   Set to @true to list the OS types in a not-so-compact mode.
     875 * @param   fSorted                 Set to @true to list the OS types in a sorted manner (by guest OS type ID).
     876 * @param   enmFilterByPlatformArch Filters the output by the given platform architecture, or shows all supported guest OS types
     877 *                                  if PlatformArchitecture_None is specified.
     878 */
     879static HRESULT listGuestOSTypes(const com::SafeIfaceArray<IGuestOSType> &aGuestOSTypes, bool fLong, bool fSorted,
     880                                PlatformArchitecture_T enmFilterByPlatformArch)
     881{
     882    RTPrintf(List::tr("Supported guest OS types%s:\n\n"),
     883                      enmFilterByPlatformArch != PlatformArchitecture_None ? " (filtered)" : "");
     884
     885/** Filters the guest OS type output by skipping the current iteration. */
     886#define FILTER_OUTPUT(a_GuestOSType) \
     887    PlatformArchitecture_T enmPlatformArch = (PlatformArchitecture_T)PlatformArchitecture_None; \
     888    ptrGuestOS->COMGETTER(PlatformArchitecture)(&enmPlatformArch); \
     889    if (   enmFilterByPlatformArch != PlatformArchitecture_None \
     890        && enmFilterByPlatformArch != enmPlatformArch) \
     891        continue;
     892
     893    if (fSorted)
     894    {
     895        std::vector<std::pair<com::Bstr, IGuestOSType *> > sortedGuestOSTypes;
     896        for (size_t i = 0; i < aGuestOSTypes.size(); ++i)
     897        {
     898            ComPtr<IGuestOSType> ptrGuestOS = aGuestOSTypes[i];
     899            FILTER_OUTPUT(ptrGuestOS);
     900
     901            /* We sort by guest type ID. */
     902            Bstr guestId;
     903            ptrGuestOS->COMGETTER(Id)(guestId.asOutParam());
     904            sortedGuestOSTypes.push_back(std::pair<com::Bstr, IGuestOSType *>(guestId, ptrGuestOS));
     905        }
     906
     907        std::sort(sortedGuestOSTypes.begin(), sortedGuestOSTypes.end());
     908        for (size_t i = 0; i < sortedGuestOSTypes.size(); ++i)
     909            showGuestOSType(sortedGuestOSTypes[i].second, fLong);
     910    }
     911    else
     912    {
     913        for (size_t i = 0; i < aGuestOSTypes.size(); ++i)
     914        {
     915            ComPtr<IGuestOSType> ptrGuestOS = aGuestOSTypes[i];
     916            FILTER_OUTPUT(ptrGuestOS);
     917
     918            showGuestOSType(ptrGuestOS, fLong);
     919        }
     920    }
     921
     922#undef FILTER_OUTPUT
    837923
    838924    return S_OK;
     
    896982        listPlatformChipsetProperties(platformProperties, saChipset[i]);
    897983    }
    898 
    899     RTPrintf("\n");
    900 
    901     RTPrintf(List::tr("Supported guest OS types:\n\n"));
    902 
    903     com::SafeIfaceArray<IGuestOSType> coll;
    904     platformProperties->COMGETTER(SupportedGuestOSTypes(ComSafeArrayAsOutParam(coll)));
    905         listGuestOSTypes(coll);
    906984
    907985    return S_OK;
     
    21102188 * @param   enmList             The list to produce.
    21112189 * @param   fOptLong            Long (@c true) or short list format.
     2190 * @param   fOptSorted          Whether the output shall be sorted or not (depends on the actual command).
     2191 * @param   enmPlatformArch     Filters the list by the given platform architecture,
     2192 *                              or processes all platforms if PlatformArchitecture_None is specified.
    21122193 * @param   pVirtualBox         Reference to the IVirtualBox smart pointer.
    21132194 */
    2114 static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
     2195static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, PlatformArchitecture_T enmPlatformArch,
     2196                           const ComPtr<IVirtualBox> &pVirtualBox)
    21152197{
    21162198    HRESULT hrc = S_OK;
     
    22072289            hrc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
    22082290            if (SUCCEEDED(hrc))
    2209                 listGuestOSTypes(coll);
     2291                listGuestOSTypes(coll, fOptLong, fOptSorted, enmPlatformArch);
    22102292            break;
    22112293        }
     
    24662548RTEXITCODE handleList(HandlerArg *a)
    24672549{
    2468     bool                fOptLong      = false;
    2469     bool                fOptMultiple  = false;
    2470     bool                fOptSorted    = false;
    2471     bool                fFirst        = true;
    2472     enum ListType_T     enmOptCommand = kListNotSpecified;
    2473     RTEXITCODE          rcExit = RTEXITCODE_SUCCESS;
     2550    bool                   fOptLong        = false;
     2551    bool                   fOptMultiple    = false;
     2552    bool                   fOptSorted      = false;
     2553    PlatformArchitecture_T enmPlatformArch = PlatformArchitecture_None;
     2554    bool                   fFirst          = true;
     2555    enum ListType_T        enmOptCommand   = kListNotSpecified;
     2556    RTEXITCODE             rcExit          = RTEXITCODE_SUCCESS;
    24742557
    24752558    static const RTGETOPTDEF s_aListOptions[] =
     
    24772560        { "--long",             'l',                     RTGETOPT_REQ_NOTHING },
    24782561        { "--multiple",         'm',                     RTGETOPT_REQ_NOTHING }, /* not offical yet */
     2562        { "--platform-arch",    'p',                     RTGETOPT_REQ_STRING  },
     2563        { "--platform",         'p',                     RTGETOPT_REQ_STRING  }, /* shortcut for '--platform-arch' */
    24792564        { "--sorted",           's',                     RTGETOPT_REQ_NOTHING },
    24802565        { "vms",                kListVMs,                RTGETOPT_REQ_NOTHING },
     
    25342619                break;
    25352620
    2536             case 's':
    2537                 fOptSorted = true;
    2538                 break;
    2539 
    25402621            case 'm':
    25412622                fOptMultiple = true;
     
    25442625                ch = enmOptCommand;
    25452626                RT_FALL_THRU();
     2627
     2628            case 'p':  /* --platform[-arch] */
     2629                enmPlatformArch = platformArchitectureToStr(ValueUnion.psz);
     2630                if (enmPlatformArch == PlatformArchitecture_None)
     2631                    return errorSyntax(List::tr("Invalid platform architecture specified"));
     2632                break;
     2633
     2634            case 's':
     2635                fOptSorted = true;
     2636                break;
    25462637
    25472638            case kListVMs:
     
    25922683                        RTPrintf("\n");
    25932684                    RTPrintf("[%s]\n", ValueUnion.pDef->pszLong);
    2594                     HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
     2685                    HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, enmPlatformArch, a->virtualBox);
    25952686                    if (FAILED(hrc))
    25962687                        rcExit = RTEXITCODE_FAILURE;
     
    26132704    if (!fOptMultiple)
    26142705    {
    2615         HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
     2706        HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, enmPlatformArch, a->virtualBox);
    26162707        if (FAILED(hrc))
    26172708            rcExit = RTEXITCODE_FAILURE;
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