VirtualBox

Changeset 15570 in vbox for trunk/src/VBox/Main


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/Main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • 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