1 | /* $Id: DhcpServerImpl.cpp 17911 2009-03-16 10:30:55Z 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 |
|
---|
32 | DEFINE_EMPTY_CTOR_DTOR (DhcpServer)
|
---|
33 |
|
---|
34 | HRESULT DhcpServer::FinalConstruct()
|
---|
35 | {
|
---|
36 | return S_OK;
|
---|
37 | }
|
---|
38 |
|
---|
39 | void DhcpServer::FinalRelease()
|
---|
40 | {
|
---|
41 | uninit ();
|
---|
42 | }
|
---|
43 |
|
---|
44 | void 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 |
|
---|
60 | HRESULT 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 |
|
---|
87 | HRESULT 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 |
|
---|
112 | HRESULT 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 |
|
---|
135 | STDMETHODIMP 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 | STDMETHODIMP DhcpServer::COMGETTER(Enabled) (BOOL *aEnabled)
|
---|
148 | {
|
---|
149 | CheckComArgOutPointerValid(aEnabled);
|
---|
150 |
|
---|
151 | AutoCaller autoCaller (this);
|
---|
152 | CheckComRCReturnRC (autoCaller.rc());
|
---|
153 |
|
---|
154 | *aEnabled = m.enabled;
|
---|
155 |
|
---|
156 | return S_OK;
|
---|
157 | }
|
---|
158 |
|
---|
159 | STDMETHODIMP DhcpServer::COMSETTER(Enabled) (BOOL aEnabled)
|
---|
160 | {
|
---|
161 | AutoCaller autoCaller (this);
|
---|
162 | CheckComRCReturnRC (autoCaller.rc());
|
---|
163 |
|
---|
164 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
165 | AutoMultiWriteLock2 alock (mVirtualBox, this);
|
---|
166 |
|
---|
167 | m.enabled = aEnabled;
|
---|
168 |
|
---|
169 | HRESULT rc = mVirtualBox->saveSettings();
|
---|
170 |
|
---|
171 | return rc;
|
---|
172 | }
|
---|
173 |
|
---|
174 | STDMETHODIMP DhcpServer::COMGETTER(IPAddress) (BSTR *aIPAddress)
|
---|
175 | {
|
---|
176 | CheckComArgOutPointerValid(aIPAddress);
|
---|
177 |
|
---|
178 | AutoCaller autoCaller (this);
|
---|
179 | CheckComRCReturnRC (autoCaller.rc());
|
---|
180 |
|
---|
181 | m.IPAddress.cloneTo(aIPAddress);
|
---|
182 |
|
---|
183 | return S_OK;
|
---|
184 | }
|
---|
185 |
|
---|
186 | STDMETHODIMP DhcpServer::COMGETTER(NetworkMask) (BSTR *aNetworkMask)
|
---|
187 | {
|
---|
188 | CheckComArgOutPointerValid(aNetworkMask);
|
---|
189 |
|
---|
190 | AutoCaller autoCaller (this);
|
---|
191 | CheckComRCReturnRC (autoCaller.rc());
|
---|
192 |
|
---|
193 | m.networkMask.cloneTo(aNetworkMask);
|
---|
194 |
|
---|
195 | return S_OK;
|
---|
196 | }
|
---|
197 |
|
---|
198 | STDMETHODIMP DhcpServer::COMGETTER(LowerIP) (BSTR *aIPAddress)
|
---|
199 | {
|
---|
200 | CheckComArgOutPointerValid(aIPAddress);
|
---|
201 |
|
---|
202 | AutoCaller autoCaller (this);
|
---|
203 | CheckComRCReturnRC (autoCaller.rc());
|
---|
204 |
|
---|
205 | m.lowerIP.cloneTo(aIPAddress);
|
---|
206 |
|
---|
207 | return S_OK;
|
---|
208 | }
|
---|
209 |
|
---|
210 | STDMETHODIMP DhcpServer::COMGETTER(UpperIP) (BSTR *aIPAddress)
|
---|
211 | {
|
---|
212 | CheckComArgOutPointerValid(aIPAddress);
|
---|
213 |
|
---|
214 | AutoCaller autoCaller (this);
|
---|
215 | CheckComRCReturnRC (autoCaller.rc());
|
---|
216 |
|
---|
217 | m.upperIP.cloneTo(aIPAddress);
|
---|
218 |
|
---|
219 | return S_OK;
|
---|
220 | }
|
---|
221 |
|
---|
222 | STDMETHODIMP DhcpServer::SetConfiguration (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aLowerIP, IN_BSTR aUpperIP)
|
---|
223 | {
|
---|
224 | AssertReturn (aIPAddress != NULL, E_INVALIDARG);
|
---|
225 | AssertReturn (aNetworkMask != NULL, E_INVALIDARG);
|
---|
226 | AssertReturn (aLowerIP != NULL, E_INVALIDARG);
|
---|
227 | AssertReturn (aUpperIP != NULL, E_INVALIDARG);
|
---|
228 |
|
---|
229 | AutoCaller autoCaller (this);
|
---|
230 | CheckComRCReturnRC (autoCaller.rc());
|
---|
231 |
|
---|
232 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
233 | AutoMultiWriteLock2 alock (mVirtualBox, this);
|
---|
234 |
|
---|
235 | m.IPAddress = aIPAddress;
|
---|
236 | m.networkMask = aNetworkMask;
|
---|
237 | m.lowerIP = aLowerIP;
|
---|
238 | m.upperIP = aUpperIP;
|
---|
239 |
|
---|
240 | return mVirtualBox->saveSettings();
|
---|
241 | }
|
---|