Changeset 10305 in vbox for trunk/src/VBox/Main
- Timestamp:
- Jul 7, 2008 10:33:33 AM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r10247 r10305 3533 3533 } 3534 3534 3535 /** 3536 * @note Temporarily locks this object for writing. 3537 */ 3535 3538 HRESULT Console::getGuestProperty (INPTR BSTR aKey, BSTR *aValue) 3536 3539 { 3537 #if ndef VBOX_WITH_INFO_SVC3538 HRESULT hrc =E_NOTIMPL;3540 #if !defined (VBOX_WITH_INFO_SVC) 3541 return E_NOTIMPL; 3539 3542 #else 3540 if (!VALID_PTR(aKey)) 3543 if (!VALID_PTR (aKey)) 3544 return E_INVALIDARG; 3545 if (!VALID_PTR (aValue)) 3541 3546 return E_POINTER; 3542 if (!VALID_PTR(aValue))3543 return E_POINTER;3544 3547 3545 3548 AutoCaller autoCaller (this); 3546 CheckComRCReturnRC (autoCaller.rc());3549 AssertComRCReturnRC (autoCaller.rc()); 3547 3550 3548 3551 /* protect mpVM (if not NULL) */ … … 3550 3553 CheckComRCReturnRC (autoVMCaller.rc()); 3551 3554 3552 HRESULT hrc = E_UNEXPECTED; 3555 /* Note: validity of mVMMDev which is bound to uninit() is guaranteed by 3556 * autoVMCaller, so there is no need to hold a lock of this */ 3557 3558 HRESULT rc = E_UNEXPECTED; 3553 3559 using namespace svcInfo; 3554 3560 3555 3561 VBOXHGCMSVCPARM parm[3]; 3556 3562 Utf8Str Utf8Key = aKey; 3557 Utf8Str Utf8Value (KEY_MAX_VALUE_LEN);3563 Utf8Str Utf8Value (KEY_MAX_VALUE_LEN); 3558 3564 3559 3565 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; … … 3565 3571 parm[1].u.pointer.addr = Utf8Value.mutableRaw(); 3566 3572 parm[1].u.pointer.size = KEY_MAX_VALUE_LEN; 3567 int rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", GET_CONFIG_KEY_HOST, 3, &parm[0]); 3573 int vrc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", GET_CONFIG_KEY_HOST, 3574 3, &parm[0]); 3568 3575 /* The returned string should never be able to be greater than our buffer */ 3569 AssertLogRel (rc != VERR_BUFFER_OVERFLOW);3570 if (RT_SUCCESS (rc) || (VERR_NOT_FOUND ==rc))3571 { 3572 hrc = S_OK;3573 if ( rc != VERR_NOT_FOUND)3574 Utf8Value.cloneTo (aValue);3576 AssertLogRel (vrc != VERR_BUFFER_OVERFLOW); 3577 if (RT_SUCCESS (vrc) || (VERR_NOT_FOUND == vrc)) 3578 { 3579 rc = S_OK; 3580 if (vrc != VERR_NOT_FOUND) 3581 Utf8Value.cloneTo (aValue); 3575 3582 else 3576 3583 aValue = NULL; 3577 3584 } 3578 3585 else 3579 hrc = setError (E_UNEXPECTED, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc); 3580 #endif 3581 return hrc; 3582 } 3583 3586 rc = setError (E_UNEXPECTED, 3587 tr ("Failed to call the VBoxSharedInfoSvc service (%Rrc)"), vrc); 3588 return rc; 3589 #endif /* else !defined (VBOX_WITH_INFO_SVC) */ 3590 } 3591 3592 /** 3593 * @note Temporarily locks this object for writing. 3594 */ 3584 3595 HRESULT Console::setGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue) 3585 3596 { 3586 #if ndef VBOX_WITH_INFO_SVC3587 HRESULT hrc =E_NOTIMPL;3597 #if !defined (VBOX_WITH_INFO_SVC) 3598 return E_NOTIMPL; 3588 3599 #else 3589 if (!VALID_PTR (aKey))3590 return E_ POINTER;3591 if ((aValue != NULL) && !VALID_PTR (aValue))3592 return E_ POINTER;3600 if (!VALID_PTR (aKey)) 3601 return E_INVALIDARG; 3602 if ((aValue != NULL) && !VALID_PTR (aValue)) 3603 return E_INVALIDARG; 3593 3604 3594 3605 AutoCaller autoCaller (this); 3595 CheckComRCReturnRC (autoCaller.rc());3606 AssertComRCReturnRC (autoCaller.rc()); 3596 3607 3597 3608 /* protect mpVM (if not NULL) */ … … 3599 3610 CheckComRCReturnRC (autoVMCaller.rc()); 3600 3611 3601 HRESULT hrc = E_UNEXPECTED; 3612 /* Note: validity of mVMMDev which is bound to uninit() is guaranteed by 3613 * autoVMCaller, so there is no need to hold a lock of this */ 3614 3615 HRESULT rc = E_UNEXPECTED; 3602 3616 using namespace svcInfo; 3603 3617 3604 3618 VBOXHGCMSVCPARM parm[2]; 3605 3619 Utf8Str Utf8Key = aKey; 3606 int rc = VINF_SUCCESS;3620 int vrc = VINF_SUCCESS; 3607 3621 3608 3622 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; … … 3619 3633 /* The + 1 is the null terminator */ 3620 3634 parm[1].u.pointer.size = Utf8Value.length() + 1; 3621 rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST, 2, &parm[0]); 3635 vrc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST, 3636 2, &parm[0]); 3622 3637 } 3623 3638 else 3624 rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", DEL_CONFIG_KEY_HOST, 1, &parm[0]); 3625 if (RT_SUCCESS(rc)) 3626 hrc = S_OK; 3639 vrc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", DEL_CONFIG_KEY_HOST, 3640 1, &parm[0]); 3641 if (RT_SUCCESS (vrc)) 3642 rc = S_OK; 3627 3643 else 3628 hrc = setError (E_UNEXPECTED, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc); 3629 #endif 3630 return hrc; 3644 rc = setError (E_UNEXPECTED, 3645 tr ("Failed to call the VBoxSharedInfoSvc service (%Rrc)"), vrc); 3646 return rc; 3647 #endif /* else !defined (VBOX_WITH_INFO_SVC) */ 3631 3648 } 3632 3649 … … 4181 4198 pValue = CFGMR3GetNextValue (pValue); 4182 4199 } 4183 /* In a second stage, we remove any extra data keys corresponding to 4200 /* In a second stage, we remove any extra data keys corresponding to 4184 4201 * properties which aren't in the CFGM node. */ 4185 4202 Bstr strExtraDataKey; -
trunk/src/VBox/Main/MachineImpl.cpp
r10233 r10305 2678 2678 } 2679 2679 2680 /**2681 * Read a value from the host/guest property store. If a session is2682 * currently open for the guest then query the session object for the value,2683 * since the current values of the property store will be held in RAM in the2684 * session. Otherwise read the value from machine extra data, where it is2685 * stored between sessions. Returns E_FAIL if we are currently transitioning2686 * between states.2687 */2688 2680 STDMETHODIMP Machine::GetGuestProperty (INPTR BSTR aKey, BSTR *aValue) 2689 2681 { 2690 #if ndef VBOX_WITH_INFO_SVC2691 HRESULT hrc =E_NOTIMPL;2682 #if !defined (VBOX_WITH_INFO_SVC) 2683 return E_NOTIMPL; 2692 2684 #else 2693 if (!VALID_PTR(aKey)) 2685 if (!VALID_PTR (aKey)) 2686 return E_INVALIDARG; 2687 if (!VALID_PTR (aValue)) 2694 2688 return E_POINTER; 2695 if (!VALID_PTR(aValue))2696 return E_POINTER;2697 2689 2698 2690 AutoCaller autoCaller (this); 2699 2691 CheckComRCReturnRC (autoCaller.rc()); 2700 2692 2693 AutoReadLock alock (this); 2694 2701 2695 using namespace svcInfo; 2702 HRESULT hrc = E_FAIL;2696 HRESULT rc = E_FAIL; 2703 2697 2704 2698 switch (mData->mSession.mState) … … 2706 2700 case SessionState_Closed: 2707 2701 { 2708 AutoReadLock alock (this);2709 2710 2702 /* The "+ 1" in the length is the null terminator. */ 2711 Bstr strKey (Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);2703 Bstr strKey (Bstr (aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1); 2712 2704 BSTR strKeyRaw = strKey.mutableRaw(); 2713 2705 … … 2716 2708 for (unsigned i = 0; i < VBOX_SHARED_INFO_PREFIX_LEN; ++i) 2717 2709 /* I take it this is legal, at least g++ accepts it. */ 2718 strKeyRaw [i] = VBOX_SHARED_INFO_KEY_PREFIX[i];2710 strKeyRaw [i] = VBOX_SHARED_INFO_KEY_PREFIX[i]; 2719 2711 /* The "+ 1" in the length is the null terminator. */ 2720 for (unsigned i = 0, len = Bstr (aKey).length() + 1; i < len; ++i)2721 strKeyRaw [i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey[i];2722 hrc = GetExtraData(strKey, aValue);2712 for (unsigned i = 0, len = Bstr (aKey).length() + 1; i < len; ++i) 2713 strKeyRaw [i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey [i]; 2714 rc = GetExtraData (strKey, aValue); 2723 2715 break; 2724 2716 } 2725 2717 case SessionState_Open: 2726 2718 { 2727 ComPtr <IInternalSessionControl> directControl;2719 if (mData->mSession.mState != SessionState_Open) 2728 2720 { 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; 2721 rc = setError (E_FAIL, 2722 tr ("Session is not open (session state: %d)"), 2723 mData->mSession.mState); 2724 break; 2737 2725 } 2738 2726 2739 hrc = directControl->AccessGuestProperty (aKey, NULL, 2740 false /* isSetter */, 2741 aValue); 2727 ComPtr <IInternalSessionControl> directControl = 2728 mData->mSession.mDirectControl; 2729 2730 /* just be on the safe side when calling another process */ 2731 alock.unlock(); 2732 2733 rc = directControl->AccessGuestProperty (aKey, NULL, 2734 false /* isSetter */, 2735 aValue); 2742 2736 break; 2743 2737 } 2744 2738 default: 2745 hrc = setError (E_FAIL, tr ("Machine session is currently transitioning (session state: %d) - please retry."), 2746 mData->mSession.mState); 2747 } 2748 #endif /* VBOX_WITH_INFO_SVC not defined */ 2749 return hrc; 2739 rc = setError (E_FAIL, 2740 tr ("Session is currently transitioning (session state: %d)"), 2741 mData->mSession.mState); 2742 } 2743 return rc; 2744 #endif /* else !defined (VBOX_WITH_INFO_SVC) */ 2750 2745 } 2751 2746 … … 2760 2755 STDMETHODIMP Machine::SetGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue) 2761 2756 { 2762 #if ndef VBOX_WITH_INFO_SVC2763 HRESULT hrc =E_NOTIMPL;2757 #if !defined (VBOX_WITH_INFO_SVC) 2758 return E_NOTIMPL; 2764 2759 #else 2765 if (!VALID_PTR (aKey))2766 return E_ POINTER;2767 if ((aValue != NULL) && !VALID_PTR (aValue))2768 return E_ POINTER;2760 if (!VALID_PTR (aKey)) 2761 return E_INVALIDARG; 2762 if ((aValue != NULL) && !VALID_PTR (aValue)) 2763 return E_INVALIDARG; 2769 2764 2770 2765 AutoCaller autoCaller (this); 2771 2766 CheckComRCReturnRC (autoCaller.rc()); 2772 2767 2768 /* SetExtraData() needs a write lock */ 2769 AutoWriteLock alock (this); 2770 2773 2771 using namespace svcInfo; 2774 HRESULT hrc = E_FAIL;2772 HRESULT rc = E_FAIL; 2775 2773 2776 2774 switch (mData->mSession.mState) … … 2778 2776 case SessionState_Closed: 2779 2777 { 2780 AutoWriteLock alock (this);2781 2782 2778 /* The "+ 1" in the length is the null terminator. */ 2783 Bstr strKey (Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);2779 Bstr strKey (Bstr (aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1); 2784 2780 BSTR strKeyRaw = strKey.mutableRaw(); 2785 2781 … … 2788 2784 for (unsigned i = 0; i < VBOX_SHARED_INFO_PREFIX_LEN; ++i) 2789 2785 /* I take it this is legal, at least g++ accepts it. */ 2790 strKeyRaw [i] = VBOX_SHARED_INFO_KEY_PREFIX[i];2786 strKeyRaw [i] = VBOX_SHARED_INFO_KEY_PREFIX[i]; 2791 2787 /* The "+ 1" in the length is the null terminator. */ 2792 for (unsigned i = 0, len = Bstr (aKey).length() + 1; i < len; ++i)2793 strKeyRaw [i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey[i];2794 hrc = SetExtraData(strKey, aValue);2788 for (unsigned i = 0, len = Bstr (aKey).length() + 1; i < len; ++i) 2789 strKeyRaw [i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey [i]; 2790 rc = SetExtraData (strKey, aValue); 2795 2791 break; 2796 2792 } 2797 2793 case SessionState_Open: 2798 2794 { 2799 ComPtr <IInternalSessionControl> directControl;2795 if (mData->mSession.mState != SessionState_Open) 2800 2796 { 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; 2797 rc = setError (E_FAIL, 2798 tr ("Session is not open (session state: %d)"), 2799 mData->mSession.mState); 2800 break; 2809 2801 } 2810 2802 2811 BSTR dummy; 2812 hrc = directControl->AccessGuestProperty (aKey, aValue, 2813 true /* isSetter */, 2814 &dummy); 2803 ComPtr <IInternalSessionControl> directControl = 2804 mData->mSession.mDirectControl; 2805 2806 /* just be on the safe side when calling another process */ 2807 alock.leave(); 2808 2809 BSTR dummy = NULL; 2810 rc = directControl->AccessGuestProperty (aKey, aValue, 2811 true /* isSetter */, 2812 &dummy); 2815 2813 break; 2816 2814 } 2817 2815 default: 2818 hrc = setError (E_FAIL, tr ("Machine session is currently transitioning (session state: %d) - please retry."), 2819 mData->mSession.mState); 2820 } 2821 #endif /* VBOX_WITH_INFO_SVC not defined */ 2822 return hrc; 2816 rc = setError (E_FAIL, 2817 tr ("Session is currently transitioning (session state: %d)"), 2818 mData->mSession.mState); 2819 } 2820 return rc; 2821 #endif /* else !defined (VBOX_WITH_INFO_SVC) */ 2823 2822 } 2824 2823 -
trunk/src/VBox/Main/SessionImpl.cpp
r10233 r10305 655 655 656 656 STDMETHODIMP Session::AccessGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue, 657 BOOL isSetter, BSTR *retValue)657 BOOL aIsSetter, BSTR *aRetValue) 658 658 { 659 659 #ifdef VBOX_WITH_INFO_SVC … … 663 663 if (mState != SessionState_Open) 664 664 return setError (E_FAIL, 665 tr ("Machine session is not open (session state: %d) - please retry."),666 665 tr ("Machine session is not open (session state: %d)."), 666 mState); 667 667 AssertReturn (mType == SessionType_Direct, E_UNEXPECTED); 668 if (!VALID_PTR (aKey))668 if (!VALID_PTR (aKey)) 669 669 return E_POINTER; 670 if (! isSetter && !VALID_PTR(retValue))670 if (!aIsSetter && !VALID_PTR (aRetValue)) 671 671 return E_POINTER; 672 672 /* aValue can be NULL for a setter call if the property is to be deleted. */ 673 if ( isSetter && (aValue != NULL) && !VALID_PTR(aValue))674 return E_ POINTER;675 if (! isSetter)676 return mConsole->getGuestProperty (aKey, retValue);673 if (aIsSetter && (aValue != NULL) && !VALID_PTR (aValue)) 674 return E_INVALIDARG; 675 if (!aIsSetter) 676 return mConsole->getGuestProperty (aKey, aRetValue); 677 677 else 678 return mConsole->setGuestProperty (aKey, aValue);678 return mConsole->setGuestProperty (aKey, aValue); 679 679 #else 680 680 return E_NOTIMPL; -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r10233 r10305 3471 3471 <desc> 3472 3472 Reads a value from the machine's host/guest property store. 3473 3474 Reads a value from the machine's host/guest property store. 3475 3476 If a session for this virtual machine is currently open then queries the 3477 session object for the value, since the current values of the property 3478 store will be held in RAM in the session. Otherwise reads the value from 3479 machine extra data, where it is stored between sessions. 3480 3481 This method will fail if we are currently transitioning between session 3482 states. 3473 3483 </desc> 3474 3484 <param name="key" type="wstring" dir="in"> … … 3489 3499 Sets, changes or deletes a value in the machine's host/guest 3490 3500 property store. 3501 3502 If a session for this virtual machine is currently open then changes the 3503 value on the session object, since the current values of the property 3504 store will be held in RAM in the session. Otherwise changes the value 3505 in machine extra data, where it is stored between sessions. 3506 3507 This method will fail if we are currently transitioning between session 3508 states. 3491 3509 </desc> 3492 3510 <param name="key" type="wstring" dir="in"> -
trunk/src/VBox/Main/include/SessionImpl.h
r10233 r10305 106 106 STDMETHOD(OnUSBDeviceDetach) (INPTR GUIDPARAM aId, IVirtualBoxErrorInfo *aError); 107 107 STDMETHOD(OnShowWindow) (BOOL aCheck, BOOL *aCanShow, ULONG64 *aWinId); 108 STDMETHOD(AccessGuestProperty) (INPTR BSTR aKey, INPTR BSTR aValue, BOOL isSetter, BSTR *retValue); 108 STDMETHOD(AccessGuestProperty) (INPTR BSTR aKey, INPTR BSTR aValue, 109 BOOL aIsSetter, BSTR *aRetValue); 109 110 110 111 // for VirtualBoxSupportErrorInfoImpl
Note:
See TracChangeset
for help on using the changeset viewer.