VirtualBox

Changeset 15570 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 16, 2008 10:39:34 AM (16 years ago)
Author:
vboxsync
Message:

#3282: Collection got replaced with safe array. Warning, windows builds/tests may break.

Location:
trunk/src/VBox
Files:
10 edited

Legend:

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

    r15372 r15570  
    203203        ComPtr<IHost> host;
    204204        CHECK_ERROR(virtualBox, COMGETTER(Host)(host.asOutParam()));
    205         ComPtr<IHostNetworkInterfaceCollection> coll;
    206         ComPtr<IHostNetworkInterfaceEnumerator> enumerator;
    207         CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(coll.asOutParam()));
    208         if (SUCCEEDED(rc) && coll)
    209         {
    210             CHECK_ERROR(coll, Enumerate(enumerator.asOutParam()));
    211             BOOL hasMore;
    212             while (SUCCEEDED(enumerator->HasMore(&hasMore)) && hasMore)
    213             {
    214                 ComPtr<IHostNetworkInterface> networkInterface;
    215                 CHECK_RC_BREAK(enumerator->GetNext(networkInterface.asOutParam()));
     205        com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
     206        CHECK_ERROR(host,
     207                    COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces)));
     208        for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
     209        {
     210            ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
    216211#ifndef VBOX_WITH_HOSTNETIF_API
    217                 Bstr interfaceName;
    218                 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
    219                 RTPrintf("Name:        %lS\n", interfaceName.raw());
    220                 Guid interfaceGuid;
    221                 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
    222                 RTPrintf("GUID:        %lS\n\n", Bstr(interfaceGuid.toString()).raw());
     212            Bstr interfaceName;
     213            networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
     214            RTPrintf("Name:        %lS\n", interfaceName.raw());
     215            Guid interfaceGuid;
     216            networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
     217            RTPrintf("GUID:        %lS\n\n", Bstr(interfaceGuid.toString()).raw());
    223218#else /* VBOX_WITH_HOSTNETIF_API */
    224                 Bstr interfaceName;
    225                 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
    226                 RTPrintf("Name:            %lS\n", interfaceName.raw());
    227                 Guid interfaceGuid;
    228                 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
    229                 RTPrintf("GUID:            %lS\n", Bstr(interfaceGuid.toString()).raw());
    230                 ULONG IPAddress;
    231                 networkInterface->COMGETTER(IPAddress)(&IPAddress);
    232                 RTPrintf("IPAddress:       %d.%d.%d.%d\n",
    233                          ((uint8_t*)&IPAddress)[0],
    234                          ((uint8_t*)&IPAddress)[1],
    235                          ((uint8_t*)&IPAddress)[2],
    236                          ((uint8_t*)&IPAddress)[3]);
    237                 ULONG NetworkMask;
    238                 networkInterface->COMGETTER(NetworkMask)(&NetworkMask);
    239                 RTPrintf("NetworkMask:     %d.%d.%d.%d\n",
    240                          ((uint8_t*)&NetworkMask)[0],
    241                          ((uint8_t*)&NetworkMask)[1],
    242                          ((uint8_t*)&NetworkMask)[2],
    243                          ((uint8_t*)&NetworkMask)[3]);
    244                 Bstr IPV6Address;
    245                 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
    246                 RTPrintf("IPV6Address:     %lS\n", IPV6Address.raw());
    247                 Bstr IPV6NetworkMask;
    248                 networkInterface->COMGETTER(IPV6NetworkMask)(IPV6NetworkMask.asOutParam());
    249                 RTPrintf("IPV6NetworkMask: %lS\n", IPV6NetworkMask.raw());
    250                 Bstr HardwareAddress;
    251                 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
    252                 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
    253                 HostNetworkInterfaceType_T Type;
    254                 networkInterface->COMGETTER(Type)(&Type);
    255                 RTPrintf("Type:            %s\n", getHostIfTypeText(Type));
    256                 HostNetworkInterfaceStatus_T Status;
    257                 networkInterface->COMGETTER(Status)(&Status);
    258                 RTPrintf("Status:          %s\n\n", getHostIfStatusText(Status));
     219            Bstr interfaceName;
     220            networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
     221            RTPrintf("Name:            %lS\n", interfaceName.raw());
     222            Guid interfaceGuid;
     223            networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
     224            RTPrintf("GUID:            %lS\n", Bstr(interfaceGuid.toString()).raw());
     225            ULONG IPAddress;
     226            networkInterface->COMGETTER(IPAddress)(&IPAddress);
     227            RTPrintf("IPAddress:       %d.%d.%d.%d\n",
     228                     ((uint8_t*)&IPAddress)[0],
     229                     ((uint8_t*)&IPAddress)[1],
     230                     ((uint8_t*)&IPAddress)[2],
     231                     ((uint8_t*)&IPAddress)[3]);
     232            ULONG NetworkMask;
     233            networkInterface->COMGETTER(NetworkMask)(&NetworkMask);
     234            RTPrintf("NetworkMask:     %d.%d.%d.%d\n",
     235                     ((uint8_t*)&NetworkMask)[0],
     236                     ((uint8_t*)&NetworkMask)[1],
     237                     ((uint8_t*)&NetworkMask)[2],
     238                     ((uint8_t*)&NetworkMask)[3]);
     239            Bstr IPV6Address;
     240            networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
     241            RTPrintf("IPV6Address:     %lS\n", IPV6Address.raw());
     242            Bstr IPV6NetworkMask;
     243            networkInterface->COMGETTER(IPV6NetworkMask)(IPV6NetworkMask.asOutParam());
     244            RTPrintf("IPV6NetworkMask: %lS\n", IPV6NetworkMask.raw());
     245            Bstr HardwareAddress;
     246            networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
     247            RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
     248            HostNetworkInterfaceType_T Type;
     249            networkInterface->COMGETTER(Type)(&Type);
     250            RTPrintf("Type:            %s\n", getHostIfTypeText(Type));
     251            HostNetworkInterfaceStatus_T Status;
     252            networkInterface->COMGETTER(Status)(&Status);
     253            RTPrintf("Status:          %s\n\n", getHostIfStatusText(Status));
    259254#endif
    260             }
    261255        }
    262256    }
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r13580 r15570  
    982982    mInterfaceList.clear();
    983983    /* load current inner list */
    984     CHostNetworkInterfaceEnumerator en =
    985         vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
    986     while (en.HasMore())
    987         mInterfaceList += en.GetNext().GetName();
     984    CHostNetworkInterfaceVector interfaces =
     985        vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
     986    for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
     987         it != interfaces.end(); ++it)
     988        mInterfaceList += it->GetName();
    988989    /* save current list item name */
    989990    QString currentListItemName = lbHostInterface->currentText();
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsNetwork.cpp

    r15110 r15570  
    674674    /* Load current inner list */
    675675    QList<QTreeWidgetItem*> itemsList;
    676     CHostNetworkInterfaceEnumerator en =
    677         vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces().Enumerate();
    678     while (en.HasMore())
    679         itemsList << new VBoxNIListItem (en.GetNext().GetName());
     676    CHostNetworkInterfaceVector interfaces =
     677        vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces();
     678    for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin();
     679         it != interfaces.end(); ++it)
     680        itemsList << new VBoxNIListItem (it->GetName());
    680681
    681682    /* Save current list item name */
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r15448 r15570  
    42984298                ComPtr<IHost> host;
    42994299                virtualBox->COMGETTER(Host)(host.asOutParam());
    4300                 ComPtr<IHostNetworkInterfaceCollection> coll;
    4301                 host->COMGETTER(NetworkInterfaces)(coll.asOutParam());
    4302                 ComPtr<IHostNetworkInterface> hostInterface;
    4303                 if (!SUCCEEDED(coll->FindByName(hostif, hostInterface.asOutParam())))
     4300                com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
     4301                CHECK_ERROR(host,
     4302                            COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces)));
     4303                bool found = false;
     4304                for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
     4305                {
     4306                    Bstr name;
     4307                    hostNetworkInterfaces[i].COMGETTER(Name) (name.asOutParam());
     4308                    if (name == hostif)
     4309                    {
     4310                        found = true;
     4311                        break;
     4312                    }
     4313                }
     4314                if (!found)
    43044315                {
    43054316                    return setError (VBOX_E_HOST_ERROR,
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r15498 r15570  
    13121312
    13131313# elif defined(RT_OS_WINDOWS)
    1314                     ComPtr<IHostNetworkInterfaceCollection> coll;
    1315                     hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam());
     1314                    com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
     1315                    hrc = host->COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces)));
    13161316                    if(FAILED(hrc))
    13171317                    {
     
    13201320                    }
    13211321                    ComPtr<IHostNetworkInterface> hostInterface;
    1322                     rc = coll->FindByName(HifName, hostInterface.asOutParam());
    1323                     if (!SUCCEEDED(rc))
     1322                    for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
     1323                    {
     1324                        Bstr name;
     1325                        hostNetworkInterfaces[i].COMGETTER(Name) (name.asOutParam());
     1326                        if (name == hostif)
     1327                        {
     1328                            hostInterface = hostNetworkInterfaces[i];
     1329                            break;
     1330                        }
     1331                    }
     1332                    if (hostInterface.IsNull())
    13241333                    {
    13251334                        AssertBreakpoint();
     
    14991508                    Bstr hostInterfaceName;
    15001509                    hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
    1501                     ComPtr<IHostNetworkInterfaceCollection> coll;
    1502                     hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam());    H();
     1510                    com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
     1511                    hrc = host->COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces))); H();
    15031512                    ComPtr<IHostNetworkInterface> hostInterface;
    1504                     rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
    1505                     if (!SUCCEEDED(rc))
     1513                    for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
     1514                    {
     1515                        Bstr name;
     1516                        hostNetworkInterfaces[i].COMGETTER(Name) (name.asOutParam());
     1517                        if (name == hostif)
     1518                        {
     1519                            hostInterface = hostNetworkInterfaces[i];
     1520                            break;
     1521                        }
     1522                    }
     1523                    if (hostInterface.IsNull())
    15061524                    {
    15071525                        AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
  • trunk/src/VBox/Main/HostImpl.cpp

    r15455 r15570  
    751751 * @param drives address of result pointer
    752752 */
    753 STDMETHODIMP Host::COMGETTER(NetworkInterfaces) (IHostNetworkInterfaceCollection **networkInterfaces)
     753STDMETHODIMP Host::COMGETTER(NetworkInterfaces) (ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces))
    754754{
    755755#if defined(RT_OS_WINDOWS) ||  defined(VBOX_WITH_NETFLT) /*|| defined(RT_OS_OS2)*/
    756     if (!networkInterfaces)
     756    if (ComSafeArrayOutIsNull (aNetworkInterfaces))
    757757        return E_POINTER;
     758
    758759    AutoWriteLock alock (this);
    759760    CHECK_READY();
     
    10561057# endif /* RT_OS_LINUX */
    10571058#endif
    1058     ComObjPtr <HostNetworkInterfaceCollection> collection;
    1059     collection.createObject();
    1060     collection->init (list);
    1061     collection.queryInterfaceTo (networkInterfaces);
     1059    SafeIfaceArray <IHostNetworkInterface> networkInterfaces (list);
     1060    networkInterfaces.detachTo (ComSafeArrayOutArg (aNetworkInterfaces));
     1061
    10621062    return S_OK;
    10631063
     
    13771377    /* first check whether an interface with the given name already exists */
    13781378    {
    1379         ComPtr <IHostNetworkInterfaceCollection> coll;
    1380         rc = COMGETTER(NetworkInterfaces) (coll.asOutParam());
     1379        com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
     1380        rc = host->COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces)));
    13811381        CheckComRCReturnRC (rc);
    1382         ComPtr <IHostNetworkInterface> iface;
    1383         if (SUCCEEDED (coll->FindByName (aName, iface.asOutParam())))
    1384             return setError (E_INVALIDARG,
    1385                 tr ("Host network interface '%ls' already exists"), aName);
     1382        for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
     1383        {
     1384            Bstr name;
     1385            hostNetworkInterfaces[i].COMGETTER(Name) (name.asOutParam());
     1386            if (name == aName)
     1387            {
     1388                return setError (E_INVALIDARG,
     1389                                 tr ("Host network interface '%ls' already exists"), aName);
     1390            }
     1391        }
    13861392    }
    13871393
     
    14391445    /* first check whether an interface with the given name already exists */
    14401446    {
    1441         ComPtr <IHostNetworkInterfaceCollection> coll;
    1442         rc = COMGETTER(NetworkInterfaces) (coll.asOutParam());
     1447        com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
     1448        rc = host->COMGETTER(NetworkInterfaces) (ComSafeArrayAsOutParam (hostNetworkInterfaces)));
    14431449        CheckComRCReturnRC (rc);
    14441450        ComPtr <IHostNetworkInterface> iface;
    1445         if (FAILED (coll->FindById (aId, iface.asOutParam())))
     1451        for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
     1452        {
     1453            Guid guid;
     1454            hostNetworkInterfaces[i].COMGETTER(Id) (guid.asOutParam());
     1455            if (guid == aId)
     1456            {
     1457                iface = hostNetworkInterfaces[i];
     1458                break;
     1459            }
     1460        }
     1461        if (iface.IsNull())
    14461462            return setError (VBOX_E_OBJECT_NOT_FOUND,
    14471463                tr ("Host network interface with UUID {%RTuuid} does not exist"),
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r15546 r15570  
    59685968  </interface>
    59695969
    5970   <enumerator
    5971      name="IHostNetworkInterfaceEnumerator" type="IHostNetworkInterface"
    5972      uuid="7B52FEF7-56E8-4aec-92F5-15E6D11EC630"
    5973      />
    5974 
    5975   <collection
    5976      name="IHostNetworkInterfaceCollection" type="IHostNetworkInterface"
    5977      enumerator="IHostNetworkInterfaceEnumerator"
    5978      uuid="BF1D41F2-B97B-4314-A0FB-D4823AF42FB5"
    5979      readonly="yes"
    5980      >
    5981     <method name="findByName">
    5982       <desc>
    5983         Searches this collection for a host network interface with the given name.
    5984         <note>
    5985           The method returns an error if the given name does not
    5986           correspond to any host network interface in the collection.
    5987         </note>
    5988       </desc>
    5989       <param name="name" type="wstring" dir="in">
    5990         <desc>Name of the host network interface to search for.</desc>
    5991       </param>
    5992       <param name="networkInterface" type="IHostNetworkInterface" dir="return">
    5993         <desc>Found host network interface object.</desc>
    5994       </param>
    5995     </method>
    5996     <method name="findById">
    5997       <desc>
    5998         Searches this collection for a host network interface with the given GUID.
    5999         <note>
    6000           The method returns an error if the given GUID does not
    6001           correspond to any host network interface in the collection.
    6002         </note>
    6003       </desc>
    6004       <param name="id" type="uuid" dir="in">
    6005         <desc>GUID of the host network interface to search for.</desc>
    6006       </param>
    6007       <param name="networkInterface" type="IHostNetworkInterface" dir="return">
    6008         <desc>Found host network interface object.</desc>
    6009       </param>
    6010     </method>
    6011   </collection>
    6012 
    60135970  <interface
    60145971     name="IHost" extends="$unknown"
    6015      uuid="4be2e85f-a54c-4bc7-8bf6-f070f9113940"
     5972     uuid="f39438d7-abfd-409b-bc80-5f5291d92897"
    60165973     wsmap="managed"
    60175974     >
     
    60776034    </attribute>
    60786035
    6079     <attribute name="networkInterfaces" type="IHostNetworkInterfaceCollection" readonly="yes">
     6036    <attribute name="networkInterfaces" type="IHostNetworkInterface" safearray="yes" readonly="yes">
    60806037      <desc>List of host network interfaces currently defined on the host.</desc>
    60816038    </attribute>
  • trunk/src/VBox/Main/include/HostImpl.h

    r15051 r15570  
    8585    STDMETHOD(COMGETTER(USBDevices))(IHostUSBDeviceCollection **aUSBDevices);
    8686    STDMETHOD(COMGETTER(USBDeviceFilters))(IHostUSBDeviceFilterCollection ** aUSBDeviceFilters);
    87     STDMETHOD(COMGETTER(NetworkInterfaces))(IHostNetworkInterfaceCollection **networkInterfaces);
     87    STDMETHOD(COMGETTER(NetworkInterfaces))(ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces));
    8888    STDMETHOD(COMGETTER(ProcessorCount))(ULONG *count);
    8989    STDMETHOD(COMGETTER(ProcessorOnlineCount))(ULONG *count);
  • trunk/src/VBox/Main/include/HostNetworkInterfaceImpl.h

    r15442 r15570  
    9999};
    100100
    101 COM_DECL_READONLY_ENUM_AND_COLLECTION_BEGIN (HostNetworkInterface)
    102 
    103     STDMETHOD(FindByName) (IN_BSTR name, IHostNetworkInterface **networkInterface)
    104     {
    105         if (!name)
    106             return E_INVALIDARG;
    107         if (!networkInterface)
    108             return E_POINTER;
    109 
    110         *networkInterface = NULL;
    111         Vector::value_type found;
    112         Vector::iterator it = vec.begin();
    113         while (it != vec.end() && !found)
    114         {
    115             Bstr n;
    116             (*it)->COMGETTER(Name) (n.asOutParam());
    117             if (n == name)
    118                 found = *it;
    119             ++ it;
    120         }
    121 
    122         if (!found)
    123             return setError (E_INVALIDARG, HostNetworkInterfaceCollection::tr (
    124                 "The host network interface with the given name could not be found"));
    125 
    126         return found.queryInterfaceTo (networkInterface);
    127     }
    128 
    129     STDMETHOD(FindById) (IN_GUID id, IHostNetworkInterface **networkInterface)
    130     {
    131         if (Guid(id).isEmpty())
    132             return E_INVALIDARG;
    133         if (!networkInterface)
    134             return E_POINTER;
    135 
    136         *networkInterface = NULL;
    137         Vector::value_type found;
    138         Vector::iterator it = vec.begin();
    139         while (it != vec.end() && !found)
    140         {
    141             Guid g;
    142             (*it)->COMGETTER(Id) (g.asOutParam());
    143             if (g == Guid(id))
    144                 found = *it;
    145             ++ it;
    146         }
    147 
    148         if (!found)
    149             return setError (E_INVALIDARG, HostNetworkInterfaceCollection::tr (
    150                 "The host network interface with the given GUID could not be found"));
    151 
    152         return found.queryInterfaceTo (networkInterface);
    153     }
    154 
    155 
    156 COM_DECL_READONLY_ENUM_AND_COLLECTION_END (HostNetworkInterface)
    157 
    158 
    159101#endif // ____H_H_HOSTNETWORKINTERFACEIMPL
    160102/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/xpcom/server.cpp

    r14831 r15570  
    235235COM_IMPL_READONLY_ENUM_AND_COLLECTION(HostDVDDrive)
    236236COM_IMPL_READONLY_ENUM_AND_COLLECTION(HostFloppyDrive)
    237 COM_IMPL_READONLY_ENUM_AND_COLLECTION(HostNetworkInterface)
    238237COM_IMPL_READONLY_ENUM_AND_COLLECTION(SharedFolder)
    239238#ifdef VBOX_WITH_USB
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