VirtualBox

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

Last change on this file since 16560 was 16560, checked in by vboxsync, 15 years ago

Main: do not include include/VBox/settings.h from other header files but only from implementations that need it (save compile time)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.8 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 16560 2009-02-06 18:06:04Z 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 "SystemPropertiesImpl.h"
25#include "VirtualBoxImpl.h"
26#include "MachineImpl.h"
27#include "Logging.h"
28
29// generated header
30#include "SchemaDefs.h"
31
32#include <iprt/path.h>
33#include <iprt/dir.h>
34
35#include <VBox/err.h>
36#include <VBox/param.h>
37#include <VBox/settings.h>
38
39// defines
40/////////////////////////////////////////////////////////////////////////////
41
42// constructor / destructor
43/////////////////////////////////////////////////////////////////////////////
44
45DEFINE_EMPTY_CTOR_DTOR (SystemProperties)
46
47HRESULT SystemProperties::FinalConstruct()
48{
49 return S_OK;
50}
51
52void SystemProperties::FinalRelease()
53{
54 uninit ();
55}
56
57// public methods only for internal purposes
58/////////////////////////////////////////////////////////////////////////////
59
60/**
61 * Initializes the system information object.
62 *
63 * @returns COM result indicator
64 */
65HRESULT SystemProperties::init (VirtualBox *aParent)
66{
67 LogFlowThisFunc (("aParent=%p\n", aParent));
68
69 ComAssertRet (aParent, E_FAIL);
70
71 /* Enclose the state transition NotReady->InInit->Ready */
72 AutoInitSpan autoInitSpan (this);
73 AssertReturn (autoInitSpan.isOk(), E_FAIL);
74
75 unconst (mParent) = aParent;
76
77 setDefaultMachineFolder (NULL);
78 setDefaultHardDiskFolder (NULL);
79 setDefaultHardDiskFormat (NULL);
80
81 setRemoteDisplayAuthLibrary (NULL);
82
83 mHWVirtExEnabled = false;
84 mLogHistoryCount = 3;
85
86 HRESULT rc = S_OK;
87
88 /* Fetch info of all available hd backends. */
89
90 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
91 /// any number of backends
92
93 /// @todo We currently leak memory because it's not actually clear what to
94 /// free in structures returned by VDBackendInfo. Must be fixed ASAP!
95
96 VDBACKENDINFO aVDInfo [100];
97 unsigned cEntries;
98 int vrc = VDBackendInfo (RT_ELEMENTS (aVDInfo), aVDInfo, &cEntries);
99 AssertRC (vrc);
100 if (RT_SUCCESS (vrc))
101 {
102 for (unsigned i = 0; i < cEntries; ++ i)
103 {
104 ComObjPtr <HardDiskFormat> hdf;
105 rc = hdf.createObject();
106 CheckComRCBreakRC (rc);
107
108 rc = hdf->init (&aVDInfo [i]);
109 CheckComRCBreakRC (rc);
110
111 mHardDiskFormats.push_back (hdf);
112 }
113 }
114
115 /* Confirm a successful initialization */
116 if (SUCCEEDED (rc))
117 autoInitSpan.setSucceeded();
118
119 return rc;
120}
121
122/**
123 * Uninitializes the instance and sets the ready flag to FALSE.
124 * Called either from FinalRelease() or by the parent when it gets destroyed.
125 */
126void SystemProperties::uninit()
127{
128 LogFlowThisFunc (("\n"));
129
130 /* Enclose the state transition Ready->InUninit->NotReady */
131 AutoUninitSpan autoUninitSpan (this);
132 if (autoUninitSpan.uninitDone())
133 return;
134
135 unconst (mParent).setNull();
136}
137
138// ISystemProperties properties
139/////////////////////////////////////////////////////////////////////////////
140
141
142STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
143{
144 if (!minRAM)
145 return E_POINTER;
146
147 AutoCaller autoCaller (this);
148 CheckComRCReturnRC (autoCaller.rc());
149
150 /* no need to lock, this is const */
151 *minRAM = SchemaDefs::MinGuestRAM;
152
153 return S_OK;
154}
155
156STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
157{
158 if (!maxRAM)
159 return E_POINTER;
160
161 AutoCaller autoCaller (this);
162 CheckComRCReturnRC (autoCaller.rc());
163
164 /* no need to lock, this is const */
165 *maxRAM = SchemaDefs::MaxGuestRAM;
166
167 return S_OK;
168}
169
170STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
171{
172 if (!minVRAM)
173 return E_POINTER;
174
175 AutoCaller autoCaller (this);
176 CheckComRCReturnRC (autoCaller.rc());
177
178 /* no need to lock, this is const */
179 *minVRAM = SchemaDefs::MinGuestVRAM;
180
181 return S_OK;
182}
183
184STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
185{
186 if (!maxVRAM)
187 return E_POINTER;
188
189 AutoCaller autoCaller (this);
190 CheckComRCReturnRC (autoCaller.rc());
191
192 /* no need to lock, this is const */
193 *maxVRAM = SchemaDefs::MaxGuestVRAM;
194
195 return S_OK;
196}
197
198STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
199{
200 if (!maxMonitors)
201 return E_POINTER;
202
203 AutoCaller autoCaller (this);
204 CheckComRCReturnRC (autoCaller.rc());
205
206 /* no need to lock, this is const */
207 *maxMonitors = SchemaDefs::MaxGuestMonitors;
208
209 return S_OK;
210}
211
212STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
213{
214 if (!maxVDISize)
215 return E_POINTER;
216
217 AutoCaller autoCaller (this);
218 CheckComRCReturnRC (autoCaller.rc());
219
220 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
221 * 48 bit range is in theory trivial, but the crappy compiler makes things
222 * more difficult). This translates to almost 2 TBytes (to be on the safe
223 * side, the reported limit is 1 MiByte less than that, as the total number
224 * of sectors should fit in 32 bits, too), which should bei enough for
225 * the moment. The virtual ATA disks support complete LBA48 (although for
226 * example iSCSI is also currently limited to 32 bit LBA), so the
227 * theoretical maximum disk size is 128 PiByte. The user interface cannot
228 * cope with this in a reasonable way yet. */
229 /* no need to lock, this is const */
230 *maxVDISize = 2048 * 1024 - 1;
231
232 return S_OK;
233}
234
235STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
236{
237 if (!count)
238 return E_POINTER;
239
240 AutoCaller autoCaller (this);
241 CheckComRCReturnRC (autoCaller.rc());
242
243 /* no need to lock, this is const */
244 *count = SchemaDefs::NetworkAdapterCount;
245
246 return S_OK;
247}
248
249STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
250{
251 if (!count)
252 return E_POINTER;
253
254 AutoCaller autoCaller (this);
255 CheckComRCReturnRC (autoCaller.rc());
256
257 /* no need to lock, this is const */
258 *count = SchemaDefs::SerialPortCount;
259
260 return S_OK;
261}
262
263STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
264{
265 if (!count)
266 return E_POINTER;
267
268 AutoCaller autoCaller (this);
269 CheckComRCReturnRC (autoCaller.rc());
270
271 /* no need to lock, this is const */
272 *count = SchemaDefs::ParallelPortCount;
273
274 return S_OK;
275}
276
277STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
278{
279 CheckComArgOutPointerValid(aMaxBootPosition);
280
281 AutoCaller autoCaller (this);
282 CheckComRCReturnRC (autoCaller.rc());
283
284 /* no need to lock, this is const */
285 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
286
287 return S_OK;
288}
289
290STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
291{
292 CheckComArgOutPointerValid(aDefaultMachineFolder);
293
294 AutoCaller autoCaller (this);
295 CheckComRCReturnRC (autoCaller.rc());
296
297 AutoReadLock alock (this);
298
299 mDefaultMachineFolderFull.cloneTo (aDefaultMachineFolder);
300
301 return S_OK;
302}
303
304STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
305{
306 AutoCaller autoCaller (this);
307 CheckComRCReturnRC (autoCaller.rc());
308
309 /* VirtualBox::saveSettings() needs a write lock */
310 AutoMultiWriteLock2 alock (mParent, this);
311
312 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
313 if (SUCCEEDED (rc))
314 rc = mParent->saveSettings();
315
316 return rc;
317}
318
319STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder) (BSTR *aDefaultHardDiskFolder)
320{
321 CheckComArgOutPointerValid(aDefaultHardDiskFolder);
322
323 AutoCaller autoCaller (this);
324 CheckComRCReturnRC (autoCaller.rc());
325
326 AutoReadLock alock (this);
327
328 mDefaultHardDiskFolderFull.cloneTo (aDefaultHardDiskFolder);
329
330 return S_OK;
331}
332
333STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder) (IN_BSTR aDefaultHardDiskFolder)
334{
335 AutoCaller autoCaller (this);
336 CheckComRCReturnRC (autoCaller.rc());
337
338 /* VirtualBox::saveSettings() needs a write lock */
339 AutoMultiWriteLock2 alock (mParent, this);
340
341 HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
342 if (SUCCEEDED (rc))
343 rc = mParent->saveSettings();
344
345 return rc;
346}
347
348STDMETHODIMP SystemProperties::
349COMGETTER(HardDiskFormats) (ComSafeArrayOut (IHardDiskFormat *, aHardDiskFormats))
350{
351 if (ComSafeArrayOutIsNull (aHardDiskFormats))
352 return E_POINTER;
353
354 AutoCaller autoCaller (this);
355 CheckComRCReturnRC (autoCaller.rc());
356
357 AutoReadLock alock (this);
358
359 SafeIfaceArray <IHardDiskFormat> hardDiskFormats (mHardDiskFormats);
360 hardDiskFormats.detachTo (ComSafeArrayOutArg (aHardDiskFormats));
361
362 return S_OK;
363}
364
365STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
366{
367 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
368
369 AutoCaller autoCaller (this);
370 CheckComRCReturnRC (autoCaller.rc());
371
372 AutoReadLock alock (this);
373
374 mDefaultHardDiskFormat.cloneTo (aDefaultHardDiskFormat);
375
376 return S_OK;
377}
378
379STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
380{
381 AutoCaller autoCaller (this);
382 CheckComRCReturnRC (autoCaller.rc());
383
384 /* VirtualBox::saveSettings() needs a write lock */
385 AutoMultiWriteLock2 alock (mParent, this);
386
387 HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
388 if (SUCCEEDED (rc))
389 rc = mParent->saveSettings();
390
391 return rc;
392}
393
394STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
395{
396 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
397
398 AutoCaller autoCaller (this);
399 CheckComRCReturnRC (autoCaller.rc());
400
401 AutoReadLock alock (this);
402
403 mRemoteDisplayAuthLibrary.cloneTo (aRemoteDisplayAuthLibrary);
404
405 return S_OK;
406}
407
408STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
409{
410 AutoCaller autoCaller (this);
411 CheckComRCReturnRC (autoCaller.rc());
412
413 /* VirtualBox::saveSettings() needs a write lock */
414 AutoMultiWriteLock2 alock (mParent, this);
415
416 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
417 if (SUCCEEDED (rc))
418 rc = mParent->saveSettings();
419
420 return rc;
421}
422
423STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
424{
425 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
426
427 AutoCaller autoCaller (this);
428 CheckComRCReturnRC (autoCaller.rc());
429
430 AutoReadLock alock (this);
431
432 mWebServiceAuthLibrary.cloneTo (aWebServiceAuthLibrary);
433
434 return S_OK;
435}
436
437STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
438{
439 AutoCaller autoCaller (this);
440 CheckComRCReturnRC (autoCaller.rc());
441
442 /* VirtualBox::saveSettings() needs a write lock */
443 AutoMultiWriteLock2 alock (mParent, this);
444
445 HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
446 if (SUCCEEDED (rc))
447 rc = mParent->saveSettings();
448
449 return rc;
450}
451
452STDMETHODIMP SystemProperties::COMGETTER(HWVirtExEnabled) (BOOL *enabled)
453{
454 if (!enabled)
455 return E_POINTER;
456
457 AutoCaller autoCaller (this);
458 CheckComRCReturnRC (autoCaller.rc());
459
460 AutoReadLock alock (this);
461
462 *enabled = mHWVirtExEnabled;
463
464 return S_OK;
465}
466
467STDMETHODIMP SystemProperties::COMSETTER(HWVirtExEnabled) (BOOL enabled)
468{
469 AutoCaller autoCaller (this);
470 CheckComRCReturnRC (autoCaller.rc());
471
472 /* VirtualBox::saveSettings() needs a write lock */
473 AutoMultiWriteLock2 alock (mParent, this);
474
475 mHWVirtExEnabled = enabled;
476
477 HRESULT rc = mParent->saveSettings();
478
479 return rc;
480}
481
482STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
483{
484 if (!count)
485 return E_POINTER;
486
487 AutoCaller autoCaller (this);
488 CheckComRCReturnRC (autoCaller.rc());
489
490 AutoReadLock alock (this);
491
492 *count = mLogHistoryCount;
493
494 return S_OK;
495}
496
497STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
498{
499 AutoCaller autoCaller (this);
500 CheckComRCReturnRC (autoCaller.rc());
501
502 /* VirtualBox::saveSettings() needs a write lock */
503 AutoMultiWriteLock2 alock (mParent, this);
504
505 mLogHistoryCount = count;
506
507 HRESULT rc = mParent->saveSettings();
508
509 return rc;
510}
511
512// public methods only for internal purposes
513/////////////////////////////////////////////////////////////////////////////
514
515HRESULT SystemProperties::loadSettings (const settings::Key &aGlobal)
516{
517 using namespace settings;
518
519 AutoCaller autoCaller (this);
520 CheckComRCReturnRC (autoCaller.rc());
521
522 AutoWriteLock alock (this);
523
524 AssertReturn (!aGlobal.isNull(), E_FAIL);
525
526 HRESULT rc = S_OK;
527
528 Key properties = aGlobal.key ("SystemProperties");
529
530 Bstr bstr;
531
532 bstr = properties.stringValue ("defaultMachineFolder");
533 rc = setDefaultMachineFolder (bstr);
534 CheckComRCReturnRC (rc);
535
536 bstr = properties.stringValue ("defaultHardDiskFolder");
537 rc = setDefaultHardDiskFolder (bstr);
538 CheckComRCReturnRC (rc);
539
540 bstr = properties.stringValue ("defaultHardDiskFormat");
541 rc = setDefaultHardDiskFormat (bstr);
542 CheckComRCReturnRC (rc);
543
544 bstr = properties.stringValue ("remoteDisplayAuthLibrary");
545 rc = setRemoteDisplayAuthLibrary (bstr);
546 CheckComRCReturnRC (rc);
547
548 bstr = properties.stringValue ("webServiceAuthLibrary");
549 rc = setWebServiceAuthLibrary (bstr);
550 CheckComRCReturnRC (rc);
551
552 /* Note: not <BOOL> because Win32 defines BOOL as int */
553 mHWVirtExEnabled = properties.valueOr <bool> ("HWVirtExEnabled", false);
554
555 mLogHistoryCount = properties.valueOr <ULONG> ("LogHistoryCount", 3);
556
557 return S_OK;
558}
559
560HRESULT SystemProperties::saveSettings (settings::Key &aGlobal)
561{
562 using namespace settings;
563
564 AutoCaller autoCaller (this);
565 CheckComRCReturnRC (autoCaller.rc());
566
567 AutoReadLock alock (this);
568
569 ComAssertRet (!aGlobal.isNull(), E_FAIL);
570
571 /* first, delete the entry */
572 Key properties = aGlobal.findKey ("SystemProperties");
573 if (!properties.isNull())
574 properties.zap();
575 /* then, recreate it */
576 properties = aGlobal.createKey ("SystemProperties");
577
578 if (mDefaultMachineFolder)
579 properties.setValue <Bstr> ("defaultMachineFolder", mDefaultMachineFolder);
580
581 if (mDefaultHardDiskFolder)
582 properties.setValue <Bstr> ("defaultHardDiskFolder", mDefaultHardDiskFolder);
583
584 if (mDefaultHardDiskFormat)
585 properties.setValue <Bstr> ("defaultHardDiskFormat", mDefaultHardDiskFormat);
586
587 if (mRemoteDisplayAuthLibrary)
588 properties.setValue <Bstr> ("remoteDisplayAuthLibrary", mRemoteDisplayAuthLibrary);
589
590 if (mWebServiceAuthLibrary)
591 properties.setValue <Bstr> ("webServiceAuthLibrary", mWebServiceAuthLibrary);
592
593 properties.setValue <bool> ("HWVirtExEnabled", !!mHWVirtExEnabled);
594
595 properties.setValue <ULONG> ("LogHistoryCount", mLogHistoryCount);
596
597 return S_OK;
598}
599
600/**
601 * Rerurns a hard disk format object corresponding to the given format
602 * identifier or null if no such format.
603 *
604 * @param aFormat Format identifier.
605 *
606 * @return ComObjPtr<HardDiskFormat>
607 */
608ComObjPtr <HardDiskFormat> SystemProperties::hardDiskFormat (CBSTR aFormat)
609{
610 ComObjPtr <HardDiskFormat> format;
611
612 AutoCaller autoCaller (this);
613 AssertComRCReturn (autoCaller.rc(), format);
614
615 AutoReadLock alock (this);
616
617 for (HardDiskFormatList::const_iterator it = mHardDiskFormats.begin();
618 it != mHardDiskFormats.end(); ++ it)
619 {
620 /* HardDiskFormat is all const, no need to lock */
621
622 if ((*it)->id().compareIgnoreCase (aFormat) == 0)
623 {
624 format = *it;
625 break;
626 }
627 }
628
629 return format;
630}
631
632// private methods
633/////////////////////////////////////////////////////////////////////////////
634
635HRESULT SystemProperties::setDefaultMachineFolder (CBSTR aPath)
636{
637 Utf8Str path;
638 if (aPath && *aPath)
639 path = aPath;
640 else
641 path = "Machines";
642
643 /* get the full file name */
644 Utf8Str folder;
645 int vrc = mParent->calculateFullPath (path, folder);
646 if (RT_FAILURE (vrc))
647 return setError (E_FAIL,
648 tr ("Invalid default machine folder '%ls' (%Rrc)"),
649 path.raw(), vrc);
650
651 mDefaultMachineFolder = path;
652 mDefaultMachineFolderFull = folder;
653
654 return S_OK;
655}
656
657HRESULT SystemProperties::setDefaultHardDiskFolder (CBSTR aPath)
658{
659 Utf8Str path;
660 if (aPath && *aPath)
661 path = aPath;
662 else
663 path = "HardDisks";
664
665 /* get the full file name */
666 Utf8Str folder;
667 int vrc = mParent->calculateFullPath (path, folder);
668 if (RT_FAILURE (vrc))
669 return setError (E_FAIL,
670 tr ("Invalid default hard disk folder '%ls' (%Rrc)"),
671 path.raw(), vrc);
672
673 mDefaultHardDiskFolder = path;
674 mDefaultHardDiskFolderFull = folder;
675
676 return S_OK;
677}
678
679HRESULT SystemProperties::setDefaultHardDiskFormat (CBSTR aFormat)
680{
681 if (aFormat && *aFormat)
682 mDefaultHardDiskFormat = aFormat;
683 else
684 mDefaultHardDiskFormat = "VDI";
685
686 return S_OK;
687}
688
689HRESULT SystemProperties::setRemoteDisplayAuthLibrary (CBSTR aPath)
690{
691 if (aPath && *aPath)
692 mRemoteDisplayAuthLibrary = aPath;
693 else
694 mRemoteDisplayAuthLibrary = "VRDPAuth";
695
696 return S_OK;
697}
698
699HRESULT SystemProperties::setWebServiceAuthLibrary (CBSTR aPath)
700{
701 if (aPath && *aPath)
702 mWebServiceAuthLibrary = aPath;
703 else
704 mWebServiceAuthLibrary = "VRDPAuth";
705
706 return S_OK;
707}
708/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use