VirtualBox

Ignore:
Timestamp:
Jan 9, 2023 9:46:16 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155122
Message:

Audio/Main: Made the Backupable<T> align with the rest of Main (via a private struct), added more documentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/AudioSettingsImpl.cpp

    r96407 r98028  
    4848{
    4949    Data()
    50         : pParent(NULL)
     50        : pMachine(NULL)
    5151    { }
    5252
    53     Machine * const                pParent;
     53    Machine * const                pMachine;
    5454    const ComObjPtr<AudioAdapter>  pAdapter;
    5555    const ComObjPtr<AudioSettings> pPeer;
     
    7676 * Initializes the audio settings object.
    7777 *
    78  * @param aParent  Handle of the parent object.
     78 * @returns HRESULT
     79 * @param   aParent             Pointer of the parent object.
    7980 */
    8081HRESULT AudioSettings::init(Machine *aParent)
    8182{
    82     LogFlowThisFunc(("aParent=%p\n", aParent));
    83 
    8483    ComAssertRet(aParent, E_INVALIDARG);
    8584
     
    9190
    9291    /* share the parent weakly */
    93     unconst(m->pParent) = aParent;
     92    unconst(m->pMachine) = aParent;
    9493
    9594    /* create the audio adapter object (always present, default is disabled) */
     
    109108 *
    110109 * @note This object must be destroyed before the original object
    111  * it shares data with is destroyed.
     110 *       it shares data with is destroyed.
    112111 *
    113112 * @note Locks @a aThat object for reading.
     113 *
     114 * @returns HRESULT
     115 * @param   aParent             Pointer of the parent object.
     116 * @param   aThat               Pointer to audio adapter to use settings from.
    114117 */
    115118HRESULT AudioSettings::init(Machine *aParent, AudioSettings *aThat)
    116119{
    117     LogFlowThisFuncEnter();
    118     LogFlowThisFunc(("aParent: %p, aThat: %p\n", aParent, aThat));
    119 
    120120    ComAssertRet(aParent && aThat, E_INVALIDARG);
    121121
     
    126126    m = new Data();
    127127
    128     unconst(m->pParent) = aParent;
    129     unconst(m->pPeer)   = aThat;
     128    unconst(m->pMachine) = aParent;
     129    unconst(m->pPeer)    = aThat;
    130130
    131131    AutoCaller thatCaller(aThat);
     
    134134    AutoReadLock thatlock(aThat COMMA_LOCKVAL_SRC_POS);
    135135
    136     unconst(m->pAdapter) = aThat->m->pAdapter;
     136    HRESULT hrc = unconst(m->pAdapter).createObject();
     137    ComAssertComRCRet(hrc, hrc);
     138    hrc = m->pAdapter->init(this, aThat->m->pAdapter);
     139    ComAssertComRCRet(hrc, hrc);
    137140
    138141    autoInitSpan.setSucceeded();
    139142
    140     LogFlowThisFuncLeave();
    141143    return S_OK;
    142144}
     
    148150 *
    149151 * @note Locks @a aThat object for reading.
     152 *
     153 * @returns HRESULT
     154 * @param   aParent             Pointer of the parent object.
     155 * @param   aThat               Pointer to audio adapter to use settings from.
    150156 */
    151157HRESULT AudioSettings::initCopy(Machine *aParent, AudioSettings *aThat)
    152158{
    153     LogFlowThisFuncEnter();
    154     LogFlowThisFunc(("aParent: %p, aThat: %p\n", aParent, aThat));
    155 
    156159    ComAssertRet(aParent && aThat, E_INVALIDARG);
    157160
     
    162165    m = new Data();
    163166
    164     unconst(m->pParent) = aParent;
     167    unconst(m->pMachine) = aParent;
    165168    // pPeer is left null
    166169
     
    175178    autoInitSpan.setSucceeded();
    176179
    177     LogFlowThisFuncLeave();
    178180    return S_OK;
    179181}
     
    185187void AudioSettings::uninit(void)
    186188{
    187     LogFlowThisFunc(("\n"));
    188 
    189189    /* Enclose the state transition Ready->InUninit->NotReady */
    190190    AutoUninitSpan autoUninitSpan(this);
     
    192192        return;
    193193
     194    unconst(m->pPeer)    = NULL;
     195    unconst(m->pMachine) = NULL;
     196
    194197    delete m;
    195198    m = NULL;
     
    230233
    231234/**
    232  * Returns the parent object as a weak pointer.
    233  */
    234 Machine* AudioSettings::i_getParent(void)
    235 {
    236     AutoCaller autoCaller(this);
    237     AssertComRCReturn(autoCaller.rc(), NULL);
    238 
    239     AssertPtrReturn(m, NULL);
    240     return m->pParent;
    241 }
    242 
    243 /**
    244235 * Determines whether the audio settings currently can be changed or not.
    245236 *
     
    248239bool AudioSettings::i_canChangeSettings(void)
    249240{
    250     AutoAnyStateDependency adep(m->pParent);
     241    AutoAnyStateDependency adep(m->pMachine);
    251242    if (FAILED(adep.rc()))
    252243        return false;
     
    259250 * Gets called when the machine object needs to know that audio adapter settings
    260251 * have been changed.
     252 *
     253 * @param   pAdapter             Pointer to audio adapter which has changed.
    261254 */
    262255void AudioSettings::i_onAdapterChanged(IAudioAdapter *pAdapter)
    263256{
    264     LogFlowThisFuncEnter();
    265 
    266257    AssertPtrReturnVoid(pAdapter);
    267 
    268     m->pParent->i_onAudioAdapterChange(pAdapter); // mParent is const, needs no locking
    269 
    270     LogFlowThisFuncLeave();
     258    m->pMachine->i_onAudioAdapterChange(pAdapter); // mParent is const, needs no locking
    271259}
    272260
     
    274262 * Gets called when the machine object needs to know that a host audio device
    275263 * has been changed.
     264 *
     265 * @param   pDevice             Host audio device which has changed.
     266 * @param   fIsNew              Set to \c true if this is a new device (i.e. has not been present before), \c false if not.
     267 * @param   enmState            The current state of the device.
     268 * @param   pErrInfo            Additional error information in case of error(s).
    276269 */
    277270void AudioSettings::i_onHostDeviceChanged(IHostAudioDevice *pDevice,
    278271                                          bool fIsNew, AudioDeviceState_T enmState, IVirtualBoxErrorInfo *pErrInfo)
    279272{
    280     LogFlowThisFuncEnter();
    281 
    282273    AssertPtrReturnVoid(pDevice);
    283 
    284     m->pParent->i_onHostAudioDeviceChange(pDevice, fIsNew, enmState, pErrInfo); // mParent is const, needs no locking
    285 
    286     LogFlowThisFuncLeave();
     274    m->pMachine->i_onHostAudioDeviceChange(pDevice, fIsNew, enmState, pErrInfo); // mParent is const, needs no locking
    287275}
    288276
     
    293281void AudioSettings::i_onSettingsChanged(void)
    294282{
    295     LogFlowThisFuncEnter();
    296 
    297     AutoWriteLock mlock(m->pParent COMMA_LOCKVAL_SRC_POS);
    298     m->pParent->i_setModified(Machine::IsModified_AudioSettings);
     283    AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS);
     284    m->pMachine->i_setModified(Machine::IsModified_AudioSettings);
    299285    mlock.release();
    300 
    301     LogFlowThisFuncLeave();
    302286}
    303287
     
    306290 * May be called once right after this object creation.
    307291 *
    308  * @param data Configuration settings.
     292 * @returns HRESULT
     293 * @param   data                Audio adapter configuration settings to load from.
    309294 *
    310295 * @note Locks this object for writing.
     
    324309
    325310/**
    326  * Saves settings to the given node.
    327  *
    328  * @param data Configuration settings.
     311 * Saves audio settings to the given machine node.
     312 *
     313 * @returns HRESULT
     314 * @param   data                Audio configuration settings to save to.
    329315 *
    330316 * @note Locks this object for reading.
     
    344330
    345331/**
     332 * Copies settings from a given audio settings object.
     333 *
     334 * This object makes a private copy of data of the original object passed as
     335 * an argument.
     336 *
    346337 * @note Locks this object for writing, together with the peer object
    347  * represented by @a aThat (locked for reading).
     338 *       represented by @a aThat (locked for reading).
     339 *
     340 * @param aThat                 Audio settings to load from.
    348341 */
    349342void AudioSettings::i_copyFrom(AudioSettings *aThat)
     
    406399
    407400/**
     401 * Rolls back the current configuration to a former state.
     402 *
    408403 * @note Locks this object for writing.
    409404 */
     
    422417
    423418/**
     419 * Commits the current settings and propagates those to a peer (if assigned).
     420 *
    424421 * @note Locks this object for writing, together with the peer object (also
    425  * for writing) if there is one.
     422 *       for writing) if there is one.
    426423 */
    427424void AudioSettings::i_commit(void)
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