VirtualBox

Changeset 9809

Show
Ignore:
Timestamp:
06/19/08 10:28:07 (6 months ago)
Author:
vboxsync
Message:

Main: save and reload the guest/host registry in extra data at machine startup and shutdown

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/HostServices/VBoxInfoSvc.h

    r9727 r9809  
    5757/** Prefix for extra data keys used by the get and set key value functions */ 
    5858#define VBOX_SHARED_INFO_KEY_PREFIX          "Guest/" 
     59/** Helper macro for the length of the prefix VBOX_SHARED_INFO_KEY_PREFIX */ 
     60#define VBOX_SHARED_INFO_PREFIX_LEN          (sizeof(VBOX_SHARED_INFO_KEY_PREFIX) - 1) 
    5961/** Maximum length for extra data keys used by the get and set key value functions */ 
    6062enum { KEY_MAX_LEN = 64 }; 
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r8684 r9809  
    8282 
    8383#include <VBox/HostServices/VBoxClipboardSvc.h> 
     84#ifdef VBOX_WITH_INFO_SVC 
     85# include <VBox/HostServices/VBoxInfoSvc.h> 
     86#endif 
    8487 
    8588#include <set> 
     
    40134016 
    40144017    AutoWriteLock alock (this); 
     4018    int vrc = VINF_SUCCESS; 
    40154019 
    40164020    /* sanity */ 
     
    40524056        alock.enter(); 
    40534057    } 
     4058# ifdef VBOX_WITH_INFO_SVC 
     4059    /* Save all guest/host configuration registry entries to the machine XML 
     4060     * file as extra data. */ 
     4061    PCFGMNODE pRegistry = CFGMR3GetChild (CFGMR3GetRoot (mpVM), "Guest/Registry/"); 
     4062    PCFGMLEAF pValue = CFGMR3GetFirstValue (pRegistry); 
     4063    vrc = VINF_SUCCESS; 
     4064    while (pValue != NULL && RT_SUCCESS(vrc)) 
     4065    { 
     4066        using namespace svcInfo; 
     4067        char szKeyName[KEY_MAX_LEN]; 
     4068        char szKeyValue[KEY_MAX_VALUE_LEN]; 
     4069        char szExtraDataName[VBOX_SHARED_INFO_PREFIX_LEN + KEY_MAX_LEN]; 
     4070        vrc = CFGMR3GetValueName (pValue, szKeyName, KEY_MAX_LEN); 
     4071        if (RT_SUCCESS(vrc)) 
     4072            vrc = CFGMR3QueryString (pRegistry, szKeyName, szKeyValue, sizeof(szKeyValue)); 
     4073        if (RT_SUCCESS(vrc)) 
     4074        { 
     4075            strcpy(szExtraDataName, VBOX_SHARED_INFO_KEY_PREFIX); 
     4076            strncpy(szExtraDataName + VBOX_SHARED_INFO_PREFIX_LEN, szKeyName, sizeof(szKeyName)); 
     4077            szExtraDataName[sizeof(szExtraDataName) - 1] = 0; 
     4078        } 
     4079        if (RT_SUCCESS(vrc)) 
     4080            if (FAILED(mMachine->SetExtraData(Bstr(szExtraDataName).raw(), Bstr(szKeyValue).raw()))) 
     4081                vrc = VERR_UNRESOLVED_ERROR;  /* We only need to know that we have to stop. */ 
     4082        if (RT_SUCCESS(vrc)) 
     4083            pValue = CFGMR3GetNextValue (pValue); 
     4084    } 
     4085# endif /* VBOX_WITH_INFO_SVC defined */ 
    40544086#endif /* VBOX_HGCM */ 
    40554087 
     
    40864118 
    40874119    HRESULT rc = S_OK; 
    4088     int vrc = VINF_SUCCESS; 
     4120    vrc = VINF_SUCCESS; 
    40894121 
    40904122    /* 
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r9728 r9809  
    16641664            rc = CFGMR3InsertNode(pRoot,     "Guest", &pGuest);                            RC_CHECK(); 
    16651665            rc = CFGMR3InsertNode(pGuest,    "Registry", &pRegistry);                      RC_CHECK(); 
     1666            /* Load the saved machine registry.  This is stored as extra data 
     1667             * keys in the machine XML file, starting with the prefix 
     1668             * VBOX_SHARED_INFO_KEY_PREFIX. */ 
     1669            Bstr strExtraDataKey; 
     1670            for (;;) 
     1671            { 
     1672                Bstr strNextExtraDataKey; 
     1673                Bstr strExtraDataValue; 
     1674         
     1675                /* get the next key */ 
     1676                hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(), 
     1677                                                    strExtraDataValue.asOutParam()); 
     1678         
     1679                /* stop if for some reason there's nothing more to request */ 
     1680                if (FAILED(hrc) || !strNextExtraDataKey) 
     1681                    break; 
     1682         
     1683                strExtraDataKey = strNextExtraDataKey; 
     1684                Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey); 
     1685         
     1686                /* we only care about keys starting with VBOX_SHARED_INFO_KEY_PREFIX */ 
     1687                if (strncmp(strExtraDataKeyUtf8.raw(), VBOX_SHARED_INFO_KEY_PREFIX, VBOX_SHARED_INFO_PREFIX_LEN) != 0) 
     1688                    continue; 
     1689                char *pszCFGMValueName = (char*)strExtraDataKeyUtf8.raw() + VBOX_SHARED_INFO_PREFIX_LEN; 
     1690         
     1691                /* now let's have a look at the value */ 
     1692                Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue); 
     1693                const char *pszCFGMValue = strCFGMValueUtf8.raw(); 
     1694                /* empty value means remove value which we've already done */ 
     1695                if (pszCFGMValue && *pszCFGMValue) 
     1696                { 
     1697                    rc = CFGMR3InsertString(pRegistry, pszCFGMValueName, pszCFGMValue); 
     1698                    AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszCFGMValueName)); 
     1699                } 
     1700            } 
     1701 
    16661702            /* Setup the service. */ 
    16671703            VBOXHGCMSVCPARM parm; 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy