VirtualBox

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

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

dhcp settings

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