VirtualBox

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

Last change on this file since 33223 was 32531, checked in by vboxsync, 14 years ago

Main/Medium+MediumFormat+GuestOSType+SystemPropertiesImpl+Console+Global: consistently use bytes as size units, forgotten const value in API, MaxVDISize method renamed to InfoVDSize, STDMETHOD macro usage fixes, whitespace cleanup

Frontends/VirtualBox+VBoxManage+VBoxShell: adapt to changed disk size units

Main/StorageControllerImpl: check the storage controller instance limit to avoid creating unusable VM configs, simplify unnecessarily complex code for querying the controller properties

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.1 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 32531 2010-09-15 17:04:48Z 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/VBoxHDD.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 setDefaultHardDiskFolder(Utf8Str::Empty);
88 setDefaultHardDiskFormat(Utf8Str::Empty);
89
90 setRemoteDisplayAuthLibrary(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 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
250 * 48 bit range is in theory trivial, but the crappy compiler makes things
251 * more difficult). This translates to almost 2 TBytes (to be on the safe
252 * side, the reported limit is 1 MiByte less than that, as the total number
253 * of sectors should fit in 32 bits, too), which should be enough for the
254 * moment. The virtual ATA/SATA disks support complete LBA48, and SCSI
255 * supports LBA64 (almost, more like LBA55 in practice), so the theoretical
256 * maximum disk size is 128 PiByte/16 EiByte. The GUI works nicely with 6
257 * orders of magnitude, but not with 11/13 orders of magnitude. */
258 /* no need to lock, this is const */
259 *infoVDSize = (2048LL * 1024 - 1) * _1M;
260
261 return S_OK;
262}
263
264STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
265{
266 CheckComArgOutPointerValid(count);
267
268 AutoCaller autoCaller(this);
269 if (FAILED(autoCaller.rc())) return autoCaller.rc();
270
271 /* no need to lock, this is const */
272 *count = SchemaDefs::NetworkAdapterCount;
273
274 return S_OK;
275}
276
277STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
278{
279 CheckComArgOutPointerValid(count);
280
281 AutoCaller autoCaller(this);
282 if (FAILED(autoCaller.rc())) return autoCaller.rc();
283
284 /* no need to lock, this is const */
285 *count = SchemaDefs::SerialPortCount;
286
287 return S_OK;
288}
289
290STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
291{
292 CheckComArgOutPointerValid(count);
293
294 AutoCaller autoCaller(this);
295 if (FAILED(autoCaller.rc())) return autoCaller.rc();
296
297 /* no need to lock, this is const */
298 *count = SchemaDefs::ParallelPortCount;
299
300 return S_OK;
301}
302
303STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
304{
305 CheckComArgOutPointerValid(aMaxBootPosition);
306
307 AutoCaller autoCaller(this);
308 if (FAILED(autoCaller.rc())) return autoCaller.rc();
309
310 /* no need to lock, this is const */
311 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
312
313 return S_OK;
314}
315
316STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
317 ULONG *aMaxDevicesPerPort)
318{
319 CheckComArgOutPointerValid(aMaxDevicesPerPort);
320
321 AutoCaller autoCaller(this);
322 if (FAILED(autoCaller.rc())) return autoCaller.rc();
323
324 /* no need to lock, this is const */
325 switch (aBus)
326 {
327 case StorageBus_SATA:
328 case StorageBus_SCSI:
329 case StorageBus_SAS:
330 {
331 /* SATA and both SCSI controllers only support one device per port. */
332 *aMaxDevicesPerPort = 1;
333 break;
334 }
335 case StorageBus_IDE:
336 case StorageBus_Floppy:
337 {
338 /* The IDE and Floppy controllers support 2 devices. One as master
339 * and one as slave (or floppy drive 0 and 1). */
340 *aMaxDevicesPerPort = 2;
341 break;
342 }
343 default:
344 AssertMsgFailed(("Invalid bus type %d\n", aBus));
345 }
346
347 return S_OK;
348}
349
350STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
351 ULONG *aMinPortCount)
352{
353 CheckComArgOutPointerValid(aMinPortCount);
354
355 AutoCaller autoCaller(this);
356 if (FAILED(autoCaller.rc())) return autoCaller.rc();
357
358 /* no need to lock, this is const */
359 switch (aBus)
360 {
361 case StorageBus_SATA:
362 {
363 *aMinPortCount = 1;
364 break;
365 }
366 case StorageBus_SCSI:
367 {
368 *aMinPortCount = 16;
369 break;
370 }
371 case StorageBus_IDE:
372 {
373 *aMinPortCount = 2;
374 break;
375 }
376 case StorageBus_Floppy:
377 {
378 *aMinPortCount = 1;
379 break;
380 }
381 case StorageBus_SAS:
382 {
383 *aMinPortCount = 8;
384 break;
385 }
386 default:
387 AssertMsgFailed(("Invalid bus type %d\n", aBus));
388 }
389
390 return S_OK;
391}
392
393STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
394 ULONG *aMaxPortCount)
395{
396 CheckComArgOutPointerValid(aMaxPortCount);
397
398 AutoCaller autoCaller(this);
399 if (FAILED(autoCaller.rc())) return autoCaller.rc();
400
401 /* no need to lock, this is const */
402 switch (aBus)
403 {
404 case StorageBus_SATA:
405 {
406 *aMaxPortCount = 30;
407 break;
408 }
409 case StorageBus_SCSI:
410 {
411 *aMaxPortCount = 16;
412 break;
413 }
414 case StorageBus_IDE:
415 {
416 *aMaxPortCount = 2;
417 break;
418 }
419 case StorageBus_Floppy:
420 {
421 *aMaxPortCount = 1;
422 break;
423 }
424 case StorageBus_SAS:
425 {
426 *aMaxPortCount = 8;
427 break;
428 }
429 default:
430 AssertMsgFailed(("Invalid bus type %d\n", aBus));
431 }
432
433 return S_OK;
434}
435
436STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus,
437 ULONG *aMaxInstances)
438{
439 CheckComArgOutPointerValid(aMaxInstances);
440
441 AutoCaller autoCaller(this);
442 if (FAILED(autoCaller.rc())) return autoCaller.rc();
443
444 /* no need to lock, this is const */
445 switch (aBus)
446 {
447 case StorageBus_SATA:
448 case StorageBus_SCSI:
449 case StorageBus_IDE:
450 case StorageBus_SAS:
451 case StorageBus_Floppy:
452 {
453 /** @todo raise the limits ASAP, per bus type */
454 *aMaxInstances = 1;
455 break;
456 }
457 default:
458 AssertMsgFailed(("Invalid bus type %d\n", aBus));
459 }
460
461 return S_OK;
462}
463
464STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
465 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
466{
467 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
468
469 AutoCaller autoCaller(this);
470 if (FAILED(autoCaller.rc())) return autoCaller.rc();
471
472 /* no need to lock, this is const */
473 switch (aBus)
474 {
475 case StorageBus_IDE:
476 case StorageBus_SATA:
477 {
478 com::SafeArray<DeviceType_T> saDeviceTypes(2);
479 saDeviceTypes[0] = DeviceType_DVD;
480 saDeviceTypes[1] = DeviceType_HardDisk;
481 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
482 break;
483 }
484 case StorageBus_SCSI:
485 case StorageBus_SAS:
486 {
487 com::SafeArray<DeviceType_T> saDeviceTypes(1);
488 saDeviceTypes[0] = DeviceType_HardDisk;
489 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
490 break;
491 }
492 case StorageBus_Floppy:
493 {
494 com::SafeArray<DeviceType_T> saDeviceTypes(1);
495 saDeviceTypes[0] = DeviceType_Floppy;
496 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
497 break;
498 }
499 default:
500 AssertMsgFailed(("Invalid bus type %d\n", aBus));
501 }
502
503 return S_OK;
504}
505
506STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
507{
508 CheckComArgOutPointerValid(aEnabled);
509
510 AutoCaller autoCaller(this);
511 if (FAILED(autoCaller.rc())) return autoCaller.rc();
512
513 /* no need to lock, this is const */
514 switch (aControllerType)
515 {
516 case StorageControllerType_LsiLogic:
517 case StorageControllerType_BusLogic:
518 case StorageControllerType_IntelAhci:
519 case StorageControllerType_LsiLogicSas:
520 *aEnabled = false;
521 break;
522 case StorageControllerType_PIIX3:
523 case StorageControllerType_PIIX4:
524 case StorageControllerType_ICH6:
525 case StorageControllerType_I82078:
526 *aEnabled = true;
527 break;
528 default:
529 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
530 }
531 return S_OK;
532}
533
534STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
535{
536 CheckComArgOutPointerValid(aDefaultMachineFolder);
537
538 AutoCaller autoCaller(this);
539 if (FAILED(autoCaller.rc())) return autoCaller.rc();
540
541 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
542
543 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
544
545 return S_OK;
546}
547
548STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
549{
550 AutoCaller autoCaller(this);
551 if (FAILED(autoCaller.rc())) return autoCaller.rc();
552
553 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
554 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
555 alock.release();
556
557 if (SUCCEEDED(rc))
558 {
559 // VirtualBox::saveSettings() needs vbox write lock
560 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
561 rc = mParent->saveSettings();
562 }
563
564 return rc;
565}
566
567STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder)(BSTR *aDefaultHardDiskFolder)
568{
569 CheckComArgOutPointerValid(aDefaultHardDiskFolder);
570
571 AutoCaller autoCaller(this);
572 if (FAILED(autoCaller.rc())) return autoCaller.rc();
573
574 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
575
576 m_strDefaultHardDiskFolderFull.cloneTo(aDefaultHardDiskFolder);
577
578 return S_OK;
579}
580
581STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder)(IN_BSTR aDefaultHardDiskFolder)
582{
583 AutoCaller autoCaller(this);
584 if (FAILED(autoCaller.rc())) return autoCaller.rc();
585
586 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
587 HRESULT rc = setDefaultHardDiskFolder(aDefaultHardDiskFolder);
588 alock.release();
589
590 if (SUCCEEDED(rc))
591 {
592 // VirtualBox::saveSettings() needs vbox write lock
593 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
594 rc = mParent->saveSettings();
595 }
596
597 return rc;
598}
599
600STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
601{
602 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
603
604 AutoCaller autoCaller(this);
605 if (FAILED(autoCaller.rc())) return autoCaller.rc();
606
607 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
608
609 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
610 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
611
612 return S_OK;
613}
614
615STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
616{
617 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
618
619 AutoCaller autoCaller(this);
620 if (FAILED(autoCaller.rc())) return autoCaller.rc();
621
622 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
623
624 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
625
626 return S_OK;
627}
628
629STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
630{
631 AutoCaller autoCaller(this);
632 if (FAILED(autoCaller.rc())) return autoCaller.rc();
633
634 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
635 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
636 alock.release();
637
638 if (SUCCEEDED(rc))
639 {
640 // VirtualBox::saveSettings() needs vbox write lock
641 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
642 rc = mParent->saveSettings();
643 }
644
645 return rc;
646}
647
648STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
649{
650 CheckComArgOutPointerValid(aFreeSpace);
651
652 ReturnComNotImplemented();
653}
654
655STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
656{
657 ReturnComNotImplemented();
658}
659
660STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
661{
662 CheckComArgOutPointerValid(aFreeSpacePercent);
663
664 ReturnComNotImplemented();
665}
666
667STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
668{
669 ReturnComNotImplemented();
670}
671
672STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
673{
674 CheckComArgOutPointerValid(aFreeSpace);
675
676 ReturnComNotImplemented();
677}
678
679STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
680{
681 ReturnComNotImplemented();
682}
683
684STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
685{
686 CheckComArgOutPointerValid(aFreeSpacePercent);
687
688 ReturnComNotImplemented();
689}
690
691STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
692{
693 ReturnComNotImplemented();
694}
695
696STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary)(BSTR *aRemoteDisplayAuthLibrary)
697{
698 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
699
700 AutoCaller autoCaller(this);
701 if (FAILED(autoCaller.rc())) return autoCaller.rc();
702
703 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
704
705 m->strRemoteDisplayAuthLibrary.cloneTo(aRemoteDisplayAuthLibrary);
706
707 return S_OK;
708}
709
710STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary)(IN_BSTR aRemoteDisplayAuthLibrary)
711{
712 AutoCaller autoCaller(this);
713 if (FAILED(autoCaller.rc())) return autoCaller.rc();
714
715 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
716 HRESULT rc = setRemoteDisplayAuthLibrary(aRemoteDisplayAuthLibrary);
717 alock.release();
718
719 if (SUCCEEDED(rc))
720 {
721 // VirtualBox::saveSettings() needs vbox write lock
722 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
723 rc = mParent->saveSettings();
724 }
725
726 return rc;
727}
728
729STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
730{
731 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
732
733 AutoCaller autoCaller(this);
734 if (FAILED(autoCaller.rc())) return autoCaller.rc();
735
736 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
737
738 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
739
740 return S_OK;
741}
742
743STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
744{
745 AutoCaller autoCaller(this);
746 if (FAILED(autoCaller.rc())) return autoCaller.rc();
747
748 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
749 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
750 alock.release();
751
752 if (SUCCEEDED(rc))
753 {
754 // VirtualBox::saveSettings() needs vbox write lock
755 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
756 rc = mParent->saveSettings();
757 }
758
759 return rc;
760}
761
762STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
763{
764 CheckComArgOutPointerValid(count);
765
766 AutoCaller autoCaller(this);
767 if (FAILED(autoCaller.rc())) return autoCaller.rc();
768
769 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
770
771 *count = m->ulLogHistoryCount;
772
773 return S_OK;
774}
775
776STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
777{
778 AutoCaller autoCaller(this);
779 if (FAILED(autoCaller.rc())) return autoCaller.rc();
780
781 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
782 m->ulLogHistoryCount = count;
783 alock.release();
784
785 // VirtualBox::saveSettings() needs vbox write lock
786 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
787 HRESULT rc = mParent->saveSettings();
788
789 return rc;
790}
791
792STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
793{
794 CheckComArgOutPointerValid(aAudioDriver);
795
796 AutoCaller autoCaller(this);
797 if (FAILED(autoCaller.rc())) return autoCaller.rc();
798
799 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
800
801 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
802
803 return S_OK;
804}
805
806// public methods only for internal purposes
807/////////////////////////////////////////////////////////////////////////////
808
809HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
810{
811 AutoCaller autoCaller(this);
812 if (FAILED(autoCaller.rc())) return autoCaller.rc();
813
814 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
815
816 HRESULT rc = S_OK;
817
818 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
819 if (FAILED(rc)) return rc;
820
821 rc = setDefaultHardDiskFolder(data.strDefaultHardDiskFolder);
822 if (FAILED(rc)) return rc;
823
824 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
825 if (FAILED(rc)) return rc;
826
827 rc = setRemoteDisplayAuthLibrary(data.strRemoteDisplayAuthLibrary);
828 if (FAILED(rc)) return rc;
829
830 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
831 if (FAILED(rc)) return rc;
832
833 m->ulLogHistoryCount = data.ulLogHistoryCount;
834
835 return S_OK;
836}
837
838HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
839{
840 AutoCaller autoCaller(this);
841 if (FAILED(autoCaller.rc())) return autoCaller.rc();
842
843 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
844
845 data = *m;
846
847 return S_OK;
848}
849
850/**
851 * Returns a medium format object corresponding to the given format
852 * identifier or null if no such format.
853 *
854 * @param aFormat Format identifier.
855 *
856 * @return ComObjPtr<MediumFormat>
857 */
858ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
859{
860 ComObjPtr<MediumFormat> format;
861
862 AutoCaller autoCaller(this);
863 AssertComRCReturn (autoCaller.rc(), format);
864
865 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
866
867 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
868 it != m_llMediumFormats.end();
869 ++ it)
870 {
871 /* MediumFormat is all const, no need to lock */
872
873 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
874 {
875 format = *it;
876 break;
877 }
878 }
879
880 return format;
881}
882
883// private methods
884/////////////////////////////////////////////////////////////////////////////
885
886HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
887{
888 Utf8Str path(aPath);
889 if (path.isEmpty())
890 path = "Machines";
891
892 /* get the full file name */
893 Utf8Str folder;
894 int vrc = mParent->calculateFullPath(path, folder);
895 if (RT_FAILURE(vrc))
896 return setError(E_FAIL,
897 tr("Invalid default machine folder '%s' (%Rrc)"),
898 path.c_str(),
899 vrc);
900
901 m->strDefaultMachineFolder = path;
902 m_strDefaultMachineFolderFull = folder;
903
904 return S_OK;
905}
906
907HRESULT SystemProperties::setDefaultHardDiskFolder(const Utf8Str &aPath)
908{
909 Utf8Str path(aPath);
910 if (path.isEmpty())
911 path = "HardDisks";
912
913 /* get the full file name */
914 Utf8Str folder;
915 int vrc = mParent->calculateFullPath(path, folder);
916 if (RT_FAILURE(vrc))
917 return setError(E_FAIL,
918 tr("Invalid default hard disk folder '%s' (%Rrc)"),
919 path.c_str(),
920 vrc);
921
922 m->strDefaultHardDiskFolder = path;
923 m_strDefaultHardDiskFolderFull = folder;
924
925 return S_OK;
926}
927
928HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
929{
930 if (!aFormat.isEmpty())
931 m->strDefaultHardDiskFormat = aFormat;
932 else
933 m->strDefaultHardDiskFormat = "VDI";
934
935 return S_OK;
936}
937
938HRESULT SystemProperties::setRemoteDisplayAuthLibrary(const Utf8Str &aPath)
939{
940 if (!aPath.isEmpty())
941 m->strRemoteDisplayAuthLibrary = aPath;
942 else
943 m->strRemoteDisplayAuthLibrary = "VRDPAuth";
944
945 return S_OK;
946}
947
948HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
949{
950 if (!aPath.isEmpty())
951 m->strWebServiceAuthLibrary = aPath;
952 else
953 m->strWebServiceAuthLibrary = "VRDPAuth";
954
955 return S_OK;
956}
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