Changeset 31358 in vbox
- Timestamp:
- Aug 4, 2010 2:48:26 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 64409
- Location:
- trunk/src/VBox/Main
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r31346 r31358 1746 1746 { 1747 1747 ComObjPtr<Medium> hostDVDDriveObj; 1748 Bstr location(it->mDevice);1749 Bstr description(it->mDescription);1748 Utf8Str location(it->mDevice); 1749 Utf8Str description(it->mDescription); 1750 1750 if (SUCCEEDED(rc)) 1751 1751 rc = hostDVDDriveObj.createObject(); … … 1819 1819 { 1820 1820 ComObjPtr<Medium> hostFloppyDriveObj; 1821 Bstr location(it->mDevice);1822 Bstr description(it->mDescription);1821 Utf8Str location(it->mDevice); 1822 Utf8Str description(it->mDescription); 1823 1823 if (SUCCEEDED(rc)) 1824 1824 rc = hostFloppyDriveObj.createObject(); -
trunk/src/VBox/Main/MachineImpl.cpp
r31344 r31358 3415 3415 diff.createObject(); 3416 3416 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(), 3420 3420 &fNeedsSaveSettings); 3421 3421 if (FAILED(rc)) return rc; … … 8399 8399 diff.createObject(); 8400 8400 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(), 8404 8404 pfNeedsSaveSettings); 8405 8405 if (FAILED(rc)) throw rc; -
trunk/src/VBox/Main/MediumFormatImpl.cpp
r30764 r31358 60 60 61 61 /* The ID of the backend */ 62 unconst(m. id) = aVDInfo->pszBackend;62 unconst(m.strId) = aVDInfo->pszBackend; 63 63 /* The Name of the backend */ 64 64 /* Use id for now as long as VDBACKENDINFO hasn't any extra 65 65 * name/description field. */ 66 unconst(m. name) = aVDInfo->pszBackend;66 unconst(m.strName) = aVDInfo->pszBackend; 67 67 /* The capabilities of the backend */ 68 68 unconst(m.capabilities) = aVDInfo->uBackendCaps; … … 73 73 while (*papsz != NULL) 74 74 { 75 unconst (m.fileExtensions).push_back(*papsz);76 ++ 75 unconst(m.llFileExtensions).push_back(*papsz); 76 ++papsz; 77 77 } 78 78 } … … 131 131 132 132 /* Create one property structure */ 133 const Property prop = { Utf8Str 134 Utf8Str 133 const Property prop = { Utf8Str(pa->pszKey), 134 Utf8Str(""), 135 135 dt, 136 136 flags, 137 137 defaultValue }; 138 unconst (m.properties).push_back(prop);139 ++ 138 unconst(m.llProperties).push_back(prop); 139 ++pa; 140 140 } 141 141 } … … 160 160 return; 161 161 162 unconst (m.properties).clear();163 unconst (m.fileExtensions).clear();164 unconst 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(); 167 167 } 168 168 … … 178 178 179 179 /* this is const, no need to lock */ 180 m. id.cloneTo(aId);180 m.strId.cloneTo(aId); 181 181 182 182 return S_OK; … … 191 191 192 192 /* this is const, no need to lock */ 193 m. name.cloneTo(aName);193 m.strName.cloneTo(aName); 194 194 195 195 return S_OK; … … 205 205 206 206 /* this is const, no need to lock */ 207 com::SafeArray<BSTR> fileExtentions(m. fileExtensions.size());207 com::SafeArray<BSTR> fileExtentions(m.llFileExtensions.size()); 208 208 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(); 211 211 ++it, ++i) 212 212 (*it).cloneTo(&fileExtentions[i]); … … 236 236 } 237 237 238 STDMETHODIMP MediumFormat::DescribeProperties(ComSafeArrayOut 239 ComSafeArrayOut(BSTR, aDescriptions),240 ComSafeArrayOut(DataType_T, aTypes),241 ComSafeArrayOut(ULONG, aFlags),242 ComSafeArrayOut(BSTR, aDefaults))238 STDMETHODIMP MediumFormat::DescribeProperties(ComSafeArrayOut(BSTR, aNames), 239 ComSafeArrayOut(BSTR, aDescriptions), 240 ComSafeArrayOut(DataType_T, aTypes), 241 ComSafeArrayOut(ULONG, aFlags), 242 ComSafeArrayOut(BSTR, aDefaults)) 243 243 { 244 244 CheckComArgSafeArrayNotNull(aNames); … … 252 252 253 253 /* 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); 259 260 260 261 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(); 263 264 ++it, ++i) 264 265 { 265 266 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]); 268 269 propertyTypes[i] = prop.type; 269 270 propertyFlags[i] = prop.flags; 270 prop. defaultValue.cloneTo(&propertyDefaults[i]);271 prop.strDefaultValue.cloneTo(&propertyDefaults[i]); 271 272 } 272 273 -
trunk/src/VBox/Main/MediumImpl.cpp
r31333 r31358 730 730 731 731 /** 732 * Initializes thehard disk object without creating or opening an associated732 * Initializes an empty hard disk object without creating or opening an associated 733 733 * storage unit. 734 * 735 * This gets called by VirtualBox::CreateHardDisk(). 734 736 * 735 737 * For hard disks that don't have the VD_CAP_CREATE_FIXED or … … 744 746 */ 745 747 HRESULT Medium::init(VirtualBox *aVirtualBox, 746 CBSTRaFormat,747 CBSTRaLocation,748 const Utf8Str &aFormat, 749 const Utf8Str &aLocation, 748 750 bool *pfNeedsSaveSettings) 749 751 { 750 752 AssertReturn(aVirtualBox != NULL, E_FAIL); 751 AssertReturn( aFormat != NULL && *aFormat != '\0', E_FAIL);753 AssertReturn(!aFormat.isEmpty(), E_FAIL); 752 754 753 755 /* Enclose the state transition NotReady->InInit->Ready */ … … 771 773 if (FAILED(rc)) return rc; 772 774 773 if (m->formatObj-> capabilities() & MediumFormatCapabilities_File)775 if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File) 774 776 { 775 777 rc = setLocation(aLocation); … … 782 784 } 783 785 784 if (!(m->formatObj-> capabilities() & ( MediumFormatCapabilities_CreateFixed785 | MediumFormatCapabilities_CreateDynamic))786 if (!(m->formatObj->getCapabilities() & ( MediumFormatCapabilities_CreateFixed 787 | MediumFormatCapabilities_CreateDynamic)) 786 788 ) 787 789 { … … 807 809 * location. The enOpenMode parameter defines whether the medium will be opened 808 810 * 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. 809 815 * 810 816 * Note that the UUID, format and the parent of this medium will be … … 825 831 */ 826 832 HRESULT Medium::init(VirtualBox *aVirtualBox, 827 CBSTRaLocation,833 const Utf8Str &aLocation, 828 834 HDDOpenMode enOpenMode, 829 835 DeviceType_T aDeviceType, … … 834 840 { 835 841 AssertReturn(aVirtualBox, E_INVALIDARG); 836 AssertReturn( aLocation, E_INVALIDARG);842 AssertReturn(!aLocation.isEmpty(), E_INVALIDARG); 837 843 838 844 /* Enclose the state transition NotReady->InInit->Ready */ … … 954 960 { 955 961 AssertReturn(!data.strFormat.isEmpty(), E_FAIL); 956 rc = setFormat( Bstr(data.strFormat));962 rc = setFormat(data.strFormat); 957 963 if (FAILED(rc)) return rc; 958 964 } … … 961 967 /// @todo handle host drive settings here as well? 962 968 if (!data.strFormat.isEmpty()) 963 rc = setFormat( Bstr(data.strFormat));969 rc = setFormat(data.strFormat); 964 970 else 965 rc = setFormat( Bstr("RAW"));971 rc = setFormat("RAW"); 966 972 if (FAILED(rc)) return rc; 967 973 } … … 1045 1051 * Not used for anything but the host floppy/host DVD case. 1046 1052 * 1047 * @todo optimize all callers to avoid reconstructing objects with the same1048 * information over and over again - in the typical case each VM referring to1049 * a particular host drive has its own instance.1050 *1051 1053 * @param aVirtualBox VirtualBox object. 1052 1054 * @param aDeviceType Device type of the medium. … … 1058 1060 HRESULT Medium::init(VirtualBox *aVirtualBox, 1059 1061 DeviceType_T aDeviceType, 1060 CBSTRaLocation,1061 CBSTR aDescription)1062 const Utf8Str &aLocation, 1063 const Utf8Str &aDescription /* = Utf8Str::Empty */) 1062 1064 { 1063 1065 ComAssertRet(aDeviceType == DeviceType_DVD || aDeviceType == DeviceType_Floppy, E_INVALIDARG); 1064 ComAssertRet( aLocation, E_INVALIDARG);1066 ComAssertRet(!aLocation.isEmpty(), E_INVALIDARG); 1065 1067 1066 1068 /* Enclose the state transition NotReady->InInit->Ready */ … … 1079 1081 memcpy(&uuid.au8[0], "FD", 2); 1080 1082 /* 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); 1085 1086 else 1086 memcpy(&uuid.au8[4 + 12 - cbLocation], loc.raw(), cbLocation);1087 memcpy(&uuid.au8[4 + 12 - lenLocation], aLocation.raw(), lenLocation); 1087 1088 unconst(m->id) = uuid; 1088 1089 … … 1091 1092 m->state = MediumState_Created; 1092 1093 m->hostDrive = true; 1093 HRESULT rc = setFormat( Bstr("RAW"));1094 HRESULT rc = setFormat("RAW"); 1094 1095 if (FAILED(rc)) return rc; 1095 1096 rc = setLocation(aLocation); … … 2106 2107 aVariant = (MediumVariant_T)((unsigned)aVariant & (unsigned)~MediumVariant_Diff); 2107 2108 if ( !(aVariant & MediumVariant_Fixed) 2108 && !(m->formatObj-> capabilities() & MediumFormatCapabilities_CreateDynamic))2109 && !(m->formatObj->getCapabilities() & MediumFormatCapabilities_CreateDynamic)) 2109 2110 throw setError(VBOX_E_NOT_SUPPORTED, 2110 2111 tr("Medium format '%s' does not support dynamic storage creation"), 2111 2112 m->strFormat.raw()); 2112 2113 if ( (aVariant & MediumVariant_Fixed) 2113 && !(m->formatObj-> capabilities() & MediumFormatCapabilities_CreateDynamic))2114 && !(m->formatObj->getCapabilities() & MediumFormatCapabilities_CreateDynamic)) 2114 2115 throw setError(VBOX_E_NOT_SUPPORTED, 2115 2116 tr("Medium format '%s' does not support fixed storage creation"), … … 2554 2555 //////////////////////////////////////////////////////////////////////////////// 2555 2556 // 2556 // Medium internal methods2557 // Medium public internal methods 2557 2558 // 2558 2559 //////////////////////////////////////////////////////////////////////////////// … … 2643 2644 * @return 2644 2645 */ 2645 const ComObjPtr<MediumFormat> 2646 const ComObjPtr<MediumFormat>& Medium::getMediumFormat() const 2646 2647 { 2647 2648 return m->formatObj; … … 3099 3100 /// @todo NEWMEDIA delegate the comparison to the backend? 3100 3101 3101 if (m->formatObj-> capabilities() & MediumFormatCapabilities_File)3102 if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File) 3102 3103 { 3103 3104 Utf8Str location(aLocation); … … 3222 3223 * Returns a preferred format for differencing media. 3223 3224 */ 3224 Bstr Medium::preferredDiffFormat() 3225 { 3226 Utf8Str strFormat; 3227 3225 Utf8Str Medium::getPreferredDiffFormat() 3226 { 3228 3227 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(); 3230 3234 3231 3235 /* 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; 3243 3237 } 3244 3238 … … 3260 3254 return m->type; 3261 3255 } 3262 3263 // private methods3264 ////////////////////////////////////////////////////////////////////////////////3265 3256 3266 3257 /** … … 3296 3287 * @note Must be called from under this object's write lock. 3297 3288 */ 3298 HRESULT Medium::setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat) 3289 HRESULT Medium::setLocation(const Utf8Str &aLocation, 3290 const Utf8Str &aFormat /* = Utf8Str::Empty */) 3299 3291 { 3300 3292 AssertReturn(!aLocation.isEmpty(), E_FAIL); … … 3318 3310 3319 3311 if ( isImport 3320 || ( (m->formatObj-> capabilities() & MediumFormatCapabilities_File)3312 || ( (m->formatObj->getCapabilities() & MediumFormatCapabilities_File) 3321 3313 && !m->hostDrive)) 3322 3314 { … … 3328 3320 { 3329 3321 /* must be a file (formatObj must be already known) */ 3330 Assert(m->formatObj-> capabilities() & MediumFormatCapabilities_File);3322 Assert(m->formatObj->getCapabilities() & MediumFormatCapabilities_File); 3331 3323 3332 3324 if (RTPathFilename(location.c_str()) == NULL) … … 3336 3328 * this */ 3337 3329 3338 ComAssertMsgRet(!m->formatObj-> fileExtensions().empty(),3330 ComAssertMsgRet(!m->formatObj->getFileExtensions().empty(), 3339 3331 ("Must be at least one extension if it is MediumFormatCapabilities_File\n"), 3340 3332 E_FAIL); 3341 3333 3342 Bstr ext = m->formatObj->fileExtensions().front();3343 ComAssertMsgRet(! ext.isEmpty(),3334 Utf8Str strExt = m->formatObj->getFileExtensions().front(); 3335 ComAssertMsgRet(!strExt.isEmpty(), 3344 3336 ("Default extension must not be empty\n"), 3345 3337 E_FAIL); … … 3347 3339 id.create(); 3348 3340 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()); 3351 3343 } 3352 3344 } … … 3402 3394 else 3403 3395 { 3404 HRESULT rc = setFormat( Bstr(aFormat));3396 HRESULT rc = setFormat(aFormat); 3405 3397 /* setFormat() must not fail since we've just used the backend so 3406 3398 * the format object must be there */ … … 3412 3404 ComAssertRet(backendName != NULL && *backendName != '\0', E_FAIL); 3413 3405 3414 HRESULT rc = setFormat( Bstr(backendName));3406 HRESULT rc = setFormat(backendName); 3415 3407 RTStrFree(backendName); 3416 3408 … … 3422 3414 3423 3415 /* is it still a file? */ 3424 if (m->formatObj-> capabilities() & MediumFormatCapabilities_File)3416 if (m->formatObj->getCapabilities() & MediumFormatCapabilities_File) 3425 3417 { 3426 3418 m->strLocation = location; … … 3572 3564 } 3573 3565 3574 if (formatObj-> capabilities() & MediumFormatCapabilities_Uuid)3566 if (formatObj->getCapabilities() & MediumFormatCapabilities_Uuid) 3575 3567 { 3576 3568 /* Modify the UUIDs if necessary. The associated fields are … … 3612 3604 { 3613 3605 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()); 3619 3611 throw S_OK; 3620 3612 } … … 3660 3652 Guid id = parentId; 3661 3653 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); 3665 3655 if (FAILED(rc)) 3666 3656 { 3667 3657 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()); 3671 3661 throw S_OK; 3672 3662 } … … 3691 3681 { 3692 3682 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()); 3696 3686 throw S_OK; 3697 3687 } … … 3702 3692 { 3703 3693 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()); 3708 3698 throw S_OK; 3709 3699 } … … 3748 3738 m->strLastAccessError = lastAccessError; 3749 3739 LogWarningFunc(("'%s' is not accessible (error='%s', rc=%Rhrc, vrc=%Rrc)\n", 3750 3751 3740 location.c_str(), m->strLastAccessError.c_str(), 3741 rc, vrc)); 3752 3742 } 3753 3743 … … 3963 3953 LogFlowThisFunc(("aWait=%RTbool locationFull=%s\n", aWait, getLocationFull().c_str() )); 3964 3954 3965 if ( !(m->formatObj-> capabilities() & ( MediumFormatCapabilities_CreateDynamic3966 | MediumFormatCapabilities_CreateFixed)))3955 if ( !(m->formatObj->getCapabilities() & ( MediumFormatCapabilities_CreateDynamic 3956 | MediumFormatCapabilities_CreateFixed))) 3967 3957 throw setError(VBOX_E_NOT_SUPPORTED, 3968 3958 tr("Medium format '%s' does not support storage deletion"), … … 4834 4824 } 4835 4825 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 */ 4841 HRESULT 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 */ 4864 HRESULT 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 4836 4909 /** 4837 4910 * Checks that the format ID is valid and sets it on success. … … 4843 4916 * @note Must be called from under this object's write lock. 4844 4917 */ 4845 HRESULT Medium::setFormat( CBSTRaFormat)4918 HRESULT Medium::setFormat(const Utf8Str &aFormat) 4846 4919 { 4847 4920 /* get the format object first */ … … 4853 4926 if (m->formatObj.isNull()) 4854 4927 return setError(E_INVALIDARG, 4855 tr("Invalid medium storage format '% ls'"),4856 aFormat );4928 tr("Invalid medium storage format '%s'"), 4929 aFormat.c_str()); 4857 4930 4858 4931 /* reference the format permanently to prevent its unexpected … … 4867 4940 Assert(m->properties.empty()); 4868 4941 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(); 4872 4944 ++it) 4873 4945 { 4874 m->properties.insert(std::make_pair(it-> name, Bstr::Empty));4946 m->properties.insert(std::make_pair(it->strName, Utf8Str::Empty)); 4875 4947 } 4876 4948 } … … 4879 4951 4880 4952 return S_OK; 4881 }4882 4883 /**4884 * Performs extra checks if the medium can be closed and returns S_OK in4885 * this case. Otherwise, returns a respective error message. Called by4886 * 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 depending4908 * 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 true4911 * 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 let4918 * 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 registry4952 m->pParent = pParentBackup;4953 m->pParent->m->llChildren.push_back(this);4954 }4955 }4956 4957 return rc;4958 4953 } 4959 4954 … … 5370 5365 Utf8Str format(m->strFormat); 5371 5366 Utf8Str location(m->strLocationFull); 5372 uint64_t capabilities = m->formatObj-> capabilities();5367 uint64_t capabilities = m->formatObj->getCapabilities(); 5373 5368 ComAssertThrow(capabilities & ( VD_CAP_CREATE_FIXED 5374 5369 | VD_CAP_CREATE_DYNAMIC), E_FAIL); … … 5506 5501 Utf8Str targetFormat(pTarget->m->strFormat); 5507 5502 Utf8Str targetLocation(pTarget->m->strLocationFull); 5508 uint64_t capabilities = m->formatObj-> capabilities();5503 uint64_t capabilities = m->formatObj->getCapabilities(); 5509 5504 ComAssertThrow(capabilities & VD_CAP_CREATE_DYNAMIC, E_FAIL); 5510 5505 -
trunk/src/VBox/Main/SnapshotImpl.cpp
r31333 r31358 2624 2624 // Diff medium not backed by a file - cannot get status so 2625 2625 // be pessimistic. 2626 if (!(sourceFormat-> capabilities() & MediumFormatCapabilities_File))2626 if (!(sourceFormat->getCapabilities() & MediumFormatCapabilities_File)) 2627 2627 throw rc; 2628 2628 const Utf8Str &loc = it->mpSource->getLocationFull(); -
trunk/src/VBox/Main/SystemPropertiesImpl.cpp
r31281 r31358 828 828 * @return ComObjPtr<MediumFormat> 829 829 */ 830 ComObjPtr<MediumFormat> SystemProperties::mediumFormat (CBSTRaFormat)830 ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat) 831 831 { 832 832 ComObjPtr<MediumFormat> format; … … 843 843 /* MediumFormat is all const, no need to lock */ 844 844 845 if ((*it)-> id().compare(aFormat, Bstr::CaseInsensitive) == 0)845 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0) 846 846 { 847 847 format = *it; -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r31308 r31358 1376 1376 /* we don't access non-const data members so no need to lock */ 1377 1377 1378 Bstr format = aFormat;1378 Utf8Str format(aFormat); 1379 1379 if (format.isEmpty()) 1380 1380 format = getDefaultHardDiskFormat(); … … 1386 1386 ComObjPtr<Medium> hardDisk; 1387 1387 hardDisk.createObject(); 1388 rc = hardDisk->init(this, format.raw(), aLocation, &fNeedsSaveSettings); 1388 rc = hardDisk->init(this, 1389 format, 1390 aLocation, 1391 &fNeedsSaveSettings); 1389 1392 1390 1393 if (SUCCEEDED(rc)) … … 1502 1505 1503 1506 /** @note Doesn't lock anything. */ 1504 STDMETHODIMP VirtualBox::OpenDVDImage(IN_BSTR aLocation, IN_BSTR aId, 1507 STDMETHODIMP VirtualBox::OpenDVDImage(IN_BSTR aLocation, 1508 IN_BSTR aId, 1505 1509 IMedium **aDVDImage) 1506 1510 { … … 1520 1524 ComObjPtr<Medium> image; 1521 1525 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()); 1523 1534 if (SUCCEEDED(rc)) 1524 1535 { … … 1578 1589 1579 1590 /** @note Doesn't lock anything. */ 1580 STDMETHODIMP VirtualBox::OpenFloppyImage(IN_BSTR aLocation, IN_BSTR aId, 1591 STDMETHODIMP VirtualBox::OpenFloppyImage(IN_BSTR aLocation, 1592 IN_BSTR aId, 1581 1593 IMedium **aFloppyImage) 1582 1594 { … … 1596 1608 ComObjPtr<Medium> image; 1597 1609 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()); 1599 1618 if (SUCCEEDED(rc)) 1600 1619 { … … 2956 2975 * @return 2957 2976 */ 2958 const Utf8Str&VirtualBox::getDefaultMachineFolder() const2977 Utf8Str VirtualBox::getDefaultMachineFolder() const 2959 2978 { 2960 2979 AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS); … … 2967 2986 * @return 2968 2987 */ 2969 const Utf8Str&VirtualBox::getDefaultHardDiskFolder() const2988 Utf8Str VirtualBox::getDefaultHardDiskFolder() const 2970 2989 { 2971 2990 AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS); … … 2978 2997 * @return 2979 2998 */ 2980 const Utf8Str&VirtualBox::getDefaultHardDiskFormat() const2999 Utf8Str VirtualBox::getDefaultHardDiskFormat() const 2981 3000 { 2982 3001 AutoReadLock propsLock(m->pSystemProperties COMMA_LOCKVAL_SRC_POS); -
trunk/src/VBox/Main/include/MediumFormatImpl.h
r30764 r31358 46 46 struct Property 47 47 { 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; 53 53 }; 54 54 55 typedef std::list <Bstr> BstrList;56 typedef std::list 55 typedef std::list<Utf8Str> StrList; 56 typedef std::list<Property> PropertyList; 57 57 58 58 struct Data … … 60 60 Data() : capabilities (0) {} 61 61 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; 67 67 }; 68 68 … … 107 107 108 108 /** Const, no need to lock */ 109 const Bstr &id() const { return m.id; }109 const Utf8Str& getId() const { return m.strId; } 110 110 /** Const, no need to lock */ 111 const BstrList &fileExtensions() const { return m.fileExtensions; }111 const StrList& getFileExtensions() const { return m.llFileExtensions; } 112 112 /** Const, no need to lock */ 113 uint64_t capabilities() const { return m.capabilities; }113 uint64_t getCapabilities() const { return m.capabilities; } 114 114 /** Const, no need to lock */ 115 const PropertyList &properties() const { return m.properties; }115 const PropertyList& getProperties() const { return m.llProperties; } 116 116 117 117 private: -
trunk/src/VBox/Main/include/MediumImpl.h
r31306 r31358 67 67 68 68 // public initializer/uninitializer for internal purposes only 69 70 // initializer to create empty medium (VirtualBox::CreateHardDisk()) 69 71 HRESULT init(VirtualBox *aVirtualBox, 70 CBSTRaFormat,71 CBSTRaLocation,72 const Utf8Str &aFormat, 73 const Utf8Str &aLocation, 72 74 bool *pfNeedsSaveSettings); 75 76 // initializer for opening existing media 77 // (VirtualBox::OpenHardDisk/DVD(); Machine::AttachDevice()) 73 78 HRESULT init(VirtualBox *aVirtualBox, 74 CBSTRaLocation,79 const Utf8Str &aLocation, 75 80 HDDOpenMode enOpenMode, 76 81 DeviceType_T aDeviceType, … … 79 84 BOOL aSetParentId, 80 85 const Guid &aParentId); 86 81 87 // initializer used when loading settings 82 88 HRESULT init(VirtualBox *aVirtualBox, … … 84 90 DeviceType_T aDeviceType, 85 91 const settings::Medium &data); 92 86 93 // initializer for host floppy/DVD 87 94 HRESULT init(VirtualBox *aVirtualBox, 88 95 DeviceType_T aDeviceType, 89 CBSTR aLocation, 90 CBSTR aDescription = NULL); 96 const Utf8Str &aLocation, 97 const Utf8Str &aDescription = Utf8Str::Empty); 98 91 99 void uninit(); 92 100 … … 150 158 STDMETHOD(Reset)(IProgress **aProgress); 151 159 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!) 153 162 const ComObjPtr<Medium>& getParent() const; 154 163 const MediaList& getChildren() const; 155 164 156 // unsafe methods for internal purposes only (ensure there is157 // a caller and a read lock before calling them!)158 165 const Guid& getId() const; 159 166 MediumState_T getState() const; … … 233 240 234 241 /** Returns a preferred format for a differencing hard disk. */ 235 Bstr preferredDiffFormat();242 Utf8Str getPreferredDiffFormat(); 236 243 237 244 private: … … 244 251 HRESULT setStateError(); 245 252 246 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str ());247 HRESULT setFormat( CBSTRaFormat);253 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty); 254 HRESULT setFormat(const Utf8Str &aFormat); 248 255 249 256 Utf8Str vdError(int aVRC); -
trunk/src/VBox/Main/include/SystemPropertiesImpl.h
r30950 r31358 107 107 HRESULT saveSettings(settings::SystemProperties &data); 108 108 109 ComObjPtr<MediumFormat> mediumFormat( CBSTRaFormat);109 ComObjPtr<MediumFormat> mediumFormat(const Utf8Str &aFormat); 110 110 111 111 // public methods for internal purposes only -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r31308 r31358 242 242 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 243 243 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; 247 247 248 248 /** Returns the VirtualBox home directory */
Note:
See TracChangeset
for help on using the changeset viewer.