VirtualBox

Changeset 3424 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 4, 2007 4:10:37 PM (18 years ago)
Author:
vboxsync
Message:

Main: Removed outdated CHECK_MACHINE_MUTABILITY and CHECK_STATE macros.

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

Legend:

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

    r3191 r3424  
    7171// defines / prototypes
    7272/////////////////////////////////////////////////////////////////////////////
    73 
    74 /**
    75  *  Local mutability check macro for Machine implementation only.
    76  */
    77 #define CHECK_SETTER() \
    78     if (!isMutable()) \
    79         return setError (E_ACCESSDENIED, tr ("The machine is not mutable"));
    8073
    8174// globals
     
    801794    AutoLock alock (this);
    802795
    803     CHECK_SETTER();
     796    HRESULT rc = checkStateDependency (MutableStateDep);
     797    CheckComRCReturnRC (rc);
    804798
    805799    mUserData.backup();
     
    831825    AutoLock alock (this);
    832826
    833     CHECK_SETTER();
     827    HRESULT rc = checkStateDependency (MutableStateDep);
     828    CheckComRCReturnRC (rc);
    834829
    835830    mUserData.backup();
     
    885880    AutoLock alock (this);
    886881
    887     CHECK_SETTER();
     882    rc = checkStateDependency (MutableStateDep);
     883    CheckComRCReturnRC (rc);
    888884
    889885    mUserData.backup();
     
    922918    AutoLock alock (this);
    923919
    924     CHECK_SETTER();
     920    HRESULT rc = checkStateDependency (MutableStateDep);
     921    CheckComRCReturnRC (rc);
    925922
    926923    mHWData.backup();
     
    959956    AutoLock alock (this);
    960957
    961     CHECK_SETTER();
     958    HRESULT rc = checkStateDependency (MutableStateDep);
     959    CheckComRCReturnRC (rc);
    962960
    963961    mHWData.backup();
     
    995993    AutoLock alock (this);
    996994
    997     CHECK_SETTER();
     995    HRESULT rc = checkStateDependency (MutableStateDep);
     996    CheckComRCReturnRC (rc);
    998997
    999998    mHWData.backup();
     
    10391038    AutoLock alock (this);
    10401039
    1041     CHECK_SETTER();
     1040    HRESULT rc = checkStateDependency (MutableStateDep);
     1041    CheckComRCReturnRC (rc);
    10421042
    10431043    /** @todo check validity! */
     
    10781078    AutoLock alock (this);
    10791079
    1080     CHECK_SETTER();
     1080    HRESULT rc = checkStateDependency (MutableStateDep);
     1081    CheckComRCReturnRC (rc);
    10811082
    10821083    if (!mData->mCurrentSnapshot.isNull())
     
    12451246    AutoLock alock (this);
    12461247
    1247     CHECK_SETTER();
     1248    HRESULT rc = checkStateDependency (MutableStateDep);
     1249    CheckComRCReturnRC (rc);
    12481250
    12491251    if (!isConfigLocked())
     
    14671469    AutoLock alock (this);
    14681470
    1469     CHECK_SETTER();
     1471    HRESULT rc = checkStateDependency (MutableStateDep);
     1472    CheckComRCReturnRC (rc);
    14701473
    14711474    mHWData.backup();
     
    14941497    AutoLock alock (this);
    14951498
    1496     CHECK_SETTER();
     1499    HRESULT rc = checkStateDependency (MutableStateDep);
     1500    CheckComRCReturnRC (rc);
    14971501
    14981502    mHWData.backup();
     
    15341538    AutoLock alock (this);
    15351539
    1536     CHECK_SETTER();
     1540    HRESULT rc = checkStateDependency (MutableStateDep);
     1541    CheckComRCReturnRC (rc);
    15371542
    15381543    if (!mData->mRegistered)
     
    15641569    /* find a hard disk by UUID */
    15651570    ComObjPtr <HardDisk> hd;
    1566     HRESULT rc = mParent->getHardDisk (id, hd);
    1567     if (FAILED (rc))
    1568         return rc;
     1571    rc = mParent->getHardDisk (id, hd);
     1572    CheckComRCReturnRC (rc);
    15691573
    15701574    AutoLock hdLock (hd);
     
    17281732    AutoLock alock (this);
    17291733
    1730     CHECK_SETTER();
     1734    HRESULT rc = checkStateDependency (MutableStateDep);
     1735    CheckComRCReturnRC (rc);
    17311736
    17321737    AssertReturn (mData->mMachineState != MachineState_Saved, E_FAIL);
     
    19952000
    19962001    if (mType == IsSnapshotMachine)
    1997         CHECK_SETTER();
     2002    {
     2003        HRESULT rc = checkStateDependency (MutableStateDep);
     2004        CheckComRCReturnRC (rc);
     2005    }
    19982006
    19992007    bool changed = false;
     
    21262134    AutoMultiLock <2> alock (mParent->wlock(), this->wlock());
    21272135
    2128     CHECK_SETTER();
     2136    HRESULT rc = checkStateDependency (MutableStateDep);
     2137    CheckComRCReturnRC (rc);
    21292138
    21302139    /* the settings file path may never be null */
     
    21422151    AutoLock alock (this);
    21432152
    2144     CHECK_SETTER();
     2153    HRESULT rc = checkStateDependency (MutableStateDep);
     2154    CheckComRCReturnRC (rc);
    21452155
    21462156    /*
     
    21602170    AutoLock alock (this);
    21612171
    2162     CHECK_SETTER();
     2172    HRESULT rc = checkStateDependency (MutableStateDep);
     2173    CheckComRCReturnRC (rc);
    21632174
    21642175    if (mData->mRegistered)
     
    22772288    AutoLock alock (this);
    22782289
    2279     CHECK_SETTER();
     2290    HRESULT rc = checkStateDependency (MutableStateDep);
     2291    CheckComRCReturnRC (rc);
    22802292
    22812293    /// @todo (dmik) check global shared folders when they are done
    22822294
    22832295    ComObjPtr <SharedFolder> sharedFolder;
    2284     HRESULT rc = findSharedFolder (aName, sharedFolder, false /* aSetError */);
     2296    rc = findSharedFolder (aName, sharedFolder, false /* aSetError */);
    22852297    if (SUCCEEDED (rc))
    22862298        return setError (E_FAIL,
     
    22892301    sharedFolder.createObject();
    22902302    rc = sharedFolder->init (machine(), aName, aHostPath);
    2291     if (FAILED (rc))
    2292         return rc;
     2303    CheckComRCReturnRC (rc);
    22932304
    22942305    BOOL accessible = FALSE;
    22952306    rc = sharedFolder->COMGETTER(Accessible) (&accessible);
    2296     if (FAILED (rc))
    2297         return rc;
     2307    CheckComRCReturnRC (rc);
    22982308
    22992309    if (!accessible)
     
    23172327    AutoReaderLock alock (this);
    23182328
    2319     CHECK_SETTER();
     2329    HRESULT rc = checkStateDependency (MutableStateDep);
     2330    CheckComRCReturnRC (rc);
    23202331
    23212332    ComObjPtr <SharedFolder> sharedFolder;
    2322     HRESULT rc = findSharedFolder (aName, sharedFolder, true /* aSetError */);
    2323     if (FAILED (rc))
    2324         return rc;
     2333    rc = findSharedFolder (aName, sharedFolder, true /* aSetError */);
     2334    CheckComRCReturnRC (rc);
    23252335
    23262336    mHWData.backup();
     
    23392349
    23402350    AutoCaller autoCaller (this);
    2341     AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
     2351    AssertComRCReturnRC (autoCaller.rc());
    23422352
    23432353    ComPtr <IInternalSessionControl> directControl;
     
    30343044 *
    30353045 *  Depending on the @a aDepType value, additional state checks may be
    3036  *  made. These checks will set extended error info on failure.
     3046 *  made. These checks will set extended error info on failure. See
     3047 *  #checkStateDependency() for more info.
    30373048 *
    30383049 *  If this method returns a failure, the dependency is not added and the
     
    30413052 *  upper level.
    30423053 *
    3043  *  @param aDepType     Dependency type to choose
     3054 *  @param aDepType     Dependency type to add.
    30443055 *  @param aState       Current machine state (NULL if not interested).
    30453056 *  @param aRegistered  Current registered state (NULL if not interested).
     
    30683079            mData->mMachineState);
    30693080    }
     3081
     3082    HRESULT rc = checkStateDependency (aDepType);
     3083    CheckComRCReturnRC (rc);
     3084
     3085    if (aState)
     3086        *aState = mData->mMachineState;
     3087    if (aRegistered)
     3088        *aRegistered = mData->mRegistered;
     3089
     3090    ++ mData->mMachineStateDeps;
     3091
     3092    return S_OK;
     3093}
     3094
     3095/**
     3096 *  Decreases the number of objects dependent on the machine state.
     3097 *  Must always complete the #addStateDependency() call after the state
     3098 *  dependency no more necessary.
     3099 */
     3100void Machine::releaseStateDependency()
     3101{
     3102    AutoCaller autoCaller (this);
     3103    AssertComRCReturnVoid (autoCaller.rc());
     3104
     3105    AutoLock alock (this);
     3106
     3107    AssertReturnVoid (mData->mMachineStateDeps > 0);
     3108    -- mData->mMachineStateDeps;
     3109
     3110    if (mData->mMachineStateDeps == 0 &&
     3111        mData->mZeroMachineStateDepsSem != NIL_RTSEMEVENT)
     3112    {
     3113        /* inform checkStateDependencies() that there are no more deps */
     3114        RTSemEventSignal (mData->mZeroMachineStateDepsSem);
     3115    }
     3116}
     3117
     3118// protected methods
     3119/////////////////////////////////////////////////////////////////////////////
     3120
     3121/**
     3122 *  Performs machine state checks based on the @a aDepType value. If a check
     3123 *  fails, this method will set extended error info, otherwise it will return
     3124 *  S_OK. It is supposed, that on failure, the caller will immedieately return
     3125 *  the return value of this method to the upper level.
     3126 *
     3127 *  When @a aDepType is AnyStateDep, this method always returns S_OK.
     3128 *
     3129 *  When @a aDepType is MutableStateDep, this method returns S_OK only if the
     3130 *  current state of this machine object allows to change settings of the
     3131 *  machine (i.e. the machine is not registered, or registered but not running
     3132 *  and not saved). It is useful to call this method from Machine setters
     3133 *  before performing any change.
     3134 *
     3135 *  When @a aDepType is MutableOrSavedStateDep, this method behaves the same
     3136 *  as for MutableStateDep except that if the machine is saved, S_OK is also
     3137 *  returned. This is useful in setters which allow changing machine
     3138 *  properties when it is in the saved state.
     3139 *
     3140 *  @param aDepType     Dependency type to check.
     3141 *
     3142 *  @note External classes should use #addStateDependency() and
     3143 *  #releaseStateDependency() methods or the smart AutoStateDependency
     3144 *  template.
     3145 *
     3146 *  @note This method must be called from under this object's lock.
     3147 */
     3148HRESULT Machine::checkStateDependency (StateDependency aDepType)
     3149{
     3150    AssertReturn (isLockedOnCurrentThread(), E_FAIL);
    30703151
    30713152    switch (aDepType)
     
    30983179    }
    30993180
    3100     if (aState)
    3101         *aState = mData->mMachineState;
    3102     if (aRegistered)
    3103         *aRegistered = mData->mRegistered;
    3104 
    3105     ++ mData->mMachineStateDeps;
    3106 
    31073181    return S_OK;
    31083182}
    3109 
    3110 /**
    3111  *  Decreases the number of objects dependent on the machine state.
    3112  *  Must always complete the #addStateDependency() call after the state
    3113  *  dependency no more necessary.
    3114  */
    3115 void Machine::releaseStateDependency()
    3116 {
    3117     AutoCaller autoCaller (this);
    3118     AssertComRCReturnVoid (autoCaller.rc());
    3119 
    3120     AutoLock alock (this);
    3121 
    3122     AssertReturnVoid (mData->mMachineStateDeps > 0);
    3123     -- mData->mMachineStateDeps;
    3124 
    3125     if (mData->mMachineStateDeps == 0 &&
    3126         mData->mZeroMachineStateDepsSem != NIL_RTSEMEVENT)
    3127     {
    3128         /* inform checkStateDependencies() that there are no more deps */
    3129         RTSemEventSignal (mData->mZeroMachineStateDepsSem);
    3130     }
    3131 }
    3132 
    3133 // protected methods
    3134 /////////////////////////////////////////////////////////////////////////////
    31353183
    31363184/**
     
    35463594         *  otherwise it will be not possible to change the settings
    35473595         *  somewehere in the code above because all setters will be
    3548          *  blocked by CHECK_SETTER()
     3596         *  blocked by checkStateDependency (MutableStateDep).
    35493597         */
    35503598
     
    38203868#ifdef VBOX_VRDP
    38213869    /* RemoteDisplay node (optional) */
    3822     /// @todo (dmik) move the code to VRDPServer
    3823     /// @todo r=sunlover: moved. dmik, please review.
    38243870    {
    38253871        CFGNODE remoteDisplayNode = 0;
     
    38273873        if (remoteDisplayNode)
    38283874        {
    3829             mVRDPServer->loadConfig (remoteDisplayNode);
     3875            HRESULT rc = mVRDPServer->loadSettings (remoteDisplayNode);
    38303876            CFGLDRReleaseNode (remoteDisplayNode);
     3877            CheckComRCReturnRC (rc);
    38313878        }
    38323879    }
     
    40704117        CFGLDRReleaseNode (driveNode);
    40714118
    4072         if (FAILED (rc))
    4073             return rc;
     4119        CheckComRCReturnRC (rc);
    40744120    }
    40754121
     
    40774123    {
    40784124        HRESULT rc = mUSBController->loadSettings (aNode);
    4079         if (FAILED (rc))
    4080             return rc;
     4125        CheckComRCReturnRC (rc);
    40814126    }
    40824127
     
    56785723    while (0);
    56795724
    5680     if (FAILED (rc))
    5681         return rc;
     5725    CheckComRCReturnRC (rc);
    56825726
    56835727    /* display (required) */
     
    56925736#ifdef VBOX_VRDP
    56935737    /* VRDP settings (optional) */
    5694     /// @todo (dmik) move the code to VRDPServer
    5695     /// @todo r=sunlover: moved. dmik, please review.
    56965738    {
    56975739        CFGNODE remoteDisplayNode = 0;
    56985740        CFGLDRCreateChildNode (aNode, "RemoteDisplay", &remoteDisplayNode);
    5699 
    57005741        if (remoteDisplayNode)
    57015742        {
    5702             mVRDPServer->saveConfig (remoteDisplayNode);
     5743            rc = mVRDPServer->saveSettings (remoteDisplayNode);
    57035744            CFGLDRReleaseNode (remoteDisplayNode);
     5745            CheckComRCReturnRC (rc);
    57045746        }
    57055747    }
     
    58295871    while (0);
    58305872
    5831     if (FAILED (rc))
    5832         return rc;
     5873    CheckComRCReturnRC (rc);
    58335874
    58345875    /* Flooppy drive (required) */
     
    58865927    while (0);
    58875928
    5888     if (FAILED (rc))
    5889         return rc;
     5929    CheckComRCReturnRC (rc);
    58905930
    58915931
    58925932    /* USB Controller (required) */
    58935933    rc = mUSBController->saveSettings (aNode);
    5894     if (FAILED (rc))
    5895         return rc;
     5934    CheckComRCReturnRC (rc);
    58965935
    58975936    /* Network adapters (required) */
  • trunk/src/VBox/Main/include/MachineImpl.h

    r3302 r3424  
    4848// defines
    4949////////////////////////////////////////////////////////////////////////////////
    50 
    51 /**
    52  *  Checks whether the given Machine object is mutable (allows for calling setters)
    53  *  or not. When the machine is not mutable, sets error info and returns E_ACCESSDENIED.
    54  *  The translatable error message is defined in null context.
    55  *
    56  *  This macro <b>must</b> be used within setters of all Machine children
    57  *  (DVDDrive, NetworkAdapter, AudioAdapter, etc.).
    58  *
    59  *  @param machine  the machine object (must cast to Machine *)
    60  */
    61 /// @todo replace with AutoStateDependency
    62 #define CHECK_MACHINE_MUTABILITY(machine) \
    63     do { \
    64         if (!machine->isMutable()) \
    65             return setError (E_ACCESSDENIED, tr ("The machine is not mutable")); \
    66     } while (0)
    67 
    68 /** Like CHECK_MACHINE_MUTABILITY but a saved state is OK, too. */
    69 /// @todo replace with AutoStateDependency
    70 #define CHECK_MACHINE_MUTABILITY_IGNORING_SAVED(machine) \
    71     do { \
    72         if (!machine->isMutableIgnoringSavedState()) \
    73             return setError (E_ACCESSDENIED, \
    74                              tr ("The machine is not mutable or in saved state")); \
    75     } while (0)
    76 
    7750
    7851// helper declarations
     
    525498
    526499    /// @todo (dmik) add lock and make non-inlined after revising classes
    527     //  that use it (actually, the CHECK_MACHINE_MUTABILITY macro).
    528     //  Note: these classes should enter Machine lock to keep the returned
    529     //  information valid!
    530     /// @todo replace with AutoStateDependency
    531     bool isMutable()
    532     {
    533         return ((!mData->mRegistered) ||
    534                 (mType == IsSessionMachine &&
    535                  mData->mMachineState <= MachineState_Paused &&
    536                  mData->mMachineState != MachineState_Saved));
    537     }
    538 
    539     /// @todo (dmik) add lock and make non-inlined after revising classes
    540     //  that use it (actually, the CHECK_MACHINE_MUTABILITY_IGNORING_SAVED macro).
    541     //  Note: these classes should enter Machine lock to keep the returned
    542     //  information valid!
    543     /// @todo replace with AutoStateDependency
    544     bool isMutableIgnoringSavedState()
    545     {
    546         return ((!mData->mRegistered) ||
    547                 (mType == IsSessionMachine &&
    548                  mData->mMachineState <= MachineState_Paused));
    549     }
    550 
    551     /// @todo (dmik) add lock and make non-inlined after revising classes
    552500    //  that use it. Note: they should enter Machine lock to keep the returned
    553501    //  information valid!
     
    614562
    615563    HRESULT registeredInit();
     564
     565    HRESULT checkStateDependency (StateDependency aDepType);
    616566
    617567    inline Machine *machine();
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