VirtualBox

Changeset 31358 in vbox


Ignore:
Timestamp:
Aug 4, 2010 2:48:26 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64409
Message:

Main: convert more Medium and MediumFormat internals to Utf8Str

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

Legend:

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

    r31346 r31358  
    17461746            {
    17471747                ComObjPtr<Medium> hostDVDDriveObj;
    1748                 Bstr location(it->mDevice);
    1749                 Bstr description(it->mDescription);
     1748                Utf8Str location(it->mDevice);
     1749                Utf8Str description(it->mDescription);
    17501750                if (SUCCEEDED(rc))
    17511751                    rc = hostDVDDriveObj.createObject();
     
    18191819            {
    18201820                ComObjPtr<Medium> hostFloppyDriveObj;
    1821                 Bstr location(it->mDevice);
    1822                 Bstr description(it->mDescription);
     1821                Utf8Str location(it->mDevice);
     1822                Utf8Str description(it->mDescription);
    18231823                if (SUCCEEDED(rc))
    18241824                    rc = hostFloppyDriveObj.createObject();
  • trunk/src/VBox/Main/MachineImpl.cpp

    r31344 r31358  
    34153415        diff.createObject();
    34163416        rc = diff->init(mParent,
    3417                         medium->preferredDiffFormat().raw(),
    3418                         BstrFmt("%ls"RTPATH_SLASH_STR,
    3419                                  mUserData->mSnapshotFolderFull.raw()).raw(),
     3417                        medium->getPreferredDiffFormat(),
     3418                        Utf8StrFmt("%ls"RTPATH_SLASH_STR,
     3419                                   mUserData->mSnapshotFolderFull.raw()).raw(),
    34203420                        &fNeedsSaveSettings);
    34213421        if (FAILED(rc)) return rc;
     
    83998399            diff.createObject();
    84008400            rc = diff->init(mParent,
    8401                             pMedium->preferredDiffFormat().raw(),
    8402                             BstrFmt("%ls"RTPATH_SLASH_STR,
    8403                                     mUserData->mSnapshotFolderFull.raw()).raw(),
     8401                            pMedium->getPreferredDiffFormat(),
     8402                            Utf8StrFmt("%ls"RTPATH_SLASH_STR,
     8403                                       mUserData->mSnapshotFolderFull.raw()).raw(),
    84048404                            pfNeedsSaveSettings);
    84058405            if (FAILED(rc)) throw rc;
  • trunk/src/VBox/Main/MediumFormatImpl.cpp

    r30764 r31358  
    6060
    6161    /* The ID of the backend */
    62     unconst(m.id) = aVDInfo->pszBackend;
     62    unconst(m.strId) = aVDInfo->pszBackend;
    6363    /* The Name of the backend */
    6464    /* Use id for now as long as VDBACKENDINFO hasn't any extra
    6565     * name/description field. */
    66     unconst(m.name) = aVDInfo->pszBackend;
     66    unconst(m.strName) = aVDInfo->pszBackend;
    6767    /* The capabilities of the backend */
    6868    unconst(m.capabilities) = aVDInfo->uBackendCaps;
     
    7373        while (*papsz != NULL)
    7474        {
    75             unconst (m.fileExtensions).push_back (*papsz);
    76             ++ papsz;
     75            unconst(m.llFileExtensions).push_back(*papsz);
     76            ++papsz;
    7777        }
    7878    }
     
    131131
    132132            /* Create one property structure */
    133             const Property prop = { Utf8Str (pa->pszKey),
    134                                     Utf8Str (""),
     133            const Property prop = { Utf8Str(pa->pszKey),
     134                                    Utf8Str(""),
    135135                                    dt,
    136136                                    flags,
    137137                                    defaultValue };
    138             unconst (m.properties).push_back (prop);
    139             ++ pa;
     138            unconst(m.llProperties).push_back(prop);
     139            ++pa;
    140140        }
    141141    }
     
    160160        return;
    161161
    162     unconst (m.properties).clear();
    163     unconst (m.fileExtensions).clear();
    164     unconst (m.capabilities) = 0;
    165     unconst (m.name).setNull();
    166     unconst (m.id).setNull();
     162    unconst(m.llProperties).clear();
     163    unconst(m.llFileExtensions).clear();
     164    unconst(m.capabilities) = 0;
     165    unconst(m.strName).setNull();
     166    unconst(m.strId).setNull();
    167167}
    168168
     
    178178
    179179    /* this is const, no need to lock */
    180     m.id.cloneTo (aId);
     180    m.strId.cloneTo(aId);
    181181
    182182    return S_OK;
     
    191191
    192192    /* this is const, no need to lock */
    193     m.name.cloneTo (aName);
     193    m.strName.cloneTo(aName);
    194194
    195195    return S_OK;
     
    205205
    206206    /* this is const, no need to lock */
    207     com::SafeArray<BSTR> fileExtentions(m.fileExtensions.size());
     207    com::SafeArray<BSTR> fileExtentions(m.llFileExtensions.size());
    208208    int i = 0;
    209     for (BstrList::const_iterator it = m.fileExtensions.begin();
    210          it != m.fileExtensions.end();
     209    for (StrList::const_iterator it = m.llFileExtensions.begin();
     210         it != m.llFileExtensions.end();
    211211         ++it, ++i)
    212212        (*it).cloneTo(&fileExtentions[i]);
     
    236236}
    237237
    238 STDMETHODIMP MediumFormat::DescribeProperties(ComSafeArrayOut (BSTR, aNames),
    239                                                 ComSafeArrayOut (BSTR, aDescriptions),
    240                                                 ComSafeArrayOut (DataType_T, aTypes),
    241                                                 ComSafeArrayOut (ULONG, aFlags),
    242                                                 ComSafeArrayOut (BSTR, aDefaults))
     238STDMETHODIMP MediumFormat::DescribeProperties(ComSafeArrayOut(BSTR, aNames),
     239                                              ComSafeArrayOut(BSTR, aDescriptions),
     240                                              ComSafeArrayOut(DataType_T, aTypes),
     241                                              ComSafeArrayOut(ULONG, aFlags),
     242                                              ComSafeArrayOut(BSTR, aDefaults))
    243243{
    244244    CheckComArgSafeArrayNotNull(aNames);
     
    252252
    253253    /* this is const, no need to lock */
    254     com::SafeArray<BSTR>        propertyNames(m.properties.size());
    255     com::SafeArray<BSTR>        propertyDescriptions (m.properties.size());
    256     com::SafeArray<DataType_T>  propertyTypes(m.properties.size());
    257     com::SafeArray<ULONG>       propertyFlags(m.properties.size());
    258     com::SafeArray<BSTR>        propertyDefaults(m.properties.size());
     254    size_t c = m.llProperties.size();
     255    com::SafeArray<BSTR>        propertyNames(c);
     256    com::SafeArray<BSTR>        propertyDescriptions(c);
     257    com::SafeArray<DataType_T>  propertyTypes(c);
     258    com::SafeArray<ULONG>       propertyFlags(c);
     259    com::SafeArray<BSTR>        propertyDefaults(c);
    259260
    260261    int i = 0;
    261     for (PropertyList::const_iterator it = m.properties.begin();
    262          it != m.properties.end();
     262    for (PropertyList::const_iterator it = m.llProperties.begin();
     263         it != m.llProperties.end();
    263264         ++it, ++i)
    264265    {
    265266        const Property &prop = (*it);
    266         prop.name.cloneTo(&propertyNames[i]);
    267         prop.description.cloneTo(&propertyDescriptions[i]);
     267        prop.strName.cloneTo(&propertyNames[i]);
     268        prop.strDescription.cloneTo(&propertyDescriptions[i]);
    268269        propertyTypes[i] = prop.type;
    269270        propertyFlags[i] = prop.flags;
    270         prop.defaultValue.cloneTo(&propertyDefaults[i]);
     271        prop.strDefaultValue.cloneTo(&propertyDefaults[i]);
    271272    }
    272273
  • trunk/src/VBox/Main/MediumImpl.cpp

    r31333 r31358  
    730730
    731731/**
    732  * Initializes the hard disk object without creating or opening an associated
     732 * Initializes an empty hard disk object without creating or opening an associated
    733733 * storage unit.
     734 *
     735 * This gets called by VirtualBox::CreateHardDisk().
    734736 *
    735737 * For hard disks that don't have the VD_CAP_CREATE_FIXED or
     
    744746 */
    745747HRESULT Medium::init(VirtualBox *aVirtualBox,
    746                      CBSTR aFormat,
    747                      CBSTR aLocation,
     748                     const Utf8Str &aFormat,
     749                     const Utf8Str &aLocation,
    748750                     bool *pfNeedsSaveSettings)
    749751{
    750752    AssertReturn(aVirtualBox != NULL, E_FAIL);
    751     AssertReturn(aFormat != NULL && *aFormat != '\0', E_FAIL);
     753    AssertReturn(!aFormat.isEmpty(), E_FAIL);
    752754
    753755    /* Enclose the state transition NotReady->InInit->Ready */
     
    771773    if (FAILED(rc)) return rc;
    772774
    773     if (m->formatObj->capabilities() & MediumFormatCapabilities_File)
     775    if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    774776    {
    775777        rc = setLocation(aLocation);
     
    782784    }
    783785
    784     if (!(m->formatObj->capabilities() & (   MediumFormatCapabilities_CreateFixed
    785                                            | MediumFormatCapabilities_CreateDynamic))
     786    if (!(m->formatObj->getCapabilities() & (   MediumFormatCapabilities_CreateFixed
     787                                              | MediumFormatCapabilities_CreateDynamic))
    786788       )
    787789    {
     
    807809 * location. The enOpenMode parameter defines whether the medium will be opened
    808810 * read/write or read-only.
     811 *
     812 * This gets called by VirtualBox::OpenHardDisk(), OpenDVDImage and OpenFloppyImage();
     813 * this also gets called by Machine::AttachDevice() and createImplicitDiffs()
     814 * when new diff images are created.
    809815 *
    810816 * Note that the UUID, format and the parent of this medium will be
     
    825831 */
    826832HRESULT Medium::init(VirtualBox *aVirtualBox,
    827                      CBSTR aLocation,
     833                     const Utf8Str &aLocation,
    828834                     HDDOpenMode enOpenMode,
    829835                     DeviceType_T aDeviceType,
     
    834840{
    835841    AssertReturn(aVirtualBox, E_INVALIDARG);
    836     AssertReturn(aLocation, E_INVALIDARG);
     842    AssertReturn(!aLocation.isEmpty(), E_INVALIDARG);
    837843
    838844    /* Enclose the state transition NotReady->InInit->Ready */
     
    954960    {
    955961        AssertReturn(!data.strFormat.isEmpty(), E_FAIL);
    956         rc = setFormat(Bstr(data.strFormat));
     962        rc = setFormat(data.strFormat);
    957963        if (FAILED(rc)) return rc;
    958964    }
     
    961967        /// @todo handle host drive settings here as well?
    962968        if (!data.strFormat.isEmpty())
    963             rc = setFormat(Bstr(data.strFormat));
     969            rc = setFormat(data.strFormat);
    964970        else
    965             rc = setFormat(Bstr("RAW"));
     971            rc = setFormat("RAW");
    966972        if (FAILED(rc)) return rc;
    967973    }
     
    10451051 * Not used for anything but the host floppy/host DVD case.
    10461052 *
    1047  * @todo optimize all callers to avoid reconstructing objects with the same
    1048  * information over and over again - in the typical case each VM referring to
    1049  * a particular host drive has its own instance.
    1050  *
    10511053 * @param aVirtualBox   VirtualBox object.
    10521054 * @param aDeviceType   Device type of the medium.
     
    10581060HRESULT Medium::init(VirtualBox *aVirtualBox,
    10591061                     DeviceType_T aDeviceType,
    1060                      CBSTR aLocation,
    1061                      CBSTR aDescription)
     1062                     const Utf8Str &aLocation,
     1063                     const Utf8Str &aDescription /* = Utf8Str::Empty */)
    10621064{
    10631065    ComAssertRet(aDeviceType == DeviceType_DVD || aDeviceType == DeviceType_Floppy, E_INVALIDARG);
    1064     ComAssertRet(aLocation, E_INVALIDARG);
     1066    ComAssertRet(!aLocation.isEmpty(), E_INVALIDARG);
    10651067
    10661068    /* Enclose the state transition NotReady->InInit->Ready */
     
    10791081        memcpy(&uuid.au8[0], "FD", 2);
    10801082    /* use device name, adjusted to the end of uuid, shortened if necessary */
    1081     Utf8Str loc(aLocation);
    1082     size_t cbLocation = strlen(loc.raw());
    1083     if (cbLocation > 12)
    1084         memcpy(&uuid.au8[4], loc.raw() + (cbLocation - 12), 12);
     1083    size_t lenLocation = aLocation.length();
     1084    if (lenLocation > 12)
     1085        memcpy(&uuid.au8[4], aLocation.raw() + (lenLocation - 12), 12);
    10851086    else
    1086         memcpy(&uuid.au8[4 + 12 - cbLocation], loc.raw(), cbLocation);
     1087        memcpy(&uuid.au8[4 + 12 - lenLocation], aLocation.raw(), lenLocation);
    10871088    unconst(m->id) = uuid;
    10881089
     
    10911092    m->state = MediumState_Created;
    10921093    m->hostDrive = true;
    1093     HRESULT rc = setFormat(Bstr("RAW"));
     1094    HRESULT rc = setFormat("RAW");
    10941095    if (FAILED(rc)) return rc;
    10951096    rc = setLocation(aLocation);
     
    21062107        aVariant = (MediumVariant_T)((unsigned)aVariant & (unsigned)~MediumVariant_Diff);
    21072108        if (    !(aVariant & MediumVariant_Fixed)
    2108             &&  !(m->formatObj->capabilities() & MediumFormatCapabilities_CreateDynamic))
     2109            &&  !(m->formatObj->getCapabilities() & MediumFormatCapabilities_CreateDynamic))
    21092110            throw setError(VBOX_E_NOT_SUPPORTED,
    21102111                           tr("Medium format '%s' does not support dynamic storage creation"),
    21112112                           m->strFormat.raw());
    21122113        if (    (aVariant & MediumVariant_Fixed)
    2113             &&  !(m->formatObj->capabilities() & MediumFormatCapabilities_CreateDynamic))
     2114            &&  !(m->formatObj->getCapabilities() & MediumFormatCapabilities_CreateDynamic))
    21142115            throw setError(VBOX_E_NOT_SUPPORTED,
    21152116                           tr("Medium format '%s' does not support fixed storage creation"),
     
    25542555////////////////////////////////////////////////////////////////////////////////
    25552556//
    2556 // Medium internal methods
     2557// Medium public internal methods
    25572558//
    25582559////////////////////////////////////////////////////////////////////////////////
     
    26432644 * @return
    26442645 */
    2645 const ComObjPtr<MediumFormat> & Medium::getMediumFormat() const
     2646const ComObjPtr<MediumFormat>& Medium::getMediumFormat() const
    26462647{
    26472648    return m->formatObj;
     
    30993100    /// @todo NEWMEDIA delegate the comparison to the backend?
    31003101
    3101     if (m->formatObj->capabilities() & MediumFormatCapabilities_File)
     3102    if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    31023103    {
    31033104        Utf8Str location(aLocation);
     
    32223223 * Returns a preferred format for differencing media.
    32233224 */
    3224 Bstr Medium::preferredDiffFormat()
    3225 {
    3226     Utf8Str strFormat;
    3227 
     3225Utf8Str Medium::getPreferredDiffFormat()
     3226{
    32283227    AutoCaller autoCaller(this);
    3229     AssertComRCReturn(autoCaller.rc(), strFormat);
     3228    AssertComRCReturn(autoCaller.rc(), Utf8Str::Empty);
     3229
     3230    /* check that our own format supports diffs */
     3231    if (!(m->formatObj->getCapabilities() & MediumFormatCapabilities_Differencing))
     3232        /* use the default format if not */
     3233        return m->pVirtualBox->getDefaultHardDiskFormat();
    32303234
    32313235    /* m->strFormat is const, no need to lock */
    3232     strFormat = m->strFormat;
    3233 
    3234     /* check that our own format supports diffs */
    3235     if (!(m->formatObj->capabilities() & MediumFormatCapabilities_Differencing))
    3236     {
    3237         /* use the default format if not */
    3238         AutoReadLock propsLock(m->pVirtualBox->getSystemProperties() COMMA_LOCKVAL_SRC_POS);
    3239         strFormat = m->pVirtualBox->getDefaultHardDiskFormat();
    3240     }
    3241 
    3242     return strFormat;
     3236    return m->strFormat;
    32433237}
    32443238
     
    32603254    return m->type;
    32613255}
    3262 
    3263 // private methods
    3264 ////////////////////////////////////////////////////////////////////////////////
    32653256
    32663257/**
     
    32963287 * @note Must be called from under this object's write lock.
    32973288 */
    3298 HRESULT Medium::setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat)
     3289HRESULT Medium::setLocation(const Utf8Str &aLocation,
     3290                            const Utf8Str &aFormat /* = Utf8Str::Empty */)
    32993291{
    33003292    AssertReturn(!aLocation.isEmpty(), E_FAIL);
     
    33183310
    33193311    if (   isImport
    3320         || (   (m->formatObj->capabilities() & MediumFormatCapabilities_File)
     3312        || (   (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    33213313            && !m->hostDrive))
    33223314    {
     
    33283320        {
    33293321            /* must be a file (formatObj must be already known) */
    3330             Assert(m->formatObj->capabilities() & MediumFormatCapabilities_File);
     3322            Assert(m->formatObj->getCapabilities() & MediumFormatCapabilities_File);
    33313323
    33323324            if (RTPathFilename(location.c_str()) == NULL)
     
    33363328                 * this */
    33373329
    3338                 ComAssertMsgRet(!m->formatObj->fileExtensions().empty(),
     3330                ComAssertMsgRet(!m->formatObj->getFileExtensions().empty(),
    33393331                                ("Must be at least one extension if it is MediumFormatCapabilities_File\n"),
    33403332                                E_FAIL);
    33413333
    3342                 Bstr ext = m->formatObj->fileExtensions().front();
    3343                 ComAssertMsgRet(!ext.isEmpty(),
     3334                Utf8Str strExt = m->formatObj->getFileExtensions().front();
     3335                ComAssertMsgRet(!strExt.isEmpty(),
    33443336                                ("Default extension must not be empty\n"),
    33453337                                E_FAIL);
     
    33473339                id.create();
    33483340
    3349                 location = Utf8StrFmt("%s{%RTuuid}.%ls",
    3350                                       location.raw(), id.raw(), ext.raw());
     3341                location = Utf8StrFmt("%s{%RTuuid}.%s",
     3342                                      location.raw(), id.raw(), strExt.c_str());
    33513343            }
    33523344        }
     
    34023394                else
    34033395                {
    3404                     HRESULT rc = setFormat(Bstr(aFormat));
     3396                    HRESULT rc = setFormat(aFormat);
    34053397                    /* setFormat() must not fail since we've just used the backend so
    34063398                     * the format object must be there */
     
    34123404                ComAssertRet(backendName != NULL && *backendName != '\0', E_FAIL);
    34133405
    3414                 HRESULT rc = setFormat(Bstr(backendName));
     3406                HRESULT rc = setFormat(backendName);
    34153407                RTStrFree(backendName);
    34163408
     
    34223414
    34233415        /* is it still a file? */
    3424         if (m->formatObj->capabilities() & MediumFormatCapabilities_File)
     3416        if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File)
    34253417        {
    34263418            m->strLocation = location;
     
    35723564            }
    35733565
    3574             if (formatObj->capabilities() & MediumFormatCapabilities_Uuid)
     3566            if (formatObj->getCapabilities() & MediumFormatCapabilities_Uuid)
    35753567            {
    35763568                /* Modify the UUIDs if necessary. The associated fields are
     
    36123604                    {
    36133605                        lastAccessError = Utf8StrFmt(
    3614                             tr("UUID {%RTuuid} of the medium '%s' does not match the value {%RTuuid} stored in the media registry ('%s')"),
    3615                             &uuid,
    3616                             location.c_str(),
    3617                             mediumId.raw(),
    3618                             m->pVirtualBox->settingsFilePath().c_str());
     3606                                tr("UUID {%RTuuid} of the medium '%s' does not match the value {%RTuuid} stored in the media registry ('%s')"),
     3607                                &uuid,
     3608                                location.c_str(),
     3609                                mediumId.raw(),
     3610                                m->pVirtualBox->settingsFilePath().c_str());
    36193611                        throw S_OK;
    36203612                    }
     
    36603652                    Guid id = parentId;
    36613653                    ComObjPtr<Medium> pParent;
    3662                     rc = m->pVirtualBox->findHardDisk(&id, NULL,
    3663                                                       false /* aSetError */,
    3664                                                       &pParent);
     3654                    rc = m->pVirtualBox->findHardDisk(&id, NULL, false /* aSetError */, &pParent);
    36653655                    if (FAILED(rc))
    36663656                    {
    36673657                        lastAccessError = Utf8StrFmt(
    3668                             tr("Parent medium with UUID {%RTuuid} of the medium '%s' is not found in the media registry ('%s')"),
    3669                             &parentId, location.c_str(),
    3670                             m->pVirtualBox->settingsFilePath().c_str());
     3658                                tr("Parent medium with UUID {%RTuuid} of the medium '%s' is not found in the media registry ('%s')"),
     3659                                &parentId, location.c_str(),
     3660                                m->pVirtualBox->settingsFilePath().c_str());
    36713661                        throw S_OK;
    36723662                    }
     
    36913681                    {
    36923682                        lastAccessError = Utf8StrFmt(
    3693                             tr("Medium type of '%s' is differencing but it is not associated with any parent medium in the media registry ('%s')"),
    3694                             location.c_str(),
    3695                             m->pVirtualBox->settingsFilePath().c_str());
     3683                                tr("Medium type of '%s' is differencing but it is not associated with any parent medium in the media registry ('%s')"),
     3684                                location.c_str(),
     3685                                m->pVirtualBox->settingsFilePath().c_str());
    36963686                        throw S_OK;
    36973687                    }
     
    37023692                    {
    37033693                        lastAccessError = Utf8StrFmt(
    3704                             tr("Parent UUID {%RTuuid} of the medium '%s' does not match UUID {%RTuuid} of its parent medium stored in the media registry ('%s')"),
    3705                             &parentId, location.c_str(),
    3706                             m->pParent->getId().raw(),
    3707                             m->pVirtualBox->settingsFilePath().c_str());
     3694                                tr("Parent UUID {%RTuuid} of the medium '%s' does not match UUID {%RTuuid} of its parent medium stored in the media registry ('%s')"),
     3695                                &parentId, location.c_str(),
     3696                                m->pParent->getId().raw(),
     3697                                m->pVirtualBox->settingsFilePath().c_str());
    37083698                        throw S_OK;
    37093699                    }
     
    37483738        m->strLastAccessError = lastAccessError;
    37493739        LogWarningFunc(("'%s' is not accessible (error='%s', rc=%Rhrc, vrc=%Rrc)\n",
    3750                          location.c_str(), m->strLastAccessError.c_str(),
    3751                          rc, vrc));
     3740                        location.c_str(), m->strLastAccessError.c_str(),
     3741                        rc, vrc));
    37523742    }
    37533743
     
    39633953        LogFlowThisFunc(("aWait=%RTbool locationFull=%s\n", aWait, getLocationFull().c_str() ));
    39643954
    3965         if (    !(m->formatObj->capabilities() & (   MediumFormatCapabilities_CreateDynamic
    3966                                                    | MediumFormatCapabilities_CreateFixed)))
     3955        if (    !(m->formatObj->getCapabilities() & (   MediumFormatCapabilities_CreateDynamic
     3956                                                      | MediumFormatCapabilities_CreateFixed)))
    39673957            throw setError(VBOX_E_NOT_SUPPORTED,
    39683958                           tr("Medium format '%s' does not support storage deletion"),
     
    48344824}
    48354825
     4826////////////////////////////////////////////////////////////////////////////////
     4827//
     4828// Private methods
     4829//
     4830////////////////////////////////////////////////////////////////////////////////
     4831
     4832/**
     4833 * Performs extra checks if the medium can be closed and returns S_OK in
     4834 * this case. Otherwise, returns a respective error message. Called by
     4835 * Close() under the medium tree lock and the medium lock.
     4836 *
     4837 * @note Also reused by Medium::Reset().
     4838 *
     4839 * @note Caller must hold the media tree write lock!
     4840 */
     4841HRESULT Medium::canClose()
     4842{
     4843    Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     4844
     4845    if (getChildren().size() != 0)
     4846        return setError(VBOX_E_OBJECT_IN_USE,
     4847                        tr("Cannot close medium '%s' because it has %d child media"),
     4848                        m->strLocationFull.raw(), getChildren().size());
     4849
     4850    return S_OK;
     4851}
     4852
     4853/**
     4854 * Unregisters this medium with mVirtualBox. Called by close() under the medium tree lock.
     4855 *
     4856 * This calls either VirtualBox::unregisterImage or VirtualBox::unregisterHardDisk depending
     4857 * on the device type of this medium.
     4858 *
     4859 * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
     4860 *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
     4861 *
     4862 * @note Caller must have locked the media tree lock for writing!
     4863 */
     4864HRESULT Medium::unregisterWithVirtualBox(bool *pfNeedsSaveSettings)
     4865{
     4866    /* Note that we need to de-associate ourselves from the parent to let
     4867     * unregisterHardDisk() properly save the registry */
     4868
     4869    /* we modify mParent and access children */
     4870    Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread());
     4871
     4872    Medium *pParentBackup = m->pParent;
     4873    AssertReturn(getChildren().size() == 0, E_FAIL);
     4874    if (m->pParent)
     4875        deparent();
     4876
     4877    HRESULT rc = E_FAIL;
     4878    switch (m->devType)
     4879    {
     4880        case DeviceType_DVD:
     4881            rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD, pfNeedsSaveSettings);
     4882        break;
     4883
     4884        case DeviceType_Floppy:
     4885            rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy, pfNeedsSaveSettings);
     4886        break;
     4887
     4888        case DeviceType_HardDisk:
     4889            rc = m->pVirtualBox->unregisterHardDisk(this, pfNeedsSaveSettings);
     4890        break;
     4891
     4892        default:
     4893        break;
     4894    }
     4895
     4896    if (FAILED(rc))
     4897    {
     4898        if (pParentBackup)
     4899        {
     4900            // re-associate with the parent as we are still relatives in the registry
     4901            m->pParent = pParentBackup;
     4902            m->pParent->m->llChildren.push_back(this);
     4903        }
     4904    }
     4905
     4906    return rc;
     4907}
     4908
    48364909/**
    48374910 * Checks that the format ID is valid and sets it on success.
     
    48434916 * @note Must be called from under this object's write lock.
    48444917 */
    4845 HRESULT Medium::setFormat(CBSTR aFormat)
     4918HRESULT Medium::setFormat(const Utf8Str &aFormat)
    48464919{
    48474920    /* get the format object first */
     
    48534926        if (m->formatObj.isNull())
    48544927            return setError(E_INVALIDARG,
    4855                             tr("Invalid medium storage format '%ls'"),
    4856                             aFormat);
     4928                            tr("Invalid medium storage format '%s'"),
     4929                            aFormat.c_str());
    48574930
    48584931        /* reference the format permanently to prevent its unexpected
     
    48674940        Assert(m->properties.empty());
    48684941
    4869         for (MediumFormat::PropertyList::const_iterator it =
    4870                 m->formatObj->properties().begin();
    4871              it != m->formatObj->properties().end();
     4942        for (MediumFormat::PropertyList::const_iterator it = m->formatObj->getProperties().begin();
     4943             it != m->formatObj->getProperties().end();
    48724944             ++it)
    48734945        {
    4874             m->properties.insert(std::make_pair(it->name, Bstr::Empty));
     4946            m->properties.insert(std::make_pair(it->strName, Utf8Str::Empty));
    48754947        }
    48764948    }
     
    48794951
    48804952    return S_OK;
    4881 }
    4882 
    4883 /**
    4884  * Performs extra checks if the medium can be closed and returns S_OK in
    4885  * this case. Otherwise, returns a respective error message. Called by
    4886  * Close() under the medium tree lock and the medium lock.
    4887  *
    4888  * @note Also reused by Medium::Reset().
    4889  *
    4890  * @note Caller must hold the media tree write lock!
    4891  */
    4892 HRESULT Medium::canClose()
    4893 {
    4894     Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread());
    4895 
    4896     if (getChildren().size() != 0)
    4897         return setError(VBOX_E_OBJECT_IN_USE,
    4898                         tr("Cannot close medium '%s' because it has %d child media"),
    4899                         m->strLocationFull.raw(), getChildren().size());
    4900 
    4901     return S_OK;
    4902 }
    4903 
    4904 /**
    4905  * Unregisters this medium with mVirtualBox. Called by close() under the medium tree lock.
    4906  *
    4907  * This calls either VirtualBox::unregisterImage or VirtualBox::unregisterHardDisk depending
    4908  * on the device type of this medium.
    4909  *
    4910  * @param pfNeedsSaveSettings Optional pointer to a bool that must have been initialized to false and that will be set to true
    4911  *                by this function if the caller should invoke VirtualBox::saveSettings() because the global settings have changed.
    4912  *
    4913  * @note Caller must have locked the media tree lock for writing!
    4914  */
    4915 HRESULT Medium::unregisterWithVirtualBox(bool *pfNeedsSaveSettings)
    4916 {
    4917     /* Note that we need to de-associate ourselves from the parent to let
    4918      * unregisterHardDisk() properly save the registry */
    4919 
    4920     /* we modify mParent and access children */
    4921     Assert(m->pVirtualBox->getMediaTreeLockHandle().isWriteLockOnCurrentThread());
    4922 
    4923     Medium *pParentBackup = m->pParent;
    4924     AssertReturn(getChildren().size() == 0, E_FAIL);
    4925     if (m->pParent)
    4926         deparent();
    4927 
    4928     HRESULT rc = E_FAIL;
    4929     switch (m->devType)
    4930     {
    4931         case DeviceType_DVD:
    4932             rc = m->pVirtualBox->unregisterImage(this, DeviceType_DVD, pfNeedsSaveSettings);
    4933         break;
    4934 
    4935         case DeviceType_Floppy:
    4936             rc = m->pVirtualBox->unregisterImage(this, DeviceType_Floppy, pfNeedsSaveSettings);
    4937         break;
    4938 
    4939         case DeviceType_HardDisk:
    4940             rc = m->pVirtualBox->unregisterHardDisk(this, pfNeedsSaveSettings);
    4941         break;
    4942 
    4943         default:
    4944         break;
    4945     }
    4946 
    4947     if (FAILED(rc))
    4948     {
    4949         if (pParentBackup)
    4950         {
    4951             // re-associate with the parent as we are still relatives in the registry
    4952             m->pParent = pParentBackup;
    4953             m->pParent->m->llChildren.push_back(this);
    4954         }
    4955     }
    4956 
    4957     return rc;
    49584953}
    49594954
     
    53705365        Utf8Str format(m->strFormat);
    53715366        Utf8Str location(m->strLocationFull);
    5372         uint64_t capabilities = m->formatObj->capabilities();
     5367        uint64_t capabilities = m->formatObj->getCapabilities();
    53735368        ComAssertThrow(capabilities & (  VD_CAP_CREATE_FIXED
    53745369                                       | VD_CAP_CREATE_DYNAMIC), E_FAIL);
     
    55065501        Utf8Str targetFormat(pTarget->m->strFormat);
    55075502        Utf8Str targetLocation(pTarget->m->strLocationFull);
    5508         uint64_t capabilities = m->formatObj->capabilities();
     5503        uint64_t capabilities = m->formatObj->getCapabilities();
    55095504        ComAssertThrow(capabilities & VD_CAP_CREATE_DYNAMIC, E_FAIL);
    55105505
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r31333 r31358  
    26242624                    // Diff medium not backed by a file - cannot get status so
    26252625                    // be pessimistic.
    2626                     if (!(sourceFormat->capabilities() & MediumFormatCapabilities_File))
     2626                    if (!(sourceFormat->getCapabilities() & MediumFormatCapabilities_File))
    26272627                        throw rc;
    26282628                    const Utf8Str &loc = it->mpSource->getLocationFull();
  • trunk/src/VBox/Main/SystemPropertiesImpl.cpp

    r31281 r31358  
    828828 * @return ComObjPtr<MediumFormat>
    829829 */
    830 ComObjPtr<MediumFormat> SystemProperties::mediumFormat (CBSTR aFormat)
     830ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
    831831{
    832832    ComObjPtr<MediumFormat> format;
     
    843843        /* MediumFormat is all const, no need to lock */
    844844
    845         if ((*it)->id().compare(aFormat, Bstr::CaseInsensitive) == 0)
     845        if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
    846846        {
    847847            format = *it;
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r31308 r31358  
    13761376    /* we don't access non-const data members so no need to lock */
    13771377
    1378     Bstr format = aFormat;
     1378    Utf8Str format(aFormat);
    13791379    if (format.isEmpty())
    13801380        format = getDefaultHardDiskFormat();
     
    13861386    ComObjPtr<Medium> hardDisk;
    13871387    hardDisk.createObject();
    1388     rc = hardDisk->init(this, format.raw(), aLocation, &fNeedsSaveSettings);
     1388    rc = hardDisk->init(this,
     1389                        format,
     1390                        aLocation,
     1391                        &fNeedsSaveSettings);
    13891392
    13901393    if (SUCCEEDED(rc))
     
    15021505
    15031506/** @note Doesn't lock anything. */
    1504 STDMETHODIMP VirtualBox::OpenDVDImage(IN_BSTR aLocation, IN_BSTR aId,
     1507STDMETHODIMP VirtualBox::OpenDVDImage(IN_BSTR aLocation,
     1508                                      IN_BSTR aId,
    15051509                                      IMedium **aDVDImage)
    15061510{
     
    15201524    ComObjPtr<Medium> image;
    15211525    image.createObject();
    1522     rc = image->init(this, aLocation, Medium::OpenReadOnly, DeviceType_DVD, true, id, false, Guid());
     1526    rc = image->init(this,
     1527                     aLocation,
     1528                     Medium::OpenReadOnly,
     1529                     DeviceType_DVD,
     1530                     true /* aSetImageId */,
     1531                     id,
     1532                     false /* aSetParentId */,
     1533                     Guid());
    15231534    if (SUCCEEDED(rc))
    15241535    {
     
    15781589
    15791590/** @note Doesn't lock anything. */
    1580 STDMETHODIMP VirtualBox::OpenFloppyImage(IN_BSTR aLocation, IN_BSTR aId,
     1591STDMETHODIMP VirtualBox::OpenFloppyImage(IN_BSTR aLocation,
     1592                                         IN_BSTR aId,
    15811593                                         IMedium **aFloppyImage)
    15821594{
     
    15961608    ComObjPtr<Medium> image;
    15971609    image.createObject();
    1598     rc = image->init(this, aLocation, Medium::OpenReadWrite, DeviceType_Floppy, true, id, false, Guid());
     1610    rc = image->init(this,
     1611                     aLocation,
     1612                     Medium::OpenReadWrite,
     1613                     DeviceType_Floppy,
     1614                     true /* aSetImageId */,
     1615                     id,
     1616                     false /* aSetParentId */,
     1617                     Guid());
    15991618    if (SUCCEEDED(rc))
    16001619    {
     
    29562975 * @return
    29572976 */
    2958 const Utf8Str& VirtualBox::getDefaultMachineFolder() const
     2977Utf8Str VirtualBox::getDefaultMachineFolder() const
    29592978{
    29602979    AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS);
     
    29672986 * @return
    29682987 */
    2969 const Utf8Str& VirtualBox::getDefaultHardDiskFolder() const
     2988Utf8Str VirtualBox::getDefaultHardDiskFolder() const
    29702989{
    29712990    AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS);
     
    29782997 * @return
    29792998 */
    2980 const Utf8Str& VirtualBox::getDefaultHardDiskFormat() const
     2999Utf8Str VirtualBox::getDefaultHardDiskFormat() const
    29813000{
    29823001    AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS);
  • trunk/src/VBox/Main/include/MediumFormatImpl.h

    r30764 r31358  
    4646    struct Property
    4747    {
    48         Bstr name;
    49         Bstr description;
    50         DataType_T type;
    51         ULONG flags;
    52         Bstr defaultValue;
     48        Utf8Str     strName;
     49        Utf8Str     strDescription;
     50        DataType_T  type;
     51        ULONG       flags;
     52        Utf8Str     strDefaultValue;
    5353    };
    5454
    55     typedef std::list <Bstr> BstrList;
    56     typedef std::list <Property> PropertyList;
     55    typedef std::list<Utf8Str>  StrList;
     56    typedef std::list<Property> PropertyList;
    5757
    5858    struct Data
     
    6060        Data() : capabilities (0) {}
    6161
    62         const Bstr id;
    63         const Bstr name;
    64         const BstrList fileExtensions;
    65         const uint64_t capabilities;
    66         const PropertyList properties;
     62        const Utf8Str       strId;
     63        const Utf8Str       strName;
     64        const StrList       llFileExtensions;
     65        const uint64_t      capabilities;
     66        const PropertyList  llProperties;
    6767    };
    6868
     
    107107
    108108    /** Const, no need to lock */
    109     const Bstr &id() const { return m.id; }
     109    const Utf8Str& getId() const { return m.strId; }
    110110    /** Const, no need to lock */
    111     const BstrList &fileExtensions() const { return m.fileExtensions; }
     111    const StrList& getFileExtensions() const { return m.llFileExtensions; }
    112112    /** Const, no need to lock */
    113     uint64_t capabilities() const { return m.capabilities; }
     113    uint64_t getCapabilities() const { return m.capabilities; }
    114114    /** Const, no need to lock */
    115     const PropertyList &properties() const { return m.properties; }
     115    const PropertyList& getProperties() const { return m.llProperties; }
    116116
    117117private:
  • trunk/src/VBox/Main/include/MediumImpl.h

    r31306 r31358  
    6767
    6868    // public initializer/uninitializer for internal purposes only
     69
     70    // initializer to create empty medium (VirtualBox::CreateHardDisk())
    6971    HRESULT init(VirtualBox *aVirtualBox,
    70                  CBSTR aFormat,
    71                  CBSTR aLocation,
     72                 const Utf8Str &aFormat,
     73                 const Utf8Str &aLocation,
    7274                 bool *pfNeedsSaveSettings);
     75
     76    // initializer for opening existing media
     77    // (VirtualBox::OpenHardDisk/DVD(); Machine::AttachDevice())
    7378    HRESULT init(VirtualBox *aVirtualBox,
    74                  CBSTR aLocation,
     79                 const Utf8Str &aLocation,
    7580                 HDDOpenMode enOpenMode,
    7681                 DeviceType_T aDeviceType,
     
    7984                 BOOL aSetParentId,
    8085                 const Guid &aParentId);
     86
    8187    // initializer used when loading settings
    8288    HRESULT init(VirtualBox *aVirtualBox,
     
    8490                 DeviceType_T aDeviceType,
    8591                 const settings::Medium &data);
     92
    8693    // initializer for host floppy/DVD
    8794    HRESULT init(VirtualBox *aVirtualBox,
    8895                 DeviceType_T aDeviceType,
    89                  CBSTR aLocation,
    90                  CBSTR aDescription = NULL);
     96                 const Utf8Str &aLocation,
     97                 const Utf8Str &aDescription = Utf8Str::Empty);
     98
    9199    void uninit();
    92100
     
    150158    STDMETHOD(Reset)(IProgress **aProgress);
    151159
    152     // public methods for internal purposes only
     160    // unsafe methods for internal purposes only (ensure there is
     161    // a caller and a read lock before calling them!)
    153162    const ComObjPtr<Medium>& getParent() const;
    154163    const MediaList& getChildren() const;
    155164
    156     // unsafe methods for internal purposes only (ensure there is
    157     // a caller and a read lock before calling them!)
    158165    const Guid& getId() const;
    159166    MediumState_T getState() const;
     
    233240
    234241    /** Returns a preferred format for a differencing hard disk. */
    235     Bstr preferredDiffFormat();
     242    Utf8Str getPreferredDiffFormat();
    236243
    237244private:
     
    244251    HRESULT setStateError();
    245252
    246     HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
    247     HRESULT setFormat(CBSTR aFormat);
     253    HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
     254    HRESULT setFormat(const Utf8Str &aFormat);
    248255
    249256    Utf8Str vdError(int aVRC);
  • trunk/src/VBox/Main/include/SystemPropertiesImpl.h

    r30950 r31358  
    107107    HRESULT saveSettings(settings::SystemProperties &data);
    108108
    109     ComObjPtr<MediumFormat> mediumFormat(CBSTR aFormat);
     109    ComObjPtr<MediumFormat> mediumFormat(const Utf8Str &aFormat);
    110110
    111111    // public methods for internal purposes only
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r31308 r31358  
    242242#endif /* VBOX_WITH_RESOURCE_USAGE_API */
    243243
    244     const Utf8Str& getDefaultMachineFolder() const;
    245     const Utf8Str& getDefaultHardDiskFolder() const;
    246     const Utf8Str& getDefaultHardDiskFormat() const;
     244    Utf8Str getDefaultMachineFolder() const;
     245    Utf8Str getDefaultHardDiskFolder() const;
     246    Utf8Str getDefaultHardDiskFormat() const;
    247247
    248248    /** Returns the VirtualBox home directory */
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