VirtualBox

Changeset 26156 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 2, 2010 4:30:28 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
57170
Message:

Main: get rid of isReallyChanged() voodoo in Machine and subclasses; instead check in the XML classes whether things really changed via operator==; documentation, cleanup

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/AudioAdapterImpl.cpp

    r26088 r26156  
    420420}
    421421
    422 bool AudioAdapter::isReallyModified()
    423 {
    424     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    425     return mData.hasActualChanges();
    426 }
    427 
    428422/**
    429423 *  @note Locks this object for writing.
  • trunk/src/VBox/Main/BIOSSettingsImpl.cpp

    r26046 r26156  
    525525    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    526526    return m->bd.isBackedUp();
    527 }
    528 
    529 bool BIOSSettings::isReallyModified()
    530 {
    531     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    532     return m->bd.hasActualChanges();
    533527}
    534528
  • trunk/src/VBox/Main/MachineImpl.cpp

    r26088 r26156  
    70357035    ensureNoStateDependencies();
    70367036
    7037     AssertReturn(getClassID() == clsidMachine || getClassID() == clsidSessionMachine, E_FAIL);
    7038 
    7039     BOOL currentStateModified = mData->mCurrentStateModified;
    7040     bool settingsModified;
    7041 
    7042     if (!(aFlags & SaveS_ResetCurStateModified) && !currentStateModified)
    7043     {
    7044         /* We ignore changes to user data when setting mCurrentStateModified
    7045          * because the current state will not differ from the current snapshot
    7046          * if only user data has been changed (user data is shared by all
    7047          * snapshots). */
    7048         currentStateModified = isReallyModified (true /* aIgnoreUserData */);
    7049         settingsModified = mUserData.hasActualChanges() || currentStateModified;
    7050     }
    7051     else
    7052     {
    7053         if (aFlags & SaveS_ResetCurStateModified)
    7054             currentStateModified = FALSE;
    7055         settingsModified = isReallyModified();
    7056     }
     7037    AssertReturn(    getClassID() == clsidMachine
     7038                  || getClassID() == clsidSessionMachine,
     7039                 E_FAIL);
    70577040
    70587041    HRESULT rc = S_OK;
     7042    bool fNeedsWrite = false;
    70597043
    70607044    /* First, prepare to save settings. It will care about renaming the
    70617045     * settings directory and file if the machine name was changed and about
    70627046     * creating a new settings file if this is a new machine. */
    7063     bool isRenamed = false;
    7064     bool isNew = false;
    7065     rc = prepareSaveSettings(isRenamed, isNew);
     7047    bool fIsRenamed = false;
     7048    bool fIsNew = false;
     7049    rc = prepareSaveSettings(fIsRenamed, fIsNew);
    70667050    if (FAILED(rc)) return rc;
    70677051
     7052    // keep a pointer to the current settings structures
     7053    settings::MachineConfigFile *pOldConfig = mData->m_pMachineConfigFile;
     7054
    70687055    try
    70697056    {
     7057        // make a fresh one to have everyone write stuff into
     7058        mData->m_pMachineConfigFile = new settings::MachineConfigFile(NULL);
     7059        mData->m_pMachineConfigFile->copyBaseFrom(*pOldConfig);
     7060
     7061        // deep copy extradata
     7062        mData->m_pMachineConfigFile->mapExtraDataItems = pOldConfig->mapExtraDataItems;
     7063
    70707064        mData->m_pMachineConfigFile->uuid = mData->mUuid;
    70717065        mData->m_pMachineConfigFile->strName = mUserData->mName;
     
    70997093
    71007094        mData->m_pMachineConfigFile->strSnapshotFolder = mUserData->mSnapshotFolder;
    7101         mData->m_pMachineConfigFile->fCurrentStateModified = !!currentStateModified;
     7095        // mData->m_pMachineConfigFile->fCurrentStateModified is special, see below
    71027096        mData->m_pMachineConfigFile->timeLastStateChange = mData->mLastStateChange;
    71037097        mData->m_pMachineConfigFile->fAborted = (mData->mMachineState == MachineState_Aborted);
     
    71217115        if (FAILED(rc)) throw rc;
    71227116
    7123         // now spit it all out
    7124         mData->m_pMachineConfigFile->write(mData->m_strConfigFileFull);
     7117        if (aFlags & SaveS_ResetCurStateModified)
     7118        {
     7119            // this gets set by restoreSnapshot()
     7120            mData->mCurrentStateModified = FALSE;
     7121            fNeedsWrite = true;     // always, no need to compare
     7122        }
     7123        else
     7124        {
     7125            if (!mData->mCurrentStateModified)
     7126            {
     7127                // do a deep compare of the settings that we just saved with the settings
     7128                // previously stored in the config file; this invokes MachineConfigFile::operator==
     7129                // which does a deep compare of all the settings, which is expensive but less expensive
     7130                // than writing out XML in vain
     7131                bool fAnySettingsChanged = (*mData->m_pMachineConfigFile == *pOldConfig);
     7132
     7133                // could still be modified if any settings changed
     7134                mData->mCurrentStateModified = fAnySettingsChanged;
     7135
     7136                fNeedsWrite = fAnySettingsChanged;
     7137            }
     7138            else
     7139                fNeedsWrite = true;
     7140        }
     7141
     7142        mData->m_pMachineConfigFile->fCurrentStateModified = !!mData->mCurrentStateModified;
     7143
     7144        if (fNeedsWrite)
     7145            // now spit it all out!
     7146            mData->m_pMachineConfigFile->write(mData->m_strConfigFileFull);
    71257147    }
    71267148    catch (HRESULT err)
    71277149    {
    7128         /* we assume that error info is set by the thrower */
     7150        // we assume that error info is set by the thrower
    71297151        rc = err;
     7152
     7153        // restore old config
     7154        delete mData->m_pMachineConfigFile;
     7155        mData->m_pMachineConfigFile = pOldConfig;
    71307156    }
    71317157    catch (...)
     
    71377163    {
    71387164        commit();
    7139 
    7140         /* memorize the new modified state */
    7141         mData->mCurrentStateModified = currentStateModified;
    7142     }
    7143 
    7144     if (settingsModified || (aFlags & SaveS_InformCallbacksAnyway))
     7165        delete pOldConfig;
     7166    }
     7167
     7168    if (fNeedsWrite || (aFlags & SaveS_InformCallbacksAnyway))
    71457169    {
    71467170        /* Fire the data change event, even on failure (since we've already
     
    82368260        (mUSBController && mUSBController->isModified()) ||
    82378261        (mBIOSSettings && mBIOSSettings->isModified());
    8238 }
    8239 
    8240 /**
    8241  * Returns the logical OR of data.hasActualChanges() of this and all child
    8242  * objects.
    8243  *
    8244  * @param aIgnoreUserData       @c true to ignore changes to mUserData
    8245  *
    8246  * @note Locks objects for reading!
    8247  */
    8248 bool Machine::isReallyModified (bool aIgnoreUserData /* = false */)
    8249 {
    8250     AutoCaller autoCaller(this);
    8251     AssertComRCReturn (autoCaller.rc(), false);
    8252 
    8253     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    8254 
    8255     for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); slot ++)
    8256         if (mNetworkAdapters [slot] && mNetworkAdapters [slot]->isReallyModified())
    8257             return true;
    8258 
    8259     for (ULONG slot = 0; slot < RT_ELEMENTS (mSerialPorts); slot ++)
    8260         if (mSerialPorts [slot] && mSerialPorts [slot]->isReallyModified())
    8261             return true;
    8262 
    8263     for (ULONG slot = 0; slot < RT_ELEMENTS (mParallelPorts); slot ++)
    8264         if (mParallelPorts [slot] && mParallelPorts [slot]->isReallyModified())
    8265             return true;
    8266 
    8267     if (!mStorageControllers.isBackedUp())
    8268     {
    8269         /* see whether any of the devices has changed its data */
    8270         for (StorageControllerList::const_iterator
    8271              it = mStorageControllers->begin();
    8272              it != mStorageControllers->end();
    8273              ++it)
    8274         {
    8275             if ((*it)->isReallyModified())
    8276                 return true;
    8277         }
    8278     }
    8279     else
    8280     {
    8281         if (mStorageControllers->size() != mStorageControllers.backedUpData()->size())
    8282             return true;
    8283     }
    8284 
    8285     return
    8286         (!aIgnoreUserData && mUserData.hasActualChanges()) ||
    8287         mHWData.hasActualChanges() ||
    8288         mMediaData.hasActualChanges() ||
    8289         mStorageControllers.hasActualChanges() ||
    8290 #ifdef VBOX_WITH_VRDP
    8291         (mVRDPServer && mVRDPServer->isReallyModified()) ||
    8292 #endif
    8293         (mAudioAdapter && mAudioAdapter->isReallyModified()) ||
    8294         (mUSBController && mUSBController->isReallyModified()) ||
    8295         (mBIOSSettings && mBIOSSettings->isReallyModified());
    82968262}
    82978263
  • trunk/src/VBox/Main/ParallelPortImpl.cpp

    r26046 r26156  
    458458}
    459459
    460 bool ParallelPort::isReallyModified()
    461 {
    462     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    463     return m->bd.hasActualChanges();
    464 }
    465 
    466460/**
    467461 *  @note Locks this object for writing.
  • trunk/src/VBox/Main/SerialPortImpl.cpp

    r26046 r26156  
    571571}
    572572
    573 bool SerialPort::isReallyModified()
    574 {
    575     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    576     return m->bd.hasActualChanges();
    577 }
    578 
    579573/**
    580574 *  @note Locks this object for writing.
  • trunk/src/VBox/Main/StorageControllerImpl.cpp

    r26046 r26156  
    721721}
    722722
    723 bool StorageController::isReallyModified()
    724 {
    725     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    726     return m->bd.hasActualChanges();
    727 }
    728 
    729723/** @note Locks objects for writing! */
    730724bool StorageController::rollback()
  • trunk/src/VBox/Main/USBControllerImpl.cpp

    r26084 r26156  
    738738}
    739739
    740 /** @note Locks objects for reading! */
    741 bool USBController::isReallyModified()
    742 {
    743     AutoCaller autoCaller(this);
    744     AssertComRCReturn (autoCaller.rc(), false);
    745 
    746     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    747 
    748     if (m->bd.hasActualChanges())
    749         return true;
    750 
    751 #ifdef VBOX_WITH_USB
    752     if (!m->llDeviceFilters.isBackedUp())
    753     {
    754         /* see whether any of filters has changed its data */
    755         for (DeviceFilterList::const_iterator
    756              it = m->llDeviceFilters->begin();
    757              it != m->llDeviceFilters->end();
    758              ++ it)
    759         {
    760             if ((*it)->isReallyModified())
    761                 return true;
    762         }
    763 
    764         return false;
    765     }
    766 
    767     if (m->llDeviceFilters->size() != m->llDeviceFilters.backedUpData()->size())
    768         return true;
    769 
    770     if (m->llDeviceFilters->size() == 0)
    771         return false;
    772 
    773     /* Make copies to speed up comparison */
    774     DeviceFilterList devices = *m->llDeviceFilters.data();
    775     DeviceFilterList backDevices = *m->llDeviceFilters.backedUpData();
    776 
    777     DeviceFilterList::iterator it = devices.begin();
    778     while (it != devices.end())
    779     {
    780         bool found = false;
    781         DeviceFilterList::iterator thatIt = backDevices.begin();
    782         while (thatIt != backDevices.end())
    783         {
    784             if ((*it)->getData() == (*thatIt)->getData())
    785             {
    786                 backDevices.erase (thatIt);
    787                 found = true;
    788                 break;
    789             }
    790             else
    791                 ++ thatIt;
    792         }
    793         if (found)
    794             it = devices.erase (it);
    795         else
    796             return false;
    797     }
    798 
    799     Assert (devices.size() == 0 && backDevices.size() == 0);
    800 #endif /* VBOX_WITH_USB */
    801 
    802     return false;
    803 }
    804 
    805740/** @note Locks objects for writing! */
    806741bool USBController::rollback()
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r26042 r26156  
    4848#include <algorithm>
    4949#include <set>
     50#include <vector>
    5051#include <memory> // for auto_ptr
    5152
  • trunk/src/VBox/Main/include/AudioAdapterImpl.h

    r26088 r26156  
    9393
    9494    bool isModified();
    95     bool isReallyModified();
    9695    bool rollback();
    9796    void commit();
  • trunk/src/VBox/Main/include/BIOSSettingsImpl.h

    r26044 r26156  
    8585
    8686    bool isModified();
    87     bool isReallyModified();
    8887    void rollback();
    8988    void commit();
  • trunk/src/VBox/Main/include/MachineImpl.h

    r26046 r26156  
    746746
    747747    bool isModified();
    748     bool isReallyModified(bool aIgnoreUserData = false);
    749748    void rollback(bool aNotify);
    750749    void commit();
  • trunk/src/VBox/Main/include/NetworkAdapterImpl.h

    r26044 r26156  
    140140
    141141    bool isModified() { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); return mData.isBackedUp(); }
    142     bool isReallyModified() { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); return mData.hasActualChanges(); }
    143142    bool rollback();
    144143    void commit();
  • trunk/src/VBox/Main/include/ParallelPortImpl.h

    r26044 r26156  
    7979
    8080    bool isModified();
    81     bool isReallyModified();
    8281    bool rollback();
    8382    void commit();
  • trunk/src/VBox/Main/include/SerialPortImpl.h

    r26044 r26156  
    8585
    8686    bool isModified();
    87     bool isReallyModified();
    8887    bool rollback();
    8988    void commit();
  • trunk/src/VBox/Main/include/StorageControllerImpl.h

    r26044 r26156  
    9090
    9191    bool isModified();
    92     bool isReallyModified();
    9392    bool rollback();
    9493    void commit();
  • trunk/src/VBox/Main/include/USBControllerImpl.h

    r26044 r26156  
    8484
    8585    bool isModified();
    86     bool isReallyModified();
    8786    bool rollback();
    8887    void commit();
  • trunk/src/VBox/Main/include/VRDPServerImpl.h

    r26044 r26156  
    112112
    113113    bool isModified() { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); return mData.isBackedUp(); }
    114     bool isReallyModified() { AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); return mData.hasActualChanges(); }
    115114    bool rollback();
    116115    void commit();
  • trunk/src/VBox/Main/xml/Settings.cpp

    r26043 r26156  
    147147                                                        // or SettingsVersion_Null if none
    148148
     149    void copyFrom(const Data &d)
     150    {
     151        strFilename = d.strFilename;
     152        fFileExists = d.fFileExists;
     153        strSettingsVersionFull = d.strSettingsVersionFull;
     154        sv = d.sv;
     155        svRead = d.svRead;
     156    }
     157
    149158    void cleanup()
    150159    {
     
    704713}
    705714
     715/**
     716 * Copies the base variables from another instance. Used by Machine::saveSettings
     717 * so that the settings version does not get lost when a copy of the Machine settings
     718 * file is made to see if settings have actually changed.
     719 * @param b
     720 */
     721void ConfigFileBase::copyBaseFrom(const ConfigFileBase &b)
     722{
     723    m->copyFrom(*b.m);
     724}
     725
     726////////////////////////////////////////////////////////////////////////////////
     727//
     728// Structures shared between Machine XML and VirtualBox.xml
     729//
     730////////////////////////////////////////////////////////////////////////////////
     731
     732/**
     733 * Comparison operator. This gets called from MachineConfigFile::operator==,
     734 * which in turn gets called from Machine::saveSettings to figure out whether
     735 * machine settings have really changed and thus need to be written out to disk.
     736 */
     737bool USBDeviceFilter::operator==(const USBDeviceFilter &u) const
     738{
     739    return (    (this == &u)
     740             || (    (strName           == u.strName)
     741                  && (fActive           == u.fActive)
     742                  && (strVendorId       == u.strVendorId)
     743                  && (strProductId      == u.strProductId)
     744                  && (strRevision       == u.strRevision)
     745                  && (strManufacturer   == u.strManufacturer)
     746                  && (strProduct        == u.strProduct)
     747                  && (strSerialNumber   == u.strSerialNumber)
     748                  && (strPort           == u.strPort)
     749                  && (action            == u.action)
     750                  && (strRemote         == u.strRemote)
     751                  && (ulMaskedInterfaces == u.ulMaskedInterfaces)
     752                )
     753           );
     754}
    706755
    707756////////////////////////////////////////////////////////////////////////////////
     
    12421291}
    12431292
     1293////////////////////////////////////////////////////////////////////////////////
     1294//
     1295// Machine XML structures
     1296//
     1297////////////////////////////////////////////////////////////////////////////////
     1298
     1299/**
     1300 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1301 * which in turn gets called from Machine::saveSettings to figure out whether
     1302 * machine settings have really changed and thus need to be written out to disk.
     1303 */
     1304bool VRDPSettings::operator==(const VRDPSettings& v) const
     1305{
     1306    return (    (this == &v)
     1307             || (    (fEnabled                  == v.fEnabled)
     1308                  && (strPort                   == v.strPort)
     1309                  && (strNetAddress             == v.strNetAddress)
     1310                  && (authType                  == v.authType)
     1311                  && (ulAuthTimeout             == v.ulAuthTimeout)
     1312                  && (fAllowMultiConnection     == v.fAllowMultiConnection)
     1313                  && (fReuseSingleConnection    == v.fReuseSingleConnection)
     1314                )
     1315           );
     1316}
     1317
     1318/**
     1319 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1320 * which in turn gets called from Machine::saveSettings to figure out whether
     1321 * machine settings have really changed and thus need to be written out to disk.
     1322 */
     1323bool BIOSSettings::operator==(const BIOSSettings &d) const
     1324{
     1325    return (    (this == &d)
     1326             || (    fACPIEnabled        == d.fACPIEnabled
     1327                  && fIOAPICEnabled      == d.fIOAPICEnabled
     1328                  && fLogoFadeIn         == d.fLogoFadeIn
     1329                  && fLogoFadeOut        == d.fLogoFadeOut
     1330                  && ulLogoDisplayTime   == d.ulLogoDisplayTime
     1331                  && strLogoImagePath    == d.strLogoImagePath
     1332                  && biosBootMenuMode    == d.biosBootMenuMode
     1333                  && fPXEDebugEnabled    == d.fPXEDebugEnabled
     1334                  && llTimeOffset        == d.llTimeOffset)
     1335           );
     1336}
     1337
     1338/**
     1339 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1340 * which in turn gets called from Machine::saveSettings to figure out whether
     1341 * machine settings have really changed and thus need to be written out to disk.
     1342 */
     1343bool USBController::operator==(const USBController &u) const
     1344{
     1345    return (    (this == &u)
     1346                 || (    (fEnabled          == u.fEnabled)
     1347                      && (fEnabledEHCI      == u.fEnabledEHCI)
     1348                      && (llDeviceFilters   == u.llDeviceFilters)
     1349                    )
     1350           );
     1351}
     1352
     1353/**
     1354 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1355 * which in turn gets called from Machine::saveSettings to figure out whether
     1356 * machine settings have really changed and thus need to be written out to disk.
     1357 */
     1358bool NetworkAdapter::operator==(const NetworkAdapter &n) const
     1359{
     1360    return (    (this == &n)
     1361             || (    (ulSlot            == n.ulSlot)
     1362                  && (type              == n.type)
     1363                  && (fEnabled          == n.fEnabled)
     1364                  && (strMACAddress     == n.strMACAddress)
     1365                  && (fCableConnected   == n.fCableConnected)
     1366                  && (ulLineSpeed       == n.ulLineSpeed)
     1367                  && (fTraceEnabled     == n.fTraceEnabled)
     1368                  && (strTraceFile      == n.strTraceFile)
     1369                  && (mode              == n.mode)
     1370                  && (strName           == n.strName)
     1371                )
     1372           );
     1373}
     1374
     1375/**
     1376 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1377 * which in turn gets called from Machine::saveSettings to figure out whether
     1378 * machine settings have really changed and thus need to be written out to disk.
     1379 */
     1380bool SerialPort::operator==(const SerialPort &s) const
     1381{
     1382    return (    (this == &s)
     1383             || (    (ulSlot            == s.ulSlot)
     1384                  && (fEnabled          == s.fEnabled)
     1385                  && (ulIOBase          == s.ulIOBase)
     1386                  && (ulIRQ             == s.ulIRQ)
     1387                  && (portMode          == s.portMode)
     1388                  && (strPath           == s.strPath)
     1389                  && (fServer           == s.fServer)
     1390                )
     1391           );
     1392}
     1393
     1394/**
     1395 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1396 * which in turn gets called from Machine::saveSettings to figure out whether
     1397 * machine settings have really changed and thus need to be written out to disk.
     1398 */
     1399bool ParallelPort::operator==(const ParallelPort &s) const
     1400{
     1401    return (    (this == &s)
     1402             || (    (ulSlot            == s.ulSlot)
     1403                  && (fEnabled          == s.fEnabled)
     1404                  && (ulIOBase          == s.ulIOBase)
     1405                  && (ulIRQ             == s.ulIRQ)
     1406                  && (strPath           == s.strPath)
     1407                )
     1408           );
     1409}
     1410
     1411/**
     1412 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1413 * which in turn gets called from Machine::saveSettings to figure out whether
     1414 * machine settings have really changed and thus need to be written out to disk.
     1415 */
     1416bool SharedFolder::operator==(const SharedFolder &g) const
     1417{
     1418    return (    (this == &g)
     1419             || (    (strName       == g.strName)
     1420                  && (strHostPath   == g.strHostPath)
     1421                  && (fWritable     == g.fWritable)
     1422                )
     1423           );
     1424}
     1425
     1426/**
     1427 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1428 * which in turn gets called from Machine::saveSettings to figure out whether
     1429 * machine settings have really changed and thus need to be written out to disk.
     1430 */
     1431bool GuestProperty::operator==(const GuestProperty &g) const
     1432{
     1433    return (    (this == &g)
     1434             || (    (strName           == g.strName)
     1435                  && (strValue          == g.strValue)
     1436                  && (timestamp         == g.timestamp)
     1437                  && (strFlags          == g.strFlags)
     1438                )
     1439           );
     1440}
     1441
    12441442// use a define for the platform-dependent default value of
    12451443// hwvirt exclusivity, since we'll need to check that value
     
    12851483    fPAE = true;
    12861484#endif
     1485}
     1486
     1487/**
     1488 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1489 * which in turn gets called from Machine::saveSettings to figure out whether
     1490 * machine settings have really changed and thus need to be written out to disk.
     1491 */
     1492bool Hardware::operator==(const Hardware& h) const
     1493{
     1494    return (    (this == &h)
     1495             || (    (strVersion                == h.strVersion)
     1496                  && (uuid                      == h.uuid)
     1497                  && (fHardwareVirt             == h.fHardwareVirt)
     1498                  && (fHardwareVirtExclusive    == h.fHardwareVirtExclusive)
     1499                  && (fNestedPaging             == h.fNestedPaging)
     1500                  && (fVPID                     == h.fVPID)
     1501                  && (fSyntheticCpu             == h.fSyntheticCpu)
     1502                  && (fPAE                      == h.fPAE)
     1503                  && (cCPUs                     == h.cCPUs)
     1504                  && (fCpuHotPlug               == h.fCpuHotPlug)
     1505                  && (llCpus                    == h.llCpus)
     1506                  && (llCpuIdLeafs              == h.llCpuIdLeafs)
     1507                  && (ulMemorySizeMB            == h.ulMemorySizeMB)
     1508                  && (mapBootOrder              == h.mapBootOrder)
     1509                  && (ulVRAMSizeMB              == h.ulVRAMSizeMB)
     1510                  && (cMonitors                 == h.cMonitors)
     1511                  && (fAccelerate3D             == h.fAccelerate3D)
     1512                  && (fAccelerate2DVideo        == h.fAccelerate2DVideo)
     1513                  && (firmwareType              == h.firmwareType)
     1514                  && (vrdpSettings              == h.vrdpSettings)
     1515                  && (biosSettings              == h.biosSettings)
     1516                  && (usbController             == h.usbController)
     1517                  && (llNetworkAdapters         == h.llNetworkAdapters)
     1518                  && (llSerialPorts             == h.llSerialPorts)
     1519                  && (llParallelPorts           == h.llParallelPorts)
     1520                  && (audioAdapter              == h.audioAdapter)
     1521                  && (llSharedFolders           == h.llSharedFolders)
     1522                  && (clipboardMode             == h.clipboardMode)
     1523                  && (ulMemoryBalloonSize       == h.ulMemoryBalloonSize)
     1524                  && (ulStatisticsUpdateInterval == h.ulStatisticsUpdateInterval)
     1525                  && (llGuestProperties         == h.llGuestProperties)
     1526                  && (strNotificationPatterns   == h.strNotificationPatterns)
     1527                )
     1528            );
     1529}
     1530
     1531/**
     1532 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1533 * which in turn gets called from Machine::saveSettings to figure out whether
     1534 * machine settings have really changed and thus need to be written out to disk.
     1535 */
     1536bool AttachedDevice::operator==(const AttachedDevice &a) const
     1537{
     1538    return (    (this == &a)
     1539             || (    (deviceType                == a.deviceType)
     1540                  && (fPassThrough              == a.fPassThrough)
     1541                  && (lPort                     == a.lPort)
     1542                  && (lDevice                   == a.lDevice)
     1543                  && (uuid                      == a.uuid)
     1544                  && (strHostDriveSrc           == a.strHostDriveSrc)
     1545                )
     1546           );
     1547}
     1548
     1549/**
     1550 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1551 * which in turn gets called from Machine::saveSettings to figure out whether
     1552 * machine settings have really changed and thus need to be written out to disk.
     1553 */
     1554bool StorageController::operator==(const StorageController &s) const
     1555{
     1556    return (    (this == &s)
     1557             || (    (strName                   == s.strName)
     1558                  && (storageBus                == s.storageBus)
     1559                  && (controllerType            == s.controllerType)
     1560                  && (ulPortCount               == s.ulPortCount)
     1561                  && (ulInstance                == s.ulInstance)
     1562                  && (lIDE0MasterEmulationPort  == s.lIDE0MasterEmulationPort)
     1563                  && (lIDE0SlaveEmulationPort   == s.lIDE0SlaveEmulationPort)
     1564                  && (lIDE1MasterEmulationPort  == s.lIDE1MasterEmulationPort)
     1565                  && (lIDE1SlaveEmulationPort   == s.lIDE1SlaveEmulationPort)
     1566                  && (llAttachedDevices         == s.llAttachedDevices)
     1567                )
     1568           );
     1569}
     1570
     1571/**
     1572 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1573 * which in turn gets called from Machine::saveSettings to figure out whether
     1574 * machine settings have really changed and thus need to be written out to disk.
     1575 */
     1576bool Storage::operator==(const Storage &s) const
     1577{
     1578    return (    (this == &s)
     1579             || (llStorageControllers == s.llStorageControllers)            // deep compare
     1580           );
     1581}
     1582
     1583/**
     1584 * Comparison operator. This gets called from MachineConfigFile::operator==,
     1585 * which in turn gets called from Machine::saveSettings to figure out whether
     1586 * machine settings have really changed and thus need to be written out to disk.
     1587 */
     1588bool Snapshot::operator==(const Snapshot &s) const
     1589{
     1590    return (    (this == &s)
     1591             || (    (uuid                  == s.uuid)
     1592                  && (strName               == s.strName)
     1593                  && (strDescription        == s.strDescription)
     1594                  && (RTTimeSpecIsEqual(&timestamp, &s.timestamp))
     1595                  && (strStateFile          == s.strStateFile)
     1596                  && (hardware              == s.hardware)                  // deep compare
     1597                  && (storage               == s.storage)                   // deep compare
     1598                  && (llChildSnapshots      == s.llChildSnapshots)          // deep compare
     1599                )
     1600           );
     1601}
     1602
     1603////////////////////////////////////////////////////////////////////////////////
     1604//
     1605// MachineConfigFile
     1606//
     1607////////////////////////////////////////////////////////////////////////////////
     1608
     1609/**
     1610 * Constructor.
     1611 *
     1612 * If pstrFilename is != NULL, this reads the given settings file into the member
     1613 * variables and various substructures and lists. Otherwise, the member variables
     1614 * are initialized with default values.
     1615 *
     1616 * Throws variants of xml::Error for I/O, XML and logical content errors, which
     1617 * the caller should catch; if this constructor does not throw, then the member
     1618 * variables contain meaningful values (either from the file or defaults).
     1619 *
     1620 * @param strFilename
     1621 */
     1622MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename)
     1623    : ConfigFileBase(pstrFilename),
     1624      fNameSync(true),
     1625      fTeleporterEnabled(false),
     1626      uTeleporterPort(0),
     1627      fRTCUseUTC(false),
     1628      fCurrentStateModified(true),
     1629      fAborted(false)
     1630{
     1631    RTTimeNow(&timeLastStateChange);
     1632
     1633    if (pstrFilename)
     1634    {
     1635        // the ConfigFileBase constructor has loaded the XML file, so now
     1636        // we need only analyze what is in there
     1637
     1638        xml::NodesLoop nlRootChildren(*m->pelmRoot);
     1639        const xml::ElementNode *pelmRootChild;
     1640        while ((pelmRootChild = nlRootChildren.forAllNodes()))
     1641        {
     1642            if (pelmRootChild->nameEquals("Machine"))
     1643                readMachine(*pelmRootChild);
     1644        }
     1645
     1646        // clean up memory allocated by XML engine
     1647        clearDocument();
     1648    }
     1649}
     1650
     1651/**
     1652 * Comparison operator. This gets called from Machine::saveSettings to figure out
     1653 * whether machine settings have really changed and thus need to be written out to disk.
     1654 *
     1655 * Even though this is called operator==, this does NOT compare all fields; the "equals"
     1656 * should be understood as "has the same machine config as". The following fields are
     1657 * NOT compared:
     1658 *      -- settings versions and file names inherited from ConfigFileBase;
     1659 *      -- fCurrentStateModified because that is considered separately in Machine::saveSettings!!
     1660 *
     1661 * The "deep" comparisons marked below will invoke the operator== functions of the
     1662 * structs defined in this file, which may in turn go into comparing lists of
     1663 * other structures. As a result, invoking this can be expensive, but it's
     1664 * less expensive than writing out XML to disk.
     1665 */
     1666bool MachineConfigFile::operator==(const MachineConfigFile &c) const
     1667{
     1668    return (    (this == &c)
     1669            || (    (uuid                       == c.uuid)
     1670                 && (strName                    == c.strName)
     1671                 && (fNameSync                  == c.fNameSync)
     1672                 && (strDescription             == c.strDescription)
     1673                 && (strOsType                  == c.strOsType)
     1674                 && (strStateFile               == c.strStateFile)
     1675                 && (uuidCurrentSnapshot        == c.uuidCurrentSnapshot)
     1676                 && (strSnapshotFolder          == c.strSnapshotFolder)
     1677                 && (fTeleporterEnabled         == c.fTeleporterEnabled)
     1678                 && (uTeleporterPort            == c.uTeleporterPort)
     1679                 && (strTeleporterAddress       == c.strTeleporterAddress)
     1680                 && (strTeleporterPassword      == c.strTeleporterPassword)
     1681                 && (fRTCUseUTC                 == c.fRTCUseUTC)
     1682                 // skip fCurrentStateModified!
     1683                 && (RTTimeSpecIsEqual(&timeLastStateChange, &c.timeLastStateChange))
     1684                 && (fAborted                   == c.fAborted)
     1685                 && (hardwareMachine            == c.hardwareMachine)       // this one's deep
     1686                 && (storageMachine             == c.storageMachine)        // this one's deep
     1687                 && (mapExtraDataItems          == c.mapExtraDataItems)     // this one's deep
     1688                 && (llFirstSnapshot            == c.llFirstSnapshot)       // this one's deep
     1689               )
     1690           );
    12871691}
    12881692
     
    24172821}
    24182822
    2419 ////////////////////////////////////////////////////////////////////////////////
    2420 //
    2421 // MachineConfigFile
    2422 //
    2423 ////////////////////////////////////////////////////////////////////////////////
    2424 
    2425 /**
    2426  * Constructor.
    2427  *
    2428  * If pstrFilename is != NULL, this reads the given settings file into the member
    2429  * variables and various substructures and lists. Otherwise, the member variables
    2430  * are initialized with default values.
    2431  *
    2432  * Throws variants of xml::Error for I/O, XML and logical content errors, which
    2433  * the caller should catch; if this constructor does not throw, then the member
    2434  * variables contain meaningful values (either from the file or defaults).
    2435  *
    2436  * @param strFilename
    2437  */
    2438 MachineConfigFile::MachineConfigFile(const Utf8Str *pstrFilename)
    2439     : ConfigFileBase(pstrFilename),
    2440       fNameSync(true),
    2441       fTeleporterEnabled(false),
    2442       uTeleporterPort(0),
    2443       fRTCUseUTC(false),
    2444       fCurrentStateModified(true),
    2445       fAborted(false)
    2446 {
    2447     RTTimeNow(&timeLastStateChange);
    2448 
    2449     if (pstrFilename)
    2450     {
    2451         // the ConfigFileBase constructor has loaded the XML file, so now
    2452         // we need only analyze what is in there
    2453 
    2454         xml::NodesLoop nlRootChildren(*m->pelmRoot);
    2455         const xml::ElementNode *pelmRootChild;
    2456         while ((pelmRootChild = nlRootChildren.forAllNodes()))
    2457         {
    2458             if (pelmRootChild->nameEquals("Machine"))
    2459                 readMachine(*pelmRootChild);
    2460         }
    2461 
    2462         // clean up memory allocated by XML engine
    2463         clearDocument();
    2464     }
    2465 }
    2466 
    24672823/**
    24682824 * Creates a <Hardware> node under elmParent and then writes out the XML
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