VirtualBox

source: vbox/trunk/src/VBox/Main/DhcpServerImpl.cpp@ 17895

Last change on this file since 17895 was 17893, checked in by vboxsync, 16 years ago

dhcp settings uninit fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: DhcpServerImpl.cpp 17893 2009-03-15 17:57:49Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "DhcpServerImpl.h"
25#include "Logging.h"
26
27#include <VBox/settings.h>
28
29// constructor / destructor
30/////////////////////////////////////////////////////////////////////////////
31
32DEFINE_EMPTY_CTOR_DTOR (DhcpServer)
33
34HRESULT DhcpServer::FinalConstruct()
35{
36 return S_OK;
37}
38
39void DhcpServer::FinalRelease()
40{
41 uninit ();
42}
43
44void DhcpServer::uninit()
45{
46 /* Enclose the state transition Ready->InUninit->NotReady */
47 AutoUninitSpan autoUninitSpan (this);
48 if (autoUninitSpan.uninitDone())
49 return;
50
51// /* we uninit children and reset mParent
52// * and VirtualBox::removeDependentChild() needs a write lock */
53// AutoMultiWriteLock2 alock (mVirtualBox->lockHandle(), this->treeLock());
54
55 mVirtualBox->removeDependentChild (this);
56
57 unconst (mVirtualBox).setNull();
58}
59
60HRESULT DhcpServer::init(VirtualBox *aVirtualBox, IN_BSTR aName)
61{
62 AssertReturn (aName != NULL, E_INVALIDARG);
63
64 AutoInitSpan autoInitSpan (this);
65 AssertReturn (autoInitSpan.isOk(), E_FAIL);
66
67 /* share VirtualBox weakly (parent remains NULL so far) */
68 unconst (mVirtualBox) = aVirtualBox;
69
70 unconst(mName) = aName;
71 m.IPAddress = "0.0.0.0";
72 m.networkMask = "0.0.0.0";
73 m.enabled = FALSE;
74 m.lowerIP = "0.0.0.0";
75 m.upperIP = "0.0.0.0";
76
77 /* register with VirtualBox early, since uninit() will
78 * unconditionally unregister on failure */
79 aVirtualBox->addDependentChild (this);
80
81 /* Confirm a successful initialization */
82 autoInitSpan.setSucceeded();
83
84 return S_OK;
85}
86
87HRESULT DhcpServer::init(VirtualBox *aVirtualBox, const settings::Key &aNode)
88{
89 using namespace settings;
90
91 /* Enclose the state transition NotReady->InInit->Ready */
92 AutoInitSpan autoInitSpan (this);
93 AssertReturn (autoInitSpan.isOk(), E_FAIL);
94
95 /* share VirtualBox weakly (parent remains NULL so far) */
96 unconst (mVirtualBox) = aVirtualBox;
97
98 aVirtualBox->addDependentChild (this);
99
100 unconst(mName) = aNode.stringValue ("networkName");
101 m.IPAddress = aNode.stringValue ("IPAddress");
102 m.networkMask = aNode.stringValue ("networkMask");
103 m.enabled = aNode.value <BOOL> ("enabled");
104 m.lowerIP = aNode.stringValue ("lowerIP");
105 m.upperIP = aNode.stringValue ("upperIP");
106
107 autoInitSpan.setSucceeded();
108
109 return S_OK;
110}
111
112HRESULT DhcpServer::saveSettings (settings::Key &aParentNode)
113{
114 using namespace settings;
115
116 AssertReturn (!aParentNode.isNull(), E_FAIL);
117
118 AutoCaller autoCaller (this);
119 CheckComRCReturnRC (autoCaller.rc());
120
121 AutoReadLock alock (this);
122
123 Key aNode = aParentNode.appendKey ("DhcpServer");
124 /* required */
125 aNode.setValue <Bstr> ("networkName", mName);
126 aNode.setValue <Bstr> ("IPAddress", m.IPAddress);
127 aNode.setValue <Bstr> ("networkMask", m.networkMask);
128 aNode.setValue <Bstr> ("lowerIP", m.lowerIP);
129 aNode.setValue <Bstr> ("upperIP", m.upperIP);
130 aNode.setValue <BOOL> ("enabled", m.enabled);
131
132 return S_OK;
133}
134
135STDMETHODIMP DhcpServer::COMGETTER(NetworkName) (BSTR *aName)
136{
137 CheckComArgOutPointerValid(aName);
138
139 AutoCaller autoCaller (this);
140 CheckComRCReturnRC (autoCaller.rc());
141
142 mName.cloneTo(aName);
143
144 return S_OK;
145
146}
147
148STDMETHODIMP DhcpServer::COMGETTER(Enabled) (BOOL *aEnabled)
149{
150 CheckComArgOutPointerValid(aEnabled);
151
152 AutoCaller autoCaller (this);
153 CheckComRCReturnRC (autoCaller.rc());
154
155 *aEnabled = m.enabled;
156
157 return S_OK;
158
159}
160
161STDMETHODIMP DhcpServer::COMSETTER(Enabled) (BOOL aEnabled)
162{
163 AutoCaller autoCaller (this);
164 CheckComRCReturnRC (autoCaller.rc());
165
166 /* VirtualBox::saveSettings() needs a write lock */
167 AutoMultiWriteLock2 alock (mVirtualBox, this);
168
169 m.enabled = aEnabled;
170
171 HRESULT rc = mVirtualBox->saveSettings();
172
173 return rc;
174}
175
176STDMETHODIMP DhcpServer::COMGETTER(IPAddress) (BSTR *aIPAddress)
177{
178 CheckComArgOutPointerValid(aIPAddress);
179
180 AutoCaller autoCaller (this);
181 CheckComRCReturnRC (autoCaller.rc());
182
183 m.IPAddress.cloneTo(aIPAddress);
184
185 return S_OK;
186
187}
188
189STDMETHODIMP DhcpServer::COMGETTER(NetworkMask) (BSTR *aNetworkMask)
190{
191 CheckComArgOutPointerValid(aNetworkMask);
192
193 AutoCaller autoCaller (this);
194 CheckComRCReturnRC (autoCaller.rc());
195
196 m.networkMask.cloneTo(aNetworkMask);
197
198 return S_OK;
199
200}
201
202STDMETHODIMP DhcpServer::COMGETTER(LowerIP) (BSTR *aIPAddress)
203{
204 CheckComArgOutPointerValid(aIPAddress);
205
206 AutoCaller autoCaller (this);
207 CheckComRCReturnRC (autoCaller.rc());
208
209 m.lowerIP.cloneTo(aIPAddress);
210
211 return S_OK;
212
213}
214
215STDMETHODIMP DhcpServer::COMGETTER(UpperIP) (BSTR *aIPAddress)
216{
217 CheckComArgOutPointerValid(aIPAddress);
218
219 AutoCaller autoCaller (this);
220 CheckComRCReturnRC (autoCaller.rc());
221
222 m.upperIP.cloneTo(aIPAddress);
223
224 return S_OK;
225
226}
227
228STDMETHODIMP DhcpServer::SetConfiguration (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aLowerIP, IN_BSTR aUpperIP)
229{
230 AssertReturn (aIPAddress != NULL, E_INVALIDARG);
231 AssertReturn (aNetworkMask != NULL, E_INVALIDARG);
232 AssertReturn (aLowerIP != NULL, E_INVALIDARG);
233 AssertReturn (aUpperIP != NULL, E_INVALIDARG);
234
235 AutoCaller autoCaller (this);
236 CheckComRCReturnRC (autoCaller.rc());
237
238 /* VirtualBox::saveSettings() needs a write lock */
239 AutoMultiWriteLock2 alock (mVirtualBox, this);
240
241 m.IPAddress = aIPAddress;
242 m.networkMask = aNetworkMask;
243 m.lowerIP = aLowerIP;
244 m.upperIP = aUpperIP;
245
246 HRESULT rc = mVirtualBox->saveSettings();
247
248 return S_OK;
249}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette