VirtualBox

source: vbox/trunk/src/VBox/Main/SystemPropertiesImpl.cpp@ 3942

Last change on this file since 3942 was 3652, checked in by vboxsync, 17 years ago

Parallel port support. Contributed by: Alexander Eichner

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include "SystemPropertiesImpl.h"
23#include "VirtualBoxImpl.h"
24#include "MachineImpl.h"
25#include "Logging.h"
26
27// generated header
28#include "SchemaDefs.h"
29
30#include <iprt/path.h>
31#include <iprt/dir.h>
32#include <VBox/param.h>
33#include <VBox/err.h>
34
35// defines
36/////////////////////////////////////////////////////////////////////////////
37
38// constructor / destructor
39/////////////////////////////////////////////////////////////////////////////
40
41HRESULT SystemProperties::FinalConstruct()
42{
43 return S_OK;
44}
45
46void SystemProperties::FinalRelease()
47{
48 if (isReady())
49 uninit ();
50}
51
52// public methods only for internal purposes
53/////////////////////////////////////////////////////////////////////////////
54
55/**
56 * Initializes the system information object.
57 *
58 * @returns COM result indicator
59 */
60HRESULT SystemProperties::init (VirtualBox *aParent)
61{
62 LogFlowMember (("SystemProperties::init()\n"));
63
64 ComAssertRet (aParent, E_FAIL);
65
66 AutoLock alock (this);
67 ComAssertRet (!isReady(), E_UNEXPECTED);
68
69 mParent = aParent;
70
71 setDefaultVDIFolder (NULL);
72 setDefaultMachineFolder (NULL);
73 setRemoteDisplayAuthLibrary (NULL);
74
75 mHWVirtExEnabled = false;
76
77 setReady(true);
78 return S_OK;
79}
80
81/**
82 * Uninitializes the instance and sets the ready flag to FALSE.
83 * Called either from FinalRelease() or by the parent when it gets destroyed.
84 */
85void SystemProperties::uninit()
86{
87 LogFlowMember (("SystemProperties::uninit()\n"));
88
89 AutoLock alock (this);
90 AssertReturn (isReady(), (void) 0);
91
92 setReady (false);
93}
94
95// ISystemProperties properties
96/////////////////////////////////////////////////////////////////////////////
97
98
99STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
100{
101 if (!minRAM)
102 return E_POINTER;
103 AutoLock lock(this);
104 CHECK_READY();
105
106 *minRAM = SchemaDefs::MinGuestRAM;
107
108 return S_OK;
109}
110
111STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
112{
113 if (!maxRAM)
114 return E_POINTER;
115 AutoLock lock(this);
116 CHECK_READY();
117
118 *maxRAM = SchemaDefs::MaxGuestRAM;
119
120 return S_OK;
121}
122
123STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
124{
125 if (!minVRAM)
126 return E_POINTER;
127 AutoLock lock(this);
128 CHECK_READY();
129
130 *minVRAM = SchemaDefs::MinGuestVRAM;
131
132 return S_OK;
133}
134
135STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
136{
137 if (!maxVRAM)
138 return E_POINTER;
139 AutoLock lock(this);
140 CHECK_READY();
141
142 *maxVRAM = SchemaDefs::MaxGuestVRAM;
143
144 return S_OK;
145}
146
147STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
148{
149 if (!maxMonitors)
150 return E_POINTER;
151 AutoLock lock(this);
152 CHECK_READY();
153
154 *maxMonitors = SchemaDefs::MaxGuestMonitors;
155
156 return S_OK;
157}
158
159STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
160{
161 if (!maxVDISize)
162 return E_POINTER;
163 AutoLock lock(this);
164 CHECK_READY();
165
166 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
167 * 48 bit range is in theory trivial, but the crappy compiler makes things
168 * more difficult). This translates to almost 2 TBytes (to be on the safe
169 * side, the reported limit is 1 MiByte less than that, as the total number
170 * of sectors should fit in 32 bits, too), which should bei enough for
171 * the moment. The virtual ATA disks support complete LBA48 (although for
172 * example iSCSI is also currently limited to 32 bit LBA), so the
173 * theoretical maximum disk size is 128 PiByte. The user interface cannot
174 * cope with this in a reasonable way yet. */
175 *maxVDISize = 2048 * 1024 - 1;
176
177 return S_OK;
178}
179
180STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
181{
182 if (!count)
183 return E_POINTER;
184 AutoLock lock (this);
185 CHECK_READY();
186
187 *count = SchemaDefs::NetworkAdapterCount;
188
189 return S_OK;
190}
191
192STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
193{
194 if (!count)
195 return E_POINTER;
196 AutoLock lock (this);
197 CHECK_READY();
198
199 *count = SchemaDefs::SerialPortCount;
200
201 return S_OK;
202}
203
204STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
205{
206 if (!count)
207 return E_POINTER;
208 AutoLock lock (this);
209 CHECK_READY();
210
211 *count = SchemaDefs::ParallelPortCount;
212
213 return S_OK;
214}
215
216STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
217{
218 if (!aMaxBootPosition)
219 return E_POINTER;
220 AutoLock lock (this);
221 CHECK_READY();
222
223 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
224
225 return S_OK;
226}
227
228STDMETHODIMP SystemProperties::COMGETTER(DefaultVDIFolder) (BSTR *aDefaultVDIFolder)
229{
230 if (!aDefaultVDIFolder)
231 return E_POINTER;
232
233 AutoLock alock (this);
234 CHECK_READY();
235
236 mDefaultVDIFolderFull.cloneTo (aDefaultVDIFolder);
237
238 return S_OK;
239}
240
241STDMETHODIMP SystemProperties::COMSETTER(DefaultVDIFolder) (INPTR BSTR aDefaultVDIFolder)
242{
243 AutoLock alock (this);
244 CHECK_READY();
245
246 HRESULT rc = setDefaultVDIFolder (aDefaultVDIFolder);
247 if (FAILED (rc))
248 return rc;
249
250 alock.unlock();
251 return mParent->saveSettings();
252}
253
254STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
255{
256 if (!aDefaultMachineFolder)
257 return E_POINTER;
258
259 AutoLock alock (this);
260 CHECK_READY();
261
262 mDefaultMachineFolderFull.cloneTo (aDefaultMachineFolder);
263
264 return S_OK;
265}
266
267STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (INPTR BSTR aDefaultMachineFolder)
268{
269 AutoLock alock (this);
270 CHECK_READY();
271
272 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
273 if (FAILED (rc))
274 return rc;
275
276 alock.unlock();
277 return mParent->saveSettings();
278}
279
280STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
281{
282 if (!aRemoteDisplayAuthLibrary)
283 return E_POINTER;
284
285 AutoLock alock (this);
286 CHECK_READY();
287
288 mRemoteDisplayAuthLibrary.cloneTo (aRemoteDisplayAuthLibrary);
289
290 return S_OK;
291}
292
293STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (INPTR BSTR aRemoteDisplayAuthLibrary)
294{
295 AutoLock alock (this);
296 CHECK_READY();
297
298 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
299 if (FAILED (rc))
300 return rc;
301
302 alock.unlock();
303 return mParent->saveSettings();
304}
305
306STDMETHODIMP SystemProperties::COMGETTER(HWVirtExEnabled) (BOOL *enabled)
307{
308 if (!enabled)
309 return E_POINTER;
310
311 AutoLock alock (this);
312 CHECK_READY();
313
314 *enabled = mHWVirtExEnabled;
315
316 return S_OK;
317}
318
319STDMETHODIMP SystemProperties::COMSETTER(HWVirtExEnabled) (BOOL enabled)
320{
321 AutoLock alock (this);
322 CHECK_READY();
323
324 mHWVirtExEnabled = enabled;
325
326 alock.unlock();
327 return mParent->saveSettings();
328}
329
330// public methods only for internal purposes
331/////////////////////////////////////////////////////////////////////////////
332
333HRESULT SystemProperties::loadSettings (CFGNODE aGlobal)
334{
335 AutoLock lock (this);
336 CHECK_READY();
337
338 ComAssertRet (aGlobal, E_FAIL);
339
340 CFGNODE properties = NULL;
341 CFGLDRGetChildNode (aGlobal, "SystemProperties", 0, &properties);
342 ComAssertRet (properties, E_FAIL);
343
344 HRESULT rc = E_FAIL;
345
346 do
347 {
348 Bstr bstr;
349
350 CFGLDRQueryBSTR (properties, "defaultVDIFolder",
351 bstr.asOutParam());
352 rc = setDefaultVDIFolder (bstr);
353 if (FAILED (rc))
354 break;
355
356 CFGLDRQueryBSTR (properties, "defaultMachineFolder",
357 bstr.asOutParam());
358 rc = setDefaultMachineFolder (bstr);
359 if (FAILED (rc))
360 break;
361
362 CFGLDRQueryBSTR (properties, "remoteDisplayAuthLibrary",
363 bstr.asOutParam());
364 rc = setRemoteDisplayAuthLibrary (bstr);
365 if (FAILED (rc))
366 break;
367
368 CFGLDRQueryBool (properties, "HWVirtExEnabled", (bool*)&mHWVirtExEnabled);
369
370 }
371 while (0);
372
373 CFGLDRReleaseNode (properties);
374
375 return rc;
376}
377
378HRESULT SystemProperties::saveSettings (CFGNODE aGlobal)
379{
380 AutoLock lock (this);
381 CHECK_READY();
382
383 ComAssertRet (aGlobal, E_FAIL);
384
385 // first, delete the entry
386 CFGNODE properties = NULL;
387 int vrc = CFGLDRGetChildNode (aGlobal, "SystemProperties", 0, &properties);
388 if (VBOX_SUCCESS (vrc))
389 {
390 vrc = CFGLDRDeleteNode (properties);
391 ComAssertRCRet (vrc, E_FAIL);
392 }
393 // then, recreate it
394 vrc = CFGLDRCreateChildNode (aGlobal, "SystemProperties", &properties);
395 ComAssertRCRet (vrc, E_FAIL);
396
397 if (mDefaultVDIFolder)
398 CFGLDRSetBSTR (properties, "defaultVDIFolder",
399 mDefaultVDIFolder);
400
401 if (mDefaultMachineFolder)
402 CFGLDRSetBSTR (properties, "defaultMachineFolder",
403 mDefaultMachineFolder);
404
405 if (mRemoteDisplayAuthLibrary)
406 CFGLDRSetBSTR (properties, "remoteDisplayAuthLibrary",
407 mRemoteDisplayAuthLibrary);
408
409 CFGLDRSetBool (properties, "HWVirtExEnabled", !!mHWVirtExEnabled);
410
411 return S_OK;
412}
413
414// private methods
415/////////////////////////////////////////////////////////////////////////////
416
417HRESULT SystemProperties::setDefaultVDIFolder (const BSTR aPath)
418{
419 Utf8Str path;
420 if (aPath && *aPath)
421 path = aPath;
422 else
423 path = "VDI";
424
425 // get the full file name
426 char folder [RTPATH_MAX];
427 int vrc = RTPathAbsEx (mParent->homeDir(), path, folder, sizeof (folder));
428 if (VBOX_FAILURE (vrc))
429 return setError (E_FAIL,
430 tr ("Cannot set the default VDI folder to '%ls' (%Vrc)"),
431 path.raw(), vrc);
432
433 mDefaultVDIFolder = path;
434 mDefaultVDIFolderFull = folder;
435
436 return S_OK;
437}
438
439HRESULT SystemProperties::setDefaultMachineFolder (const BSTR aPath)
440{
441 Utf8Str path;
442 if (aPath && *aPath)
443 path = aPath;
444 else
445 path = "Machines";
446
447 // get the full file name
448 char folder [RTPATH_MAX];
449 int vrc = RTPathAbsEx (mParent->homeDir(), path, folder, sizeof (folder));
450 if (VBOX_FAILURE (vrc))
451 return setError (E_FAIL,
452 tr ("Cannot set the default machines folder to '%ls' (%Vrc)"),
453 path.raw(), vrc);
454
455 mDefaultMachineFolder = path;
456 mDefaultMachineFolderFull = folder;
457
458 return S_OK;
459}
460
461HRESULT SystemProperties::setRemoteDisplayAuthLibrary (const BSTR aPath)
462{
463 Utf8Str path;
464 if (aPath && *aPath)
465 path = aPath;
466 else
467 path = "VRDPAuth";
468
469 mRemoteDisplayAuthLibrary = path;
470
471 return S_OK;
472}
473
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