Changeset 3348 in vbox for trunk/src/VBox/Main/AudioAdapterImpl.cpp
- Timestamp:
- Jul 2, 2007 12:44:39 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/AudioAdapterImpl.cpp
r3191 r3348 24 24 #include "Logging.h" 25 25 26 #include <iprt/cpputils.h> 27 26 28 // constructor / destructor 27 29 ///////////////////////////////////////////////////////////////////////////// 28 30 31 DEFINE_EMPTY_CTOR_DTOR (AudioAdapter) 32 29 33 HRESULT AudioAdapter::FinalConstruct() 30 34 { … … 34 38 void AudioAdapter::FinalRelease() 35 39 { 36 if (isReady()) 37 uninit (); 40 uninit (); 38 41 } 39 42 … … 42 45 43 46 /** 44 * Initializes the audio adapter object. 45 * 46 * @returns COM result indicator 47 */ 48 HRESULT AudioAdapter::init (Machine *parent) 49 { 50 LogFlowMember (("AudioAdapter::init (%p)\n", parent)); 51 52 ComAssertRet (parent, E_INVALIDARG); 53 54 AutoLock alock (this); 55 ComAssertRet (!isReady(), E_UNEXPECTED); 56 57 mParent = parent; 58 // mPeer is left null 47 * Initializes the audio adapter object. 48 * 49 * @param aParent Handle of the parent object. 50 */ 51 HRESULT AudioAdapter::init (Machine *aParent) 52 { 53 LogFlowThisFunc (("aParent=%p\n", aParent)); 54 55 ComAssertRet (aParent, E_INVALIDARG); 56 57 /* Enclose the state transition NotReady->InInit->Ready */ 58 AutoInitSpan autoInitSpan (this); 59 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 60 61 unconst (mParent) = aParent; 62 /* mPeer is left null */ 59 63 60 64 mData.allocate(); 61 65 62 setReady (true); 66 /* Confirm a successful initialization */ 67 autoInitSpan.setSucceeded(); 68 63 69 return S_OK; 64 70 } … … 71 77 * @note This object must be destroyed before the original object 72 78 * it shares data with is destroyed. 73 */ 74 HRESULT AudioAdapter::init (Machine *parent, AudioAdapter *that) 75 { 76 LogFlowMember (("AudioAdapter::init (%p, %p)\n", parent, that)); 77 78 ComAssertRet (parent && that, E_INVALIDARG); 79 80 AutoLock alock (this); 81 ComAssertRet (!isReady(), E_UNEXPECTED); 82 83 mParent = parent; 84 mPeer = that; 85 86 AutoLock thatlock (that); 87 mData.share (that->mData); 88 89 setReady (true); 79 * 80 * @note Locks @a aThat object for reading. 81 */ 82 HRESULT AudioAdapter::init (Machine *aParent, AudioAdapter *aThat) 83 { 84 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 85 86 ComAssertRet (aParent && aThat, E_INVALIDARG); 87 88 /* Enclose the state transition NotReady->InInit->Ready */ 89 AutoInitSpan autoInitSpan (this); 90 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 91 92 unconst (mParent) = aParent; 93 unconst (mPeer) = aThat; 94 95 AutoCaller thatCaller (aThat); 96 AssertComRCReturnRC (thatCaller.rc()); 97 98 AutoReaderLock thatLock (aThat); 99 mData.share (aThat->mData); 100 101 /* Confirm a successful initialization */ 102 autoInitSpan.setSucceeded(); 103 90 104 return S_OK; 91 105 } … … 95 109 * (a kind of copy constructor). This object makes a private copy of data 96 110 * of the original object passed as an argument. 97 */ 98 HRESULT AudioAdapter::initCopy (Machine *parent, AudioAdapter *that) 99 { 100 LogFlowMember (("AudioAdapter::initCopy (%p, %p)\n", parent, that)); 101 102 ComAssertRet (parent && that, E_INVALIDARG); 103 104 AutoLock alock (this); 105 ComAssertRet (!isReady(), E_UNEXPECTED); 106 107 mParent = parent; 108 // mPeer is left null 109 110 AutoLock thatlock (that); 111 mData.attachCopy (that->mData); 112 113 setReady (true); 111 * 112 * @note Locks @a aThat object for reading. 113 */ 114 HRESULT AudioAdapter::initCopy (Machine *aParent, AudioAdapter *aThat) 115 { 116 LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat)); 117 118 ComAssertRet (aParent && aThat, E_INVALIDARG); 119 120 /* Enclose the state transition NotReady->InInit->Ready */ 121 AutoInitSpan autoInitSpan (this); 122 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED); 123 124 unconst (mParent) = aParent; 125 /* mPeer is left null */ 126 127 AutoCaller thatCaller (aThat); 128 AssertComRCReturnRC (thatCaller.rc()); 129 130 AutoReaderLock thatLock (aThat); 131 mData.attachCopy (aThat->mData); 132 133 /* Confirm a successful initialization */ 134 autoInitSpan.setSucceeded(); 135 114 136 return S_OK; 115 137 } … … 121 143 void AudioAdapter::uninit() 122 144 { 123 LogFlowMember (("AudioAdapter::uninit()\n")); 145 LogFlowThisFunc (("\n")); 146 147 /* Enclose the state transition Ready->InUninit->NotReady */ 148 AutoUninitSpan autoUninitSpan (this); 149 if (autoUninitSpan.uninitDone()) 150 return; 151 152 mData.free(); 153 154 unconst (mPeer).setNull(); 155 unconst (mParent).setNull(); 156 } 157 158 // IAudioAdapter properties 159 ///////////////////////////////////////////////////////////////////////////// 160 161 STDMETHODIMP AudioAdapter::COMGETTER(Enabled)(BOOL *aEnabled) 162 { 163 if (!aEnabled) 164 return E_POINTER; 165 166 AutoCaller autoCaller (this); 167 CheckComRCReturnRC (autoCaller.rc()); 168 169 AutoReaderLock alock (this); 170 171 *aEnabled = mData->mEnabled; 172 173 return S_OK; 174 } 175 176 STDMETHODIMP AudioAdapter::COMSETTER(Enabled)(BOOL aEnabled) 177 { 178 AutoCaller autoCaller (this); 179 CheckComRCReturnRC (autoCaller.rc()); 180 181 /* the machine needs to be mutable */ 182 Machine::AutoMutableStateDependency adep (mParent); 183 CheckComRCReturnRC (adep.rc()); 124 184 125 185 AutoLock alock (this); 126 AssertReturn (isReady(), (void) 0); 127 128 mData.free(); 129 130 mPeer.setNull(); 131 mParent.setNull(); 132 133 setReady(false); 134 } 135 136 // IAudioAdapter properties 137 ///////////////////////////////////////////////////////////////////////////// 138 139 /** 140 * Returns the enabled status 141 * 142 * @returns COM status code 143 * @param enabled address of result variable 144 */ 145 STDMETHODIMP AudioAdapter::COMGETTER(Enabled)(BOOL *enabled) 146 { 147 if (!enabled) 148 return E_POINTER; 149 150 AutoLock lock(this); 151 CHECK_READY(); 152 153 *enabled = mData->mEnabled; 154 return S_OK; 155 } 156 157 /** 158 * Sets the enabled state 159 * 160 * @returns COM status code 161 * @param enabled address of result variable 162 */ 163 STDMETHODIMP AudioAdapter::COMSETTER(Enabled)(BOOL enabled) 164 { 165 AutoLock lock(this); 166 CHECK_READY(); 167 168 CHECK_MACHINE_MUTABILITY (mParent); 169 170 if (mData->mEnabled != enabled) 186 187 if (mData->mEnabled != aEnabled) 171 188 { 172 189 mData.backup(); 173 mData->mEnabled = enabled;190 mData->mEnabled = aEnabled; 174 191 } 175 192 … … 177 194 } 178 195 179 /** 180 * Returns the current audio driver type 181 * 182 * @returns COM status code 183 * @param audioDriver address of result variable 184 */ 185 STDMETHODIMP AudioAdapter::COMGETTER(AudioDriver)(AudioDriverType_T *audioDriver) 186 { 187 if (!audioDriver) 196 STDMETHODIMP AudioAdapter::COMGETTER(AudioDriver)(AudioDriverType_T *aAudioDriver) 197 { 198 if (!aAudioDriver) 188 199 return E_POINTER; 189 200 190 AutoLock lock(this); 191 CHECK_READY(); 192 193 *audioDriver = mData->mAudioDriver; 194 return S_OK; 195 } 196 197 /** 198 * Sets the audio driver type 199 * 200 * @returns COM status code 201 * @param audioDriver audio driver type to use 202 */ 203 STDMETHODIMP AudioAdapter::COMSETTER(AudioDriver)(AudioDriverType_T audioDriver) 204 { 205 AutoLock lock(this); 206 CHECK_READY(); 207 208 CHECK_MACHINE_MUTABILITY (mParent); 201 AutoCaller autoCaller (this); 202 CheckComRCReturnRC (autoCaller.rc()); 203 204 AutoReaderLock alock (this); 205 206 *aAudioDriver = mData->mAudioDriver; 207 208 return S_OK; 209 } 210 211 STDMETHODIMP AudioAdapter::COMSETTER(AudioDriver)(AudioDriverType_T aAudioDriver) 212 { 213 AutoCaller autoCaller (this); 214 CheckComRCReturnRC (autoCaller.rc()); 215 216 /* the machine needs to be mutable */ 217 Machine::AutoMutableStateDependency adep (mParent); 218 CheckComRCReturnRC (adep.rc()); 219 220 AutoLock alock (this); 209 221 210 222 HRESULT rc = S_OK; 211 223 212 if (mData->mAudioDriver != a udioDriver)224 if (mData->mAudioDriver != aAudioDriver) 213 225 { 214 226 /* 215 227 * which audio driver type are we supposed to use? 216 228 */ 217 switch (a udioDriver)229 switch (aAudioDriver) 218 230 { 219 231 case AudioDriverType_NullAudioDriver: … … 238 250 { 239 251 mData.backup(); 240 mData->mAudioDriver = a udioDriver;252 mData->mAudioDriver = aAudioDriver; 241 253 break; 242 254 } … … 244 256 default: 245 257 { 246 Log(("wrong audio driver type specified!\n")); 258 AssertMsgFailed (("Wrong audio driver type %d\n", 259 aAudioDriver)); 247 260 rc = E_FAIL; 248 261 } … … 259 272 ///////////////////////////////////////////////////////////////////////////// 260 273 274 /** 275 * @note Locks this object for writing. 276 */ 277 bool AudioAdapter::rollback() 278 { 279 /* sanity */ 280 AutoCaller autoCaller (this); 281 AssertComRCReturn (autoCaller.rc(), false); 282 283 AutoLock alock (this); 284 285 bool changed = false; 286 287 if (mData.isBackedUp()) 288 { 289 /* we need to check all data to see whether anything will be changed 290 * after rollback */ 291 changed = mData.hasActualChanges(); 292 mData.rollback(); 293 } 294 295 return changed; 296 } 297 298 /** 299 * @note Locks this object for writing, together with the peer object (also 300 * for writing) if there is one. 301 */ 261 302 void AudioAdapter::commit() 262 303 { 263 AutoLock alock (this); 304 /* sanity */ 305 AutoCaller autoCaller (this); 306 AssertComRCReturnVoid (autoCaller.rc()); 307 308 /* sanity too */ 309 AutoCaller thatCaller (mPeer); 310 AssertComRCReturnVoid (thatCaller.rc()); 311 312 /* lock both for writing since we modify both */ 313 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeWlock (mPeer)); 314 264 315 if (mData.isBackedUp()) 265 316 { … … 267 318 if (mPeer) 268 319 { 269 // attach new data to the peer and reshare it 270 AutoLock peerlock (mPeer); 320 /* attach new data to the peer and reshare it */ 271 321 mPeer->mData.attach (mData); 272 322 } … … 274 324 } 275 325 326 /** 327 * @note Locks this object for writing, together with the peer object 328 * represented by @a aThat (locked for reading). 329 */ 276 330 void AudioAdapter::copyFrom (AudioAdapter *aThat) 277 331 { 278 AutoLock alock (this); 279 280 // this will back up current data 332 AssertReturnVoid (aThat != NULL); 333 334 /* sanity */ 335 AutoCaller autoCaller (this); 336 AssertComRCReturnVoid (autoCaller.rc()); 337 338 /* sanity too */ 339 AutoCaller thatCaller (mPeer); 340 AssertComRCReturnVoid (thatCaller.rc()); 341 342 /* peer is not modified, lock it for reading */ 343 AutoMultiLock <2> alock (this->wlock(), aThat->rlock()); 344 345 /* this will back up current data */ 281 346 mData.assignCopy (aThat->mData); 282 347 } 283
Note:
See TracChangeset
for help on using the changeset viewer.