Example #1
0
HRESULT SystemProperties::setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
{
    HRESULT hrc = S_OK;
    if (aExtPack.isNotEmpty())
    {
        if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
            hrc = S_OK;
        else
#ifdef VBOX_WITH_EXTPACK
            hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&aExtPack);
#else
            hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
#endif
    }
    if (SUCCEEDED(hrc))
    {
        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
        hrc = i_setDefaultVRDEExtPack(aExtPack);
        if (SUCCEEDED(hrc))
        {
            /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
            alock.release();
            AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
            hrc = mParent->i_saveSettings();
        }
    }

    return hrc;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
HRESULT VRDEServer::setVRDEExtPack(const com::Utf8Str &aExtPack)
{
    HRESULT hrc = S_OK;
    /* the machine can also be in saved state for this property to change */
    AutoMutableOrSavedOrRunningStateDependency adep(mParent);
    hrc = adep.rc();
    if (SUCCEEDED(hrc))
    {
        /*
         * If not empty, check the specific extension pack.
         */
        if (!aExtPack.isEmpty())
        {
            if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
                hrc = S_OK;
            else
            {
#ifdef VBOX_WITH_EXTPACK
                ExtPackManager *pExtPackMgr = mParent->i_getVirtualBox()->i_getExtPackManager();
                hrc = pExtPackMgr->i_checkVrdeExtPack(&aExtPack);
#else
                hrc = setError(E_FAIL, tr("Extension pack '%s' does not exist"), aExtPack.c_str());
#endif
            }
        }
        if (SUCCEEDED(hrc))
        {
            /*
             * Update the setting if there is an actual change, post an
             * change event to trigger a VRDE server restart.
             */
             AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
             if (aExtPack != mData->mVrdeExtPack)
             {
                 mData.backup();
                 mData->mVrdeExtPack = aExtPack;

                /* leave the lock before informing callbacks */
                alock.release();

                AutoWriteLock mlock(mParent COMMA_LOCKVAL_SRC_POS);
                mParent->i_setModified(Machine::IsModified_VRDEServer);
                mlock.release();

                mParent->i_onVRDEServerChange(/* aRestart */ TRUE);
            }
        }
    }

    return hrc;
}