VirtualBox

Changeset 17872 in vbox


Ignore:
Timestamp:
Mar 14, 2009 5:23:39 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
44426
Message:

partial dhcp settings impl

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

Legend:

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

    r17865 r17872  
    9292    "    <MachineRegistry/>"RTFILE_LINEFEED
    9393    "    <MediaRegistry/>"RTFILE_LINEFEED
     94    "    <NetserviceRegistry/>"RTFILE_LINEFEED
    9495    "    <USBDeviceFilters/>"RTFILE_LINEFEED
    9596    "    <SystemProperties/>"RTFILE_LINEFEED
     
    290291            CheckComRCThrowRC (rc);
    291292
     293            /* net services */
     294            rc = loadNetservices(global);
     295            CheckComRCThrowRC (rc);
     296
    292297            /* check hard disk consistency */
    293298/// @todo (r=dmik) add IVirtualBox::cleanupHardDisks() instead or similar
     
    31133118
    31143119/**
     3120 *  Reads in the network service registration entries from the global settings file
     3121 *  and creates the relevant objects.
     3122 *
     3123 *  @param aGlobal  <Global> node
     3124 *
     3125 *  @note Can be called only from #init().
     3126 *  @note Doesn't lock anything.
     3127 */
     3128HRESULT VirtualBox::loadNetservices (const settings::Key &aGlobal)
     3129{
     3130    using namespace settings;
     3131
     3132    AutoCaller autoCaller (this);
     3133    AssertReturn (autoCaller.state() == InInit, E_FAIL);
     3134
     3135    HRESULT rc = S_OK;
     3136
     3137    Key registry = aGlobal.findKey ("NetserviceRegistry");
     3138    if(registry.isNull())
     3139        return S_OK;
     3140
     3141    const char *kMediaNodes[] = { "DhcpServers" };
     3142
     3143    for (size_t n = 0; n < RT_ELEMENTS (kMediaNodes); ++ n)
     3144    {
     3145        /* All three media nodes are optional */
     3146        Key node = registry.findKey (kMediaNodes [n]);
     3147        if (node.isNull())
     3148            continue;
     3149
     3150        if (n == 0)
     3151        {
     3152            Key::List dhcpServers = node.keys ("DhcpServer");
     3153            for (Key::List::const_iterator it = dhcpServers.begin();
     3154                 it != dhcpServers.end(); ++ it)
     3155            {
     3156                ComObjPtr<DhcpServer> dhcpServer;
     3157                dhcpServer.createObject();
     3158                rc = dhcpServer->init (*it);
     3159                CheckComRCBreakRC (rc);
     3160
     3161                rc = registerDhcpServer(dhcpServer, false /* aSaveRegistry */);
     3162                CheckComRCBreakRC (rc);
     3163            }
     3164
     3165            continue;
     3166        }
     3167    }
     3168   return rc;
     3169}
     3170
     3171/**
    31153172 *  Helper function to write out the configuration tree.
    31163173 *
     
    32103267                {
    32113268                    rc = (*it)->saveSettings (imagesNode);
     3269                    CheckComRCThrowRC (rc);
     3270                }
     3271            }
     3272        }
     3273
     3274        /* netservices */
     3275        {
     3276            /* first, delete the entire netservice registry */
     3277            Key registryNode = global.findKey ("NetserviceRegistry");
     3278            if (!registryNode.isNull())
     3279                registryNode.zap();
     3280            /* then, recreate it */
     3281            registryNode = global.createKey ("NetserviceRegistry");
     3282
     3283            /* hard disks */
     3284            {
     3285                Key dhcpServersNode = registryNode.createKey ("DhcpServers");
     3286
     3287                for (DhcpServerList::const_iterator it =
     3288                        mData.mDhcpServers.begin();
     3289                     it != mData.mDhcpServers.end();
     3290                     ++ it)
     3291                {
     3292                    rc = (*it)->saveSettings (dhcpServersNode);
    32123293                    CheckComRCThrowRC (rc);
    32133294                }
     
    45924673}
    45934674
     4675/**
     4676 * Remembers the given dhcp server by storing it in the hard disk registry.
     4677 *
     4678 * @param aDhcpServer     Dhcp Server object to remember.
     4679 * @param aSaveRegistry @c true to save hard disk registry to disk (default).
     4680 *
     4681 * When @a aSaveRegistry is @c true, this operation may fail because of the
     4682 * failed #saveSettings() method it calls. In this case, the dhcp server object
     4683 * will not be remembered. It is therefore the responsibility of the caller to
     4684 * call this method as the last step of some action that requires registration
     4685 * in order to make sure that only fully functional dhcp server objects get
     4686 * registered.
     4687 *
     4688 * @note Locks this object for writing and @a aDhcpServer for reading.
     4689 */
     4690HRESULT VirtualBox::registerDhcpServer(DhcpServer *aDhcpServer,
     4691                                     bool aSaveRegistry /*= true*/)
     4692{
     4693    AssertReturn (aDhcpServer != NULL, E_INVALIDARG);
     4694
     4695    AutoCaller autoCaller (this);
     4696    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
     4697
     4698    AutoWriteLock alock (this);
     4699
     4700    AutoCaller dhcpServerCaller (aDhcpServer);
     4701    AssertComRCReturn (dhcpServerCaller.rc(), dhcpServerCaller.rc());
     4702
     4703    AutoReadLock dhcpServerLock (aDhcpServer);
     4704
     4705    Bstr name;
     4706    HRESULT rc;
     4707    rc = aDhcpServer->COMGETTER(NetworkName) (name.asOutParam());
     4708    CheckComRCReturnRC (rc);
     4709
     4710    ComPtr<IDhcpServer> existing;
     4711    rc = FindDhcpServerByName(name.mutableRaw(), existing.asOutParam());
     4712    CheckComRCReturnRC (rc);
     4713
     4714    mData.mDhcpServers.push_back (aDhcpServer);
     4715
     4716    if (aSaveRegistry)
     4717    {
     4718        rc = saveSettings();
     4719        if (FAILED (rc))
     4720            unregisterDhcpServer(aDhcpServer, false /* aSaveRegistry */);
     4721    }
     4722
     4723    return rc;
     4724}
     4725
     4726/**
     4727 * Removes the given hard disk from the hard disk registry.
     4728 *
     4729 * @param aHardDisk     Hard disk object to remove.
     4730 * @param aSaveRegistry @c true to save hard disk registry to disk (default).
     4731 *
     4732 * When @a aSaveRegistry is @c true, this operation may fail because of the
     4733 * failed #saveSettings() method it calls. In this case, the hard disk object
     4734 * will NOT be removed from the registry when this method returns. It is
     4735 * therefore the responsibility of the caller to call this method as the first
     4736 * step of some action that requires unregistration, before calling uninit() on
     4737 * @a aHardDisk.
     4738 *
     4739 * @note Locks this object for writing and @a aHardDisk for reading.
     4740 */
     4741HRESULT VirtualBox::unregisterDhcpServer(DhcpServer *aDhcpServer,
     4742                                       bool aSaveRegistry /*= true*/)
     4743{
     4744    AssertReturn (aDhcpServer != NULL, E_INVALIDARG);
     4745
     4746    AutoCaller autoCaller (this);
     4747    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
     4748
     4749    AutoWriteLock alock (this);
     4750
     4751    AutoCaller dhcpServerCaller (aDhcpServer);
     4752    AssertComRCReturn (dhcpServerCaller.rc(), dhcpServerCaller.rc());
     4753
     4754    AutoReadLock dhcpServerLock (aDhcpServer);
     4755
     4756    mData.mDhcpServers.remove (aDhcpServer);
     4757
     4758    HRESULT rc = S_OK;
     4759
     4760    if (aSaveRegistry)
     4761    {
     4762        rc = saveSettings();
     4763        if (FAILED (rc))
     4764            registerDhcpServer(aDhcpServer, false /* aSaveRegistry */);
     4765    }
     4766
     4767    return rc;
     4768}
     4769
    45944770/* vi: set tabstop=4 shiftwidth=4 expandtab: */
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r17868 r17872  
    12191219 
    12201220  <interface
    1221     name="IDhcpServer" extends="$dispatched"
     1221    name="IDhcpServer" extends="$unknown"
    12221222    uuid="f6de19f7-f4b5-4d93-b3de-664729267a53"
    12231223    wsmap="managed"
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r17865 r17872  
    5454class Host;
    5555class SystemProperties;
     56class DhcpServer;
    5657
    5758#ifdef RT_OS_WINDOWS
     
    372373    typedef std::list <ComObjPtr <FloppyImage> > FloppyImageList;
    373374    typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
     375    typedef std::list <ComObjPtr <DhcpServer> > DhcpServerList;
    374376
    375377    typedef std::map <Guid, ComObjPtr<HardDisk> > HardDiskMap;
     
    390392    HRESULT loadMachines (const settings::Key &aGlobal);
    391393    HRESULT loadMedia (const settings::Key &aGlobal);
     394    HRESULT loadNetservices (const settings::Key &aGlobal);
    392395
    393396    HRESULT registerMachine (Machine *aMachine);
     397
     398    HRESULT registerDhcpServer(DhcpServer *aDhcpServer,
     399                                         bool aSaveRegistry = true);
     400    HRESULT unregisterDhcpServer(DhcpServer *aDhcpServer,
     401                                         bool aSaveRegistry = true);
    394402
    395403    HRESULT lockConfig();
     
    439447        FloppyImageList mFloppyImages;
    440448        SharedFolderList mSharedFolders;
     449        DhcpServerList mDhcpServers;
    441450
    442451        /// @todo NEWMEDIA do we really need this map? Used only in
  • trunk/src/VBox/Main/xml/VirtualBox-settings-common.xsd

    r17843 r17872  
    255255/////////////////////////////////////////////////////////////////////////
    256256-->
     257<xsd:complexType name="TDhcpServer">
     258  <xsd:attribute name="networkName" type="xsd:string"  use="required"/>
     259  <xsd:attribute name="lowerIp"     type="xsd:string"  use="optional"/>
     260  <xsd:attribute name="upperIp"     type="xsd:string"  use="optional"/>
     261  <xsd:attribute name="IPAddress"   type="xsd:string"  use="required"/>
     262  <xsd:attribute name="networkMask" type="xsd:string"  use="required"/>
     263  <xsd:attribute name="enabled"     type="xsd:boolean" use="required"/>
     264</xsd:complexType>
    257265
    258266<xsd:complexType name="THardDiskBase">
     
    396404      </xsd:complexType>
    397405    </xsd:element>
     406    <xsd:element name="NetserviceRegistry" minOccurs="0" maxOccurs="1">
     407      <xsd:complexType>
     408        <xsd:all>
     409          <xsd:element name="DhcpServers" minOccurs="0">
     410            <xsd:complexType>
     411              <xsd:sequence>
     412                <xsd:element name="DhcpServer" type="TDhcpServer" minOccurs="0" maxOccurs="unbounded"/>
     413              </xsd:sequence>
     414            </xsd:complexType>
     415          </xsd:element>
     416        </xsd:all>
     417      </xsd:complexType>
     418    </xsd:element>
    398419    <xsd:element name="USBDeviceFilters">
    399420      <xsd:complexType>
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