1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Basic Frontend (BFE):
|
---|
4 | * Implementation of NetworkAdapter class
|
---|
5 | *
|
---|
6 | * This is adapted from frontends/VirtualBox/NetworkAdapter.cpp.
|
---|
7 | */
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
11 | *
|
---|
12 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | * available from http://www.virtualbox.org. This file is free software;
|
---|
14 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | * General Public License as published by the Free Software Foundation,
|
---|
16 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
17 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
18 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 | */
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | #include <VBox/err.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 |
|
---|
26 | #include <NetworkAdapterImpl.h>
|
---|
27 | #include <COMDefs.h>
|
---|
28 | #include <ConsoleImpl.h>
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Returns the host interface the adapter is attached to
|
---|
32 | *
|
---|
33 | * @returns COM status code
|
---|
34 | * @param hostInterface address of result string
|
---|
35 | */
|
---|
36 | STDMETHODIMP NetworkAdapter::COMGETTER(HostInterface)(BSTR *hostInterface)
|
---|
37 | {
|
---|
38 | if (!hostInterface)
|
---|
39 | return E_POINTER;
|
---|
40 | AutoLock alock(this);
|
---|
41 | // CHECK_READY();
|
---|
42 |
|
---|
43 | // mData->mHostInterface.cloneTo(hostInterface);
|
---|
44 | mData.mHostInterface.cloneTo(hostInterface);
|
---|
45 |
|
---|
46 | return S_OK;
|
---|
47 | }
|
---|
48 |
|
---|
49 | NetworkAdapter::NetworkAdapter()
|
---|
50 | {
|
---|
51 | RTCritSectInit(&mCritSec);
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | NetworkAdapter::~NetworkAdapter()
|
---|
56 | {
|
---|
57 | }
|
---|
58 |
|
---|
59 | int
|
---|
60 | NetworkAdapter::init (Console *parent, ULONG slot)
|
---|
61 | {
|
---|
62 | mParent = parent;
|
---|
63 | mData.mSlot = slot;
|
---|
64 | return S_OK;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | STDMETHODIMP
|
---|
69 | NetworkAdapter::COMGETTER(Slot)(ULONG *slot)
|
---|
70 | {
|
---|
71 | if (!slot)
|
---|
72 | return E_POINTER;
|
---|
73 |
|
---|
74 | AutoLock alock (this);
|
---|
75 | // CHECK_READY();
|
---|
76 |
|
---|
77 | *slot = mData.mSlot;
|
---|
78 | return S_OK;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | STDMETHODIMP
|
---|
83 | NetworkAdapter::COMGETTER(Enabled)(bool *enabled)
|
---|
84 | {
|
---|
85 | if (!enabled)
|
---|
86 | return E_POINTER;
|
---|
87 |
|
---|
88 | AutoLock alock (this);
|
---|
89 | // CHECK_READY();
|
---|
90 |
|
---|
91 | *enabled = mData.mEnabled;
|
---|
92 | return S_OK;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | STDMETHODIMP
|
---|
97 | NetworkAdapter::COMSETTER(Enabled)(BOOL enabled)
|
---|
98 | {
|
---|
99 | AutoLock alock(this);
|
---|
100 | // CHECK_READY();
|
---|
101 |
|
---|
102 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
103 |
|
---|
104 | if (mData.mEnabled != enabled)
|
---|
105 | {
|
---|
106 | // mData.backup();
|
---|
107 | mData.mEnabled = enabled;
|
---|
108 |
|
---|
109 | /* notify parent */
|
---|
110 | alock.unlock();
|
---|
111 | mParent->onNetworkAdapterChange (this);
|
---|
112 | }
|
---|
113 |
|
---|
114 | return S_OK;
|
---|
115 | }
|
---|
116 |
|
---|
117 | STDMETHODIMP
|
---|
118 | NetworkAdapter::COMGETTER(MACAddress)(BSTR *macAddress)
|
---|
119 | {
|
---|
120 | AssertMsg(0,("Not implemented yet\n"));
|
---|
121 | return 0;
|
---|
122 | }
|
---|
123 |
|
---|
124 | STDMETHODIMP
|
---|
125 | NetworkAdapter::COMSETTER(MACAddress)(INPTR BSTR macAddress)
|
---|
126 | {
|
---|
127 | AssertMsg(0,("Not implemented yet\n"));
|
---|
128 | return 0;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | STDMETHODIMP
|
---|
133 | NetworkAdapter::COMSETTER(HostInterface)(INPTR BSTR hostInterface)
|
---|
134 | {
|
---|
135 | #ifdef RT_OS_LINUX
|
---|
136 | // empty strings are not allowed as path names
|
---|
137 | if (hostInterface && !(*hostInterface))
|
---|
138 | return E_INVALIDARG;
|
---|
139 | #endif
|
---|
140 |
|
---|
141 |
|
---|
142 | AutoLock alock(this);
|
---|
143 | // CHECK_READY();
|
---|
144 |
|
---|
145 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
146 |
|
---|
147 | if (mData.mHostInterface != hostInterface)
|
---|
148 | {
|
---|
149 | // mData.backup();
|
---|
150 | mData.mHostInterface = hostInterface;
|
---|
151 |
|
---|
152 | /* notify parent */
|
---|
153 | alock.unlock();
|
---|
154 | mParent->onNetworkAdapterChange(this);
|
---|
155 | }
|
---|
156 |
|
---|
157 | return S_OK;
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 | STDMETHODIMP
|
---|
163 | NetworkAdapter::COMGETTER(TAPFileDescriptor)(LONG *tapFileDescriptor)
|
---|
164 | {
|
---|
165 | if (!tapFileDescriptor)
|
---|
166 | return E_POINTER;
|
---|
167 |
|
---|
168 | AutoLock alock(this);
|
---|
169 | // CHECK_READY();
|
---|
170 |
|
---|
171 | *tapFileDescriptor = mData.mTAPFD;
|
---|
172 |
|
---|
173 | return S_OK;
|
---|
174 |
|
---|
175 | }
|
---|
176 |
|
---|
177 | STDMETHODIMP
|
---|
178 | NetworkAdapter::COMSETTER(TAPFileDescriptor)(LONG tapFileDescriptor)
|
---|
179 | {
|
---|
180 | /*
|
---|
181 | * Validate input.
|
---|
182 | */
|
---|
183 | RTFILE tapFD = tapFileDescriptor;
|
---|
184 | if (tapFD != NIL_RTFILE && (LONG)tapFD != tapFileDescriptor)
|
---|
185 | {
|
---|
186 | AssertMsgFailed(("Invalid file descriptor: %ld.\n", tapFileDescriptor));
|
---|
187 |
|
---|
188 | // setError VirtualBoxSupportErrorInfoImplBase which
|
---|
189 | // is a parent class of NetworAdapter in the COM flavored version
|
---|
190 | // return setError (E_INVALIDARG,
|
---|
191 | // tr ("Invalid file descriptor: %ld"), tapFileDescriptor);
|
---|
192 |
|
---|
193 | return S_OK;
|
---|
194 |
|
---|
195 | }
|
---|
196 |
|
---|
197 | AutoLock alock(this);
|
---|
198 | // CHECK_READY();
|
---|
199 |
|
---|
200 | // CHECK_MACHINE_MUTABILITY (mParent);
|
---|
201 |
|
---|
202 | if (mData.mTAPFD != (RTFILE) tapFileDescriptor)
|
---|
203 | {
|
---|
204 | // mData.backup();
|
---|
205 | mData.mTAPFD = tapFileDescriptor;
|
---|
206 |
|
---|
207 | /* notify parent */
|
---|
208 | alock.unlock();
|
---|
209 | mParent->onNetworkAdapterChange(this);
|
---|
210 | }
|
---|
211 |
|
---|
212 | return S_OK;
|
---|
213 |
|
---|
214 | }
|
---|
215 |
|
---|
216 | STDMETHODIMP
|
---|
217 | NetworkAdapter::COMGETTER(TAPSetupApplication)(BSTR *tapSetupApplication)
|
---|
218 | {
|
---|
219 | if (!tapSetupApplication)
|
---|
220 | return E_POINTER;
|
---|
221 | AutoLock alock(this);
|
---|
222 | // CHECK_READY();
|
---|
223 |
|
---|
224 | /* we don't have to be in TAP mode to support this call */
|
---|
225 | mData.mTAPSetupApplication.cloneTo(tapSetupApplication);
|
---|
226 |
|
---|
227 | return S_OK;
|
---|
228 |
|
---|
229 | }
|
---|
230 |
|
---|
231 | STDMETHODIMP
|
---|
232 | NetworkAdapter::COMSETTER(TAPSetupApplication)(INPTR BSTR tapSetupApplication)
|
---|
233 | {
|
---|
234 | AssertMsg(0,("Not implemented yet\n"));
|
---|
235 | return 0;
|
---|
236 | }
|
---|
237 |
|
---|
238 | STDMETHODIMP
|
---|
239 | NetworkAdapter::COMGETTER(TAPTerminateApplication)(BSTR *tapTerminateApplication)
|
---|
240 | {
|
---|
241 | AssertMsg(0,("Not implemented yet\n"));
|
---|
242 | return 0;
|
---|
243 | }
|
---|
244 |
|
---|
245 | STDMETHODIMP
|
---|
246 | NetworkAdapter::COMSETTER(TAPTerminateApplication)(INPTR BSTR tapTerminateApplication)
|
---|
247 | {
|
---|
248 | AssertMsg(0,("Not implemented yet\n"));
|
---|
249 | return 0;
|
---|
250 | }
|
---|
251 |
|
---|
252 | STDMETHODIMP
|
---|
253 | NetworkAdapter::COMGETTER(InternalNetwork)(BSTR *internalNetwork)
|
---|
254 | {
|
---|
255 | AssertMsg(0,("Not implemented yet\n"));
|
---|
256 | return 0;
|
---|
257 | }
|
---|
258 | STDMETHODIMP
|
---|
259 | NetworkAdapter::COMSETTER(InternalNetwork)(INPTR BSTR internalNetwork)
|
---|
260 | {
|
---|
261 | AssertMsg(0,("Not implemented yet\n"));
|
---|
262 | return 0;
|
---|
263 | }
|
---|
264 | STDMETHODIMP
|
---|
265 | NetworkAdapter::COMGETTER(CableConnected)(BOOL *connected)
|
---|
266 | {
|
---|
267 | if (!connected)
|
---|
268 | return E_POINTER;
|
---|
269 |
|
---|
270 | AutoLock alock(this);
|
---|
271 | // CHECK_READY();
|
---|
272 |
|
---|
273 | *connected = mData.mCableConnected;
|
---|
274 | return S_OK;
|
---|
275 |
|
---|
276 | }
|
---|
277 | STDMETHODIMP
|
---|
278 | NetworkAdapter::COMSETTER(CableConnected)(BOOL connected)
|
---|
279 | {
|
---|
280 | AssertMsg(0,("Not implemented yet\n"));
|
---|
281 | return 0;
|
---|
282 | }
|
---|
283 | STDMETHODIMP
|
---|
284 | NetworkAdapter::COMGETTER(TraceEnabled)(BOOL *enabled)
|
---|
285 | {
|
---|
286 | AssertMsg(0,("Not implemented yet\n"));
|
---|
287 | return 0;
|
---|
288 | }
|
---|
289 | STDMETHODIMP
|
---|
290 | NetworkAdapter::COMSETTER(TraceEnabled)(BOOL enabled)
|
---|
291 | {
|
---|
292 | AssertMsg(0,("Not implemented yet\n"));
|
---|
293 | return 0;
|
---|
294 | }
|
---|
295 |
|
---|
296 | // INetworkAdapter methods
|
---|
297 | STDMETHODIMP
|
---|
298 | NetworkAdapter::AttachToNAT()
|
---|
299 | {
|
---|
300 | AssertMsg(0,("Not implemented yet\n"));
|
---|
301 | return 0;
|
---|
302 | }
|
---|
303 | STDMETHODIMP
|
---|
304 | NetworkAdapter::AttachToHostInterface()
|
---|
305 | {
|
---|
306 | AssertMsg(0,("Not implemented yet\n"));
|
---|
307 | return 0;
|
---|
308 | }
|
---|
309 | STDMETHODIMP
|
---|
310 | NetworkAdapter::AttachToInternalNetwork()
|
---|
311 | {
|
---|
312 | AssertMsg(0,("Not implemented yet\n"));
|
---|
313 | return 0;
|
---|
314 | }
|
---|
315 | STDMETHODIMP
|
---|
316 | NetworkAdapter::Detach()
|
---|
317 | {
|
---|
318 | AssertMsg(0,("Not implemented yet\n"));
|
---|
319 | return 0;
|
---|
320 | }
|
---|
321 |
|
---|
322 | void
|
---|
323 | NetworkAdapter::detach()
|
---|
324 | {
|
---|
325 | AssertMsg(0,("Not implemented yet\n"));
|
---|
326 | }
|
---|
327 |
|
---|
328 | void
|
---|
329 | NetworkAdapter::generateMACAddress()
|
---|
330 | {
|
---|
331 | AssertMsg(0,("Not implemented yet\n"));
|
---|
332 | }
|
---|