Changeset 3330 in vbox
- Timestamp:
- Jun 29, 2007 4:35:37 PM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 22472
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/DVDDriveImpl.cpp
r2981 r3330 22 22 #include "DVDDriveImpl.h" 23 23 #include "MachineImpl.h" 24 #include "VirtualBoxImpl.h" 24 25 #include "Logging.h" 25 26 26 27 #include <iprt/string.h> 27 28 // defines 29 //////////////////////////////////////////////////////////////////////////////// 28 #include <iprt/cpputils.h> 30 29 31 30 // constructor / destructor 32 31 //////////////////////////////////////////////////////////////////////////////// 33 32 33 DEFINE_EMPTY_CTOR_DTOR (DVDDrive) 34 34 35 HRESULT DVDDrive::FinalConstruct() 35 36 { … … 39 40 void DVDDrive::FinalRelease() 40 41 { 41 if (isReady()) 42 uninit (); 42 uninit(); 43 43 } 44 44 … … 49 49 * Initializes the DVD drive object. 50 50 * 51 * @param parent handle of our parent object51 * @param aParent Handle of our parent object. 52 52 * @return COM result indicator 53 53 */ 54 HRESULT DVDDrive::init (Machine *parent) 55 { 56 LogFlowMember (("DVDDrive::init (%p)\n", parent)); 57 58 ComAssertRet (parent, E_INVALIDARG); 59 60 AutoLock alock (this); 61 ComAssertRet (!isReady(), E_UNEXPECTED); 62 63 mParent = parent; 64 // mPeer is left null 54 HRESULT DVDDrive::init (Machine *aParent) 55 { 56 LogFlowThisFunc (("aParent=%p\n", aParent)); 57 58 ComAssertRet (aParent, E_INVALIDARG); 59 60 /* Enclose the state transition NotReady->InInit->Ready */ 61 AutoInitSpan autoInitSpan (this); 62 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 63 64 unconst (mParent) = aParent; 65 /* mPeer is left null */ 65 66 66 67 mData.allocate(); 67 68 68 setReady (true); 69 /* Confirm a successful initialization */ 70 autoInitSpan.setSucceeded(); 71 69 72 return S_OK; 70 73 } … … 77 80 * @note This object must be destroyed before the original object 78 81 * it shares data with is destroyed. 79 */ 80 HRESULT DVDDrive::init (Machine *parent, DVDDrive *that) 81 { 82 LogFlowMember (("DVDDrive::init (%p, %p)\n", parent, that)); 83 84 ComAssertRet (parent && that, E_INVALIDARG); 85 86 AutoLock alock (this); 87 ComAssertRet (!isReady(), E_UNEXPECTED); 88 89 mParent = parent; 90 mPeer = that; 91 92 AutoLock thatlock (that); 93 mData.share (that->mData); 94 95 setReady (true); 82 * 83 * @note Locks @a aThat object for reading. 84 */ 85 HRESULT DVDDrive::init (Machine *aParent, DVDDrive *aThat) 86 { 87 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 88 89 ComAssertRet (aParent && aThat, E_INVALIDARG); 90 91 /* Enclose the state transition NotReady->InInit->Ready */ 92 AutoInitSpan autoInitSpan (this); 93 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 94 95 unconst (mParent) = aParent; 96 unconst (mPeer) = aThat; 97 98 AutoCaller thatCaller (aThat); 99 AssertComRCReturnRC (thatCaller.rc()); 100 101 AutoReaderLock thatLock (aThat); 102 mData.share (aThat->mData); 103 104 /* Confirm a successful initialization */ 105 autoInitSpan.setSucceeded(); 106 96 107 return S_OK; 97 108 } 98 109 99 110 /** 100 * Initializes the guest object given another guestobject111 * Initializes the DVD drive object given another DVD drive object 101 112 * (a kind of copy constructor). This object makes a private copy of data 102 113 * of the original object passed as an argument. 103 */ 104 HRESULT DVDDrive::initCopy (Machine *parent, DVDDrive *that) 105 { 106 LogFlowMember (("DVDDrive::initCopy (%p, %p)\n", parent, that)); 107 108 ComAssertRet (parent && that, E_INVALIDARG); 109 110 AutoLock alock (this); 111 ComAssertRet (!isReady(), E_UNEXPECTED); 112 113 mParent = parent; 114 // mPeer is left null 115 116 AutoLock thatlock (that); 117 mData.attachCopy (that->mData); 118 119 setReady (true); 114 * 115 * @note Locks @a aThat object for reading. 116 */ 117 HRESULT DVDDrive::initCopy (Machine *aParent, DVDDrive *aThat) 118 { 119 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 120 121 ComAssertRet (aParent && aThat, E_INVALIDARG); 122 123 /* Enclose the state transition NotReady->InInit->Ready */ 124 AutoInitSpan autoInitSpan (this); 125 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 126 127 unconst (mParent) = aParent; 128 /* mPeer is left null */ 129 130 AutoCaller thatCaller (aThat); 131 AssertComRCReturnRC (thatCaller.rc()); 132 133 AutoReaderLock thatLock (aThat); 134 mData.attachCopy (aThat->mData); 135 136 /* Confirm a successful initialization */ 137 autoInitSpan.setSucceeded(); 138 120 139 return S_OK; 121 140 } … … 127 146 void DVDDrive::uninit() 128 147 { 129 LogFlowMember (("DVDDrive::uninit()\n")); 148 LogFlowThisFunc (("\n")); 149 150 /* Enclose the state transition Ready->InUninit->NotReady */ 151 AutoUninitSpan autoUninitSpan (this); 152 if (autoUninitSpan.uninitDone()) 153 return; 154 155 mData.free(); 156 157 unconst (mParent).setNull(); 158 unconst (mParent).setNull(); 159 } 160 161 // IDVDDrive properties 162 //////////////////////////////////////////////////////////////////////////////// 163 164 STDMETHODIMP DVDDrive::COMGETTER(State) (DriveState_T *aDriveState) 165 { 166 if (!aDriveState) 167 return E_POINTER; 168 169 AutoCaller autoCaller (this); 170 CheckComRCReturnRC (autoCaller.rc()); 171 172 AutoReaderLock alock (this); 173 174 *aDriveState = mData->mDriveState; 175 176 return S_OK; 177 } 178 179 STDMETHODIMP DVDDrive::COMGETTER(Passthrough) (BOOL *aPassthrough) 180 { 181 if (!aPassthrough) 182 return E_POINTER; 183 184 AutoCaller autoCaller (this); 185 CheckComRCReturnRC (autoCaller.rc()); 186 187 AutoReaderLock alock (this); 188 189 *aPassthrough = mData->mPassthrough; 190 191 return S_OK; 192 } 193 194 STDMETHODIMP DVDDrive::COMSETTER(Passthrough) (BOOL aPassthrough) 195 { 196 AutoCaller autoCaller (this); 197 CheckComRCReturnRC (autoCaller.rc()); 198 199 /* the machine needs to be mutable */ 200 Machine::AutoMutableStateDependency adep (mParent); 201 CheckComRCReturnRC (adep.rc()); 130 202 131 203 AutoLock alock (this); 132 204 133 AssertReturn (isReady(), (void) 0); 134 135 mData.free(); 136 137 mPeer.setNull(); 138 mParent.setNull(); 139 140 setReady (false); 141 } 142 143 // IDVDDrive properties 144 //////////////////////////////////////////////////////////////////////////////// 145 146 STDMETHODIMP DVDDrive::COMGETTER(State) (DriveState_T *driveState) 147 { 148 if (!driveState) 149 return E_POINTER; 205 if (mData->mPassthrough != aPassthrough) 206 { 207 mData.backup(); 208 mData->mPassthrough = aPassthrough; 209 } 210 211 return S_OK; 212 } 213 214 // IDVDDrive methods 215 //////////////////////////////////////////////////////////////////////////////// 216 217 STDMETHODIMP DVDDrive::MountImage (INPTR GUIDPARAM aImageId) 218 { 219 if (Guid::isEmpty (aImageId)) 220 return E_INVALIDARG; 221 222 AutoCaller autoCaller (this); 223 CheckComRCReturnRC (autoCaller.rc()); 224 225 /* the machine needs to be mutable */ 226 Machine::AutoMutableStateDependency adep (mParent); 227 CheckComRCReturnRC (adep.rc()); 150 228 151 229 AutoLock alock (this); 152 CHECK_READY();153 154 *driveState = mData->mDriveState;155 return S_OK;156 }157 158 STDMETHODIMP DVDDrive::COMGETTER(Passthrough) (BOOL *passthrough)159 {160 if (!passthrough)161 return E_POINTER;162 163 AutoLock alock(this);164 CHECK_READY();165 166 *passthrough = mData->mPassthrough;167 return S_OK;168 }169 170 STDMETHODIMP DVDDrive::COMSETTER(Passthrough) (BOOL passthrough)171 {172 AutoLock alock(this);173 CHECK_READY();174 CHECK_MACHINE_MUTABILITY (mParent);175 176 if (mData->mPassthrough != passthrough)177 {178 mData.backup();179 mData->mPassthrough = passthrough;180 }181 return S_OK;182 }183 184 // IDVDDrive methods185 ////////////////////////////////////////////////////////////////////////////////186 187 STDMETHODIMP DVDDrive::MountImage(INPTR GUIDPARAM imageId)188 {189 if (Guid::isEmpty(imageId))190 return E_INVALIDARG;191 192 AutoLock alock (this);193 CHECK_READY();194 195 CHECK_MACHINE_MUTABILITY (mParent);196 230 197 231 HRESULT rc = E_FAIL; 198 232 199 // find the image in the collection 200 ComPtr <IVirtualBox> vbox; 201 rc = mParent->COMGETTER(Parent) (vbox.asOutParam()); 202 AssertComRCReturn (rc, rc); 233 /* Our lifetime is bound to mParent's lifetime, so we don't add caller. 234 * We also don't lock mParent since its mParent field is const. */ 203 235 204 236 ComPtr <IDVDImage> image; 205 rc = vbox->GetDVDImage (imageId, image.asOutParam()); 237 rc = mParent->virtualBox()->GetDVDImage (aImageId, image.asOutParam()); 238 206 239 if (SUCCEEDED (rc)) 207 240 { … … 210 243 { 211 244 mData.backup(); 245 212 246 unmount(); 247 213 248 mData->mDVDImage = image; 214 249 mData->mDriveState = DriveState_ImageMounted; 215 250 251 /* leave the lock before informing callbacks*/ 216 252 alock.unlock(); 253 217 254 mParent->onDVDDriveChange(); 218 255 } … … 222 259 } 223 260 224 STDMETHODIMP DVDDrive::CaptureHostDrive (IHostDVDDrive *hostDVDDrive)225 { 226 if (! hostDVDDrive)261 STDMETHODIMP DVDDrive::CaptureHostDrive (IHostDVDDrive *aHostDVDDrive) 262 { 263 if (!aHostDVDDrive) 227 264 return E_INVALIDARG; 228 265 266 AutoCaller autoCaller (this); 267 CheckComRCReturnRC (autoCaller.rc()); 268 269 /* the machine needs to be mutable */ 270 Machine::AutoMutableStateDependency adep (mParent); 271 CheckComRCReturnRC (adep.rc()); 272 229 273 AutoLock alock (this); 230 CHECK_READY();231 232 CHECK_MACHINE_MUTABILITY (mParent);233 274 234 275 if (mData->mDriveState != DriveState_HostDriveCaptured || 235 !mData->mHostDrive.equalsTo ( hostDVDDrive))276 !mData->mHostDrive.equalsTo (aHostDVDDrive)) 236 277 { 237 278 mData.backup(); 279 238 280 unmount(); 239 mData->mHostDrive = hostDVDDrive; 281 282 mData->mHostDrive = aHostDVDDrive; 240 283 mData->mDriveState = DriveState_HostDriveCaptured; 241 284 285 /* leave the lock before informing callbacks*/ 242 286 alock.unlock(); 287 243 288 mParent->onDVDDriveChange(); 244 289 } … … 249 294 STDMETHODIMP DVDDrive::Unmount() 250 295 { 296 AutoCaller autoCaller (this); 297 CheckComRCReturnRC (autoCaller.rc()); 298 299 /* the machine needs to be mutable */ 300 Machine::AutoMutableStateDependency adep (mParent); 301 CheckComRCReturnRC (adep.rc()); 302 251 303 AutoLock alock (this); 252 CHECK_READY();253 254 CHECK_MACHINE_MUTABILITY (mParent);255 304 256 305 if (mData->mDriveState != DriveState_NotMounted) 257 306 { 258 307 mData.backup(); 308 259 309 unmount(); 310 260 311 mData->mDriveState = DriveState_NotMounted; 261 312 313 /* leave the lock before informing callbacks*/ 262 314 alock.unlock(); 315 263 316 mParent->onDVDDriveChange(); 264 317 } … … 267 320 } 268 321 269 STDMETHODIMP DVDDrive::GetImage (IDVDImage **dvdImage)270 { 271 if (! dvdImage)322 STDMETHODIMP DVDDrive::GetImage (IDVDImage **aDVDImage) 323 { 324 if (!aDVDImage) 272 325 return E_POINTER; 273 326 327 AutoCaller autoCaller (this); 328 CheckComRCReturnRC (autoCaller.rc()); 329 330 AutoReaderLock alock (this); 331 332 mData->mDVDImage.queryInterfaceTo (aDVDImage); 333 334 return S_OK; 335 } 336 337 STDMETHODIMP DVDDrive::GetHostDrive(IHostDVDDrive **aHostDrive) 338 { 339 if (!aHostDrive) 340 return E_POINTER; 341 342 AutoCaller autoCaller (this); 343 CheckComRCReturnRC (autoCaller.rc()); 344 345 AutoReaderLock alock (this); 346 347 mData->mHostDrive.queryInterfaceTo (aHostDrive); 348 349 return S_OK; 350 } 351 352 // public methods only for internal purposes 353 //////////////////////////////////////////////////////////////////////////////// 354 355 /** 356 * @note Locks this object for writing. 357 */ 358 bool DVDDrive::rollback() 359 { 360 /* sanity */ 361 AutoCaller autoCaller (this); 362 AssertComRCReturn (autoCaller.rc(), false); 363 274 364 AutoLock alock (this); 275 CHECK_READY();276 277 mData->mDVDImage.queryInterfaceTo (dvdImage);278 return S_OK;279 }280 281 STDMETHODIMP DVDDrive::GetHostDrive(IHostDVDDrive **hostDrive)282 {283 if (!hostDrive)284 return E_POINTER;285 286 AutoLock alock (this);287 CHECK_READY();288 289 mData->mHostDrive.queryInterfaceTo (hostDrive);290 return S_OK;291 }292 293 // public methods only for internal purposes294 ////////////////////////////////////////////////////////////////////////////////295 296 bool DVDDrive::rollback()297 {298 AutoLock alock (this);299 365 300 366 bool changed = false; … … 302 368 if (mData.isBackedUp()) 303 369 { 304 / /we need to check all data to see whether anything will be changed305 // after rollback370 /* we need to check all data to see whether anything will be changed 371 * after rollback */ 306 372 changed = mData.hasActualChanges(); 307 373 mData.rollback(); … … 311 377 } 312 378 379 /** 380 * @note Locks this object for writing, together with the peer object (also 381 * for writing) if there is one. 382 */ 313 383 void DVDDrive::commit() 314 384 { 315 AutoLock alock (this); 385 /* sanity */ 386 AutoCaller autoCaller (this); 387 AssertComRCReturnVoid (autoCaller.rc()); 388 389 /* sanity too */ 390 AutoCaller thatCaller (mPeer); 391 AssertComRCReturnVoid (thatCaller.rc()); 392 393 /* lock both for writing since we modify both */ 394 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeWlock (mPeer)); 395 316 396 if (mData.isBackedUp()) 317 397 { … … 319 399 if (mPeer) 320 400 { 321 // attach new data to the peer and reshare it 322 AutoLock peerlock (mPeer); 401 /* attach new data to the peer and reshare it */ 323 402 mPeer->mData.attach (mData); 324 403 } … … 326 405 } 327 406 407 /** 408 * @note Locks this object for writing, together with the peer object (locked 409 * for reading) if there is one. 410 */ 328 411 void DVDDrive::copyFrom (DVDDrive *aThat) 329 412 { 330 AutoLock alock (this); 331 332 // this will back up current data 413 /* sanity */ 414 AutoCaller autoCaller (this); 415 AssertComRCReturnVoid (autoCaller.rc()); 416 417 /* sanity too */ 418 AutoCaller thatCaller (mPeer); 419 AssertComRCReturnVoid (thatCaller.rc()); 420 421 /* peer is not modified, lock it for reading */ 422 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeRlock (mPeer)); 423 424 /* this will back up current data */ 333 425 mData.assignCopy (aThat->mData); 334 426 } … … 338 430 339 431 /** 340 * Helper to unmount a drive341 * 342 * @returnsCOM status code432 * Helper to unmount a drive. 433 * 434 * @return COM status code 343 435 * 344 436 */ 345 437 HRESULT DVDDrive::unmount() 346 438 { 439 AssertReturn (isLockedOnCurrentThread(), E_FAIL); 440 347 441 if (mData->mDVDImage) 348 442 mData->mDVDImage.setNull(); 349 443 if (mData->mHostDrive) 350 444 mData->mHostDrive.setNull(); 351 return S_OK; 352 } 445 446 return S_OK; 447 } -
trunk/src/VBox/Main/DVDImageImpl.cpp
r3007 r3330 27 27 #include <iprt/path.h> 28 28 #include <iprt/cpputils.h> 29 29 30 #include <VBox/err.h> 30 31 #include <VBox/param.h> -
trunk/src/VBox/Main/FloppyDriveImpl.cpp
r2981 r3330 22 22 #include "FloppyDriveImpl.h" 23 23 #include "MachineImpl.h" 24 #include "VirtualBoxImpl.h" 24 25 #include "Logging.h" 25 26 26 27 #include <iprt/string.h> 27 28 // defines 29 ///////////////////////////////////////////////////////////////////////////// 28 #include <iprt/cpputils.h> 30 29 31 30 // constructor / destructor 32 31 ///////////////////////////////////////////////////////////////////////////// 33 32 33 DEFINE_EMPTY_CTOR_DTOR (FloppyDrive) 34 34 35 HRESULT FloppyDrive::FinalConstruct() 35 36 { … … 39 40 void FloppyDrive::FinalRelease() 40 41 { 41 if (isReady()) 42 uninit (); 42 uninit(); 43 43 } 44 44 … … 49 49 * Initializes the Floppy drive object. 50 50 * 51 * @returns COM result indicator 52 * @param parent handle of our parent object 53 */ 54 HRESULT FloppyDrive::init (Machine *parent) 55 { 56 LogFlowMember (("FloppyDrive::init (%p)\n", parent)); 57 58 ComAssertRet (parent, E_INVALIDARG); 59 60 AutoLock alock (this); 61 ComAssertRet (!isReady(), E_UNEXPECTED); 62 63 mParent = parent; 64 // mPeer is left null 51 * @param aParent Handle of our parent object. 52 * @return COM result indicator 53 */ 54 HRESULT FloppyDrive::init (Machine *aParent) 55 { 56 LogFlowThisFunc (("aParent=%p\n", aParent)); 57 58 ComAssertRet (aParent, E_INVALIDARG); 59 60 /* Enclose the state transition NotReady->InInit->Ready */ 61 AutoInitSpan autoInitSpan (this); 62 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 63 64 unconst (mParent) = aParent; 65 /* mPeer is left null */ 65 66 66 67 mData.allocate(); 67 68 68 setReady (true); 69 /* Confirm a successful initialization */ 70 autoInitSpan.setSucceeded(); 71 69 72 return S_OK; 70 73 } … … 77 80 * @note This object must be destroyed before the original object 78 81 * it shares data with is destroyed. 79 */ 80 HRESULT FloppyDrive::init (Machine *parent, FloppyDrive *that) 81 { 82 LogFlowMember (("FloppyDrive::init (%p, %p)\n", parent, that)); 83 84 ComAssertRet (parent && that, E_INVALIDARG); 85 86 AutoLock alock (this); 87 ComAssertRet (!isReady(), E_UNEXPECTED); 88 89 mParent = parent; 90 mPeer = that; 91 92 AutoLock thatlock (that); 93 mData.share (that->mData); 94 95 setReady (true); 82 * 83 * @note Locks @a aThat object for reading. 84 */ 85 HRESULT FloppyDrive::init (Machine *aParent, FloppyDrive *aThat) 86 { 87 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 88 89 ComAssertRet (aParent && aThat, E_INVALIDARG); 90 91 /* Enclose the state transition NotReady->InInit->Ready */ 92 AutoInitSpan autoInitSpan (this); 93 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 94 95 unconst (mParent) = aParent; 96 unconst (mPeer) = aThat; 97 98 AutoCaller thatCaller (aThat); 99 AssertComRCReturnRC (thatCaller.rc()); 100 101 AutoReaderLock thatLock (aThat); 102 mData.share (aThat->mData); 103 104 /* Confirm a successful initialization */ 105 autoInitSpan.setSucceeded(); 106 96 107 return S_OK; 97 108 } … … 101 112 * (a kind of copy constructor). This object makes a private copy of data 102 113 * of the original object passed as an argument. 103 */ 104 HRESULT FloppyDrive::initCopy (Machine *parent, FloppyDrive *that) 105 { 106 LogFlowMember (("FloppyDrive::initCopy (%p, %p)\n", parent, that)); 107 108 ComAssertRet (parent && that, E_INVALIDARG); 109 110 AutoLock alock (this); 111 ComAssertRet (!isReady(), E_UNEXPECTED); 112 113 mParent = parent; 114 // mPeer is left null 115 116 AutoLock thatlock (that); 117 mData.attachCopy (that->mData); 118 119 setReady (true); 114 * 115 * @note Locks @a aThat object for reading. 116 */ 117 HRESULT FloppyDrive::initCopy (Machine *aParent, FloppyDrive *aThat) 118 { 119 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 120 121 ComAssertRet (aParent && aThat, E_INVALIDARG); 122 123 /* Enclose the state transition NotReady->InInit->Ready */ 124 AutoInitSpan autoInitSpan (this); 125 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 126 127 unconst (mParent) = aParent; 128 /* mPeer is left null */ 129 130 AutoCaller thatCaller (aThat); 131 AssertComRCReturnRC (thatCaller.rc()); 132 133 AutoReaderLock thatLock (aThat); 134 mData.attachCopy (aThat->mData); 135 136 /* Confirm a successful initialization */ 137 autoInitSpan.setSucceeded(); 138 120 139 return S_OK; 121 140 } … … 127 146 void FloppyDrive::uninit() 128 147 { 129 LogFlowMember (("FloppyDrive::uninit()\n")); 148 LogFlowThisFunc (("\n")); 149 150 /* Enclose the state transition Ready->InUninit->NotReady */ 151 AutoUninitSpan autoUninitSpan (this); 152 if (autoUninitSpan.uninitDone()) 153 return; 154 155 mData.free(); 156 157 unconst (mParent).setNull(); 158 unconst (mParent).setNull(); 159 } 160 161 // IFloppyDrive properties 162 ///////////////////////////////////////////////////////////////////////////// 163 164 STDMETHODIMP FloppyDrive::COMGETTER(Enabled) (BOOL *aEnabled) 165 { 166 if (!aEnabled) 167 return E_POINTER; 168 169 AutoCaller autoCaller (this); 170 CheckComRCReturnRC (autoCaller.rc()); 171 172 AutoReaderLock alock (this); 173 174 *aEnabled = mData->mEnabled; 175 176 return S_OK; 177 } 178 179 STDMETHODIMP FloppyDrive::COMSETTER(Enabled) (BOOL aEnabled) 180 { 181 LogFlowThisFunc (("aEnabled=%RTbool\n", aEnabled)); 182 183 AutoCaller autoCaller (this); 184 CheckComRCReturnRC (autoCaller.rc()); 185 186 /* the machine needs to be mutable */ 187 Machine::AutoMutableStateDependency adep (mParent); 188 CheckComRCReturnRC (adep.rc()); 130 189 131 190 AutoLock alock (this); 132 AssertReturn (isReady(), (void) 0); 133 134 mData.free(); 135 136 mPeer.setNull(); 137 mParent.setNull(); 138 139 setReady (false); 140 } 141 142 // IFloppyDrive properties 143 ///////////////////////////////////////////////////////////////////////////// 144 145 STDMETHODIMP FloppyDrive::COMGETTER(Enabled) (BOOL *enabled) 146 { 147 if (!enabled) 191 192 if (mData->mEnabled != aEnabled) 193 { 194 mData.backup(); 195 mData->mEnabled = aEnabled; 196 197 /* leave the lock before informing callbacks*/ 198 alock.unlock(); 199 200 mParent->onFloppyDriveChange(); 201 } 202 203 return S_OK; 204 } 205 206 STDMETHODIMP FloppyDrive::COMGETTER(State) (DriveState_T *aDriveState) 207 { 208 if (!aDriveState) 148 209 return E_POINTER; 149 210 150 AutoLock alock(this); 151 CHECK_READY(); 152 153 *enabled = mData->mEnabled; 154 return S_OK; 155 } 156 157 STDMETHODIMP FloppyDrive::COMSETTER(Enabled) (BOOL enabled) 158 { 159 LogFlowMember(("FloppyDrive::SetEnabled: %s\n", enabled ? "enable" : "disable")); 160 161 AutoLock alock(this); 162 CHECK_READY(); 163 164 CHECK_MACHINE_MUTABILITY (mParent); 165 166 if (mData->mEnabled != enabled) 167 { 168 mData.backup(); 169 mData->mEnabled = enabled; 170 171 alock.unlock(); 172 mParent->onFloppyDriveChange(); 173 } 174 175 return S_OK; 176 } 177 178 STDMETHODIMP FloppyDrive::COMGETTER(State) (DriveState_T *driveState) 179 { 180 if (!driveState) 181 return E_POINTER; 211 AutoCaller autoCaller (this); 212 CheckComRCReturnRC (autoCaller.rc()); 213 214 AutoReaderLock alock (this); 215 216 *aDriveState = mData->mDriveState; 217 218 return S_OK; 219 } 220 221 // IFloppyDrive methods 222 ///////////////////////////////////////////////////////////////////////////// 223 224 STDMETHODIMP FloppyDrive::MountImage (INPTR GUIDPARAM aImageId) 225 { 226 if (Guid::isEmpty (aImageId)) 227 return E_INVALIDARG; 228 229 AutoCaller autoCaller (this); 230 CheckComRCReturnRC (autoCaller.rc()); 231 232 /* the machine needs to be mutable */ 233 Machine::AutoMutableStateDependency adep (mParent); 234 CheckComRCReturnRC (adep.rc()); 182 235 183 236 AutoLock alock (this); 184 CHECK_READY();185 186 *driveState = mData->mDriveState;187 return S_OK;188 }189 190 // IFloppyDrive methods191 /////////////////////////////////////////////////////////////////////////////192 193 STDMETHODIMP FloppyDrive::MountImage(INPTR GUIDPARAM imageId)194 {195 if (Guid::isEmpty(imageId))196 return E_INVALIDARG;197 198 AutoLock alock (this);199 CHECK_READY();200 201 CHECK_MACHINE_MUTABILITY (mParent);202 237 203 238 HRESULT rc = E_FAIL; 204 239 205 // find the image in the collection 206 ComPtr <IVirtualBox> vbox; 207 rc = mParent->COMGETTER(Parent) (vbox.asOutParam()); 208 AssertComRCReturn (rc, rc); 240 /* Our lifetime is bound to mParent's lifetime, so we don't add caller. 241 * We also don't lock mParent since its mParent field is const. */ 209 242 210 243 ComPtr <IFloppyImage> image; 211 rc = vbox->GetFloppyImage (imageId, image.asOutParam()); 244 rc = mParent->virtualBox()->GetFloppyImage (aImageId, image.asOutParam()); 245 212 246 if (SUCCEEDED (rc)) 213 247 { … … 216 250 { 217 251 mData.backup(); 252 218 253 unmount(); 254 219 255 mData->mFloppyImage = image; 220 256 mData->mDriveState = DriveState_ImageMounted; 221 257 258 /* leave the lock before informing callbacks*/ 222 259 alock.unlock(); 260 223 261 mParent->onFloppyDriveChange(); 224 262 } … … 228 266 } 229 267 230 STDMETHODIMP FloppyDrive::CaptureHostDrive (IHostFloppyDrive *hostFloppyDrive)231 { 232 if (! hostFloppyDrive)268 STDMETHODIMP FloppyDrive::CaptureHostDrive (IHostFloppyDrive *aHostFloppyDrive) 269 { 270 if (!aHostFloppyDrive) 233 271 return E_INVALIDARG; 234 272 273 AutoCaller autoCaller (this); 274 CheckComRCReturnRC (autoCaller.rc()); 275 276 /* the machine needs to be mutable */ 277 Machine::AutoMutableStateDependency adep (mParent); 278 CheckComRCReturnRC (adep.rc()); 279 235 280 AutoLock alock (this); 236 CHECK_READY();237 238 CHECK_MACHINE_MUTABILITY (mParent);239 281 240 282 if (mData->mDriveState != DriveState_HostDriveCaptured || 241 !mData->mHostDrive.equalsTo ( hostFloppyDrive))283 !mData->mHostDrive.equalsTo (aHostFloppyDrive)) 242 284 { 243 285 mData.backup(); 286 244 287 unmount(); 245 mData->mHostDrive = hostFloppyDrive; 288 289 mData->mHostDrive = aHostFloppyDrive; 246 290 mData->mDriveState = DriveState_HostDriveCaptured; 247 291 292 /* leave the lock before informing callbacks*/ 248 293 alock.unlock(); 294 249 295 mParent->onFloppyDriveChange(); 250 296 } … … 255 301 STDMETHODIMP FloppyDrive::Unmount() 256 302 { 303 AutoCaller autoCaller (this); 304 CheckComRCReturnRC (autoCaller.rc()); 305 306 /* the machine needs to be mutable */ 307 Machine::AutoMutableStateDependency adep (mParent); 308 CheckComRCReturnRC (adep.rc()); 309 257 310 AutoLock alock (this); 258 CHECK_READY();259 260 CHECK_MACHINE_MUTABILITY (mParent);261 311 262 312 if (mData->mDriveState != DriveState_NotMounted) 263 313 { 264 314 mData.backup(); 315 265 316 unmount(); 317 266 318 mData->mDriveState = DriveState_NotMounted; 267 319 320 /* leave the lock before informing callbacks*/ 268 321 alock.unlock(); 322 269 323 mParent->onFloppyDriveChange(); 270 324 } … … 273 327 } 274 328 275 STDMETHODIMP FloppyDrive::GetImage (IFloppyImage **floppyImage)276 { 277 if (! floppyImage)329 STDMETHODIMP FloppyDrive::GetImage (IFloppyImage **aFloppyImage) 330 { 331 if (!aFloppyImage) 278 332 return E_POINTER; 279 333 334 AutoCaller autoCaller (this); 335 CheckComRCReturnRC (autoCaller.rc()); 336 337 AutoReaderLock alock (this); 338 339 mData->mFloppyImage.queryInterfaceTo (aFloppyImage); 340 341 return S_OK; 342 } 343 344 STDMETHODIMP FloppyDrive::GetHostDrive (IHostFloppyDrive **aHostDrive) 345 { 346 if (!aHostDrive) 347 return E_POINTER; 348 349 AutoCaller autoCaller (this); 350 CheckComRCReturnRC (autoCaller.rc()); 351 352 AutoReaderLock alock (this); 353 354 mData->mHostDrive.queryInterfaceTo (aHostDrive); 355 356 return S_OK; 357 } 358 359 // public methods only for internal purposes 360 ///////////////////////////////////////////////////////////////////////////// 361 362 /** 363 * @note Locks this object for writing. 364 */ 365 bool FloppyDrive::rollback() 366 { 367 /* sanity */ 368 AutoCaller autoCaller (this); 369 AssertComRCReturn (autoCaller.rc(), false); 370 280 371 AutoLock alock (this); 281 CHECK_READY();282 283 mData->mFloppyImage.queryInterfaceTo (floppyImage);284 return S_OK;285 }286 287 STDMETHODIMP FloppyDrive::GetHostDrive(IHostFloppyDrive **hostDrive)288 {289 if (!hostDrive)290 return E_POINTER;291 292 AutoLock alock (this);293 CHECK_READY();294 295 mData->mHostDrive.queryInterfaceTo (hostDrive);296 return S_OK;297 }298 299 // public methods only for internal purposes300 /////////////////////////////////////////////////////////////////////////////301 302 bool FloppyDrive::rollback()303 {304 AutoLock alock (this);305 372 306 373 bool changed = false; … … 308 375 if (mData.isBackedUp()) 309 376 { 310 / /we need to check all data to see whether anything will be changed311 // after rollback377 /* we need to check all data to see whether anything will be changed 378 * after rollback */ 312 379 changed = mData.hasActualChanges(); 313 380 mData.rollback(); … … 317 384 } 318 385 386 /** 387 * @note Locks this object for writing, together with the peer object (also 388 * for writing) if there is one. 389 */ 319 390 void FloppyDrive::commit() 320 391 { 321 AutoLock alock (this); 392 /* sanity */ 393 AutoCaller autoCaller (this); 394 AssertComRCReturnVoid (autoCaller.rc()); 395 396 /* sanity too */ 397 AutoCaller thatCaller (mPeer); 398 AssertComRCReturnVoid (thatCaller.rc()); 399 400 /* lock both for writing since we modify both */ 401 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeWlock (mPeer)); 402 322 403 if (mData.isBackedUp()) 323 404 { … … 325 406 if (mPeer) 326 407 { 327 // attach new data to the peer and reshare it 328 AutoLock peerlock (mPeer); 408 /* attach new data to the peer and reshare it */ 329 409 mPeer->mData.attach (mData); 330 410 } … … 332 412 } 333 413 414 /** 415 * @note Locks this object for writing, together with the peer object (locked 416 * for reading) if there is one. 417 */ 334 418 void FloppyDrive::copyFrom (FloppyDrive *aThat) 335 419 { 336 AutoLock alock (this); 337 338 // this will back up current data 420 /* sanity */ 421 AutoCaller autoCaller (this); 422 AssertComRCReturnVoid (autoCaller.rc()); 423 424 /* sanity too */ 425 AutoCaller thatCaller (mPeer); 426 AssertComRCReturnVoid (thatCaller.rc()); 427 428 /* peer is not modified, lock it for reading */ 429 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeRlock (mPeer)); 430 431 /* this will back up current data */ 339 432 mData.assignCopy (aThat->mData); 340 433 } … … 344 437 345 438 /** 346 * Helper to unmount a drive 347 * 348 * @returns COM status code 349 * 439 * Helper to unmount a drive. 440 * 441 * @return COM status code 350 442 */ 351 443 HRESULT FloppyDrive::unmount() 352 444 { 445 AssertReturn (isLockedOnCurrentThread(), E_FAIL); 446 353 447 if (mData->mFloppyImage) 354 448 mData->mFloppyImage.setNull(); 355 449 if (mData->mHostDrive) 356 450 mData->mHostDrive.setNull(); 357 return S_OK; 358 } 451 452 return S_OK; 453 } -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r3191 r3330 3164 3164 * is returned. 3165 3165 * 3166 * @param id3166 * @param aId 3167 3167 * ID of the DVD image (unused when NULL) 3168 * @param filePathFull3168 * @param aFilePathFull 3169 3169 * full path to the image file (unused when NULL) 3170 3170 * @param aSetError 3171 3171 * if TRUE, the appropriate error info is set in case when the image is not 3172 3172 * found and only one search criteria (ID or file name) is specified. 3173 * @param dvdImage3173 * @param aImage 3174 3174 * where to store the found DVD image object (can be NULL) 3175 3175 * -
trunk/src/VBox/Main/include/DVDDriveImpl.h
r2981 r3330 28 28 29 29 class ATL_NO_VTABLE DVDDrive : 30 public VirtualBoxBaseNEXT, 30 31 public VirtualBoxSupportErrorInfoImpl <DVDDrive, IDVDDrive>, 31 32 public VirtualBoxSupportTranslation <DVDDrive>, 32 public VirtualBoxBase,33 33 public IDVDDrive 34 34 { … … 56 56 }; 57 57 58 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (DVDDrive) 59 58 60 DECLARE_NOT_AGGREGATABLE(DVDDrive) 59 61 … … 67 69 NS_DECL_ISUPPORTS 68 70 71 DECLARE_EMPTY_CTOR_DTOR (DVDDrive) 72 69 73 HRESULT FinalConstruct(); 70 74 void FinalRelease(); 71 75 72 76 // public initializer/uninitializer for internal purposes only 73 HRESULT init (Machine * parent);74 HRESULT init (Machine * parent, DVDDrive *that);75 HRESULT initCopy (Machine * parent, DVDDrive *that);77 HRESULT init (Machine *aParent); 78 HRESULT init (Machine *aParent, DVDDrive *aThat); 79 HRESULT initCopy (Machine *aParent, DVDDrive *aThat); 76 80 void uninit(); 77 81 78 82 // IDVDDrive properties 79 STDMETHOD(COMGETTER(State)) (DriveState_T * driveState);80 STDMETHOD(COMGETTER(Passthrough)) (BOOL * passthrough);81 STDMETHOD(COMSETTER(Passthrough)) (BOOL passthrough);83 STDMETHOD(COMGETTER(State)) (DriveState_T *aDriveState); 84 STDMETHOD(COMGETTER(Passthrough)) (BOOL *aPassthrough); 85 STDMETHOD(COMSETTER(Passthrough)) (BOOL aPassthrough); 82 86 83 87 // IDVDDrive methods 84 STDMETHOD(MountImage) (INPTR GUIDPARAM imageId);85 STDMETHOD(CaptureHostDrive) (IHostDVDDrive *hostDVDDrive);88 STDMETHOD(MountImage) (INPTR GUIDPARAM aImageId); 89 STDMETHOD(CaptureHostDrive) (IHostDVDDrive *aHostDVDDrive); 86 90 STDMETHOD(Unmount)(); 87 STDMETHOD(GetImage) (IDVDImage **dvdImage);88 STDMETHOD(GetHostDrive) (IHostDVDDrive **hostDVDDrive);91 STDMETHOD(GetImage) (IDVDImage **aDVDImage); 92 STDMETHOD(GetHostDrive) (IHostDVDDrive **aHostDVDDrive); 89 93 90 94 // public methods only for internal purposes … … 95 99 void commit(); 96 100 void copyFrom (DVDDrive *aThat); 101 102 // public methods for internal purposes only 103 // (ensure there is a caller and a read lock before calling them!) 97 104 98 105 Backupable <Data> &data() { return mData; } … … 105 112 HRESULT unmount(); 106 113 107 ComObjPtr <Machine, ComWeakRef> mParent; 108 ComObjPtr <DVDDrive> mPeer; 114 const ComObjPtr <Machine, ComWeakRef> mParent; 115 const ComObjPtr <DVDDrive> mPeer; 116 109 117 Backupable <Data> mData; 110 118 }; -
trunk/src/VBox/Main/include/FloppyDriveImpl.h
r2981 r3330 28 28 29 29 class ATL_NO_VTABLE FloppyDrive : 30 public VirtualBoxBaseNEXT, 30 31 public VirtualBoxSupportErrorInfoImpl <FloppyDrive, IFloppyDrive>, 31 32 public VirtualBoxSupportTranslation <FloppyDrive>, 32 public VirtualBoxBase,33 33 public IFloppyDrive 34 34 { … … 57 57 }; 58 58 59 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (FloppyDrive) 60 59 61 DECLARE_NOT_AGGREGATABLE(FloppyDrive) 60 62 … … 68 70 NS_DECL_ISUPPORTS 69 71 72 DECLARE_EMPTY_CTOR_DTOR (FloppyDrive) 73 70 74 HRESULT FinalConstruct(); 71 75 void FinalRelease(); 72 76 73 77 // public initializer/uninitializer for internal purposes only 74 HRESULT init (Machine * parent);75 HRESULT init (Machine * parent, FloppyDrive *that);76 HRESULT initCopy (Machine *parent, FloppyDrive * that);78 HRESULT init (Machine *aParent); 79 HRESULT init (Machine *aParent, FloppyDrive *aThat); 80 HRESULT initCopy (Machine *parent, FloppyDrive *aThat); 77 81 void uninit(); 78 82 79 83 // IFloppyDrive properties 80 STDMETHOD(COMGETTER(Enabled)) (BOOL * enabled);81 STDMETHOD(COMSETTER(Enabled)) (BOOL enabled);82 STDMETHOD(COMGETTER(State)) (DriveState_T * driveState);84 STDMETHOD(COMGETTER(Enabled)) (BOOL *aEnabled); 85 STDMETHOD(COMSETTER(Enabled)) (BOOL aEnabled); 86 STDMETHOD(COMGETTER(State)) (DriveState_T *aDriveState); 83 87 84 88 // IFloppyDrive methods 85 STDMETHOD(MountImage) (INPTR GUIDPARAM imageId);86 STDMETHOD(CaptureHostDrive) (IHostFloppyDrive *hostFloppyDrive);89 STDMETHOD(MountImage) (INPTR GUIDPARAM aImageId); 90 STDMETHOD(CaptureHostDrive) (IHostFloppyDrive *aHostFloppyDrive); 87 91 STDMETHOD(Unmount)(); 88 STDMETHOD(GetImage) (IFloppyImage **floppyImage);89 STDMETHOD(GetHostDrive) (IHostFloppyDrive **hostFloppyDrive);92 STDMETHOD(GetImage) (IFloppyImage **aFloppyImage); 93 STDMETHOD(GetHostDrive) (IHostFloppyDrive **aHostFloppyDrive); 90 94 91 95 // public methods only for internal purposes … … 96 100 void commit(); 97 101 void copyFrom (FloppyDrive *aThat); 102 103 // public methods for internal purposes only 104 // (ensure there is a caller and a read lock before calling them!) 98 105 99 106 Backupable <Data> &data() { return mData; } … … 106 113 HRESULT unmount(); 107 114 108 ComObjPtr <Machine, ComWeakRef> mParent; 109 ComObjPtr <FloppyDrive> mPeer; 115 const ComObjPtr <Machine, ComWeakRef> mParent; 116 const ComObjPtr <FloppyDrive> mPeer; 117 110 118 Backupable <Data> mData; 111 119 };
Note:
See TracChangeset
for help on using the changeset viewer.