VirtualBox

Changeset 52251 in vbox


Ignore:
Timestamp:
Aug 1, 2014 6:07:28 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
95340
Message:

Main: update guest properties API to work with API wrappers, removed unnecesary BSTR conversion.

Location:
trunk/src/VBox/Main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/VBox/Main/idl/VirtualBox.xidl

    r52200 r52251  
    1774417744  <interface
    1774517745    name="IInternalSessionControl" extends="$unknown"
    17746     uuid="2d2124a7-0f62-4907-ae21-eee5a559bdde"
     17746    uuid="b7c71040-2761-42c4-a44a-4e2c2d7e2820"
    1774717747    internal="yes"
    1774817748    wsmap="suppress"
     
    1815118151      <param name="value" type="wstring" dir="in"/>
    1815218152      <param name="flags" type="wstring" dir="in"/>
    18153       <param name="isSetter" type="boolean" dir="in"/>
     18153      <param name="accessMode" type="unsigned long" dir="in">
     18154        <desc>0 = get, 1 = set, 2 = delete.</desc>
     18155      </param>
    1815418156      <param name="retValue" type="wstring" dir="out"/>
    1815518157      <param name="retTimestamp" type="long long" dir="out"/>
  • TabularUnified trunk/src/VBox/Main/include/ConsoleImpl.h

    r52019 r52251  
    174174    HRESULT i_onExtraDataChange(IN_BSTR aMachineId, IN_BSTR aKey, IN_BSTR aVal);
    175175
    176     HRESULT i_getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
    177     HRESULT i_setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
     176    HRESULT i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags);
     177    HRESULT i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags);
     178    HRESULT i_deleteGuestProperty(const Utf8Str &aName);
    178179    HRESULT i_enumerateGuestProperties(IN_BSTR aPatterns,
    179180                                       ComSafeArrayOut(BSTR, aNames),
  • TabularUnified trunk/src/VBox/Main/include/MachineImpl.h

    r52171 r52251  
    718718                                          LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
    719719    HRESULT i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
    720                                         const com::Utf8Str &aFlags);
     720                                        const com::Utf8Str &aFlags, bool fDelete);
    721721    HRESULT i_getGuestPropertyFromVM(const com::Utf8Str &aName, com::Utf8Str &aValue,
    722722                                     LONG64 *aTimestamp, com::Utf8Str &aFlags) const;
    723723    HRESULT i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
    724                                    const com::Utf8Str &aFlags);
     724                                   const com::Utf8Str &aFlags, bool fDelete);
    725725    HRESULT i_enumerateGuestPropertiesInService(const com::Utf8Str &aPatterns,
    726726                                                std::vector<com::Utf8Str> &aNames,
  • TabularUnified trunk/src/VBox/Main/include/SessionImpl.h

    r52248 r52251  
    107107                                const com::Utf8Str &aValue,
    108108                                const com::Utf8Str &aFlags,
    109                                 BOOL aIsSetter,
     109                                ULONG aAccessMode,
    110110                                com::Utf8Str &aRetValue,
    111111                                LONG64 *aRetTimestamp,
  • TabularUnified trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r52107 r52251  
    12831283    {
    12841284        /* Provide credentials only if there are no logged in users. */
    1285         Bstr noLoggedInUsersValue;
     1285        Utf8Str noLoggedInUsersValue;
    12861286        LONG64 ul64Timestamp = 0;
    1287         Bstr flags;
    1288 
    1289         hrc = i_getGuestProperty(Bstr("/VirtualBox/GuestInfo/OS/NoLoggedInUsers").raw(),
    1290                                  noLoggedInUsersValue.asOutParam(), &ul64Timestamp, flags.asOutParam());
    1291 
    1292         if (SUCCEEDED(hrc) && noLoggedInUsersValue != Bstr("false"))
     1287        Utf8Str flags;
     1288
     1289        hrc = i_getGuestProperty("/VirtualBox/GuestInfo/OS/NoLoggedInUsers",
     1290                                 &noLoggedInUsersValue, &ul64Timestamp, &flags);
     1291
     1292        if (SUCCEEDED(hrc) && noLoggedInUsersValue != "false")
    12931293        {
    12941294            /* And only if there are no connected clients. */
     
    55675567 * @note Temporarily locks this object for writing.
    55685568 */
    5569 HRESULT Console::i_getGuestProperty(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags)
     5569HRESULT Console::i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags)
    55705570{
    55715571#ifndef VBOX_WITH_GUEST_PROPS
    55725572    ReturnComNotImplemented();
    55735573#else  /* VBOX_WITH_GUEST_PROPS */
    5574     if (!VALID_PTR(aName))
    5575         return E_INVALIDARG;
    5576     if (!VALID_PTR(aValue))
     5574    if (!RT_VALID_PTR(aValue))
     5575         return E_POINTER;
     5576    if (aTimestamp != NULL && !RT_VALID_PTR(aTimestamp))
    55775577        return E_POINTER;
    5578     if ((aTimestamp != NULL) && !VALID_PTR(aTimestamp))
    5579         return E_POINTER;
    5580     if ((aFlags != NULL) && !VALID_PTR(aFlags))
     5578    if (aFlags != NULL && !RT_VALID_PTR(aFlags))
    55815579        return E_POINTER;
    55825580
     
    55985596    {
    55995597        VBOXHGCMSVCPARM parm[4];
    5600         Utf8Str Utf8Name = aName;
    56015598        char szBuffer[MAX_VALUE_LEN + MAX_FLAGS_LEN];
    56025599
    56035600        parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
    5604         parm[0].u.pointer.addr = (void*)Utf8Name.c_str();
    5605         /* The + 1 is the null terminator */
    5606         parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1;
     5601        parm[0].u.pointer.addr = (void*)aName.c_str();
     5602        parm[0].u.pointer.size = (uint32_t)aName.length() + 1; /* The + 1 is the null terminator */
     5603
    56075604        parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
    56085605        parm[1].u.pointer.addr = szBuffer;
    56095606        parm[1].u.pointer.size = sizeof(szBuffer);
     5607
     5608        parm[2].type = VBOX_HGCM_SVC_PARM_64BIT;
     5609        parm[2].u.uint64 = 0;
     5610
     5611        parm[3].type = VBOX_HGCM_SVC_PARM_32BIT;
     5612        parm[3].u.uint32 = 0;
     5613
    56105614        int vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", GET_PROP_HOST,
    56115615                                          4, &parm[0]);
    56125616        /* The returned string should never be able to be greater than our buffer */
    56135617        AssertLogRel(vrc != VERR_BUFFER_OVERFLOW);
    5614         AssertLogRel(RT_FAILURE(vrc) || VBOX_HGCM_SVC_PARM_64BIT == parm[2].type);
    5615         if (RT_SUCCESS(vrc) || (VERR_NOT_FOUND == vrc))
    5616         {
     5618        AssertLogRel(RT_FAILURE(vrc) || parm[2].type == VBOX_HGCM_SVC_PARM_64BIT);
     5619        if (RT_SUCCESS(vrc))
     5620        {
     5621            *aValue = szBuffer;
     5622
     5623            if (aTimestamp)
     5624                *aTimestamp = parm[2].u.uint64;
     5625
     5626            if (aFlags)
     5627                *aFlags = &szBuffer[strlen(szBuffer) + 1];
     5628
    56175629            rc = S_OK;
    5618             if (vrc != VERR_NOT_FOUND)
    5619             {
    5620                 Utf8Str strBuffer(szBuffer);
    5621                 strBuffer.cloneTo(aValue);
    5622 
    5623                 if (aTimestamp)
    5624                     *aTimestamp = parm[2].u.uint64;
    5625 
    5626                 if (aFlags)
    5627                 {
    5628                     size_t iFlags = strBuffer.length() + 1;
    5629                     Utf8Str(szBuffer + iFlags).cloneTo(aFlags);
    5630                 }
    5631             }
    5632             else
    5633                 aValue = NULL;
     5630        }
     5631        else if (vrc == VERR_NOT_FOUND)
     5632        {
     5633            *aValue = "";
     5634            rc = S_OK;
    56345635        }
    56355636        else
    5636             rc = setError(E_UNEXPECTED,
    5637                 tr("The service call failed with the error %Rrc"),
    5638                 vrc);
     5637            rc = setError(VBOX_E_IPRT_ERROR,
     5638                          tr("The VBoxGuestPropSvc service call failed with the error %Rrc"),
     5639                          vrc);
    56395640    }
    56405641    catch(std::bad_alloc & /*e*/)
     
    56425643        rc = E_OUTOFMEMORY;
    56435644    }
     5645
    56445646    return rc;
    56455647#endif /* VBOX_WITH_GUEST_PROPS */
     
    56495651 * @note Temporarily locks this object for writing.
    56505652 */
    5651 HRESULT Console::i_setGuestProperty(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags)
     5653HRESULT Console::i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags)
    56525654{
    56535655#ifndef VBOX_WITH_GUEST_PROPS
    56545656    ReturnComNotImplemented();
    56555657#else /* VBOX_WITH_GUEST_PROPS */
    5656     if (!RT_VALID_PTR(aName))
    5657         return setError(E_INVALIDARG, tr("Name cannot be NULL or an invalid pointer"));
    5658     if (aValue != NULL && !RT_VALID_PTR(aValue))
    5659         return setError(E_INVALIDARG, tr("Invalid value pointer"));
    5660     if (aFlags != NULL && !RT_VALID_PTR(aFlags))
    5661         return setError(E_INVALIDARG, tr("Invalid flags pointer"));
    56625658
    56635659    AutoCaller autoCaller(this);
     
    56765672    VBOXHGCMSVCPARM parm[3];
    56775673
    5678     Utf8Str Utf8Name = aName;
    56795674    parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
    5680     parm[0].u.pointer.addr = (void*)Utf8Name.c_str();
    5681     /* The + 1 is the null terminator */
    5682     parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1;
    5683 
    5684     Utf8Str Utf8Value;
    5685     if (aValue != NULL)
    5686     {
    5687         Utf8Value = aValue;
    5688         parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
    5689         parm[1].u.pointer.addr = (void *)Utf8Value.c_str();
    5690         /* The + 1 is the null terminator */
    5691         parm[1].u.pointer.size = (uint32_t)Utf8Value.length() + 1;
    5692     }
    5693 
    5694     Utf8Str Utf8Flags;
    5695     if (aFlags != NULL)
    5696     {
    5697         Utf8Flags = aFlags;
     5675    parm[0].u.pointer.addr = (void*)aName.c_str();
     5676    parm[0].u.pointer.size = (uint32_t)aName.length() + 1; /* The + 1 is the null terminator */
     5677
     5678    parm[1].type = VBOX_HGCM_SVC_PARM_PTR;
     5679    parm[1].u.pointer.addr = (void *)aValue.c_str();
     5680    parm[1].u.pointer.size = (uint32_t)aValue.length() + 1; /* The + 1 is the null terminator */
     5681
     5682    int vrc;
     5683    if (aFlags.isEmpty())
     5684    {
     5685        vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", SET_PROP_VALUE_HOST,
     5686                                    2, &parm[0]);
     5687    }
     5688    else
     5689    {
    56985690        parm[2].type = VBOX_HGCM_SVC_PARM_PTR;
    5699         parm[2].u.pointer.addr = (void*)Utf8Flags.c_str();
    5700         /* The + 1 is the null terminator */
    5701         parm[2].u.pointer.size = (uint32_t)Utf8Flags.length() + 1;
    5702     }
    5703 
    5704     int vrc;
    5705     if (aValue != NULL && aFlags != NULL)
     5691        parm[2].u.pointer.addr = (void*)aFlags.c_str();
     5692        parm[2].u.pointer.size = (uint32_t)aFlags.length() + 1; /* The + 1 is the null terminator */
     5693
    57065694        vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", SET_PROP_HOST,
    57075695                                      3, &parm[0]);
    5708     else if (aValue != NULL)
    5709         vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", SET_PROP_VALUE_HOST,
    5710                                     2, &parm[0]);
    5711     else
    5712         vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", DEL_PROP_HOST,
    5713                                     1, &parm[0]);
    5714     HRESULT hrc;
    5715     if (RT_SUCCESS(vrc))
    5716         hrc = S_OK;
    5717     else
    5718         hrc = setError(E_UNEXPECTED, tr("The service call failed with the error %Rrc"), vrc);
     5696    }
     5697
     5698    HRESULT hrc = S_OK;
     5699    if (RT_FAILURE(vrc))
     5700        hrc = setError(VBOX_E_IPRT_ERROR, tr("The VBoxGuestPropSvc service call failed with the error %Rrc"), vrc);
    57195701    return hrc;
    57205702#endif /* VBOX_WITH_GUEST_PROPS */
    57215703}
    57225704
     5705HRESULT Console::i_deleteGuestProperty(const Utf8Str &aName)
     5706{
     5707#ifndef VBOX_WITH_GUEST_PROPS
     5708    ReturnComNotImplemented();
     5709#else /* VBOX_WITH_GUEST_PROPS */
     5710
     5711    AutoCaller autoCaller(this);
     5712    AssertComRCReturnRC(autoCaller.rc());
     5713
     5714    /* protect mpUVM (if not NULL) */
     5715    SafeVMPtrQuiet ptrVM(this);
     5716    if (FAILED(ptrVM.rc()))
     5717        return ptrVM.rc();
     5718
     5719    /* Note: validity of mVMMDev which is bound to uninit() is guaranteed by
     5720     * ptrVM, so there is no need to hold a lock of this */
     5721
     5722    using namespace guestProp;
     5723
     5724    VBOXHGCMSVCPARM parm[1];
     5725
     5726    parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
     5727    parm[0].u.pointer.addr = (void*)aName.c_str();
     5728    parm[0].u.pointer.size = (uint32_t)aName.length() + 1; /* The + 1 is the null terminator */
     5729
     5730    int vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", DEL_PROP_HOST,
     5731                                      1, &parm[0]);
     5732
     5733    HRESULT hrc = S_OK;
     5734    if (RT_FAILURE(vrc))
     5735        hrc = setError(VBOX_E_IPRT_ERROR, tr("The VBoxGuestPropSvc service call failed with the error %Rrc"), vrc);
     5736    return hrc;
     5737#endif /* VBOX_WITH_GUEST_PROPS */
     5738}
    57235739
    57245740/**
  • TabularUnified trunk/src/VBox/Main/src-client/SessionImpl.cpp

    r52248 r52251  
    823823
    824824HRESULT Session::accessGuestProperty(const com::Utf8Str &aName, const com::Utf8Str &aValue, const com::Utf8Str &aFlags,
    825                                      BOOL aIsSetter, com::Utf8Str &aRetValue, LONG64 *aRetTimestamp, com::Utf8Str &aRetFlags)
     825                                     ULONG aAccessMode, com::Utf8Str &aRetValue, LONG64 *aRetTimestamp, com::Utf8Str &aRetFlags)
    826826{
    827827#ifdef VBOX_WITH_GUEST_PROPS
     
    834834    if (aName.isEmpty())
    835835        return E_INVALIDARG;
    836     if (!aIsSetter && !VALID_PTR(aRetTimestamp))
     836    if (aAccessMode == 0 && !RT_VALID_PTR(aRetTimestamp))
    837837        return E_POINTER;
    838838
     
    842842        return E_ACCESSDENIED;
    843843
    844     if (!aIsSetter)
    845     {
    846         Bstr bstrRetValue;
    847         Bstr bstrRetFlags;
    848         HRESULT hr = mConsole->i_getGuestProperty(Bstr(aName).raw(),
    849                                                   bstrRetValue.asOutParam(), aRetTimestamp, bstrRetFlags.asOutParam());
    850         if (SUCCEEDED(hr))
    851         {
    852             aRetValue = bstrRetValue;
    853             aRetFlags = bstrRetFlags;
    854         }
    855         return hr;
    856     }
     844    HRESULT hr;
     845    if (aAccessMode == 2)
     846        hr = mConsole->i_deleteGuestProperty(aName);
     847    else if (aAccessMode == 1)
     848        hr = mConsole->i_setGuestProperty(aName, aValue, aFlags);
     849    else if (aAccessMode == 0)
     850        hr = mConsole->i_getGuestProperty(aName, &aRetValue, aRetTimestamp, &aRetFlags);
    857851    else
    858         return mConsole->i_setGuestProperty(Bstr(aName).raw(), Bstr(aValue).raw(), Bstr(aFlags).raw());
    859 
     852        hr = E_INVALIDARG;
     853
     854    return hr;
    860855# else  /* VBOX_COM_INPROC_API_CLIENT */
    861856    /** @todo This is nonsense, non-VM API users shouldn't need to deal with this
  • TabularUnified trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r52175 r52251  
    54935493        rc = E_ACCESSDENIED;
    54945494    else
    5495         rc = directControl->AccessGuestProperty(Bstr(aName).raw(), NULL, NULL,
    5496                                                 false /* isSetter */,
     5495        rc = directControl->AccessGuestProperty(Bstr(aName).raw(), Bstr("").raw(), Bstr("").raw(),
     5496                                                0 /* accessMode */,
    54975497                                                &bValue, aTimestamp, &bFlags);
    54985498
     
    55435543 */
    55445544HRESULT Machine::i_setGuestPropertyToService(const com::Utf8Str &aName, const com::Utf8Str &aValue,
    5545                                              const com::Utf8Str &aFlags)
     5545                                             const com::Utf8Str &aFlags, bool fDelete)
    55465546{
    55475547    using namespace guestProp;
     
    55595559            return setError(E_INVALIDARG, tr("Invalid guest property flag values: '%s'"), aFlags.c_str());
    55605560
    5561         bool fDelete = aValue.isEmpty();
    55625561        HWData::GuestPropertyMap::iterator it = mHWData->mGuestProperties.find(aName);
    55635562        if (it == mHWData->mGuestProperties.end())
     
    56375636 */
    56385637HRESULT Machine::i_setGuestPropertyToVM(const com::Utf8Str &aName, const com::Utf8Str &aValue,
    5639                                         const com::Utf8Str &aFlags)
     5638                                        const com::Utf8Str &aFlags, bool fDelete)
    56405639{
    56415640    HRESULT rc;
     
    56525651            /** @todo Fix when adding DeleteGuestProperty(), see defect. */
    56535652            rc = directControl->AccessGuestProperty(Bstr(aName).raw(), Bstr(aValue).raw(), Bstr(aFlags).raw(),
    5654                                                     true /* isSetter */,
     5653                                                    fDelete? 2: 1 /* accessMode */,
    56555654                                                    &dummy, &dummy64, &dummy);
    56565655    }
     
    56705669    ReturnComNotImplemented();
    56715670#else // VBOX_WITH_GUEST_PROPS
    5672     HRESULT rc = i_setGuestPropertyToVM(aProperty, aValue, aFlags);
     5671    HRESULT rc = i_setGuestPropertyToVM(aProperty, aValue, aFlags, /* fDelete = */ false);
    56735672    if (rc == E_ACCESSDENIED)
    56745673        /* The VM is not running or the service is not (yet) accessible */
    5675         rc = i_setGuestPropertyToService(aProperty, aValue, aFlags);
     5674        rc = i_setGuestPropertyToService(aProperty, aValue, aFlags, /* fDelete = */ false);
    56765675    return rc;
    56775676#endif // VBOX_WITH_GUEST_PROPS
     
    56855684HRESULT Machine::deleteGuestProperty(const com::Utf8Str &aName)
    56865685{
    5687     return setGuestProperty(aName, "", "");
     5686#ifndef VBOX_WITH_GUEST_PROPS
     5687    ReturnComNotImplemented();
     5688#else // VBOX_WITH_GUEST_PROPS
     5689    HRESULT rc = i_setGuestPropertyToVM(aName, "", "", /* fDelete = */ true);
     5690    if (rc == E_ACCESSDENIED)
     5691        /* The VM is not running or the service is not (yet) accessible */
     5692        rc = i_setGuestPropertyToService(aName, "", "", /* fDelete = */ true);
     5693    return rc;
     5694#endif // VBOX_WITH_GUEST_PROPS
    56885695}
    56895696
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette