VirtualBox

Changeset 24258 in vbox


Ignore:
Timestamp:
Nov 2, 2009 2:38:50 PM (15 years ago)
Author:
vboxsync
Message:

Main: new method Medium::RefreshState() which refreshes medium state; make the ::state attribute return the state only without refreshing

Location:
trunk/src/VBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r24184 r24258  
    684684                /* Perform accessibility check now. */
    685685                MediumState_T state;
    686                 CHECK_ERROR_BREAK(dstDisk, COMGETTER(State)(&state));
     686                CHECK_ERROR_BREAK(dstDisk, RefreshState(&state));
    687687            }
    688688            CHECK_ERROR_BREAK(dstDisk, COMGETTER(Format) (format.asOutParam()));
     
    12161216        /// @todo NEWMEDIA print the full state value
    12171217        MediumState_T state;
    1218         CHECK_ERROR_BREAK (hardDisk, COMGETTER(State)(&state));
     1218        CHECK_ERROR_BREAK (hardDisk, RefreshState(&state));
    12191219        RTPrintf("Accessible:           %s\n", state != MediumState_Inaccessible ? "yes" : "no");
    12201220
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp

    r23223 r24258  
    527527                /// @todo NEWMEDIA check accessibility of all parents
    528528                /// @todo NEWMEDIA print the full state value
    529                 hdd->COMGETTER(State)(&enmState);
     529                hdd->RefreshState(&enmState);
    530530                RTPrintf("Accessible:   %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
    531531
     
    583583                RTPrintf("Path:       %lS\n", filePath.raw());
    584584                MediumState_T enmState;
    585                 dvdImage->COMGETTER(State)(&enmState);
     585                dvdImage->RefreshState(&enmState);
    586586                RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
    587587                /** @todo usage */
     
    605605                RTPrintf("Path:       %lS\n", filePath.raw());
    606606                MediumState_T enmState;
    607                 floppyImage->COMGETTER(State)(&enmState);
     607                floppyImage->RefreshState(&enmState);
    608608                RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
    609609                /** @todo usage */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMedium.cpp

    r24211 r24258  
    4747    if (mMedium.isNull()) return;
    4848
    49     mState = mMedium.GetState();
     49    mState = mMedium.RefreshState();
    5050
    5151    /* Save the result to distinguish between inaccessible and e.g. uninitialized objects */
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r24048 r24258  
    44774477                // force reading state, or else size will be returned as 0
    44784478                MediumState_T ms;
    4479                 rc = pMedium->COMGETTER(State)(&ms);
     4479                rc = pMedium->RefreshState(&ms);
    44804480                if (FAILED(rc)) throw rc;
    44814481
  • trunk/src/VBox/Main/MachineImpl.cpp

    r24250 r24258  
    87908790                                            IProgress **aProgress)
    87918791{
    8792     LogFlowThisFunc(("\n"));
     8792    LogFlowThisFuncEnter();
    87938793
    87948794    Guid id(aId);
     
    88708870    *aMachineState = mData->mMachineState;
    88718871
     8872    LogFlowThisFuncLeave();
     8873
    88728874    return S_OK;
    88738875}
     
    88818883                                             IProgress **aProgress)
    88828884{
    8883     LogFlowThisFunc(("\n"));
     8885    LogFlowThisFuncEnter();
    88848886
    88858887    AssertReturn(aInitiator, E_INVALIDARG);
     
    89578959                             RTTHREADTYPE_MAIN_WORKER,
    89588960                             0,
    8959                              "DiscardCurState");
     8961                             "RestoreSnap");
    89608962    if (RT_FAILURE(vrc))
    89618963    {
     
    89728974    /* return the new state to the caller */
    89738975    *aMachineState = mData->mMachineState;
     8976
     8977    LogFlowThisFuncLeave();
    89748978
    89758979    return S_OK;
     
    1030810312                if (mediumState == MediumState_Inaccessible)
    1030910313                {
    10310                     rc = medium->COMGETTER(State)(&mediumState);
     10314                    rc = medium->RefreshState(&mediumState);
    1031110315                    CheckComRCThrowRC(rc);
    1031210316
  • trunk/src/VBox/Main/MediumImpl.cpp

    r24253 r24258  
    417417           that the medium isn't fully initialized yet. */
    418418        MediumState_T m;
    419         rc = aMedium->COMGETTER(State)(&m);
     419        rc = aMedium->RefreshState(&m);
    420420        CheckComRCReturnRC(rc);
    421421        /* go to Deleting */
     
    678678            if (mediaState == MediumState_Inaccessible)
    679679            {
    680                 rc = (*it)->COMGETTER(State)(&mediaState);
     680                rc = (*it)->RefreshState(&mediaState);
    681681                CheckComRCReturnRC(rc);
    682682                Assert(mediaState == MediumState_LockedRead);
     
    735735            if (mediaState == MediumState_Inaccessible)
    736736            {
    737                 rc = (*it)->COMGETTER(State)(&mediaState);
     737                rc = (*it)->RefreshState(&mediaState);
    738738                CheckComRCReturnRC(rc);
    739739                if (it == last)
     
    13711371    CheckComRCReturnRC(autoCaller.rc());
    13721372
    1373     /* queryInfo() locks this for writing. */
    1374     AutoWriteLock alock(this);
    1375 
    1376     HRESULT rc = S_OK;
    1377 
    1378     switch (m->state)
    1379     {
    1380         case MediumState_Created:
    1381         case MediumState_Inaccessible:
    1382         case MediumState_LockedRead:
    1383         case MediumState_LockedWrite:
    1384         {
    1385             rc = queryInfo();
    1386             break;
    1387         }
    1388         default:
    1389             break;
    1390     }
    1391 
     1373    AutoReadLock alock(this);
    13921374    *aState = m->state;
    13931375
    1394     return rc;
    1395 }
     1376    return S_OK;
     1377}
     1378
    13961379
    13971380STDMETHODIMP Medium::COMGETTER(Location)(BSTR *aLocation)
     
    17561739
    17571740    return S_OK;
     1741}
     1742
     1743STDMETHODIMP Medium::RefreshState(MediumState_T *aState)
     1744{
     1745    CheckComArgOutPointerValid(aState);
     1746
     1747    AutoCaller autoCaller(this);
     1748    CheckComRCReturnRC(autoCaller.rc());
     1749
     1750    /* queryInfo() locks this for writing. */
     1751    AutoWriteLock alock(this);
     1752
     1753    HRESULT rc = S_OK;
     1754
     1755    switch (m->state)
     1756    {
     1757        case MediumState_Created:
     1758        case MediumState_Inaccessible:
     1759        case MediumState_LockedRead:
     1760        {
     1761            rc = queryInfo();
     1762            break;
     1763        }
     1764        default:
     1765            break;
     1766    }
     1767
     1768    *aState = m->state;
     1769
     1770    return rc;
    17581771}
    17591772
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r24250 r24258  
    85548554      When the storage unit cannot be read (for example, because it is located on
    85558555      a disconnected network resource, or was accidentally deleted outside VirtualBox),
    8556       the medium is considered to be <i>inaccessible</i>, which is indicated by the
     8556      the medium is considered <i>inaccessible</i>, which is indicated by the
    85578557      "Inaccessible" state. The exact reason why the medium is inaccessible can be
    85588558      obtained by reading the <link to="#lastAccessError"/> attribute.
    85598559
    8560       A new accessibility check is performed each time the <link to="#state"/>
    8561       attribute is read. This check may take long time (several seconds or even
    8562       minutes, depending on the storage unit location and format), and will
    8563       block the calling thread until finished. For this reason, it is recommended
    8564       to never read this attribute on the main UI thread to avoid making the UI
    8565       unresponsive.
     8560      A new accessibility check is performed when <link to="#refreshState"/>
     8561      is called; otherwise the <link to="#state"/> attribute returns the state
     8562      from the last refresh.
    85668563
    85678564      Note that when VirtualBox starts up (e.g. the VirtualBox object gets
     
    88448841    <attribute name="state" type="MediumState" readonly="yes">
    88458842      <desc>
    8846         Current medium state. Inspect <link to="MediumState"/> values for details.
    8847 
    8848         Reading this attribute may take a long time because an accessibility
    8849         check of the storage unit is performed each time the attribute is read.
    8850         This check may cause a significant delay if the storage unit of the
    8851         given medium is, for example, a file located on a network share which is
    8852         not currently accessible due to connectivity problems -- the call will
    8853         not return until a timeout interval defined by the host OS for this
    8854         operation expires.
    8855 
    8856         If the last known state of the medium is <link to="MediumState_Created"/>
    8857         and the accessibility check fails then the state would be set to
    8858         <link to="MediumState_Inaccessible"/> and <link to="#lastAccessError"/>
    8859         may be used to get more details about the failure. If the state of the
    8860         medium is <link to="MediumState_LockedRead"/> or
    8861         <link to="MediumState_LockedWrite"/> then it remains the same, and a
    8862         non-empty value of <link to="#lastAccessError"/> will indicate a failed
    8863         accessibility check in this case.
    8864 
    8865         Note that not all medium states are applicable to all medium types.
     8843        Returns the current medium state, which is the last state set by
     8844        the accessibility check performed by <link to="#refreshState"/>.
     8845        If that method has not yet been called on the medium, the state
     8846        is "Inaccessible"; as opposed to truly inaccessible media, the
     8847        value of <link to="#lastAccessError"/> will be an empty string in
     8848        that case.
     8849
     8850        <note>As of version 3.1, this no longer performs an accessibility check
     8851          automatically; call <link to="#refreshState"/> for that.
     8852        </note>
    88668853      </desc>
    88678854    </attribute>
     
    90769063      <desc>
    90779064        Text message that represents the result of the last accessibility
    9078         check.
    9079 
    9080         Accessibility checks are performed each time the <link to="#state"/>
    9081         attribute is read. An empty string is returned if the last
    9082         accessibility check was successful. A non-empty string indicates a
    9083         failure and should normally describe a reason of the failure (for
    9084         example, a file read error).
     9065        check performed by <link to="#refreshState"/>.
     9066
     9067        An empty string is returned if the last accessibility check
     9068        was successful or has not yet been called. As a result, if
     9069        <link to="#state" /> is "Inaccessible" and this attribute is empty,
     9070        then <link to="#refreshState"/> has yet to be called; this is the
     9071        default value of media after VirtualBox initialization.
     9072        A non-empty string indicates a failure and should normally describe
     9073        a reason of the failure (for example, a file read error).
    90859074      </desc>
    90869075    </attribute>
     
    91019090      </desc>
    91029091    </attribute>
     9092
     9093    <method name="refreshState">
     9094      <desc>
     9095        If the current medium state (see <link to="MediumState"/>
     9096        and <link to="#state" /> is one of "Created", "Inaccessible"
     9097        or "LockedRead", then this performs an accessibility check on the
     9098        medium and sets the value of the <link to="#state"/> attribute
     9099        accordingly; that value is also returned for convenience.
     9100
     9101        For all other state values, this does not perform a refresh but returns
     9102        the state only.
     9103
     9104        The refresh, if performed, may take a long time (several seconds or even
     9105        minutes, depending on the storage unit location and format) because it performs an
     9106        accessibility check of the storage unit. This check may cause a significant
     9107        delay if the storage unit of the given medium is, for example, a file located
     9108        on a network share which is not currently accessible due to connectivity
     9109        problems. In that case, the call will not return until a timeout
     9110        interval defined by the host OS for this operation expires. For this reason,
     9111        it is recommended to never read this attribute on the main UI thread to avoid
     9112        making the UI unresponsive.
     9113
     9114        If the last known state of the medium is "Created" and the accessibility
     9115        check fails, then the state would be set to "Inaccessible", and
     9116        <link to="#lastAccessError"/> may be used to get more details about the
     9117        failure. If the state of the medium is "LockedRead", then it remains the
     9118        same, and a non-empty value of <link to="#lastAccessError"/> will
     9119        indicate a failed accessibility check in this case.
     9120
     9121        Note that not all medium states are applicable to all medium types.
     9122      </desc>
     9123      <param name="state" type="MediumState" dir="return">
     9124        <desc>
     9125          New medium state.
     9126        </desc>
     9127      </param>
     9128    </method>
    91039129
    91049130    <method name="getSnapshotIds">
  • trunk/src/VBox/Main/include/MediumImpl.h

    r24210 r24258  
    122122
    123123    // IMedium methods
     124    STDMETHOD(RefreshState)(MediumState_T *aState);
    124125    STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
    125126                              ComSafeArrayOut(BSTR, aSnapshotIds));
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