VirtualBox

Changeset 31281 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 2, 2010 10:35:19 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64308
Message:

Main: one function instead of two for finding DVD and floppy images

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

Legend:

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

    r31270 r31281  
    32163216                {
    32173217                    /* find a DVD image by UUID */
    3218                     rc = mParent->findDVDImage(&uuid, NULL, true /* aSetError */, &medium);
     3218                    rc = mParent->findDVDOrFloppyImage(DeviceType_DVD, &uuid, Utf8Str::Empty, true /* aSetError */, &medium);
    32193219                    if (FAILED(rc)) return rc;
    32203220                }
     
    32493249                {
    32503250                    /* find a floppy image by UUID */
    3251                     rc = mParent->findFloppyImage(&uuid, NULL, true /* aSetError */, &medium);
     3251                    rc = mParent->findDVDOrFloppyImage(DeviceType_Floppy, &uuid, Utf8Str::Empty, true /* aSetError */, &medium);
    32523252                    if (FAILED(rc)) return rc;
    32533253                }
     
    36933693    {
    36943694        case DeviceType_DVD:
     3695        case DeviceType_Floppy:
    36953696            if (!uuid.isEmpty())
    36963697            {
    3697                 /* find a DVD by host device UUID */
    3698                 MediaList llHostDVDDrives;
    3699                 rc = mParent->host()->getDVDDrives(llHostDVDDrives);
     3698                // check if the UUID refers to a host DVD or floppy drive
     3699                MediaList llHostDrives;
     3700                rc = (mediumType == DeviceType_DVD)
     3701                        ? mParent->host()->getDVDDrives(llHostDrives)
     3702                        : mParent->host()->getFloppyDrives(llHostDrives);
    37003703                if (SUCCEEDED(rc))
    37013704                {
    3702                     for (MediaList::iterator it = llHostDVDDrives.begin();
    3703                          it != llHostDVDDrives.end();
     3705                    for (MediaList::iterator it = llHostDrives.begin();
     3706                         it != llHostDrives.end();
    37043707                         ++it)
    37053708                    {
     
    37123715                    }
    37133716                }
    3714                 /* find a DVD by UUID */
     3717
    37153718                if (medium.isNull())
    3716                     rc = mParent->findDVDImage(&uuid, NULL, true /* aDoSetError */, &medium);
     3719                    // UUID was not a host drive:
     3720                    rc = mParent->findDVDOrFloppyImage(mediumType, &uuid, Utf8Str::Empty, true /* aDoSetError */, &medium);
    37173721            }
    37183722            if (FAILED(rc)) return rc;
    3719             break;
    3720         case DeviceType_Floppy:
    3721             if (!uuid.isEmpty())
    3722             {
    3723                 /* find a Floppy by host device UUID */
    3724                 MediaList llHostFloppyDrives;
    3725                 rc = mParent->host()->getFloppyDrives(llHostFloppyDrives);
    3726                 if (SUCCEEDED(rc))
    3727                 {
    3728                     for (MediaList::iterator it = llHostFloppyDrives.begin();
    3729                          it != llHostFloppyDrives.end();
    3730                          ++it)
    3731                     {
    3732                         ComObjPtr<Medium> &p = *it;
    3733                         if (uuid == p->getId())
    3734                         {
    3735                             medium = p;
    3736                             break;
    3737                         }
    3738                     }
    3739                 }
    3740                 /* find a Floppy by UUID */
    3741                 if (medium.isNull())
    3742                     rc = mParent->findFloppyImage(&uuid, NULL, true /* aDoSetError */, &medium);
    3743             }
    3744             if (FAILED(rc)) return rc;
    3745             break;
     3723        break;
     3724
    37463725        default:
    37473726            return setError(VBOX_E_INVALID_OBJECT_STATE,
     
    71687147                /* find a floppy by UUID */
    71697148                if (!dev.uuid.isEmpty())
    7170                     rc = mParent->findFloppyImage(&dev.uuid, NULL, true /* aDoSetError */, &medium);
     7149                    rc = mParent->findDVDOrFloppyImage(DeviceType_Floppy, &dev.uuid, Utf8Str::Empty, true /* aDoSetError */, &medium);
    71717150                /* find a floppy by host device name */
    71727151                else if (!dev.strHostDriveSrc.isEmpty())
     
    71947173                /* find a DVD by UUID */
    71957174                if (!dev.uuid.isEmpty())
    7196                     rc = mParent->findDVDImage(&dev.uuid, NULL, true /* aDoSetError */, &medium);
     7175                    rc = mParent->findDVDOrFloppyImage(DeviceType_DVD, &dev.uuid, Utf8Str::Empty, true /* aDoSetError */, &medium);
    71977176                /* find a DVD by host device name */
    71987177                else if (!dev.strHostDriveSrc.isEmpty())
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31258 r31281  
    48504850             ++it)
    48514851        {
    4852             m->properties.insert(std::make_pair(it->name, Bstr::Null));
     4852            m->properties.insert(std::make_pair(it->name, Bstr::Empty));
    48534853        }
    48544854    }
  • trunk/src/VBox/Main/SystemPropertiesImpl.cpp

    r30950 r31281  
    8484    unconst(mParent) = aParent;
    8585
    86     setDefaultMachineFolder(Utf8Str::Null);
    87     setDefaultHardDiskFolder(Utf8Str::Null);
    88     setDefaultHardDiskFormat(Utf8Str::Null);
    89 
    90     setRemoteDisplayAuthLibrary(Utf8Str::Null);
     86    setDefaultMachineFolder(Utf8Str::Empty);
     87    setDefaultHardDiskFolder(Utf8Str::Empty);
     88    setDefaultHardDiskFormat(Utf8Str::Empty);
     89
     90    setRemoteDisplayAuthLibrary(Utf8Str::Empty);
    9191
    9292    m->ulLogHistoryCount = 3;
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31034 r31281  
    15511551    Guid id(aId);
    15521552    ComObjPtr<Medium> image;
    1553     HRESULT rc = findDVDImage(&id, NULL, true /* setError */, &image);
     1553    HRESULT rc = findDVDOrFloppyImage(DeviceType_DVD, &id, Utf8Str::Empty, true /* setError */, &image);
    15541554
    15551555    /* the below will set *aDVDImage to NULL if image is null */
     
    15691569
    15701570    ComObjPtr<Medium> image;
    1571     HRESULT rc = findDVDImage(NULL, aLocation, true /* setError */, &image);
     1571    HRESULT rc = findDVDOrFloppyImage(DeviceType_DVD, NULL, aLocation, true /* setError */, &image);
    15721572
    15731573    /* the below will set *aDVDImage to NULL if dvd is null */
     
    16281628    Guid id(aId);
    16291629    ComObjPtr<Medium> image;
    1630     HRESULT rc = findFloppyImage(&id, NULL, true /* setError */, &image);
     1630    HRESULT rc = findDVDOrFloppyImage(DeviceType_Floppy, &id, Utf8Str::Empty, true /* setError */, &image);
    16311631
    16321632    /* the below will set *aFloppyImage to NULL if image is null */
     
    16471647
    16481648    ComObjPtr<Medium> image;
    1649     HRESULT rc = findFloppyImage(NULL, aLocation, true /* setError */, &image);
     1649    HRESULT rc = findDVDOrFloppyImage(DeviceType_Floppy, NULL, aLocation, true /* setError */, &image);
    16501650
    16511651    /* the below will set *aFloppyImage to NULL if img is null */
     
    27552755/**
    27562756 * Searches for a Medium object with the given ID or location in the list of
    2757  * registered DVD images. If both ID and file path are specified, the first
    2758  * object that matches either of them (not necessarily both) is returned.
    2759  *
    2760  * @param aId       ID of the DVD image (unused when NULL).
     2757 * registered DVD or floppy images, depending on the @a mediumType argument.
     2758 * If both ID and file path are specified, the first object that matches either
     2759 * of them (not necessarily both) is returned.
     2760 *
     2761 * @param mediumType Must be either DeviceType_DVD or DeviceType_Floppy.
     2762 * @param aId       ID of the image file (unused when NULL).
    27612763 * @param aLocation Full path to the image file (unused when NULL).
    27622764 * @param aSetError If @c true, the appropriate error info is set in case when
     
    27642766 * @param aImage    Where to store the found image object (can be NULL).
    27652767 *
    2766  * @return S_OK when found or E_INVALIDARG when not found.
     2768 * @return S_OK when found or E_INVALIDARG or VBOX_E_OBJECT_NOT_FOUND when not found.
    27672769 *
    27682770 * @note Locks the media tree for reading.
    27692771 */
    2770 HRESULT VirtualBox::findDVDImage(const Guid *aId,
    2771                                  CBSTR aLocation,
    2772                                  bool aSetError,
    2773                                  ComObjPtr<Medium> *aImage /* = NULL */)
    2774 {
    2775     AssertReturn(aId || aLocation, E_INVALIDARG);
     2772/**
     2773 *
     2774 * @param aId
     2775 * @param aLocation
     2776 * @param aSetError
     2777 * @param aImage
     2778 * @return
     2779 */
     2780HRESULT VirtualBox::findDVDOrFloppyImage(DeviceType_T mediumType,
     2781                                         const Guid *aId,
     2782                                         const Utf8Str &aLocation,
     2783                                         bool aSetError,
     2784                                         ComObjPtr<Medium> *aImage /* = NULL */)
     2785{
     2786    AssertReturn(aId || !aLocation.isEmpty(), E_INVALIDARG);
    27762787
    27772788    Utf8Str location;
    2778 
    2779     if (aLocation != NULL)
    2780     {
    2781         int vrc = calculateFullPath(Utf8Str(aLocation), location);
     2789    if (!aLocation.isEmpty())
     2790    {
     2791        int vrc = calculateFullPath(aLocation, location);
    27822792        if (RT_FAILURE(vrc))
    27832793            return setError(VBOX_E_FILE_ERROR,
    27842794                            tr("Invalid image file location '%ls' (%Rrc)"),
    2785                             aLocation,
     2795                            aLocation.c_str(),
    27862796                            vrc);
    27872797    }
    27882798
    2789     AutoReadLock alock(m->allDVDImages.getLockHandle() COMMA_LOCKVAL_SRC_POS);
     2799    MediaOList *pMediaList;
     2800
     2801    switch (mediumType)
     2802    {
     2803        case DeviceType_DVD:
     2804            pMediaList = &m->allDVDImages;
     2805        break;
     2806
     2807        case DeviceType_Floppy:
     2808            pMediaList = &m->allFloppyImages;
     2809        break;
     2810
     2811        default:
     2812            return E_INVALIDARG;
     2813    }
     2814
     2815    AutoReadLock alock(pMediaList->getLockHandle() COMMA_LOCKVAL_SRC_POS);
    27902816
    27912817    bool found = false;
    27922818
    2793     for (MediaList::const_iterator it = m->allDVDImages.begin();
    2794          it != m->allDVDImages.end();
    2795          ++ it)
    2796     {
    2797         /* no AutoCaller, registered image life time is bound to this */
    2798         AutoReadLock imageLock(*it COMMA_LOCKVAL_SRC_POS);
    2799 
    2800         found = (aId && (*it)->getId() == *aId) ||
    2801                 (aLocation != NULL &&
    2802                  RTPathCompare(location.c_str(),
    2803                                (*it)->getLocationFull().c_str()
    2804                               ) == 0);
     2819    for (MediaList::const_iterator it = pMediaList->begin();
     2820         it != pMediaList->end();
     2821         ++it)
     2822    {
     2823        // no AutoCaller, registered image life time is bound to this
     2824        Medium *pMedium = *it;
     2825        AutoReadLock imageLock(pMedium COMMA_LOCKVAL_SRC_POS);
     2826        const Utf8Str &strLocationFull = pMedium->getLocationFull();
     2827
     2828        found =     (    aId
     2829                      && pMedium->getId() == *aId)
     2830                 || (    !aLocation.isEmpty()
     2831                      && RTPathCompare(location.c_str(),
     2832                                       strLocationFull.c_str()) == 0);
    28052833        if (found)
    28062834        {
     2835            if (pMedium->getType() != mediumType)
     2836            {
     2837                if (mediumType == DeviceType_DVD)
     2838                    return setError(E_INVALIDARG,
     2839                                    "Cannot mount DVD medium '%s' as floppy", strLocationFull.c_str());
     2840                else
     2841                    return setError(E_INVALIDARG,
     2842                                    "Cannot mount floppy medium '%s' as DVD", strLocationFull.c_str());
     2843            }
     2844
    28072845            if (aImage)
    2808                 *aImage = *it;
     2846                *aImage = pMedium;
    28092847            break;
    28102848        }
     
    28172855        if (aId)
    28182856            setError(rc,
    2819                      tr("Could not find a CD/DVD image with UUID {%RTuuid} in the media registry ('%s')"),
     2857                     tr("Could not find an image file with UUID {%RTuuid} in the media registry ('%s')"),
    28202858                     aId->raw(),
    28212859                     m->strSettingsFilePath.raw());
    28222860        else
    28232861            setError(rc,
    2824                      tr("Could not find a CD/DVD image with location '%ls' in the media registry ('%s')"),
    2825                      aLocation,
    2826                      m->strSettingsFilePath.raw());
    2827     }
    2828 
    2829     return rc;
    2830 }
    2831 
    2832 /**
    2833  * Searches for a Medium object with the given ID or location in the
    2834  * collection of registered DVD images. If both ID and file path are specified,
    2835  * the first object that matches either of them (not necessarily both) is
    2836  * returned.
    2837  *
    2838  * @param aId       ID of the DVD image (unused when NULL).
    2839  * @param aLocation Full path to the image file (unused when NULL).
    2840  * @param aSetError If @c true, the appropriate error info is set in case when
    2841  *                  the image is not found.
    2842  * @param aImage    Where to store the found image object (can be NULL).
    2843  *
    2844  * @return S_OK when found or E_INVALIDARG when not found.
    2845  *
    2846  * @note Locks the media tree for reading.
    2847  */
    2848 HRESULT VirtualBox::findFloppyImage(const Guid *aId,
    2849                                     CBSTR aLocation,
    2850                                     bool aSetError,
    2851                                     ComObjPtr<Medium> *aImage /* = NULL */)
    2852 {
    2853     AssertReturn(aId || aLocation, E_INVALIDARG);
    2854 
    2855     Utf8Str location;
    2856 
    2857     if (aLocation != NULL)
    2858     {
    2859         int vrc = calculateFullPath(Utf8Str(aLocation), location);
    2860         if (RT_FAILURE(vrc))
    2861             return setError(VBOX_E_FILE_ERROR,
    2862                             tr("Invalid image file location '%ls' (%Rrc)"),
    2863                             aLocation, vrc);
    2864     }
    2865 
    2866     AutoReadLock alock(m->allFloppyImages.getLockHandle() COMMA_LOCKVAL_SRC_POS);
    2867 
    2868     bool found = false;
    2869 
    2870     for (MediaList::const_iterator it = m->allFloppyImages.begin();
    2871          it != m->allFloppyImages.end();
    2872          ++ it)
    2873     {
    2874         /* no AutoCaller, registered image life time is bound to this */
    2875         AutoReadLock imageLock(*it COMMA_LOCKVAL_SRC_POS);
    2876 
    2877         found = (aId && (*it)->getId() == *aId) ||
    2878                 (aLocation != NULL &&
    2879                  RTPathCompare(location.c_str(),
    2880                                (*it)->getLocationFull().c_str()
    2881                               ) == 0);
    2882         if (found)
    2883         {
    2884             if (aImage)
    2885                 *aImage = *it;
    2886             break;
    2887         }
    2888     }
    2889 
    2890     HRESULT rc = found ? S_OK : VBOX_E_OBJECT_NOT_FOUND;
    2891 
    2892     if (aSetError && !found)
    2893     {
    2894         if (aId)
    2895             setError(rc,
    2896                      tr("Could not find a floppy image with UUID {%RTuuid} in the media registry ('%s')"),
    2897                      aId->raw(),
    2898                      m->strSettingsFilePath.raw());
    2899         else
    2900             setError(rc,
    2901                      tr("Could not find a floppy image with location '%ls' in the media registry ('%s')"),
    2902                      aLocation,
     2862                     tr("Could not find an image file with location '%ls' in the media registry ('%s')"),
     2863                     aLocation.c_str(),
    29032864                     m->strSettingsFilePath.raw());
    29042865    }
     
    30903051    {
    30913052        ComObjPtr<Medium> image;
    3092         rc = findDVDImage(&aId, bstrLocation, false /* aSetError */, &image);
     3053        rc = findDVDOrFloppyImage(DeviceType_DVD, &aId, bstrLocation, false /* aSetError */, &image);
    30933054        if (SUCCEEDED(rc))
    30943055        {
     
    31043065    {
    31053066        ComObjPtr<Medium> image;
    3106         rc = findFloppyImage(&aId, bstrLocation, false /* aSetError */, &image);
     3067        rc = findDVDOrFloppyImage(DeviceType_Floppy, &aId, bstrLocation, false /* aSetError */, &image);
    31073068        if (SUCCEEDED(rc))
    31083069        {
  • trunk/src/VBox/Main/glue/string.cpp

    r30750 r31281  
    3434
    3535/* static */
    36 const Bstr Bstr::Null; /* default ctor is OK */
     36const Bstr Bstr::Empty; /* default ctor is OK */
    3737
    3838/* static */
    39 const Utf8Str Utf8Str::Null; /* default ctor is OK */
     39const Utf8Str Utf8Str::Empty; /* default ctor is OK */
    4040
    4141#if defined (VBOX_WITH_XPCOM)
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31273 r31281  
    223223    HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
    224224                          bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
    225     HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
    226                          bool aSetError, ComObjPtr<Medium> *aImage = NULL);
    227     HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
    228                             bool aSetError, ComObjPtr<Medium> *aImage = NULL);
     225    HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
     226                                 const Guid *aId,
     227                                 const Utf8Str &aLocation,
     228                                 bool aSetError,
     229                                 ComObjPtr<Medium> *aImage = NULL);
    229230
    230231    HRESULT findGuestOSType(const Bstr &bstrOSType,
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette