VirtualBox

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


Ignore:
Timestamp:
Aug 11, 2010 10:02:40 AM (14 years ago)
Author:
vboxsync
Message:

Main: merge IVirtualBox::FindHardDisk, GetHardDisk, FindDVDImage, GetDVDImage, FindFloppyImage and GetFloppyImage into one IVirtualBox::findMedium method

Location:
trunk/src/VBox/Main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r30881 r31562  
    611611    /* @todo: Maybe too cost-intensive; try to find a lighter way */
    612612    while (    RTPathExists(tmpName)
    613             || mVirtualBox->FindHardDisk(Bstr(tmpName), &harddisk) != VBOX_E_OBJECT_NOT_FOUND
     613            || mVirtualBox->FindMedium(Bstr(tmpName), DeviceType_HardDisk, &harddisk) != VBOX_E_OBJECT_NOT_FOUND
    614614          )
    615615    {
  • trunk/src/VBox/Main/ApplianceImplExport.cpp

    r31539 r31562  
    14831483
    14841484            Log(("Finding source disk \"%ls\"\n", bstrSrcFilePath.raw()));
    1485             rc = mVirtualBox->FindHardDisk(bstrSrcFilePath, pSourceDisk.asOutParam());
     1485            rc = mVirtualBox->FindMedium(bstrSrcFilePath, DeviceType_HardDisk, pSourceDisk.asOutParam());
    14861486            if (FAILED(rc)) throw rc;
    14871487
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31546 r31562  
    31733173        case DeviceType_HardDisk:
    31743174            /* find a hard disk by UUID */
    3175             rc = mParent->findHardDisk(&uuid, NULL, true /* aSetError */, &medium);
     3175            rc = mParent->findHardDisk(&uuid, Utf8Str::Empty, true /* aSetError */, &medium);
    31763176            if (FAILED(rc)) return rc;
    31773177            break;
     
    71417141            {
    71427142                /* find a hard disk by UUID */
    7143                 rc = mParent->findHardDisk(&dev.uuid, NULL, true /* aDoSetError */, &medium);
     7143                rc = mParent->findHardDisk(&dev.uuid, Utf8Str::Empty, true /* aDoSetError */, &medium);
    71447144                if (FAILED(rc))
    71457145                {
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31539 r31562  
    36343634                    Guid id = parentId;
    36353635                    ComObjPtr<Medium> pParent;
    3636                     rc = m->pVirtualBox->findHardDisk(&id, NULL, false /* aSetError */, &pParent);
     3636                    rc = m->pVirtualBox->findHardDisk(&id, Utf8Str::Empty, false /* aSetError */, &pParent);
    36373637                    if (FAILED(rc))
    36383638                    {
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31552 r31562  
    14691469}
    14701470
    1471 STDMETHODIMP VirtualBox::GetHardDisk(IN_BSTR   aId,
    1472                                      IMedium **aHardDisk)
    1473 {
    1474     CheckComArgOutSafeArrayPointerValid(aHardDisk);
     1471STDMETHODIMP VirtualBox::FindMedium(IN_BSTR   aLocation,
     1472                                    DeviceType_T aDeviceType,
     1473                                    IMedium **aMedium)
     1474{
     1475    CheckComArgOutSafeArrayPointerValid(aMedium);
    14751476
    14761477    AutoCaller autoCaller(this);
    14771478    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    14781479
    1479     Guid id(aId);
    1480     ComObjPtr<Medium> hardDisk;
    1481     HRESULT rc = findHardDisk(&id, NULL, true /* setError */, &hardDisk);
     1480    Guid id(aLocation);
     1481    Utf8Str strLocation(aLocation);
     1482
     1483    HRESULT rc;
     1484    ComObjPtr<Medium> pMedium;
     1485
     1486    switch (aDeviceType)
     1487    {
     1488        case DeviceType_HardDisk:
     1489            if (!id.isEmpty())
     1490                rc = findHardDisk(&id, Utf8Str::Empty, true /* setError */, &pMedium);
     1491            else
     1492                rc = findHardDisk(NULL, strLocation, true /* setError */, &pMedium);
     1493        break;
     1494
     1495        case DeviceType_Floppy:
     1496        case DeviceType_DVD:
     1497            if (!id.isEmpty())
     1498                rc = findDVDOrFloppyImage(aDeviceType, &id, Utf8Str::Empty, true /* setError */, &pMedium);
     1499            else
     1500                rc = findDVDOrFloppyImage(aDeviceType, NULL, strLocation, true /* setError */, &pMedium);
     1501        break;
     1502
     1503        default:
     1504            return setError(E_INVALIDARG,
     1505                            tr("Invalid device type %d"), aDeviceType);
     1506    }
    14821507
    14831508    /* the below will set *aHardDisk to NULL if hardDisk is null */
    1484     hardDisk.queryInterfaceTo(aHardDisk);
    1485 
    1486     return rc;
    1487 }
    1488 
    1489 STDMETHODIMP VirtualBox::FindHardDisk(IN_BSTR aLocation,
    1490                                       IMedium **aHardDisk)
    1491 {
    1492     CheckComArgStrNotEmptyOrNull(aLocation);
    1493     CheckComArgOutSafeArrayPointerValid(aHardDisk);
    1494 
    1495     AutoCaller autoCaller(this);
    1496     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1497 
    1498     ComObjPtr<Medium> hardDisk;
    1499     HRESULT rc = findHardDisk(NULL, aLocation, true /* setError */, &hardDisk);
    1500 
    1501     /* the below will set *aHardDisk to NULL if hardDisk is null */
    1502     hardDisk.queryInterfaceTo(aHardDisk);
     1509    pMedium.queryInterfaceTo(aMedium);
    15031510
    15041511    return rc;
     
    15531560}
    15541561
    1555 /** @note Locks objects! */
    1556 STDMETHODIMP VirtualBox::GetDVDImage(IN_BSTR aId, IMedium **aDVDImage)
    1557 {
    1558     CheckComArgOutSafeArrayPointerValid(aDVDImage);
    1559 
    1560     AutoCaller autoCaller(this);
    1561     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1562 
    1563     Guid id(aId);
    1564     ComObjPtr<Medium> image;
    1565     HRESULT rc = findDVDOrFloppyImage(DeviceType_DVD, &id, Utf8Str::Empty, true /* setError */, &image);
    1566 
    1567     /* the below will set *aDVDImage to NULL if image is null */
    1568     image.queryInterfaceTo(aDVDImage);
    1569 
    1570     return rc;
    1571 }
    1572 
    1573 /** @note Locks objects! */
    1574 STDMETHODIMP VirtualBox::FindDVDImage(IN_BSTR aLocation, IMedium **aDVDImage)
    1575 {
    1576     CheckComArgStrNotEmptyOrNull(aLocation);
    1577     CheckComArgOutSafeArrayPointerValid(aDVDImage);
    1578 
    1579     AutoCaller autoCaller(this);
    1580     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1581 
    1582     ComObjPtr<Medium> image;
    1583     HRESULT rc = findDVDOrFloppyImage(DeviceType_DVD, NULL, aLocation, true /* setError */, &image);
    1584 
    1585     /* the below will set *aDVDImage to NULL if dvd is null */
    1586     image.queryInterfaceTo(aDVDImage);
    1587 
    1588     return rc;
    1589 }
    1590 
    15911562/** @note Doesn't lock anything. */
    15921563STDMETHODIMP VirtualBox::OpenFloppyImage(IN_BSTR aLocation,
     
    16331604        }
    16341605    }
    1635 
    1636     return rc;
    1637 }
    1638 
    1639 /** @note Locks objects! */
    1640 STDMETHODIMP VirtualBox::GetFloppyImage(IN_BSTR aId, IMedium **aFloppyImage)
    1641 
    1642 {
    1643     CheckComArgOutSafeArrayPointerValid(aFloppyImage);
    1644 
    1645     AutoCaller autoCaller(this);
    1646     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1647 
    1648     Guid id(aId);
    1649     ComObjPtr<Medium> image;
    1650     HRESULT rc = findDVDOrFloppyImage(DeviceType_Floppy, &id, Utf8Str::Empty, true /* setError */, &image);
    1651 
    1652     /* the below will set *aFloppyImage to NULL if image is null */
    1653     image.queryInterfaceTo(aFloppyImage);
    1654 
    1655     return rc;
    1656 }
    1657 
    1658 /** @note Locks objects! */
    1659 STDMETHODIMP VirtualBox::FindFloppyImage(IN_BSTR aLocation,
    1660                                          IMedium **aFloppyImage)
    1661 {
    1662     CheckComArgStrNotEmptyOrNull(aLocation);
    1663     CheckComArgOutSafeArrayPointerValid(aFloppyImage);
    1664 
    1665     AutoCaller autoCaller(this);
    1666     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1667 
    1668     ComObjPtr<Medium> image;
    1669     HRESULT rc = findDVDOrFloppyImage(DeviceType_Floppy, NULL, aLocation, true /* setError */, &image);
    1670 
    1671     /* the below will set *aFloppyImage to NULL if img is null */
    1672     image.queryInterfaceTo(aFloppyImage);
    16731606
    16741607    return rc;
     
    27122645 */
    27132646HRESULT VirtualBox::findHardDisk(const Guid *aId,
    2714                                  CBSTR aLocation,
     2647                                 const Utf8Str &strLocation,
    27152648                                 bool aSetError,
    27162649                                 ComObjPtr<Medium> *aHardDisk /*= NULL*/)
    27172650{
    2718     AssertReturn(aId || aLocation, E_INVALIDARG);
     2651    AssertReturn(aId || !strLocation.isEmpty(), E_INVALIDARG);
    27192652
    27202653    // we use the hard disks map, but it is protected by the
     
    27362669    /* then iterate and search by location */
    27372670    int result = -1;
    2738     if (aLocation)
    2739     {
    2740         Utf8Str location = aLocation;
    2741 
     2671    if (!strLocation.isEmpty())
     2672    {
    27422673        for (HardDiskMap::const_iterator it = m->mapHardDisks.begin();
    27432674             it != m->mapHardDisks.end();
     
    27462677            const ComObjPtr<Medium> &hd = (*it).second;
    27472678
    2748             HRESULT rc = hd->compareLocationTo(location, result);
     2679            HRESULT rc = hd->compareLocationTo(strLocation, result);
    27492680            if (FAILED(rc)) return rc;
    27502681
     
    27692700        else
    27702701            setError(rc,
    2771                      tr("Could not find a hard disk with location '%ls' in the media registry ('%s')"),
    2772                      aLocation,
     2702                     tr("Could not find a hard disk with location '%s' in the media registry ('%s')"),
     2703                     strLocation.c_str(),
    27732704                     m->strSettingsFilePath.c_str());
    27742705    }
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r31464 r31562  
    17681768        After the storage unit is successfully created, the medium gets
    17691769        remembered by this VirtualBox installation and will be accessible
    1770         through <link to="#getHardDisk"/> and <link to="#findHardDisk"/>
    1771         methods. Remembered base medium are also returned as part of
    1772         the <link to="#hardDisks"/> array. See IMedium for more details.
     1770        through the <link to="#findMedium"/> method. Remembered base medium
     1771        are also returned as part of the <link to="#hardDisks"/> array.
     1772        See <link to="IMedium" /> for more details.
    17731773
    17741774        The list of all storage formats supported by this VirtualBox
     
    18131813        After the medium is successfully opened by this method, it gets
    18141814        remembered by (known to) this VirtualBox installation and will be
    1815         accessible through <link to="#getHardDisk"/> and
    1816         <link to="#findHardDisk"/> methods. Remembered base media
     1815        accessible through the <link to="#findMedium"/> method. Remembered base media
    18171816        are also returned as part of the <link to="#hardDisks"/> array and can
    1818         be attached to virtual machines. See IMedium for more details.
     1817        be attached to virtual machines. See <link to="IMedium" /> for more details.
    18191818
    18201819        If a differencing medium is to be opened by this method, the
     
    18901889    </method>
    18911890
    1892     <method name="getHardDisk" const="yes">
    1893       <desc>
    1894         Returns a medium with the given UUID.
    1895 
    1896         The medium with the given UUID must be known to this VirtualBox
    1897         installation, i.e. it must be previously created by
    1898         <link to="#createHardDisk"/> or opened by <link
    1899         to="#openHardDisk"/>, or attached to some known virtual machine.
    1900 
    1901         <result name="VBOX_E_OBJECT_NOT_FOUND">
    1902           No medium object matching @a id found.
    1903         </result>
    1904 
    1905       </desc>
    1906       <param name="id" type="uuid" mod="string" dir="in">
    1907         <desc>UUID of the medium to look for.</desc>
    1908       </param>
    1909       <param name="medium" type="IMedium" dir="return">
    1910         <desc>Found medium object.</desc>
    1911       </param>
    1912     </method>
    1913 
    1914     <method name="findHardDisk">
    1915       <desc>
    1916         Returns a medium that uses the given location to store medium data.
     1891    <method name="findMedium">
     1892      <desc>
     1893        Returns a medium of the given type that uses the given location or
     1894        UUID to store medium data.
    19171895
    19181896        The given medium must be known to this VirtualBox installation, i.e.
    1919         it must be previously created by
    1920         <link to="#createHardDisk"/> or opened by <link
    1921         to="#openHardDisk"/>, or attached to some known virtual machine.
     1897        it must be previously created by <link to="#createHardDisk"/> or opened
     1898        by <link to="#openHardDisk"/> or <link to="#openDVDImage" /> or
     1899        <link to="#openFloppyImage" />.
    19221900
    19231901        The search is done by comparing the value of the @a location argument to
    1924         the <link to="IMedium::location"/> attribute of each known medium.
     1902        the <link to="IMedium::location"/> and <link to="IMedium::id" />
     1903        attributes of each known medium.
    19251904
    19261905        For locations represented by file names in the host's file system, the
     
    19361915          No medium object matching @a location found.
    19371916        </result>
    1938 
    19391917      </desc>
    19401918      <param name="location" type="wstring" dir="in">
    1941         <desc>Location string to search for.</desc>
     1919        <desc>What to search for. This can either be the UUID or the location string of an open medium.</desc>
     1920      </param>
     1921      <param name="type" type="DeviceType" dir="in">
     1922        <desc>Device type (must be HardDisk, DVD or Floppy)</desc>
    19421923      </param>
    19431924      <param name="medium" type="IMedium" dir="return">
    1944         <desc>Found medium object.</desc>
     1925        <desc>Medium object, if found.</desc>
    19451926      </param>
    19461927    </method>
     
    19531934        After the image is successfully opened by this method, it gets
    19541935        remembered by (known to) this VirtualBox installation and will be
    1955         accessible through <link to="#getDVDImage"/> and
    1956         <link to="#findDVDImage"/> methods. Remembered images are also
    1957         returned as part of the <link to="#DVDImages"/> array and can be mounted
    1958         to virtual machines. See IMedium for more details.
     1936        accessible through the <link to="#findMedium"/> method.
     1937        Remembered images are also returned as part of the <link to="#DVDImages"/>
     1938        array and can be mounted to virtual machines. See <link to="IMedium" />
     1939        for more details.
    19591940
    19601941        See <link to="IMedium::location"/> to get more details about the format
     
    19911972    </method>
    19921973
    1993     <method name="getDVDImage">
    1994       <desc>
    1995         Returns a CD/DVD image with the given UUID.
    1996 
    1997         The image with the given UUID must be known to this VirtualBox
    1998         installation, i.e. it must be previously opened by <link
    1999         to="#openDVDImage"/>, or mounted to some known virtual machine.
    2000 
    2001         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2002           No matching DVD image found in the media registry.
    2003         </result>
    2004 
    2005       </desc>
    2006       <param name="id" type="uuid" mod="string" dir="in">
    2007         <desc>UUID of the image to look for.</desc>
    2008       </param>
    2009       <param name="image" type="IMedium" dir="return">
    2010         <desc>Found CD/DVD image object.</desc>
    2011       </param>
    2012     </method>
    2013 
    2014     <method name="findDVDImage">
    2015       <desc>
    2016         Returns a CD/DVD image with the given image location.
    2017 
    2018         The image with the given UUID must be known to this VirtualBox
    2019         installation, i.e. it must be previously opened by <link
    2020         to="#openDVDImage"/>, or mounted to some known virtual machine.
    2021 
    2022         The search is done by comparing the value of the @a location argument to
    2023         the <link to="IMedium::location"/> attribute of each known CD/DVD image.
    2024 
    2025         The requested location can be a path relative to the
    2026         <link to="IVirtualBox::homeFolder">VirtualBox home folder</link>. If
    2027         only a file name without any path is given, the
    2028         <link to="ISystemProperties::defaultHardDiskFolder"> default hard disk
    2029         folder</link> will be prepended to the file name before searching. Note
    2030         that on case sensitive file systems, a case sensitive comparison is
    2031         performed, otherwise the case in the file path is ignored.
    2032 
    2033         <result name="VBOX_E_FILE_ERROR">
    2034           Invalid image file location.
    2035         </result>
    2036         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2037           No matching DVD image found in the media registry.
    2038         </result>
    2039 
    2040       </desc>
    2041       <param name="location" type="wstring" dir="in">
    2042         <desc>CD/DVD image file path to look for.</desc>
    2043       </param>
    2044       <param name="image" type="IMedium" dir="return">
    2045         <desc>Found CD/DVD image object.</desc>
    2046       </param>
    2047     </method>
    2048 
    20491974    <method name="openFloppyImage">
    20501975      <desc>
     
    20541979        After the image is successfully opened by this method, it gets
    20551980        remembered by (known to) this VirtualBox installation and will be
    2056         accessible through <link to="#getFloppyImage"/> and
    2057         <link to="#findFloppyImage"/> methods. Remembered images are also
    2058         returned as part of the <link to="#floppyImages"/> array and can be
    2059         mounted to virtual machines. See IMedium for more details.
     1981        accessible through the <link to="#findMedium"/> method.
     1982        Remembered images are also returned as part of the <link to="#floppyImages"/>
     1983        array and can be mounted to virtual machines. See <link to="IMedium" />
     1984        for more details.
    20601985
    20611986        See <link to="IMedium::location"/> to get more details about the format
     
    20882013      <param name="image" type="IMedium" dir="return">
    20892014        <desc>Opened floppy image object.</desc>
    2090       </param>
    2091     </method>
    2092 
    2093     <method name="getFloppyImage">
    2094       <desc>
    2095         Returns a floppy image with the given UUID.
    2096 
    2097         The image with the given UUID must be known to this VirtualBox
    2098         installation, i.e. it must be previously opened by <link
    2099         to="#openFloppyImage"/>, or mounted to some known virtual machine.
    2100 
    2101         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2102           No matching floppy image found in the media registry.
    2103         </result>
    2104 
    2105       </desc>
    2106       <param name="id" type="uuid" mod="string" dir="in">
    2107         <desc>UUID of the image to look for.</desc>
    2108       </param>
    2109       <param name="image" type="IMedium" dir="return">
    2110         <desc>Found floppy image object.</desc>
    2111       </param>
    2112     </method>
    2113 
    2114     <method name="findFloppyImage">
    2115       <desc>
    2116         Returns a floppy image with the given image location.
    2117 
    2118         The image with the given UUID must be known to this VirtualBox
    2119         installation, i.e. it must be previously opened by <link
    2120         to="#openFloppyImage"/>, or mounted to some known virtual machine.
    2121 
    2122         The search is done by comparing the value of the @a location argument to
    2123         the <link to="IMedium::location"/> attribute of each known floppy image.
    2124 
    2125         The requested location can be a path relative to the
    2126         <link to="IVirtualBox::homeFolder">VirtualBox home folder</link>. If
    2127         only a file name without any path is given, the
    2128         <link to="ISystemProperties::defaultHardDiskFolder"> default hard disk
    2129         folder</link> will be prepended to the file name before searching. Note
    2130         that on case sensitive file systems, a case sensitive comparison is
    2131         performed, otherwise the case of symbols in the file path is ignored.
    2132 
    2133         <result name="VBOX_E_FILE_ERROR">
    2134           Invalid image file location.
    2135         </result>
    2136         <result name="VBOX_E_OBJECT_NOT_FOUND">
    2137           No matching floppy image found in the media registry.
    2138         </result>
    2139 
    2140       </desc>
    2141       <param name="location" type="wstring" dir="in">
    2142         <desc>Floppy image file path to look for.</desc>
    2143       </param>
    2144       <param name="image" type="IMedium" dir="return">
    2145         <desc>Found floppy image object.</desc>
    21462015      </param>
    21472016    </method>
     
    87198588      <link to="IVirtualBox::DVDImages"/> and
    87208589      <link to="IVirtualBox::floppyImages"/> attributes. Individual media can be
    8721       quickly found by UUID using <link to="IVirtualBox::getHardDisk"/>
    8722       and similar methods or by location using
    8723       <link to="IVirtualBox::findHardDisk"/> and similar methods.
     8590      quickly found using the <link to="IVirtualBox::findMedium"/> method.
    87248591
    87258592      Only known media can be attached to virtual machines.
     
    87938660      or opened, it becomes a known hard disk (remembered in the internal media
    87948661      registry). Known hard disks can be attached to a virtual machine, accessed
    8795       through <link to="IVirtualBox::getHardDisk"/> and
    8796       <link to="IVirtualBox::findHardDisk"/> methods or enumerated using the
     8662      through <link to="IVirtualBox::findMedium"/> or enumerated using the
    87978663      <link to="IVirtualBox::hardDisks"/> array (only for base hard disks).
    87988664
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31482 r31562  
    136136                             BOOL aSetParentId, IN_BSTR aParentId,
    137137                             IMedium **aHardDisk);
    138     STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
    139     STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
     138    STDMETHOD(FindMedium) (IN_BSTR aLocation, DeviceType_T deviceType, IMedium **aMedium);
    140139
    141140    STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
    142141                             IMedium **aDVDImage);
    143     STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
    144     STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
    145 
    146142    STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
    147143                                IMedium **aFloppyImage);
    148     STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
    149     STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
    150144
    151145    STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
     
    221215                         ComObjPtr<Machine> *machine = NULL);
    222216
    223     HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
    224                           bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
     217    HRESULT findHardDisk(const Guid *aId,
     218                         const Utf8Str &strLocation,
     219                         bool aSetError,
     220                         ComObjPtr<Medium> *aHardDisk = NULL);
    225221    HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
    226222                                 const Guid *aId,
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