Changeset 9883 in vbox
- Timestamp:
- Jun 23, 2008 3:02:47 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 32274
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r9809 r9883 2486 2486 return S_OK; 2487 2487 } 2488 2489 STDMETHODIMP Console::GetConfigRegistryValue (INPTR BSTR aKey, BSTR *aValue) 2490 { 2491 if (!VALID_PTR(aValue)) 2492 return E_POINTER; 2493 2494 #ifndef VBOX_WITH_INFO_SVC 2495 HRESULT hrc = E_NOTIMPL; 2496 #else 2497 HRESULT hrc = E_FAIL; 2498 using namespace svcInfo; 2499 2500 VBOXHGCMSVCPARM parm[3]; 2501 Utf8Str Utf8Key = aKey; 2502 Utf8Str Utf8Value(KEY_MAX_VALUE_LEN); 2503 2504 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 2505 /* To save doing a const cast, we use the mutableRaw() member. */ 2506 parm[0].u.pointer.addr = Utf8Key.mutableRaw(); 2507 /* The + 1 is the null terminator */ 2508 parm[0].u.pointer.size = Utf8Key.length() + 1; 2509 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 2510 parm[1].u.pointer.addr = Utf8Value.mutableRaw(); 2511 parm[1].u.pointer.size = KEY_MAX_VALUE_LEN; 2512 int rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", GET_CONFIG_KEY_HOST, 3, &parm[0]); 2513 /* The returned string should never be able to be greater than our buffer */ 2514 AssertLogRel(rc != VINF_BUFFER_OVERFLOW); 2515 if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW)) 2516 { 2517 hrc = S_OK; 2518 if (parm[2].u.uint32 != 0) 2519 Utf8Value.cloneTo(aValue); 2520 else 2521 aValue = NULL; 2522 } 2523 else 2524 hrc = setError (E_FAIL, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc); 2525 #endif 2526 return hrc; 2527 } 2528 2529 STDMETHODIMP Console::SetConfigRegistryValue (INPTR BSTR aKey, INPTR BSTR aValue) 2530 { 2531 #ifndef VBOX_WITH_INFO_SVC 2532 HRESULT hrc = E_NOTIMPL; 2533 #else 2534 HRESULT hrc = E_FAIL; 2535 using namespace svcInfo; 2536 2537 VBOXHGCMSVCPARM parm[2]; 2538 Utf8Str Utf8Key = aKey; 2539 Utf8Str Utf8Value = aValue; 2540 2541 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 2542 /* To save doing a const cast, we use the mutableRaw() member. */ 2543 parm[0].u.pointer.addr = Utf8Key.mutableRaw(); 2544 /* The + 1 is the null terminator */ 2545 parm[0].u.pointer.size = Utf8Key.length() + 1; 2546 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 2547 /* To save doing a const cast, we use the mutableRaw() member. */ 2548 parm[1].u.pointer.addr = Utf8Value.mutableRaw(); 2549 if (parm[1].u.pointer.addr != NULL) 2550 /* The + 1 is the null terminator */ 2551 parm[1].u.pointer.size = Utf8Value.length() + 1; 2552 else 2553 parm[1].u.pointer.size = 0; 2554 int rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST, 2, &parm[0]); 2555 if (RT_SUCCESS(rc)) 2556 hrc = S_OK; 2557 else 2558 hrc = setError (E_FAIL, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc); 2559 #endif 2560 return hrc; 2561 } 2562 2488 2563 2489 2564 // Non-interface public methods -
trunk/src/VBox/Main/MachineImpl.cpp
r9332 r9883 74 74 #include <VBox/err.h> 75 75 #include <VBox/param.h> 76 #ifdef VBOX_WITH_INFO_SVC 77 # include <VBox/HostServices/VBoxInfoSvc.h> 78 #endif 76 79 77 80 #include <algorithm> … … 2650 2653 } 2651 2654 2655 /** 2656 * Read a value from the host/guest configuration registry. If a session is 2657 * currently open for the guest then query the console object for the value, 2658 * since the current values of the registry will be held in RAM in the 2659 * session. Otherwise read the value from machine extra data, where it is 2660 * stored between sessions. 2661 * 2662 * @note since the way this method is implemented depends on whether or not 2663 * a session is currently open, we grab a write lock on the object, in 2664 * order to ensure that the session state does not change during the 2665 * call, and to force us to block if it is currently changing (either 2666 * way) between open and closed. 2667 */ 2668 STDMETHODIMP Machine::GetConfigRegistryValue (INPTR BSTR aKey, BSTR *aValue) 2669 { 2670 if (!VALID_PTR(aValue)) 2671 return E_POINTER; 2672 2673 #ifndef VBOX_WITH_INFO_SVC 2674 HRESULT hrc = E_NOTIMPL; 2675 #else 2676 using namespace svcInfo; 2677 2678 HRESULT hrc = E_FAIL; 2679 AutoWriteLock alock (this); 2680 switch (mData->mSession.mState) 2681 { 2682 case SessionState_Closed: 2683 { 2684 /* The "+ 1" in the length is the null terminator. */ 2685 Bstr strKey(Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1); 2686 BSTR strKeyRaw = strKey.mutableRaw(); 2687 2688 /* String manipulation in Main is pretty painful, especially given 2689 * how often it is needed. */ 2690 for (unsigned i = 0; i < VBOX_SHARED_INFO_PREFIX_LEN; ++i) 2691 /* I take it this is legal, at least g++ accepts it. */ 2692 strKeyRaw[i] = VBOX_SHARED_INFO_KEY_PREFIX[i]; 2693 /* The "+ 1" in the length is the null terminator. */ 2694 for (unsigned i = 0, len = Bstr(aKey).length() + 1; i < len; ++i) 2695 strKeyRaw[i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey[i]; 2696 hrc = GetExtraData(strKey, aValue); 2697 break; 2698 } 2699 case SessionState_Open: 2700 { 2701 /* 2702 * Get the console from the direct session (note that we don't leave the 2703 * lock here because GetRemoteConsole must not call us back). 2704 */ 2705 ComPtr <IConsole> console; 2706 hrc = mData->mSession.mDirectControl->GetRemoteConsole (console.asOutParam()); 2707 if (!SUCCEEDED (hrc)) 2708 /* The failure may w/o any error info (from RPC), so provide one */ 2709 hrc = setError (hrc, tr ("Failed to get a console object from the direct session")); 2710 else 2711 { 2712 ComAssertRet (!console.isNull(), E_FAIL); 2713 hrc = console->GetConfigRegistryValue (aKey, aValue); 2714 } 2715 break; 2716 } 2717 default: 2718 /* If we get here then I have misunderstood the semantics. Quite possible. */ 2719 AssertLogRel(false); 2720 hrc = E_UNEXPECTED; 2721 } 2722 #endif /* VBOX_WITH_INFO_SVC not defined */ 2723 return hrc; 2724 } 2725 2726 /** 2727 * Write a value to the host/guest configuration registry. If a session is 2728 * currently open for the guest then query the console object for the value, 2729 * since the current values of the registry will be held in RAM in the 2730 * session. Otherwise read the value from machine extra data, where it is 2731 * stored between sessions. 2732 * 2733 * @note since the way this method is implemented depends on whether or not 2734 * a session is currently open, we grab a write lock on the object, in 2735 * order to ensure that the session state does not change during the 2736 * call, and to force us to block if it is currently changing (either 2737 * way) between open and closed. 2738 */ 2739 STDMETHODIMP Machine::SetConfigRegistryValue (INPTR BSTR aKey, INPTR BSTR aValue) 2740 { 2741 #ifndef VBOX_WITH_INFO_SVC 2742 HRESULT hrc = E_NOTIMPL; 2743 #else 2744 using namespace svcInfo; 2745 2746 HRESULT hrc = E_FAIL; 2747 AutoWriteLock alock (this); 2748 switch (mData->mSession.mState) 2749 { 2750 case SessionState_Closed: 2751 { 2752 /* The "+ 1" in the length is the null terminator. */ 2753 Bstr strKey(Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1); 2754 BSTR strKeyRaw = strKey.mutableRaw(); 2755 2756 /* String manipulation in Main is pretty painful, especially given 2757 * how often it is needed. */ 2758 for (unsigned i = 0; i < VBOX_SHARED_INFO_PREFIX_LEN; ++i) 2759 /* I take it this is legal, at least g++ accepts it. */ 2760 strKeyRaw[i] = VBOX_SHARED_INFO_KEY_PREFIX[i]; 2761 /* The "+ 1" in the length is the null terminator. */ 2762 for (unsigned i = 0, len = Bstr(aKey).length() + 1; i < len; ++i) 2763 strKeyRaw[i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey[i]; 2764 hrc = SetExtraData(strKey, aValue); 2765 break; 2766 } 2767 case SessionState_Open: 2768 { 2769 /* 2770 * Get the console from the direct session (note that we don't leave the 2771 * lock here because GetRemoteConsole must not call us back). 2772 */ 2773 ComPtr <IConsole> console; 2774 hrc = mData->mSession.mDirectControl->GetRemoteConsole (console.asOutParam()); 2775 if (!SUCCEEDED (hrc)) 2776 /* The failure may w/o any error info (from RPC), so provide one */ 2777 hrc = setError (hrc, tr ("Failed to get a console object from the direct session")); 2778 else 2779 { 2780 ComAssertRet (!console.isNull(), E_FAIL); 2781 hrc = console->SetConfigRegistryValue (aKey, aValue); 2782 } 2783 break; 2784 } 2785 default: 2786 /* If we get here then I have misunderstood the semantics. Quite possible. */ 2787 AssertLogRel(false); 2788 hrc = E_UNEXPECTED; 2789 } 2790 #endif /* VBOX_WITH_INFO_SVC not defined */ 2791 return hrc; 2792 } 2793 2794 2652 2795 // public methods for internal purposes 2653 2796 ///////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r9401 r9883 2495 2495 <interface 2496 2496 name="IMachine" extends="$unknown" 2497 uuid=" f95c0793-7737-49a1-85d9-6da81097173b"2497 uuid="ceb17b5b-fd1f-424f-9dd3-2ab04c06eefc" 2498 2498 wsmap="managed" 2499 2499 > … … 3467 3467 </param> 3468 3468 </method> 3469 3470 <method name="getConfigRegistryValue"> 3471 <desc> 3472 Reads a value from the machine's host/guest configuration registry. 3473 </desc> 3474 <param name="key" type="wstring" dir="in"> 3475 <desc> 3476 The name of the key to read. 3477 </desc> 3478 </param> 3479 <param name="value" type="wstring" dir="return"> 3480 <desc> 3481 The value of the key. If the key does not exist then this will be 3482 empty. 3483 </desc> 3484 </param> 3485 </method> 3486 3487 <method name="setConfigRegistryValue"> 3488 <desc> 3489 Sets, changes or deletes a value in the machine's host/guest 3490 configuration registry. 3491 </desc> 3492 <param name="key" type="wstring" dir="in"> 3493 <desc> 3494 The name of the key to set, change or delete. 3495 </desc> 3496 </param> 3497 <param name="value" type="wstring" dir="in"> 3498 <desc> 3499 The new value of the key to set, change or delete. If the key does 3500 not yet exist and @a value is non-empty, it will be created. If 3501 @a value is empty, the key will be deleted if it exists. 3502 </desc> 3503 </param> 3504 </method> 3469 3505 3470 3506 </interface> … … 3962 3998 <interface 3963 3999 name="IConsole" extends="$unknown" 3964 uuid=" d5a1cbda-f5d7-4824-9afe-d640c94c7dcf"4000 uuid="8b029405-b41f-40c2-9d01-b854a39f7d48" 3965 4001 wsmap="managed" 3966 4002 > … … 4528 4564 </desc> 4529 4565 <param name="callback" type="IConsoleCallback" dir="in"/> 4566 </method> 4567 4568 <method name="getConfigRegistryValue"> 4569 <desc> 4570 Reads a value from the host/guest configuration registry. 4571 </desc> 4572 <param name="key" type="wstring" dir="in"> 4573 <desc> 4574 The name of the key to read. 4575 </desc> 4576 </param> 4577 <param name="value" type="wstring" dir="return"> 4578 <desc> 4579 The value of the key. If the key does not exist then this will be 4580 empty. 4581 </desc> 4582 </param> 4583 </method> 4584 4585 <method name="setConfigRegistryValue"> 4586 <desc> 4587 Sets, changes or deletes a value in the host/guest configuration 4588 registry. 4589 </desc> 4590 <param name="key" type="wstring" dir="in"> 4591 <desc> 4592 The name of the key to set, change or delete. 4593 </desc> 4594 </param> 4595 <param name="value" type="wstring" dir="in"> 4596 <desc> 4597 The new value of the key to set, change or delete. If the key does 4598 not yet exist and @a value is non-empty, it will be created. If 4599 @a value is empty, the key will be deleted if it exists. 4600 </desc> 4601 </param> 4530 4602 </method> 4531 4603 -
trunk/src/VBox/Main/include/ConsoleImpl.h
r8155 r9883 148 148 STDMETHOD(RegisterCallback) (IConsoleCallback *aCallback); 149 149 STDMETHOD(UnregisterCallback)(IConsoleCallback *aCallback); 150 STDMETHOD(GetConfigRegistryValue)(INPTR BSTR aKey, BSTR *aValue); 151 STDMETHOD(SetConfigRegistryValue)(INPTR BSTR aKey, INPTR BSTR aValue); 150 152 151 153 // public methods for internal purposes only -
trunk/src/VBox/Main/include/MachineImpl.h
r8155 r9883 516 516 STDMETHOD(CanShowConsoleWindow) (BOOL *aCanShow); 517 517 STDMETHOD(ShowConsoleWindow) (ULONG64 *aWinId); 518 STDMETHOD(GetConfigRegistryValue) (INPTR BSTR aKey, BSTR *aValue); 519 STDMETHOD(SetConfigRegistryValue) (INPTR BSTR aKey, INPTR BSTR aValue); 518 520 519 521 // public methods only for internal purposes
Note:
See TracChangeset
for help on using the changeset viewer.