VirtualBox

Ignore:
Timestamp:
Jul 4, 2008 3:45:38 PM (16 years ago)
Author:
vboxsync
Message:

Main: clean up the guest property code - send accesses to the console from IMachine through IInternalSessionControl and do locking correctly

File:
1 edited

Legend:

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

    r10007 r10233  
    26802680/**
    26812681 * Read a value from the host/guest property store.  If a session is
    2682  * currently open for the guest then query the console object for the value,
     2682 * currently open for the guest then query the session object for the value,
    26832683 * since the current values of the property store will be held in RAM in the
    26842684 * session.  Otherwise read the value from machine extra data, where it is
    2685  * stored between sessions.
    2686  *
    2687  * @note since the way this method is implemented depends on whether or not
    2688  *       a session is currently open, we grab a write lock on the object, in
    2689  *       order to ensure that the session state does not change during the
    2690  *       call, and to force us to block if it is currently changing (either
    2691  *       way) between open and closed.
     2685 * stored between sessions.  Returns E_FAIL if we are currently transitioning
     2686 * between states.
    26922687 */
    26932688STDMETHODIMP Machine::GetGuestProperty (INPTR BSTR aKey, BSTR *aValue)
    26942689{
    2695     if (!VALID_PTR(aValue))
    2696         return E_POINTER;
    2697 
    26982690#ifndef VBOX_WITH_INFO_SVC
    26992691    HRESULT hrc = E_NOTIMPL;
    27002692#else
     2693    if (!VALID_PTR(aKey))
     2694        return E_POINTER;
     2695    if (!VALID_PTR(aValue))
     2696        return E_POINTER;
     2697
     2698    AutoCaller autoCaller (this);
     2699    CheckComRCReturnRC (autoCaller.rc());
     2700
    27012701    using namespace svcInfo;
    2702 
    2703     if (NULL == aKey)
    2704         return setError (E_INVALIDARG, tr ("Called with a NULL key argument"));
    27052702    HRESULT hrc = E_FAIL;
    2706     AutoWriteLock alock (this);
     2703
    27072704    switch (mData->mSession.mState)
    27082705    {
    27092706        case SessionState_Closed:
    27102707        {
     2708            AutoReadLock alock (this);
     2709
    27112710            /* The "+ 1" in the length is the null terminator. */
    27122711            Bstr strKey(Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);
     
    27262725        case SessionState_Open:
    27272726        {
    2728             /*
    2729              *  Get the console from the direct session (note that we don't leave the
    2730              *  lock here because GetRemoteConsole must not call us back).
    2731              */
    2732             ComPtr <IConsole> console;
    2733             hrc = mData->mSession.mDirectControl->GetRemoteConsole (console.asOutParam());
    2734             if (!SUCCEEDED (hrc))
    2735                 /* The failure may w/o any error info (from RPC), so provide one */
    2736                 hrc = setError (hrc, tr ("Failed to get a console object from the direct session"));
    2737             else
     2727            ComPtr <IInternalSessionControl> directControl;
    27382728            {
    2739                 ComAssertRet (!console.isNull(), E_FAIL);
    2740                 hrc = console->GetGuestProperty (aKey, aValue);
     2729                AutoReadLock alock (this);
     2730       
     2731                if (mData->mSession.mState != SessionState_Open)
     2732                    return setError (E_FAIL,
     2733                        tr ("Machine session is not open (session state: %d) - please retry."),
     2734                        mData->mSession.mState);
     2735       
     2736                directControl = mData->mSession.mDirectControl;
    27412737            }
     2738
     2739            hrc = directControl->AccessGuestProperty (aKey, NULL,
     2740                                                      false /* isSetter */,
     2741                                                      aValue);
    27422742            break;
    27432743        }
    27442744        default:
    2745             /* If we get here then I have misunderstood the semantics.  Quite possible. */
    2746             AssertLogRel(false);
    2747             hrc = E_UNEXPECTED;
     2745            hrc = setError (E_FAIL, tr ("Machine session is currently transitioning (session state: %d) - please retry."),
     2746                            mData->mSession.mState);
    27482747    }
    27492748#endif  /* VBOX_WITH_INFO_SVC not defined */
     
    27532752/**
    27542753 * Write a value to the host/guest property store.  If a session is
    2755  * currently open for the guest then query the console object for the value,
     2754 * currently open for the guest then query the session object for the value,
    27562755 * since the current values of the property store will be held in RAM in the
    27572756 * session.  Otherwise read the value from machine extra data, where it is
    2758  * stored between sessions.
    2759  *
    2760  * @note since the way this method is implemented depends on whether or not
    2761  *       a session is currently open, we grab a write lock on the object, in
    2762  *       order to ensure that the session state does not change during the
    2763  *       call, and to force us to block if it is currently changing (either
    2764  *       way) between open and closed.
     2757 * stored between sessions.  Returns E_FAIL if we are currently transitioning
     2758 * between states.
    27652759 */
    27662760STDMETHODIMP Machine::SetGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue)
     
    27692763    HRESULT hrc = E_NOTIMPL;
    27702764#else
     2765    if (!VALID_PTR(aKey))
     2766        return E_POINTER;
     2767    if ((aValue != NULL) && !VALID_PTR(aValue))
     2768        return E_POINTER;
     2769
     2770    AutoCaller autoCaller (this);
     2771    CheckComRCReturnRC (autoCaller.rc());
     2772
    27712773    using namespace svcInfo;
    2772 
    2773     if (NULL == aKey)
    2774         return setError (E_INVALIDARG, tr ("Called with a NULL key argument"));
    27752774    HRESULT hrc = E_FAIL;
    2776     AutoWriteLock alock (this);
     2775
    27772776    switch (mData->mSession.mState)
    27782777    {
    27792778        case SessionState_Closed:
    27802779        {
     2780            AutoWriteLock alock (this);
     2781
    27812782            /* The "+ 1" in the length is the null terminator. */
    27822783            Bstr strKey(Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);
     
    27962797        case SessionState_Open:
    27972798        {
    2798             /*
    2799              *  Get the console from the direct session (note that we don't leave the
    2800              *  lock here because GetRemoteConsole must not call us back).
    2801              */
    2802             ComPtr <IConsole> console;
    2803             hrc = mData->mSession.mDirectControl->GetRemoteConsole (console.asOutParam());
    2804             if (!SUCCEEDED (hrc))
    2805                 /* The failure may w/o any error info (from RPC), so provide one */
    2806                 hrc = setError (hrc, tr ("Failed to get a console object from the direct session"));
    2807             else
     2799            ComPtr <IInternalSessionControl> directControl;
    28082800            {
    2809                 ComAssertRet (!console.isNull(), E_FAIL);
    2810                 hrc = console->SetGuestProperty (aKey, aValue);
     2801                AutoReadLock alock (this);
     2802       
     2803                if (mData->mSession.mState != SessionState_Open)
     2804                    return setError (E_FAIL,
     2805                        tr ("Machine session is not open (session state: %d) - please retry."),
     2806                        mData->mSession.mState);
     2807       
     2808                directControl = mData->mSession.mDirectControl;
    28112809            }
     2810
     2811            BSTR dummy;
     2812            hrc = directControl->AccessGuestProperty (aKey, aValue,
     2813                                                      true /* isSetter */,
     2814                                                      &dummy);
    28122815            break;
    28132816        }
    28142817        default:
    2815             /* If we get here then I have misunderstood the semantics.  Quite possible. */
    2816             AssertLogRel(false);
    2817             hrc = E_UNEXPECTED;
     2818            hrc = setError (E_FAIL, tr ("Machine session is currently transitioning (session state: %d) - please retry."),
     2819                            mData->mSession.mState);
    28182820    }
    28192821#endif  /* VBOX_WITH_INFO_SVC not defined */
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