VirtualBox

Changeset 25200 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Dec 4, 2009 6:19:05 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55681
Message:

Main: make MediumAttachment instance data private

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

Legend:

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

    r25151 r25200  
    3030#endif // VBOX_WITH_USB
    3131
     32#include "MediumImpl.h"
    3233#include "HostPower.h"
    3334
  • trunk/src/VBox/Main/MediumAttachmentImpl.cpp

    r25149 r25200  
    2222#include "MediumAttachmentImpl.h"
    2323#include "MachineImpl.h"
     24#include "MediumImpl.h"
    2425#include "Global.h"
    2526
    2627#include "Logging.h"
     28
     29////////////////////////////////////////////////////////////////////////////////
     30//
     31// private member data definition
     32//
     33////////////////////////////////////////////////////////////////////////////////
     34
     35struct BackupableMediumAttachmentData
     36{
     37    BackupableMediumAttachmentData()
     38        : lPort(0),
     39          lDevice(0),
     40          type(DeviceType_Null),
     41          fPassthrough(false),
     42          fImplicit(false)
     43    { }
     44
     45    bool operator==(const BackupableMediumAttachmentData &that) const
     46    {
     47        return    this == &that
     48               || (fPassthrough == that.fPassthrough);
     49    }
     50
     51    ComObjPtr<Medium>   pMedium;
     52    /* Since MediumAttachment is not a first class citizen when it
     53     * comes to managing settings, having a reference to the storage
     54     * controller will not work - when settings are changed it will point
     55     * to the old, uninitialized instance. Changing this requires
     56     * substantial changes to MediumImpl.cpp. */
     57    const Bstr          bstrControllerName;
     58    const LONG          lPort;
     59    const LONG          lDevice;
     60    const DeviceType_T  type;
     61    bool                fPassthrough : 1;
     62    bool                fImplicit : 1;
     63};
     64
     65struct MediumAttachment::Data
     66{
     67    Data()
     68    { }
     69
     70    /** Reference to Machine object, for checking mutable state. */
     71    const ComObjPtr<Machine, ComWeakRef> pMachine;
     72    /* later: const ComObjPtr<MediumAttachment> mPeer; */
     73
     74    Backupable<BackupableMediumAttachmentData> bd;
     75};
    2776
    2877// constructor / destructor
    2978/////////////////////////////////////////////////////////////////////////////
    30 
    31 DEFINE_EMPTY_CTOR_DTOR(MediumAttachment)
    3279
    3380HRESULT MediumAttachment::FinalConstruct()
     
    75122    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    76123
    77     unconst(mParent) = aParent;
    78 
    79     m.allocate();
    80     m->medium = aMedium;
    81     unconst(m->controllerName) = aControllerName;
    82     unconst(m->port)   = aPort;
    83     unconst(m->device) = aDevice;
    84     unconst(m->type)   = aType;
    85     unconst(m->passthrough) = false;
    86 
    87     m->implicit = aImplicit;
     124    m = new Data();
     125
     126    unconst(m->pMachine) = aParent;
     127
     128    m->bd.allocate();
     129    m->bd->pMedium = aMedium;
     130    unconst(m->bd->bstrControllerName) = aControllerName;
     131    unconst(m->bd->lPort)   = aPort;
     132    unconst(m->bd->lDevice) = aDevice;
     133    unconst(m->bd->type)   = aType;
     134
     135    m->bd->fPassthrough = false;
     136    m->bd->fImplicit = aImplicit;
    88137
    89138    /* Confirm a successful initialization when it's the case */
     
    116165        return;
    117166
    118     m.free();
    119 
    120     unconst(mParent).setNull();
    121 
    122     LogFlowThisFuncLeave();
     167    m->bd.free();
     168
     169    unconst(m->pMachine).setNull();
     170
     171    delete m;
     172    m = NULL;
     173
     174    LogFlowThisFuncLeave();
     175}
     176
     177// IHardDiskAttachment properties
     178/////////////////////////////////////////////////////////////////////////////
     179
     180STDMETHODIMP MediumAttachment::COMGETTER(Medium)(IMedium **aHardDisk)
     181{
     182    LogFlowThisFuncEnter();
     183
     184    CheckComArgOutPointerValid(aHardDisk);
     185
     186    AutoCaller autoCaller(this);
     187    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     188
     189    AutoReadLock alock(this);
     190
     191    m->bd->pMedium.queryInterfaceTo(aHardDisk);
     192
     193    LogFlowThisFuncLeave();
     194    return S_OK;
     195}
     196
     197STDMETHODIMP MediumAttachment::COMGETTER(Controller)(BSTR *aController)
     198{
     199    LogFlowThisFuncEnter();
     200
     201    CheckComArgOutPointerValid(aController);
     202
     203    AutoCaller autoCaller(this);
     204    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     205
     206    /* m->controller is constant during life time, no need to lock */
     207    m->bd->bstrControllerName.cloneTo(aController);
     208
     209    LogFlowThisFuncLeave();
     210    return S_OK;
     211}
     212
     213STDMETHODIMP MediumAttachment::COMGETTER(Port)(LONG *aPort)
     214{
     215    LogFlowThisFuncEnter();
     216
     217    CheckComArgOutPointerValid(aPort);
     218
     219    AutoCaller autoCaller(this);
     220    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     221
     222    /* m->bd->port is constant during life time, no need to lock */
     223    *aPort = m->bd->lPort;
     224
     225    LogFlowThisFuncLeave();
     226    return S_OK;
     227}
     228
     229STDMETHODIMP MediumAttachment::COMGETTER(Device)(LONG *aDevice)
     230{
     231    LogFlowThisFuncEnter();
     232
     233    CheckComArgOutPointerValid(aDevice);
     234
     235    AutoCaller autoCaller(this);
     236    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     237
     238    /* m->bd->device is constant during life time, no need to lock */
     239    *aDevice = m->bd->lDevice;
     240
     241    LogFlowThisFuncLeave();
     242    return S_OK;
     243}
     244
     245STDMETHODIMP MediumAttachment::COMGETTER(Type)(DeviceType_T *aType)
     246{
     247    LogFlowThisFuncEnter();
     248
     249    CheckComArgOutPointerValid(aType);
     250
     251    AutoCaller autoCaller(this);
     252    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     253
     254    /* m->bd->type is constant during life time, no need to lock */
     255    *aType = m->bd->type;
     256
     257    LogFlowThisFuncLeave();
     258    return S_OK;
     259}
     260
     261STDMETHODIMP MediumAttachment::COMGETTER(Passthrough)(BOOL *aPassthrough)
     262{
     263    LogFlowThisFuncEnter();
     264
     265    CheckComArgOutPointerValid(aPassthrough);
     266
     267    AutoCaller autoCaller(this);
     268    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     269
     270    AutoReadLock lock(this);
     271
     272    *aPassthrough = m->bd->fPassthrough;
     273
     274    LogFlowThisFuncLeave();
     275    return S_OK;
    123276}
    124277
     
    138291    bool changed = false;
    139292
    140     if (m.isBackedUp())
     293    if (m->bd.isBackedUp())
    141294    {
    142295        /* we need to check all data to see whether anything will be changed
    143296         * after rollback */
    144         changed = m.hasActualChanges();
    145         m.rollback();
     297        changed = m->bd.hasActualChanges();
     298        m->bd.rollback();
    146299    }
    147300
     
    163316    AutoWriteLock alock(this);
    164317
    165     if (m.isBackedUp())
    166         m.commit();
    167 
    168     LogFlowThisFuncLeave();
    169 }
    170 
    171 
    172 // IHardDiskAttachment properties
    173 /////////////////////////////////////////////////////////////////////////////
    174 
    175 STDMETHODIMP MediumAttachment::COMGETTER(Medium)(IMedium **aHardDisk)
    176 {
    177     LogFlowThisFuncEnter();
    178 
    179     CheckComArgOutPointerValid(aHardDisk);
    180 
    181     AutoCaller autoCaller(this);
    182     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    183 
    184     AutoReadLock alock(this);
    185 
    186     m->medium.queryInterfaceTo(aHardDisk);
    187 
    188     LogFlowThisFuncLeave();
    189     return S_OK;
    190 }
    191 
    192 STDMETHODIMP MediumAttachment::COMGETTER(Controller)(BSTR *aController)
    193 {
    194     LogFlowThisFuncEnter();
    195 
    196     CheckComArgOutPointerValid(aController);
    197 
    198     AutoCaller autoCaller(this);
    199     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    200 
    201     /* m->controller is constant during life time, no need to lock */
    202     m->controllerName.cloneTo(aController);
    203 
    204     LogFlowThisFuncLeave();
    205     return S_OK;
    206 }
    207 
    208 STDMETHODIMP MediumAttachment::COMGETTER(Port)(LONG *aPort)
    209 {
    210     LogFlowThisFuncEnter();
    211 
    212     CheckComArgOutPointerValid(aPort);
    213 
    214     AutoCaller autoCaller(this);
    215     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    216 
    217     /* m->port is constant during life time, no need to lock */
    218     *aPort = m->port;
    219 
    220     LogFlowThisFuncLeave();
    221     return S_OK;
    222 }
    223 
    224 STDMETHODIMP MediumAttachment::COMGETTER(Device)(LONG *aDevice)
    225 {
    226     LogFlowThisFuncEnter();
    227 
    228     CheckComArgOutPointerValid(aDevice);
    229 
    230     AutoCaller autoCaller(this);
    231     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    232 
    233     /* m->device is constant during life time, no need to lock */
    234     *aDevice = m->device;
    235 
    236     LogFlowThisFuncLeave();
    237     return S_OK;
    238 }
    239 
    240 STDMETHODIMP MediumAttachment::COMGETTER(Type)(DeviceType_T *aType)
    241 {
    242     LogFlowThisFuncEnter();
    243 
    244     CheckComArgOutPointerValid(aType);
    245 
    246     AutoCaller autoCaller(this);
    247     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    248 
    249     /* m->type is constant during life time, no need to lock */
    250     *aType = m->type;
    251 
    252     LogFlowThisFuncLeave();
    253     return S_OK;
    254 }
    255 
    256 STDMETHODIMP MediumAttachment::COMGETTER(Passthrough)(BOOL *aPassthrough)
    257 {
    258     LogFlowThisFuncEnter();
    259 
    260     CheckComArgOutPointerValid(aPassthrough);
    261 
    262     AutoCaller autoCaller(this);
    263     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    264 
     318    if (m->bd.isBackedUp())
     319        m->bd.commit();
     320
     321    LogFlowThisFuncLeave();
     322}
     323
     324bool MediumAttachment::isImplicit() const
     325{
     326    return m->bd->fImplicit;
     327}
     328
     329void MediumAttachment::setImplicit(bool aImplicit)
     330{
     331    m->bd->fImplicit = aImplicit;
     332}
     333
     334const ComObjPtr<Medium>& MediumAttachment::getMedium() const
     335{
     336    return m->bd->pMedium;
     337}
     338
     339Bstr MediumAttachment::getControllerName() const
     340{
     341    return m->bd->bstrControllerName;
     342}
     343
     344LONG MediumAttachment::getPort() const
     345{
     346    return m->bd->lPort;
     347}
     348
     349LONG MediumAttachment::getDevice() const
     350{
     351    return m->bd->lDevice;
     352}
     353
     354DeviceType_T MediumAttachment::getType() const
     355{
     356    return m->bd->type;
     357}
     358
     359bool MediumAttachment::getPassthrough() const
     360{
    265361    AutoReadLock lock(this);
    266 
    267     *aPassthrough = m->passthrough;
    268 
    269     LogFlowThisFuncLeave();
    270     return S_OK;
    271 }
    272 
     362    return m->bd->fPassthrough;
     363}
     364
     365bool MediumAttachment::matches(CBSTR aControllerName, LONG aPort, LONG aDevice)
     366{
     367    return (    aControllerName == m->bd->bstrControllerName
     368             && aPort == m->bd->lPort
     369             && aDevice == m->bd->lDevice);
     370}
     371
     372/** Must be called from under this object's write lock. */
     373void MediumAttachment::updateMedium(const ComObjPtr<Medium> &aMedium, bool aImplicit)
     374{
     375    m->bd.backup();
     376    m->bd->pMedium = aMedium;
     377    m->bd->fImplicit = aImplicit;
     378}
     379
     380/** Must be called from under this object's write lock. */
     381void MediumAttachment::updatePassthrough(bool aPassthrough)
     382{
     383    m->bd.backup();
     384    m->bd->fPassthrough = aPassthrough;
     385}
     386
  • trunk/src/VBox/Main/SnapshotImpl.cpp

    r25194 r25200  
    2323
    2424#include "MachineImpl.h"
     25#include "MediumImpl.h"
    2526#include "Global.h"
    2627
  • trunk/src/VBox/Main/include/MediumAttachmentImpl.h

    r24989 r25200  
    2525#include "VirtualBoxBase.h"
    2626
    27 #include "MediumImpl.h"
    28 
    2927class Machine;
    3028class Medium;
     
    4846    END_COM_MAP()
    4947
    50     DECLARE_EMPTY_CTOR_DTOR(MediumAttachment)
     48    MediumAttachment() { };
     49    ~MediumAttachment() { };
    5150
    5251    // public initializer/uninitializer for internal purposes only
     
    6362    void FinalRelease();
    6463
    65     bool rollback();
    66     void commit();
    67 
    6864    // IMediumAttachment properties
    6965    STDMETHOD(COMGETTER(Medium))(IMedium **aMedium);
     
    7470    STDMETHOD(COMGETTER(Passthrough))(BOOL *aPassthrough);
    7571
    76     // unsafe inline public methods for internal purposes only (ensure there is
     72    // public internal methods
     73    bool rollback();
     74    void commit();
     75
     76    // unsafe public methods for internal purposes only (ensure there is
    7777    // a caller and a read lock before calling them!)
     78    bool isImplicit() const;
     79    void setImplicit(bool aImplicit);
    7880
    79     bool isImplicit() const { return m->implicit; }
    80     void setImplicit(bool aImplicit) { m->implicit = aImplicit; }
     81    const ComObjPtr<Medium>& getMedium() const;
     82    Bstr getControllerName() const;
     83    LONG getPort() const;
     84    LONG getDevice() const;
     85    DeviceType_T getType() const;
     86    bool getPassthrough() const;
    8187
    82     const ComObjPtr<Medium>& getMedium() const { return m->medium; }
    83     Bstr getControllerName() const { return m->controllerName; }
    84     LONG getPort() const { return m->port; }
    85     LONG getDevice() const { return m->device; }
    86     DeviceType_T getType() const { return m->type; }
    87     bool getPassthrough() const { AutoReadLock lock(this); return m->passthrough; }
    88 
    89     bool matches(CBSTR aControllerName, LONG aPort, LONG aDevice)
    90     {
    91         return (    aControllerName == m->controllerName
    92                  && aPort == m->port
    93                  && aDevice == m->device);
    94     }
     88    bool matches(CBSTR aControllerName, LONG aPort, LONG aDevice);
    9589
    9690    /** Must be called from under this object's write lock. */
    97     void updateMedium(const ComObjPtr<Medium> &aMedium, bool aImplicit)
    98     {
    99         m.backup();
    100         m->medium = aMedium;
    101         m->implicit = aImplicit;
    102     }
     91    void updateMedium(const ComObjPtr<Medium> &aMedium, bool aImplicit);
    10392
    10493    /** Must be called from under this object's write lock. */
    105     void updatePassthrough(bool aPassthrough)
    106     {
    107         m.backup();
    108         m->passthrough = aPassthrough;
    109     }
     94    void updatePassthrough(bool aPassthrough);
    11095
    11196    /** Get a unique and somewhat descriptive name for logging. */
     
    116101
    117102private:
    118 
    119     /** Reference to Machine object, for checking mutable state. */
    120     const ComObjPtr<Machine, ComWeakRef> mParent;
    121     /* later: const ComObjPtr<MediumAttachment> mPeer; */
    122 
    123     struct Data
    124     {
    125         Data() : port(0), device(0), type(DeviceType_Null),
    126                  passthrough(false), implicit(false) {}
    127 
    128         bool operator== (const Data &that) const
    129         {
    130             return   this == &that
    131                    || (passthrough == that.passthrough);
    132         }
    133 
    134         ComObjPtr<Medium> medium;
    135         /* Since MediumAttachment is not a first class citizen when it
    136          * comes to managing settings, having a reference to the storage
    137          * controller will not work - when settings are changed it will point
    138          * to the old, uninitialized instance. Changing this requires
    139          * substantial changes to MediumImpl.cpp. */
    140         const Bstr controllerName;
    141         const LONG port;
    142         const LONG device;
    143         const DeviceType_T type;
    144         bool passthrough : 1;
    145         bool implicit : 1;
    146     };
    147 
    148     Backupable<Data> m;
     103    struct Data;
     104    Data *m;
    149105
    150106    Utf8Str mLogName;                   /**< For logging purposes */
  • trunk/src/VBox/Main/include/MediumImpl.h

    r25152 r25200  
    2525
    2626#include "VirtualBoxBase.h"
    27 
    28 #include <VBox/com/SupportErrorInfo.h>
    2927
    3028class VirtualBox;
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r25152 r25200  
    2929
    3030#include "VBox/com/ErrorInfo.h"
     31#include <VBox/com/SupportErrorInfo.h>
    3132
    3233#include "VBox/com/VirtualBox.h"
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette