VirtualBox

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

Last change on this file since 33973 was 33915, checked in by vboxsync, 14 years ago

Main, QT/FE, VBoxManage: per-chipset controller count limits

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.5 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 33915 2010-11-09 16:44:39Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2010 Oracle Corporation
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
20#include "SystemPropertiesImpl.h"
21#include "VirtualBoxImpl.h"
22#include "MachineImpl.h"
23#include "AutoCaller.h"
24#include "Logging.h"
25
26// generated header
27#include "SchemaDefs.h"
28
29#include <iprt/path.h>
30#include <iprt/dir.h>
31#include <iprt/cpp/utils.h>
32
33#include <VBox/err.h>
34#include <VBox/param.h>
35#include <VBox/settings.h>
36#include <VBox/vd.h>
37
38// defines
39/////////////////////////////////////////////////////////////////////////////
40
41// constructor / destructor
42/////////////////////////////////////////////////////////////////////////////
43
44SystemProperties::SystemProperties()
45 : mParent(NULL),
46 m(new settings::SystemProperties)
47{
48}
49
50SystemProperties::~SystemProperties()
51{
52 delete m;
53}
54
55
56HRESULT SystemProperties::FinalConstruct()
57{
58 return S_OK;
59}
60
61void SystemProperties::FinalRelease()
62{
63 uninit();
64}
65
66// public methods only for internal purposes
67/////////////////////////////////////////////////////////////////////////////
68
69/**
70 * Initializes the system information object.
71 *
72 * @returns COM result indicator
73 */
74HRESULT SystemProperties::init(VirtualBox *aParent)
75{
76 LogFlowThisFunc(("aParent=%p\n", aParent));
77
78 ComAssertRet(aParent, E_FAIL);
79
80 /* Enclose the state transition NotReady->InInit->Ready */
81 AutoInitSpan autoInitSpan(this);
82 AssertReturn(autoInitSpan.isOk(), E_FAIL);
83
84 unconst(mParent) = aParent;
85
86 setDefaultMachineFolder(Utf8Str::Empty);
87 setDefaultHardDiskFormat(Utf8Str::Empty);
88
89 setVRDEAuthLibrary(Utf8Str::Empty);
90 setDefaultVRDELibrary(Utf8Str::Empty);
91
92 m->ulLogHistoryCount = 3;
93
94 HRESULT rc = S_OK;
95
96 /* Fetch info of all available hd backends. */
97
98 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
99 /// any number of backends
100
101 VDBACKENDINFO aVDInfo[100];
102 unsigned cEntries;
103 int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
104 AssertRC(vrc);
105 if (RT_SUCCESS(vrc))
106 {
107 for (unsigned i = 0; i < cEntries; ++ i)
108 {
109 ComObjPtr<MediumFormat> hdf;
110 rc = hdf.createObject();
111 if (FAILED(rc)) break;
112
113 rc = hdf->init(&aVDInfo[i]);
114 if (FAILED(rc)) break;
115
116 m_llMediumFormats.push_back(hdf);
117 }
118 }
119
120 /* Confirm a successful initialization */
121 if (SUCCEEDED(rc))
122 autoInitSpan.setSucceeded();
123
124 return rc;
125}
126
127/**
128 * Uninitializes the instance and sets the ready flag to FALSE.
129 * Called either from FinalRelease() or by the parent when it gets destroyed.
130 */
131void SystemProperties::uninit()
132{
133 LogFlowThisFunc(("\n"));
134
135 /* Enclose the state transition Ready->InUninit->NotReady */
136 AutoUninitSpan autoUninitSpan(this);
137 if (autoUninitSpan.uninitDone())
138 return;
139
140 unconst(mParent) = NULL;
141}
142
143// ISystemProperties properties
144/////////////////////////////////////////////////////////////////////////////
145
146
147STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
148{
149 CheckComArgOutPointerValid(minRAM);
150
151 AutoCaller autoCaller(this);
152 if (FAILED(autoCaller.rc())) return autoCaller.rc();
153
154 /* no need to lock, this is const */
155 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
156 *minRAM = MM_RAM_MIN_IN_MB;
157
158 return S_OK;
159}
160
161STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
162{
163 CheckComArgOutPointerValid(maxRAM);
164
165 AutoCaller autoCaller(this);
166 if (FAILED(autoCaller.rc())) return autoCaller.rc();
167
168 /* no need to lock, this is const */
169 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
170 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
171 ULONG maxRAMArch = maxRAMSys;
172 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
173
174 return S_OK;
175}
176
177STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
178{
179 CheckComArgOutPointerValid(minVRAM);
180
181 AutoCaller autoCaller(this);
182 if (FAILED(autoCaller.rc())) return autoCaller.rc();
183
184 /* no need to lock, this is const */
185 *minVRAM = SchemaDefs::MinGuestVRAM;
186
187 return S_OK;
188}
189
190STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
191{
192 CheckComArgOutPointerValid(maxVRAM);
193
194 AutoCaller autoCaller(this);
195 if (FAILED(autoCaller.rc())) return autoCaller.rc();
196
197 /* no need to lock, this is const */
198 *maxVRAM = SchemaDefs::MaxGuestVRAM;
199
200 return S_OK;
201}
202
203STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
204{
205 CheckComArgOutPointerValid(minCPUCount);
206
207 AutoCaller autoCaller(this);
208 if (FAILED(autoCaller.rc())) return autoCaller.rc();
209
210 /* no need to lock, this is const */
211 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
212
213 return S_OK;
214}
215
216STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
217{
218 CheckComArgOutPointerValid(maxCPUCount);
219
220 AutoCaller autoCaller(this);
221 if (FAILED(autoCaller.rc())) return autoCaller.rc();
222
223 /* no need to lock, this is const */
224 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
225
226 return S_OK;
227}
228
229STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
230{
231 CheckComArgOutPointerValid(maxMonitors);
232
233 AutoCaller autoCaller(this);
234 if (FAILED(autoCaller.rc())) return autoCaller.rc();
235
236 /* no need to lock, this is const */
237 *maxMonitors = SchemaDefs::MaxGuestMonitors;
238
239 return S_OK;
240}
241
242STDMETHODIMP SystemProperties::COMGETTER(InfoVDSize)(LONG64 *infoVDSize)
243{
244 CheckComArgOutPointerValid(infoVDSize);
245
246 AutoCaller autoCaller(this);
247 if (FAILED(autoCaller.rc())) return autoCaller.rc();
248
249 /*
250 * The BIOS supports currently 32 bit LBA numbers (implementing the full
251 * 48 bit range is in theory trivial, but the crappy compiler makes things
252 * more difficult). This translates to almost 2 TiBytes (to be on the safe
253 * side, the reported limit is 1 MiByte less than that, as the total number
254 * of sectors should fit in 32 bits, too), which should be enough for the
255 * moment. Since the MBR partition tables support only 32bit sector numbers
256 * and thus the BIOS can only boot from disks smaller than 2T this is a
257 * rather hard limit.
258 *
259 * The virtual ATA/SATA disks support complete LBA48, and SCSI supports
260 * LBA64 (almost, more like LBA55 in practice), so the theoretical maximum
261 * disk size is 128 PiByte/16 EiByte. The GUI works nicely with 6 orders
262 * of magnitude, but not with 11..13 orders of magnitude.
263 */
264 /* no need to lock, this is const */
265 *infoVDSize = 2 * _1T - _1M;
266
267 return S_OK;
268}
269
270STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
271{
272 CheckComArgOutPointerValid(count);
273
274 AutoCaller autoCaller(this);
275 if (FAILED(autoCaller.rc())) return autoCaller.rc();
276
277 /* no need to lock, this is const */
278 *count = SchemaDefs::NetworkAdapterCount;
279
280 return S_OK;
281}
282
283STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
284{
285 CheckComArgOutPointerValid(count);
286
287 AutoCaller autoCaller(this);
288 if (FAILED(autoCaller.rc())) return autoCaller.rc();
289
290 /* no need to lock, this is const */
291 *count = SchemaDefs::SerialPortCount;
292
293 return S_OK;
294}
295
296STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
297{
298 CheckComArgOutPointerValid(count);
299
300 AutoCaller autoCaller(this);
301 if (FAILED(autoCaller.rc())) return autoCaller.rc();
302
303 /* no need to lock, this is const */
304 *count = SchemaDefs::ParallelPortCount;
305
306 return S_OK;
307}
308
309STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
310{
311 CheckComArgOutPointerValid(aMaxBootPosition);
312
313 AutoCaller autoCaller(this);
314 if (FAILED(autoCaller.rc())) return autoCaller.rc();
315
316 /* no need to lock, this is const */
317 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
318
319 return S_OK;
320}
321
322STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
323 ULONG *aMaxDevicesPerPort)
324{
325 CheckComArgOutPointerValid(aMaxDevicesPerPort);
326
327 AutoCaller autoCaller(this);
328 if (FAILED(autoCaller.rc())) return autoCaller.rc();
329
330 /* no need to lock, this is const */
331 switch (aBus)
332 {
333 case StorageBus_SATA:
334 case StorageBus_SCSI:
335 case StorageBus_SAS:
336 {
337 /* SATA and both SCSI controllers only support one device per port. */
338 *aMaxDevicesPerPort = 1;
339 break;
340 }
341 case StorageBus_IDE:
342 case StorageBus_Floppy:
343 {
344 /* The IDE and Floppy controllers support 2 devices. One as master
345 * and one as slave (or floppy drive 0 and 1). */
346 *aMaxDevicesPerPort = 2;
347 break;
348 }
349 default:
350 AssertMsgFailed(("Invalid bus type %d\n", aBus));
351 }
352
353 return S_OK;
354}
355
356STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
357 ULONG *aMinPortCount)
358{
359 CheckComArgOutPointerValid(aMinPortCount);
360
361 AutoCaller autoCaller(this);
362 if (FAILED(autoCaller.rc())) return autoCaller.rc();
363
364 /* no need to lock, this is const */
365 switch (aBus)
366 {
367 case StorageBus_SATA:
368 {
369 *aMinPortCount = 1;
370 break;
371 }
372 case StorageBus_SCSI:
373 {
374 *aMinPortCount = 16;
375 break;
376 }
377 case StorageBus_IDE:
378 {
379 *aMinPortCount = 2;
380 break;
381 }
382 case StorageBus_Floppy:
383 {
384 *aMinPortCount = 1;
385 break;
386 }
387 case StorageBus_SAS:
388 {
389 *aMinPortCount = 8;
390 break;
391 }
392 default:
393 AssertMsgFailed(("Invalid bus type %d\n", aBus));
394 }
395
396 return S_OK;
397}
398
399STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
400 ULONG *aMaxPortCount)
401{
402 CheckComArgOutPointerValid(aMaxPortCount);
403
404 AutoCaller autoCaller(this);
405 if (FAILED(autoCaller.rc())) return autoCaller.rc();
406
407 /* no need to lock, this is const */
408 switch (aBus)
409 {
410 case StorageBus_SATA:
411 {
412 *aMaxPortCount = 30;
413 break;
414 }
415 case StorageBus_SCSI:
416 {
417 *aMaxPortCount = 16;
418 break;
419 }
420 case StorageBus_IDE:
421 {
422 *aMaxPortCount = 2;
423 break;
424 }
425 case StorageBus_Floppy:
426 {
427 *aMaxPortCount = 1;
428 break;
429 }
430 case StorageBus_SAS:
431 {
432 *aMaxPortCount = 8;
433 break;
434 }
435 default:
436 AssertMsgFailed(("Invalid bus type %d\n", aBus));
437 }
438
439 return S_OK;
440}
441
442STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(ChipsetType_T aChipset,
443 StorageBus_T aBus,
444 ULONG *aMaxInstances)
445{
446 CheckComArgOutPointerValid(aMaxInstances);
447
448 AutoCaller autoCaller(this);
449 if (FAILED(autoCaller.rc())) return autoCaller.rc();
450
451 ULONG cCtrs = 0;
452
453 /* no need to lock, this is const */
454 switch (aBus)
455 {
456 case StorageBus_SATA:
457 case StorageBus_SCSI:
458 case StorageBus_SAS:
459 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
460 break;
461 case StorageBus_IDE:
462 case StorageBus_Floppy:
463 {
464 cCtrs = 1;
465 break;
466 }
467 default:
468 AssertMsgFailed(("Invalid bus type %d\n", aBus));
469 }
470
471 *aMaxInstances = cCtrs;
472
473 return S_OK;
474}
475
476STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
477 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
478{
479 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
480
481 AutoCaller autoCaller(this);
482 if (FAILED(autoCaller.rc())) return autoCaller.rc();
483
484 /* no need to lock, this is const */
485 switch (aBus)
486 {
487 case StorageBus_IDE:
488 case StorageBus_SATA:
489 {
490 com::SafeArray<DeviceType_T> saDeviceTypes(2);
491 saDeviceTypes[0] = DeviceType_DVD;
492 saDeviceTypes[1] = DeviceType_HardDisk;
493 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
494 break;
495 }
496 case StorageBus_SCSI:
497 case StorageBus_SAS:
498 {
499 com::SafeArray<DeviceType_T> saDeviceTypes(1);
500 saDeviceTypes[0] = DeviceType_HardDisk;
501 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
502 break;
503 }
504 case StorageBus_Floppy:
505 {
506 com::SafeArray<DeviceType_T> saDeviceTypes(1);
507 saDeviceTypes[0] = DeviceType_Floppy;
508 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
509 break;
510 }
511 default:
512 AssertMsgFailed(("Invalid bus type %d\n", aBus));
513 }
514
515 return S_OK;
516}
517
518STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
519{
520 CheckComArgOutPointerValid(aEnabled);
521
522 AutoCaller autoCaller(this);
523 if (FAILED(autoCaller.rc())) return autoCaller.rc();
524
525 /* no need to lock, this is const */
526 switch (aControllerType)
527 {
528 case StorageControllerType_LsiLogic:
529 case StorageControllerType_BusLogic:
530 case StorageControllerType_IntelAhci:
531 case StorageControllerType_LsiLogicSas:
532 *aEnabled = false;
533 break;
534 case StorageControllerType_PIIX3:
535 case StorageControllerType_PIIX4:
536 case StorageControllerType_ICH6:
537 case StorageControllerType_I82078:
538 *aEnabled = true;
539 break;
540 default:
541 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
542 }
543 return S_OK;
544}
545
546STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
547{
548 CheckComArgOutPointerValid(aDefaultMachineFolder);
549
550 AutoCaller autoCaller(this);
551 if (FAILED(autoCaller.rc())) return autoCaller.rc();
552
553 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
554
555 m->strDefaultMachineFolder.cloneTo(aDefaultMachineFolder);
556
557 return S_OK;
558}
559
560STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
561{
562 AutoCaller autoCaller(this);
563 if (FAILED(autoCaller.rc())) return autoCaller.rc();
564
565 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
566 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
567 alock.release();
568
569 if (SUCCEEDED(rc))
570 {
571 // VirtualBox::saveSettings() needs vbox write lock
572 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
573 rc = mParent->saveSettings();
574 }
575
576 return rc;
577}
578
579STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
580{
581 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
582
583 AutoCaller autoCaller(this);
584 if (FAILED(autoCaller.rc())) return autoCaller.rc();
585
586 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
587
588 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
589 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
590
591 return S_OK;
592}
593
594STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
595{
596 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
597
598 AutoCaller autoCaller(this);
599 if (FAILED(autoCaller.rc())) return autoCaller.rc();
600
601 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
602
603 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
604
605 return S_OK;
606}
607
608STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
609{
610 AutoCaller autoCaller(this);
611 if (FAILED(autoCaller.rc())) return autoCaller.rc();
612
613 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
614 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
615 alock.release();
616
617 if (SUCCEEDED(rc))
618 {
619 // VirtualBox::saveSettings() needs vbox write lock
620 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
621 rc = mParent->saveSettings();
622 }
623
624 return rc;
625}
626
627STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
628{
629 CheckComArgOutPointerValid(aFreeSpace);
630
631 ReturnComNotImplemented();
632}
633
634STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
635{
636 ReturnComNotImplemented();
637}
638
639STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
640{
641 CheckComArgOutPointerValid(aFreeSpacePercent);
642
643 ReturnComNotImplemented();
644}
645
646STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
647{
648 ReturnComNotImplemented();
649}
650
651STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
652{
653 CheckComArgOutPointerValid(aFreeSpace);
654
655 ReturnComNotImplemented();
656}
657
658STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
659{
660 ReturnComNotImplemented();
661}
662
663STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
664{
665 CheckComArgOutPointerValid(aFreeSpacePercent);
666
667 ReturnComNotImplemented();
668}
669
670STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
671{
672 ReturnComNotImplemented();
673}
674
675STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
676{
677 CheckComArgOutPointerValid(aVRDEAuthLibrary);
678
679 AutoCaller autoCaller(this);
680 if (FAILED(autoCaller.rc())) return autoCaller.rc();
681
682 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
683
684 m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
685
686 return S_OK;
687}
688
689STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
690{
691 AutoCaller autoCaller(this);
692 if (FAILED(autoCaller.rc())) return autoCaller.rc();
693
694 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
695 HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
696 alock.release();
697
698 if (SUCCEEDED(rc))
699 {
700 // VirtualBox::saveSettings() needs vbox write lock
701 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
702 rc = mParent->saveSettings();
703 }
704
705 return rc;
706}
707
708STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
709{
710 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
711
712 AutoCaller autoCaller(this);
713 if (FAILED(autoCaller.rc())) return autoCaller.rc();
714
715 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
716
717 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
718
719 return S_OK;
720}
721
722STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
723{
724 AutoCaller autoCaller(this);
725 if (FAILED(autoCaller.rc())) return autoCaller.rc();
726
727 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
728 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
729 alock.release();
730
731 if (SUCCEEDED(rc))
732 {
733 // VirtualBox::saveSettings() needs vbox write lock
734 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
735 rc = mParent->saveSettings();
736 }
737
738 return rc;
739}
740
741STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDELibrary)(BSTR *aVRDELibrary)
742{
743 CheckComArgOutPointerValid(aVRDELibrary);
744
745 AutoCaller autoCaller(this);
746 if (FAILED(autoCaller.rc())) return autoCaller.rc();
747
748 BOOL fFound = FALSE;
749 HRESULT rc = mParent->VRDEIsLibraryRegistered(Bstr(m->strDefaultVRDELibrary).raw(), &fFound);
750
751 if (FAILED(rc)|| !fFound)
752 return setError(E_FAIL, "The library is not registered\n");
753
754 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
755
756 m->strDefaultVRDELibrary.cloneTo(aVRDELibrary);
757
758 return S_OK;
759}
760
761STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDELibrary)(IN_BSTR aVRDELibrary)
762{
763 AutoCaller autoCaller(this);
764 if (FAILED(autoCaller.rc())) return autoCaller.rc();
765
766 HRESULT rc;
767
768 Bstr bstrLibrary(aVRDELibrary);
769
770 if (!bstrLibrary.isEmpty())
771 {
772 BOOL fFound = FALSE;
773 rc = mParent->VRDEIsLibraryRegistered(bstrLibrary.raw(), &fFound);
774
775 if (FAILED(rc) || !fFound)
776 return setError(E_FAIL, "The library is not registered\n");
777 }
778
779 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
780 rc = setDefaultVRDELibrary(bstrLibrary);
781 alock.release();
782
783 if (SUCCEEDED(rc))
784 {
785 // VirtualBox::saveSettings() needs vbox write lock
786 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
787 rc = mParent->saveSettings();
788 }
789
790 return rc;
791}
792
793STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
794{
795 CheckComArgOutPointerValid(count);
796
797 AutoCaller autoCaller(this);
798 if (FAILED(autoCaller.rc())) return autoCaller.rc();
799
800 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
801
802 *count = m->ulLogHistoryCount;
803
804 return S_OK;
805}
806
807STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
808{
809 AutoCaller autoCaller(this);
810 if (FAILED(autoCaller.rc())) return autoCaller.rc();
811
812 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
813 m->ulLogHistoryCount = count;
814 alock.release();
815
816 // VirtualBox::saveSettings() needs vbox write lock
817 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
818 HRESULT rc = mParent->saveSettings();
819
820 return rc;
821}
822
823STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
824{
825 CheckComArgOutPointerValid(aAudioDriver);
826
827 AutoCaller autoCaller(this);
828 if (FAILED(autoCaller.rc())) return autoCaller.rc();
829
830 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
831
832 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
833
834 return S_OK;
835}
836
837// public methods only for internal purposes
838/////////////////////////////////////////////////////////////////////////////
839
840HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
841{
842 AutoCaller autoCaller(this);
843 if (FAILED(autoCaller.rc())) return autoCaller.rc();
844
845 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
846
847 HRESULT rc = S_OK;
848
849 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
850 if (FAILED(rc)) return rc;
851
852 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
853 if (FAILED(rc)) return rc;
854
855 rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
856 if (FAILED(rc)) return rc;
857
858 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
859 if (FAILED(rc)) return rc;
860
861 rc = setDefaultVRDELibrary(data.strDefaultVRDELibrary);
862 if (FAILED(rc)) return rc;
863
864 m->ulLogHistoryCount = data.ulLogHistoryCount;
865
866 return S_OK;
867}
868
869HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
870{
871 AutoCaller autoCaller(this);
872 if (FAILED(autoCaller.rc())) return autoCaller.rc();
873
874 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
875
876 data = *m;
877
878 return S_OK;
879}
880
881/**
882 * Returns a medium format object corresponding to the given format
883 * identifier or null if no such format.
884 *
885 * @param aFormat Format identifier.
886 *
887 * @return ComObjPtr<MediumFormat>
888 */
889ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
890{
891 ComObjPtr<MediumFormat> format;
892
893 AutoCaller autoCaller(this);
894 AssertComRCReturn (autoCaller.rc(), format);
895
896 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
897
898 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
899 it != m_llMediumFormats.end();
900 ++ it)
901 {
902 /* MediumFormat is all const, no need to lock */
903
904 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
905 {
906 format = *it;
907 break;
908 }
909 }
910
911 return format;
912}
913
914/**
915 * Returns a medium format object corresponding to the given file extension or
916 * null if no such format.
917 *
918 * @param aExt File extension.
919 *
920 * @return ComObjPtr<MediumFormat>
921 */
922ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
923{
924 ComObjPtr<MediumFormat> format;
925
926 AutoCaller autoCaller(this);
927 AssertComRCReturn (autoCaller.rc(), format);
928
929 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
930
931 bool fFound = false;
932 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
933 it != m_llMediumFormats.end() && !fFound;
934 ++it)
935 {
936 /* MediumFormat is all const, no need to lock */
937 MediumFormat::StrList aFileList = (*it)->getFileExtensions();
938 for (MediumFormat::StrList::const_iterator it1 = aFileList.begin();
939 it1 != aFileList.end();
940 ++it1)
941 {
942 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
943 {
944 format = *it;
945 fFound = true;
946 break;
947 }
948 }
949 }
950
951 return format;
952}
953
954// private methods
955/////////////////////////////////////////////////////////////////////////////
956
957/**
958 * Returns the user's home directory. Wrapper around RTPathUserHome().
959 * @param strPath
960 * @return
961 */
962HRESULT SystemProperties::getUserHomeDirectory(Utf8Str &strPath)
963{
964 char szHome[RTPATH_MAX];
965 int vrc = RTPathUserHome(szHome, sizeof(szHome));
966 if (RT_FAILURE(vrc))
967 return setError(E_FAIL,
968 tr("Cannot determine user home directory (%Rrc)"),
969 vrc);
970 strPath = szHome;
971 return S_OK;
972}
973
974/**
975 * Internal implementation to set the default machine folder. Gets called
976 * from the public attribute setter as well as loadSettings(). With 4.0,
977 * the "default default" machine folder has changed, and we now require
978 * a full path always.
979 * @param aPath
980 * @return
981 */
982HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &strPath)
983{
984 Utf8Str path(strPath); // make modifiable
985 if ( path.isEmpty() // used by API calls to reset the default
986 || path == "Machines" // this value (exactly like this, without path) is stored
987 // in VirtualBox.xml if user upgrades from before 4.0 and
988 // has not changed the default machine folder
989 )
990 {
991 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
992 HRESULT rc = getUserHomeDirectory(path);
993 if (FAILED(rc)) return rc;
994 path += RTPATH_SLASH_STR "VirtualBox VMs";
995 }
996
997 if (!RTPathStartsWithRoot(path.c_str()))
998 return setError(E_INVALIDARG,
999 tr("Given default machine folder '%s' is not fully qualified"),
1000 path.c_str());
1001
1002 m->strDefaultMachineFolder = path;
1003
1004 return S_OK;
1005}
1006
1007HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
1008{
1009 if (!aFormat.isEmpty())
1010 m->strDefaultHardDiskFormat = aFormat;
1011 else
1012 m->strDefaultHardDiskFormat = "VDI";
1013
1014 return S_OK;
1015}
1016
1017HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
1018{
1019 if (!aPath.isEmpty())
1020 m->strVRDEAuthLibrary = aPath;
1021 else
1022 m->strVRDEAuthLibrary = "VRDPAuth";
1023
1024 return S_OK;
1025}
1026
1027HRESULT SystemProperties::setDefaultVRDELibrary(const Utf8Str &aPath)
1028{
1029 m->strDefaultVRDELibrary = aPath;
1030
1031 return S_OK;
1032}
1033
1034HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
1035{
1036 if (!aPath.isEmpty())
1037 m->strWebServiceAuthLibrary = aPath;
1038 else
1039 m->strWebServiceAuthLibrary = "VRDPAuth";
1040
1041 return S_OK;
1042}
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