VirtualBox

Changeset 14698 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 27, 2008 12:04:44 PM (16 years ago)
Author:
vboxsync
Message:

Main: HardDisks: Added saving/loading properties from XML.

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

Legend:

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

    r14697 r14698  
    626626    CheckComRCReturnRC (rc);
    627627
     628    /* properties (note: after setting the format as it populates the map) */
     629    Key::List properties = aNode.keys ("Property");
     630    for (Key::List::const_iterator it = properties.begin();
     631         it != properties.end(); ++ it)
     632    {
     633        mm.properties [Bstr (it->stringValue ("name"))] =
     634            Bstr (it->stringValue ("value"));
     635    }
     636
    628637    /* required */
    629638    Bstr location = aNode.stringValue ("location");
     
    947956    CheckComArgStrNotEmptyOrNull (aName);
    948957
    949     AutoWriteLock alock (this);
     958    /* VirtualBox::saveSettings() needs a write lock */
     959    AutoMultiWriteLock2 alock (mVirtualBox, this);
     960
     961    switch (m.state)
     962    {
     963        case MediaState_Created:
     964        case MediaState_Inaccessible:
     965            break;
     966        default:
     967            return setStateError();
     968    }
    950969
    951970    Data::PropertyMap::iterator it = mm.properties.find (Bstr (aName));
     
    956975    it->second = aValue;
    957976
    958     return S_OK;
     977    HRESULT rc = mVirtualBox->saveSettings();
     978
     979    return rc;
    959980}
    960981
     
    970991
    971992    AutoReadLock alock (this);
     993
     994    /// @todo make use of aNames according to the documentation
     995    NOREF (aNames);
    972996
    973997    com::SafeArray <BSTR> names (mm.properties.size());
     
    13391363        Key descNode = diskNode.createKey ("Description");
    13401364        descNode.setKeyValue <Bstr> (m.description);
     1365    }
     1366
     1367    /* optional properties */
     1368    for (Data::PropertyMap::const_iterator it = mm.properties.begin();
     1369         it != mm.properties.end(); ++ it)
     1370    {
     1371        /* only save properties that have non-default values */
     1372        if (!it->second.isNull())
     1373        {
     1374            Key propNode = diskNode.appendKey ("Property");
     1375            propNode.setValue <Bstr> ("name", it->first);
     1376            propNode.setValue <Bstr> ("value", it->second);
     1377        }
    13411378    }
    13421379
     
    23302367                  E_FAIL);
    23312368
    2332     /* are we dealing with a hard disk opened from the existing path? */
     2369    /* are we dealing with a hard disk just opened from the existing path? */
    23332370    bool isNew = mm.format.isNull();
    23342371
     
    24792516         * properties is meant to be constant. */
    24802517
    2481         mm.properties.clear();
     2518        Assert (mm.properties.empty());
    24822519
    24832520        for (HardDiskFormat::PropertyList::const_iterator it =
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r14596 r14698  
    641641                    printf (" <none>\n");
    642642
     643                Bstr name ("TargetAddress");
     644                Bstr value = Utf8StrFmt ("lalala (%llu)", RTTimeMilliTS());
     645
     646                printf ("Settings property %ls to %ls...\n", name.raw(), value.raw());
     647                CHECK_ERROR (hd, SetProperty (name, value));
    643648            }
    644649            else
  • trunk/src/VBox/Main/xml/VirtualBox-settings-common.xsd

    r14437 r14698  
    261261  <xsd:sequence>
    262262    <xsd:element name="Description" type="xsd:string" minOccurs="0"/>
     263    <xsd:element name="Property" minOccurs="0" maxOccurs="unbounded">
     264      <xsd:complexType>
     265        <xsd:attribute name="name" type="xsd:token" use="required"/>
     266        <xsd:attribute name="value" type="xsd:string" use="required"/>
     267      </xsd:complexType>
     268    </xsd:element>
    263269    <xsd:element name="HardDisk" type="TDiffHardDisk2" minOccurs="0" maxOccurs="unbounded"/>
    264270  </xsd:sequence>
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