VirtualBox

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

Last change on this file since 4496 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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