VirtualBox

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

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

dhcp settings fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: DhcpServerImpl.cpp 17887 2009-03-15 15:27:21Z 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
44HRESULT DhcpServer::init(VirtualBox *aVirtualBox, IN_BSTR aName)
45{
46 AssertReturn (aName != NULL, E_INVALIDARG);
47
48 AutoInitSpan autoInitSpan (this);
49 AssertReturn (autoInitSpan.isOk(), E_FAIL);
50
51 /* share VirtualBox weakly (parent remains NULL so far) */
52 unconst (mVirtualBox) = aVirtualBox;
53
54 unconst(mName) = aName;
55 m.IPAddress = "0.0.0.0";
56 m.networkMask = "0.0.0.0";
57 m.enabled = FALSE;
58 m.FromIPAddress = "0.0.0.0";
59 m.ToIPAddress = "0.0.0.0";
60
61 /* register with VirtualBox early, since uninit() will
62 * unconditionally unregister on failure */
63 aVirtualBox->addDependentChild (this);
64
65 /* Confirm a successful initialization */
66 autoInitSpan.setSucceeded();
67
68 return S_OK;
69}
70
71HRESULT DhcpServer::init(VirtualBox *aVirtualBox, const settings::Key &aNode)
72{
73 using namespace settings;
74
75 /* Enclose the state transition NotReady->InInit->Ready */
76 AutoInitSpan autoInitSpan (this);
77 AssertReturn (autoInitSpan.isOk(), E_FAIL);
78
79 /* share VirtualBox weakly (parent remains NULL so far) */
80 unconst (mVirtualBox) = aVirtualBox;
81
82 aVirtualBox->addDependentChild (this);
83
84 unconst(mName) = aNode.stringValue ("networkName");
85 m.IPAddress = aNode.stringValue ("IPAddress");
86 m.networkMask = aNode.stringValue ("networkMask");
87 m.enabled = aNode.value <BOOL> ("enabled");
88 m.FromIPAddress = aNode.stringValue ("lowerIp");
89 m.ToIPAddress = aNode.stringValue ("upperIp");
90
91 autoInitSpan.setSucceeded();
92
93 return S_OK;
94}
95
96HRESULT DhcpServer::saveSettings (settings::Key &aParentNode)
97{
98 using namespace settings;
99
100 AssertReturn (!aParentNode.isNull(), E_FAIL);
101
102 AutoCaller autoCaller (this);
103 CheckComRCReturnRC (autoCaller.rc());
104
105 AutoReadLock alock (this);
106
107 Key aNode = aParentNode.appendKey ("DhcpServer");
108 /* required */
109 aNode.setValue <Bstr> ("networkName", mName);
110 aNode.setValue <Bstr> ("IPAddress", m.IPAddress);
111 aNode.setValue <Bstr> ("networkMask", m.networkMask);
112 aNode.setValue <Bstr> ("FromIPAddress", m.FromIPAddress);
113 aNode.setValue <Bstr> ("ToIPAddress", m.ToIPAddress);
114
115 return S_OK;
116}
117
118STDMETHODIMP DhcpServer::COMGETTER(NetworkName) (BSTR *aName)
119{
120 CheckComArgOutPointerValid(aName);
121
122 AutoCaller autoCaller (this);
123 CheckComRCReturnRC (autoCaller.rc());
124
125 mName.cloneTo(aName);
126
127 return S_OK;
128
129}
130
131STDMETHODIMP DhcpServer::COMGETTER(Enabled) (BOOL *aEnabled)
132{
133 CheckComArgOutPointerValid(aEnabled);
134
135 AutoCaller autoCaller (this);
136 CheckComRCReturnRC (autoCaller.rc());
137
138 *aEnabled = m.enabled;
139
140 return S_OK;
141
142}
143
144STDMETHODIMP DhcpServer::COMSETTER(Enabled) (BOOL aEnabled)
145{
146 AutoCaller autoCaller (this);
147 CheckComRCReturnRC (autoCaller.rc());
148
149 /* VirtualBox::saveSettings() needs a write lock */
150 AutoMultiWriteLock2 alock (mVirtualBox, this);
151
152 m.enabled = aEnabled;
153
154 HRESULT rc = mVirtualBox->saveSettings();
155
156 return rc;
157}
158
159STDMETHODIMP DhcpServer::COMGETTER(IPAddress) (BSTR *aIPAddress)
160{
161 CheckComArgOutPointerValid(aIPAddress);
162
163 AutoCaller autoCaller (this);
164 CheckComRCReturnRC (autoCaller.rc());
165
166 m.IPAddress.cloneTo(aIPAddress);
167
168 return S_OK;
169
170}
171
172STDMETHODIMP DhcpServer::COMGETTER(NetworkMask) (BSTR *aNetworkMask)
173{
174 CheckComArgOutPointerValid(aNetworkMask);
175
176 AutoCaller autoCaller (this);
177 CheckComRCReturnRC (autoCaller.rc());
178
179 m.networkMask.cloneTo(aNetworkMask);
180
181 return S_OK;
182
183}
184
185STDMETHODIMP DhcpServer::COMGETTER(FromIPAddress) (BSTR *aIPAddress)
186{
187 CheckComArgOutPointerValid(aIPAddress);
188
189 AutoCaller autoCaller (this);
190 CheckComRCReturnRC (autoCaller.rc());
191
192 m.FromIPAddress.cloneTo(aIPAddress);
193
194 return S_OK;
195
196}
197
198STDMETHODIMP DhcpServer::COMGETTER(ToIPAddress) (BSTR *aIPAddress)
199{
200 CheckComArgOutPointerValid(aIPAddress);
201
202 AutoCaller autoCaller (this);
203 CheckComRCReturnRC (autoCaller.rc());
204
205 m.ToIPAddress.cloneTo(aIPAddress);
206
207 return S_OK;
208
209}
210
211STDMETHODIMP DhcpServer::SetConfiguration (IN_BSTR aIPAddress, IN_BSTR aNetworkMask, IN_BSTR aFromIPAddress, IN_BSTR aToIPAddress)
212{
213 AssertReturn (aIPAddress != NULL, E_INVALIDARG);
214 AssertReturn (aNetworkMask != NULL, E_INVALIDARG);
215 AssertReturn (aFromIPAddress != NULL, E_INVALIDARG);
216 AssertReturn (aToIPAddress != NULL, E_INVALIDARG);
217
218 AutoCaller autoCaller (this);
219 CheckComRCReturnRC (autoCaller.rc());
220
221 /* VirtualBox::saveSettings() needs a write lock */
222 AutoMultiWriteLock2 alock (mVirtualBox, this);
223
224 m.IPAddress = aIPAddress;
225 m.networkMask = aNetworkMask;
226 m.FromIPAddress = aFromIPAddress;
227 m.ToIPAddress = aToIPAddress;
228
229 HRESULT rc = mVirtualBox->saveSettings();
230
231 return rc;
232}
Note: See TracBrowser for help on using the repository browser.

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