Changeset 103598 in vbox for trunk/src/VBox
- Timestamp:
- Feb 28, 2024 5:17:55 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r102167 r103598 760 760 } 761 761 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 */ 768 static 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 762 782 /** @todo r=andy Make use of SHOW_ULONG_PROP and friends like in VBoxManageInfo to have a more uniform / prettier output. 763 783 * Use nesting (as padding / tabs). */ … … 797 817 798 818 /** 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 */ 825 static 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 /** 799 870 * Lists guest OS types. 800 871 * 801 872 * @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 */ 879 static 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 837 923 838 924 return S_OK; … … 896 982 listPlatformChipsetProperties(platformProperties, saChipset[i]); 897 983 } 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);906 984 907 985 return S_OK; … … 2110 2188 * @param enmList The list to produce. 2111 2189 * @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. 2112 2193 * @param pVirtualBox Reference to the IVirtualBox smart pointer. 2113 2194 */ 2114 static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox) 2195 static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, PlatformArchitecture_T enmPlatformArch, 2196 const ComPtr<IVirtualBox> &pVirtualBox) 2115 2197 { 2116 2198 HRESULT hrc = S_OK; … … 2207 2289 hrc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll)); 2208 2290 if (SUCCEEDED(hrc)) 2209 listGuestOSTypes(coll );2291 listGuestOSTypes(coll, fOptLong, fOptSorted, enmPlatformArch); 2210 2292 break; 2211 2293 } … … 2466 2548 RTEXITCODE handleList(HandlerArg *a) 2467 2549 { 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; 2474 2557 2475 2558 static const RTGETOPTDEF s_aListOptions[] = … … 2477 2560 { "--long", 'l', RTGETOPT_REQ_NOTHING }, 2478 2561 { "--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' */ 2479 2564 { "--sorted", 's', RTGETOPT_REQ_NOTHING }, 2480 2565 { "vms", kListVMs, RTGETOPT_REQ_NOTHING }, … … 2534 2619 break; 2535 2620 2536 case 's':2537 fOptSorted = true;2538 break;2539 2540 2621 case 'm': 2541 2622 fOptMultiple = true; … … 2544 2625 ch = enmOptCommand; 2545 2626 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; 2546 2637 2547 2638 case kListVMs: … … 2592 2683 RTPrintf("\n"); 2593 2684 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); 2595 2686 if (FAILED(hrc)) 2596 2687 rcExit = RTEXITCODE_FAILURE; … … 2613 2704 if (!fOptMultiple) 2614 2705 { 2615 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);2706 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, enmPlatformArch, a->virtualBox); 2616 2707 if (FAILED(hrc)) 2617 2708 rcExit = RTEXITCODE_FAILURE;
Note:
See TracChangeset
for help on using the changeset viewer.