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/ConsoleImpl.cpp

    r10007 r10233  
    24862486    return S_OK;
    24872487}
    2488 
    2489 STDMETHODIMP Console::GetGuestProperty (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::SetGuestProperty (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     int rc = VINF_SUCCESS;
    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     if (aValue != NULL)
    2547     {
    2548         Utf8Str Utf8Value = aValue;
    2549         parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
    2550         /* To save doing a const cast, we use the mutableRaw() member. */
    2551         parm[1].u.pointer.addr = Utf8Value.mutableRaw();
    2552         /* The + 1 is the null terminator */
    2553         parm[1].u.pointer.size = Utf8Value.length() + 1;
    2554         rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST, 2, &parm[0]);
    2555     }
    2556     else
    2557         rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", DEL_CONFIG_KEY_HOST, 1, &parm[0]);
    2558     if (RT_SUCCESS(rc))
    2559         hrc = S_OK;
    2560     else
    2561         hrc = setError (E_FAIL, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc);
    2562 #endif
    2563     return hrc;
    2564 }
    2565 
    25662488
    25672489// Non-interface public methods
     
    36093531    return E_FAIL;
    36103532#endif  /* !VBOX_WITH_USB */
     3533}
     3534
     3535HRESULT Console::getGuestProperty (INPTR BSTR aKey, BSTR *aValue)
     3536{
     3537#ifndef VBOX_WITH_INFO_SVC
     3538    HRESULT hrc = E_NOTIMPL;
     3539#else
     3540    if (!VALID_PTR(aKey))
     3541        return E_POINTER;
     3542    if (!VALID_PTR(aValue))
     3543        return E_POINTER;
     3544
     3545    AutoCaller autoCaller (this);
     3546    CheckComRCReturnRC (autoCaller.rc());
     3547
     3548    /* protect mpVM (if not NULL) */
     3549    AutoVMCallerWeak autoVMCaller (this);
     3550    CheckComRCReturnRC (autoVMCaller.rc());
     3551
     3552    HRESULT hrc = E_UNEXPECTED;
     3553    using namespace svcInfo;
     3554
     3555    VBOXHGCMSVCPARM parm[3];
     3556    Utf8Str Utf8Key = aKey;
     3557    Utf8Str Utf8Value(KEY_MAX_VALUE_LEN);
     3558
     3559    parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
     3560    /* To save doing a const cast, we use the mutableRaw() member. */
     3561    parm[0].u.pointer.addr = Utf8Key.mutableRaw();
     3562    /* The + 1 is the null terminator */
     3563    parm[0].u.pointer.size = Utf8Key.length() + 1;
     3564    parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
     3565    parm[1].u.pointer.addr = Utf8Value.mutableRaw();
     3566    parm[1].u.pointer.size = KEY_MAX_VALUE_LEN;
     3567    int rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", GET_CONFIG_KEY_HOST, 3, &parm[0]);
     3568    /* The returned string should never be able to be greater than our buffer */
     3569    AssertLogRel(rc != VINF_BUFFER_OVERFLOW);
     3570    if (RT_SUCCESS(rc) && (rc != VINF_BUFFER_OVERFLOW))
     3571    {
     3572        hrc = S_OK;
     3573        if (parm[2].u.uint32 != 0)
     3574            Utf8Value.cloneTo(aValue);
     3575        else
     3576            aValue = NULL;
     3577    }
     3578    else
     3579        hrc = setError (E_UNEXPECTED, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc);
     3580#endif
     3581    return hrc;
     3582}
     3583
     3584HRESULT Console::setGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue)
     3585{
     3586#ifndef VBOX_WITH_INFO_SVC
     3587    HRESULT hrc = E_NOTIMPL;
     3588#else
     3589    if (!VALID_PTR(aKey))
     3590        return E_POINTER;
     3591    if ((aValue != NULL) && !VALID_PTR(aValue))
     3592        return E_POINTER;
     3593
     3594    AutoCaller autoCaller (this);
     3595    CheckComRCReturnRC (autoCaller.rc());
     3596
     3597    /* protect mpVM (if not NULL) */
     3598    AutoVMCallerWeak autoVMCaller (this);
     3599    CheckComRCReturnRC (autoVMCaller.rc());
     3600
     3601    HRESULT hrc = E_UNEXPECTED;
     3602    using namespace svcInfo;
     3603
     3604    VBOXHGCMSVCPARM parm[2];
     3605    Utf8Str Utf8Key = aKey;
     3606    int rc = VINF_SUCCESS;
     3607
     3608    parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
     3609    /* To save doing a const cast, we use the mutableRaw() member. */
     3610    parm[0].u.pointer.addr = Utf8Key.mutableRaw();
     3611    /* The + 1 is the null terminator */
     3612    parm[0].u.pointer.size = Utf8Key.length() + 1;
     3613    if (aValue != NULL)
     3614    {
     3615        Utf8Str Utf8Value = aValue;
     3616        parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
     3617        /* To save doing a const cast, we use the mutableRaw() member. */
     3618        parm[1].u.pointer.addr = Utf8Value.mutableRaw();
     3619        /* The + 1 is the null terminator */
     3620        parm[1].u.pointer.size = Utf8Value.length() + 1;
     3621        rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST, 2, &parm[0]);
     3622    }
     3623    else
     3624        rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", DEL_CONFIG_KEY_HOST, 1, &parm[0]);
     3625    if (RT_SUCCESS(rc))
     3626        hrc = S_OK;
     3627    else
     3628        hrc = setError (E_UNEXPECTED, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc);
     3629#endif
     3630    return hrc;
    36113631}
    36123632
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