VirtualBox

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

Last change on this file since 25414 was 25310, checked in by vboxsync, 14 years ago

Main: lock validator, first batch: implement per-thread stack to trace locking (disabled by default, use VBOX_WITH_LOCK_VALIDATOR, but that WILL FAIL presently)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.8 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 25310 2009-12-10 17:06:44Z 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#include <iprt/process.h>
35#include <iprt/ldr.h>
36
37#include <VBox/err.h>
38#include <VBox/param.h>
39#include <VBox/settings.h>
40#include <VBox/VBoxHDD.h>
41
42// defines
43/////////////////////////////////////////////////////////////////////////////
44
45// constructor / destructor
46/////////////////////////////////////////////////////////////////////////////
47
48DEFINE_EMPTY_CTOR_DTOR (SystemProperties)
49
50HRESULT SystemProperties::FinalConstruct()
51{
52 return S_OK;
53}
54
55void SystemProperties::FinalRelease()
56{
57 uninit ();
58}
59
60// public methods only for internal purposes
61/////////////////////////////////////////////////////////////////////////////
62
63/**
64 * Initializes the system information object.
65 *
66 * @returns COM result indicator
67 */
68HRESULT SystemProperties::init (VirtualBox *aParent)
69{
70 LogFlowThisFunc(("aParent=%p\n", aParent));
71
72 ComAssertRet (aParent, E_FAIL);
73
74 /* Enclose the state transition NotReady->InInit->Ready */
75 AutoInitSpan autoInitSpan(this);
76 AssertReturn(autoInitSpan.isOk(), E_FAIL);
77
78 unconst(mParent) = aParent;
79
80 setDefaultMachineFolder(Utf8Str::Null);
81 setDefaultHardDiskFolder(Utf8Str::Null);
82 setDefaultHardDiskFormat(Utf8Str::Null);
83
84 setRemoteDisplayAuthLibrary(Utf8Str::Null);
85
86 mLogHistoryCount = 3;
87
88 HRESULT rc = S_OK;
89
90 /* Fetch info of all available hd backends. */
91
92 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
93 /// any number of backends
94
95 /// @todo We currently leak memory because it's not actually clear what to
96 /// free in structures returned by VDBackendInfo. Must be fixed ASAP!
97
98 VDBACKENDINFO aVDInfo [100];
99 unsigned cEntries;
100 int vrc = VDBackendInfo (RT_ELEMENTS (aVDInfo), aVDInfo, &cEntries);
101 AssertRC (vrc);
102 if (RT_SUCCESS(vrc))
103 {
104 for (unsigned i = 0; i < cEntries; ++ i)
105 {
106 ComObjPtr<MediumFormat> hdf;
107 rc = hdf.createObject();
108 if (FAILED(rc)) break;
109
110 rc = hdf->init (&aVDInfo [i]);
111 if (FAILED(rc)) break;
112
113 mMediumFormats.push_back (hdf);
114 }
115 }
116
117 /* Driver defaults which are OS specific */
118#if defined (RT_OS_WINDOWS)
119# ifdef VBOX_WITH_WINMM
120 mDefaultAudioDriver = AudioDriverType_WinMM;
121# else /* VBOX_WITH_WINMM */
122 mDefaultAudioDriver = AudioDriverType_DirectSound;
123# endif /* !VBOX_WITH_WINMM */
124#elif defined (RT_OS_SOLARIS)
125 mDefaultAudioDriver = AudioDriverType_SolAudio;
126#elif defined (RT_OS_LINUX)
127# if defined (VBOX_WITH_PULSE)
128 /* Check for the pulse library & that the pulse audio daemon is running. */
129 if (RTProcIsRunningByName ("pulseaudio") &&
130 RTLdrIsLoadable ("libpulse.so.0"))
131 mDefaultAudioDriver = AudioDriverType_Pulse;
132 else
133# endif /* VBOX_WITH_PULSE */
134# if defined (VBOX_WITH_ALSA)
135 /* Check if we can load the ALSA library */
136 if (RTLdrIsLoadable ("libasound.so.2"))
137 mDefaultAudioDriver = AudioDriverType_ALSA;
138 else
139# endif /* VBOX_WITH_ALSA */
140 mDefaultAudioDriver = AudioDriverType_OSS;
141#elif defined (RT_OS_DARWIN)
142 mDefaultAudioDriver = AudioDriverType_CoreAudio;
143#elif defined (RT_OS_OS2)
144 mDefaultAudioDriver = AudioDriverType_MMP;
145#elif defined (RT_OS_FREEBSD)
146 mDefaultAudioDriver = AudioDriverType_OSS;
147#else
148 mDefaultAudioDriver = AudioDriverType_Null;
149#endif
150
151 /* Confirm a successful initialization */
152 if (SUCCEEDED(rc))
153 autoInitSpan.setSucceeded();
154
155 return rc;
156}
157
158/**
159 * Uninitializes the instance and sets the ready flag to FALSE.
160 * Called either from FinalRelease() or by the parent when it gets destroyed.
161 */
162void SystemProperties::uninit()
163{
164 LogFlowThisFunc(("\n"));
165
166 /* Enclose the state transition Ready->InUninit->NotReady */
167 AutoUninitSpan autoUninitSpan(this);
168 if (autoUninitSpan.uninitDone())
169 return;
170
171 unconst(mParent).setNull();
172}
173
174// ISystemProperties properties
175/////////////////////////////////////////////////////////////////////////////
176
177
178STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
179{
180 if (!minRAM)
181 return E_POINTER;
182
183 AutoCaller autoCaller(this);
184 if (FAILED(autoCaller.rc())) return autoCaller.rc();
185
186 /* no need to lock, this is const */
187 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
188 *minRAM = MM_RAM_MIN_IN_MB;
189
190 return S_OK;
191}
192
193STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
194{
195 if (!maxRAM)
196 return E_POINTER;
197
198 AutoCaller autoCaller(this);
199 if (FAILED(autoCaller.rc())) return autoCaller.rc();
200
201 /* no need to lock, this is const */
202 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
203 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
204 ULONG maxRAMArch = maxRAMSys;
205#if HC_ARCH_BITS == 32 && !defined(RT_OS_DARWIN)
206# ifdef RT_OS_WINDOWS
207 maxRAMArch = UINT32_C(1500);
208# else
209 maxRAMArch = UINT32_C(2560);
210# endif
211#endif
212 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
213
214 return S_OK;
215}
216
217STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
218{
219 if (!minVRAM)
220 return E_POINTER;
221
222 AutoCaller autoCaller(this);
223 if (FAILED(autoCaller.rc())) return autoCaller.rc();
224
225 /* no need to lock, this is const */
226 *minVRAM = SchemaDefs::MinGuestVRAM;
227
228 return S_OK;
229}
230
231STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
232{
233 if (!maxVRAM)
234 return E_POINTER;
235
236 AutoCaller autoCaller(this);
237 if (FAILED(autoCaller.rc())) return autoCaller.rc();
238
239 /* no need to lock, this is const */
240 *maxVRAM = SchemaDefs::MaxGuestVRAM;
241
242 return S_OK;
243}
244
245STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
246{
247 if (!minCPUCount)
248 return E_POINTER;
249
250 AutoCaller autoCaller(this);
251 if (FAILED(autoCaller.rc())) return autoCaller.rc();
252
253 /* no need to lock, this is const */
254 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
255
256 return S_OK;
257}
258
259STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
260{
261 if (!maxCPUCount)
262 return E_POINTER;
263
264 AutoCaller autoCaller(this);
265 if (FAILED(autoCaller.rc())) return autoCaller.rc();
266
267 /* no need to lock, this is const */
268 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
269
270 return S_OK;
271}
272
273STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
274{
275 if (!maxMonitors)
276 return E_POINTER;
277
278 AutoCaller autoCaller(this);
279 if (FAILED(autoCaller.rc())) return autoCaller.rc();
280
281 /* no need to lock, this is const */
282 *maxMonitors = SchemaDefs::MaxGuestMonitors;
283
284 return S_OK;
285}
286
287STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
288{
289 if (!maxVDISize)
290 return E_POINTER;
291
292 AutoCaller autoCaller(this);
293 if (FAILED(autoCaller.rc())) return autoCaller.rc();
294
295 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
296 * 48 bit range is in theory trivial, but the crappy compiler makes things
297 * more difficult). This translates to almost 2 TBytes (to be on the safe
298 * side, the reported limit is 1 MiByte less than that, as the total number
299 * of sectors should fit in 32 bits, too), which should bei enough for
300 * the moment. The virtual ATA disks support complete LBA48 (although for
301 * example iSCSI is also currently limited to 32 bit LBA), so the
302 * theoretical maximum disk size is 128 PiByte. The user interface cannot
303 * cope with this in a reasonable way yet. */
304 /* no need to lock, this is const */
305 *maxVDISize = 2048 * 1024 - 1;
306
307 return S_OK;
308}
309
310STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
311{
312 if (!count)
313 return E_POINTER;
314
315 AutoCaller autoCaller(this);
316 if (FAILED(autoCaller.rc())) return autoCaller.rc();
317
318 /* no need to lock, this is const */
319 *count = SchemaDefs::NetworkAdapterCount;
320
321 return S_OK;
322}
323
324STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
325{
326 if (!count)
327 return E_POINTER;
328
329 AutoCaller autoCaller(this);
330 if (FAILED(autoCaller.rc())) return autoCaller.rc();
331
332 /* no need to lock, this is const */
333 *count = SchemaDefs::SerialPortCount;
334
335 return S_OK;
336}
337
338STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
339{
340 if (!count)
341 return E_POINTER;
342
343 AutoCaller autoCaller(this);
344 if (FAILED(autoCaller.rc())) return autoCaller.rc();
345
346 /* no need to lock, this is const */
347 *count = SchemaDefs::ParallelPortCount;
348
349 return S_OK;
350}
351
352STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
353{
354 CheckComArgOutPointerValid(aMaxBootPosition);
355
356 AutoCaller autoCaller(this);
357 if (FAILED(autoCaller.rc())) return autoCaller.rc();
358
359 /* no need to lock, this is const */
360 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
361
362 return S_OK;
363}
364
365STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus (StorageBus_T aBus, ULONG *aMaxDevicesPerPort)
366{
367 CheckComArgOutPointerValid(aMaxDevicesPerPort);
368
369 AutoCaller autoCaller(this);
370 if (FAILED(autoCaller.rc())) return autoCaller.rc();
371
372 /* no need to lock, this is const */
373 switch (aBus)
374 {
375 case StorageBus_SATA:
376 case StorageBus_SCSI:
377 {
378 /* SATA and both SCSI controllers only support one device per port. */
379 *aMaxDevicesPerPort = 1;
380 break;
381 }
382 case StorageBus_IDE:
383 case StorageBus_Floppy:
384 {
385 /* The IDE and Floppy controllers support 2 devices. One as master
386 * and one as slave (or floppy drive 0 and 1). */
387 *aMaxDevicesPerPort = 2;
388 break;
389 }
390 default:
391 AssertMsgFailed(("Invalid bus type %d\n", aBus));
392 }
393
394 return S_OK;
395}
396
397STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus (StorageBus_T aBus, ULONG *aMinPortCount)
398{
399 CheckComArgOutPointerValid(aMinPortCount);
400
401 AutoCaller autoCaller(this);
402 if (FAILED(autoCaller.rc())) return autoCaller.rc();
403
404 /* no need to lock, this is const */
405 switch (aBus)
406 {
407 case StorageBus_SATA:
408 {
409 *aMinPortCount = 1;
410 break;
411 }
412 case StorageBus_SCSI:
413 {
414 *aMinPortCount = 16;
415 break;
416 }
417 case StorageBus_IDE:
418 {
419 *aMinPortCount = 2;
420 break;
421 }
422 case StorageBus_Floppy:
423 {
424 *aMinPortCount = 1;
425 break;
426 }
427 default:
428 AssertMsgFailed(("Invalid bus type %d\n", aBus));
429 }
430
431 return S_OK;
432}
433
434STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus (StorageBus_T aBus, ULONG *aMaxPortCount)
435{
436 CheckComArgOutPointerValid(aMaxPortCount);
437
438 AutoCaller autoCaller(this);
439 if (FAILED(autoCaller.rc())) return autoCaller.rc();
440
441 /* no need to lock, this is const */
442 switch (aBus)
443 {
444 case StorageBus_SATA:
445 {
446 *aMaxPortCount = 30;
447 break;
448 }
449 case StorageBus_SCSI:
450 {
451 *aMaxPortCount = 16;
452 break;
453 }
454 case StorageBus_IDE:
455 {
456 *aMaxPortCount = 2;
457 break;
458 }
459 case StorageBus_Floppy:
460 {
461 *aMaxPortCount = 1;
462 break;
463 }
464 default:
465 AssertMsgFailed(("Invalid bus type %d\n", aBus));
466 }
467
468 return S_OK;
469}
470
471STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus, ULONG *aMaxInstances)
472{
473 CheckComArgOutPointerValid(aMaxInstances);
474
475 AutoCaller autoCaller(this);
476 if (FAILED(autoCaller.rc())) return autoCaller.rc();
477
478 /* no need to lock, this is const */
479 switch (aBus)
480 {
481 case StorageBus_SATA:
482 case StorageBus_SCSI:
483 case StorageBus_IDE:
484 case StorageBus_Floppy:
485 {
486 /** @todo raise the limits ASAP, per bus type */
487 *aMaxInstances = 1;
488 break;
489 }
490 default:
491 AssertMsgFailed(("Invalid bus type %d\n", aBus));
492 }
493
494 return S_OK;
495}
496
497STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
498 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
499{
500 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
501
502 AutoCaller autoCaller(this);
503 if (FAILED(autoCaller.rc())) return autoCaller.rc();
504
505 /* no need to lock, this is const */
506 switch (aBus)
507 {
508 case StorageBus_IDE:
509 {
510 com::SafeArray<DeviceType_T> saDeviceTypes(2);
511 saDeviceTypes[0] = DeviceType_DVD;
512 saDeviceTypes[1] = DeviceType_HardDisk;
513 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
514 break;
515 }
516 case StorageBus_SATA:
517 case StorageBus_SCSI:
518 {
519 com::SafeArray<DeviceType_T> saDeviceTypes(1);
520 saDeviceTypes[0] = DeviceType_HardDisk;
521 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
522 break;
523 }
524 case StorageBus_Floppy:
525 {
526 com::SafeArray<DeviceType_T> saDeviceTypes(1);
527 saDeviceTypes[0] = DeviceType_Floppy;
528 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
529 break;
530 }
531 default:
532 AssertMsgFailed(("Invalid bus type %d\n", aBus));
533 }
534
535 return S_OK;
536}
537
538STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
539{
540 CheckComArgOutPointerValid(aDefaultMachineFolder);
541
542 AutoCaller autoCaller(this);
543 if (FAILED(autoCaller.rc())) return autoCaller.rc();
544
545 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
546
547 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
548
549 return S_OK;
550}
551
552STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
553{
554 AutoCaller autoCaller(this);
555 if (FAILED(autoCaller.rc())) return autoCaller.rc();
556
557 /* VirtualBox::saveSettings() needs a write lock */
558 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
559
560 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
561 if (SUCCEEDED(rc))
562 rc = mParent->saveSettings();
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 /* VirtualBox::saveSettings() needs a write lock */
587 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
588
589 HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
590 if (SUCCEEDED(rc))
591 rc = mParent->saveSettings();
592
593 return rc;
594}
595
596STDMETHODIMP SystemProperties::
597COMGETTER(MediumFormats) (ComSafeArrayOut(IMediumFormat *, aMediumFormats))
598{
599 if (ComSafeArrayOutIsNull(aMediumFormats))
600 return E_POINTER;
601
602 AutoCaller autoCaller(this);
603 if (FAILED(autoCaller.rc())) return autoCaller.rc();
604
605 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
606
607 SafeIfaceArray<IMediumFormat> mediumFormats (mMediumFormats);
608 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
609
610 return S_OK;
611}
612
613STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
614{
615 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
616
617 AutoCaller autoCaller(this);
618 if (FAILED(autoCaller.rc())) return autoCaller.rc();
619
620 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
621
622 m_strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
623
624 return S_OK;
625}
626
627STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
628{
629 AutoCaller autoCaller(this);
630 if (FAILED(autoCaller.rc())) return autoCaller.rc();
631
632 /* VirtualBox::saveSettings() needs a write lock */
633 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
634
635 HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
636 if (SUCCEEDED(rc))
637 rc = mParent->saveSettings();
638
639 return rc;
640}
641
642STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
643{
644 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
645
646 AutoCaller autoCaller(this);
647 if (FAILED(autoCaller.rc())) return autoCaller.rc();
648
649 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
650
651 m_strRemoteDisplayAuthLibrary.cloneTo(aRemoteDisplayAuthLibrary);
652
653 return S_OK;
654}
655
656STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
657{
658 AutoCaller autoCaller(this);
659 if (FAILED(autoCaller.rc())) return autoCaller.rc();
660
661 /* VirtualBox::saveSettings() needs a write lock */
662 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
663
664 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
665 if (SUCCEEDED(rc))
666 rc = mParent->saveSettings();
667
668 return rc;
669}
670
671STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
672{
673 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
674
675 AutoCaller autoCaller(this);
676 if (FAILED(autoCaller.rc())) return autoCaller.rc();
677
678 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
679
680 m_strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
681
682 return S_OK;
683}
684
685STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
686{
687 AutoCaller autoCaller(this);
688 if (FAILED(autoCaller.rc())) return autoCaller.rc();
689
690 /* VirtualBox::saveSettings() needs a write lock */
691 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
692
693 HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
694 if (SUCCEEDED(rc))
695 rc = mParent->saveSettings();
696
697 return rc;
698}
699
700STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
701{
702 if (!count)
703 return E_POINTER;
704
705 AutoCaller autoCaller(this);
706 if (FAILED(autoCaller.rc())) return autoCaller.rc();
707
708 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
709
710 *count = mLogHistoryCount;
711
712 return S_OK;
713}
714
715STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
716{
717 AutoCaller autoCaller(this);
718 if (FAILED(autoCaller.rc())) return autoCaller.rc();
719
720 /* VirtualBox::saveSettings() needs a write lock */
721 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
722
723 mLogHistoryCount = count;
724
725 HRESULT rc = mParent->saveSettings();
726
727 return rc;
728}
729
730STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver) (AudioDriverType_T *aAudioDriver)
731{
732 if (!aAudioDriver)
733 return E_POINTER;
734
735 AutoCaller autoCaller(this);
736 if (FAILED(autoCaller.rc())) return autoCaller.rc();
737
738 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
739
740 *aAudioDriver = mDefaultAudioDriver;
741
742 return S_OK;
743}
744
745// public methods only for internal purposes
746/////////////////////////////////////////////////////////////////////////////
747
748HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
749{
750 AutoCaller autoCaller(this);
751 if (FAILED(autoCaller.rc())) return autoCaller.rc();
752
753 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
754
755 HRESULT rc = S_OK;
756
757 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
758 if (FAILED(rc)) return rc;
759
760 rc = setDefaultHardDiskFolder(data.strDefaultHardDiskFolder);
761 if (FAILED(rc)) return rc;
762
763 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
764 if (FAILED(rc)) return rc;
765
766 rc = setRemoteDisplayAuthLibrary(data.strRemoteDisplayAuthLibrary);
767 if (FAILED(rc)) return rc;
768
769 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
770 if (FAILED(rc)) return rc;
771
772 mLogHistoryCount = data.ulLogHistoryCount;
773
774 return S_OK;
775}
776
777HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
778{
779 AutoCaller autoCaller(this);
780 if (FAILED(autoCaller.rc())) return autoCaller.rc();
781
782 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
783
784 data.strDefaultMachineFolder = m_strDefaultMachineFolder;
785 data.strDefaultHardDiskFolder = m_strDefaultHardDiskFolder;
786 data.strDefaultHardDiskFormat = m_strDefaultHardDiskFormat;
787 data.strRemoteDisplayAuthLibrary = m_strRemoteDisplayAuthLibrary;
788 data.strWebServiceAuthLibrary = m_strWebServiceAuthLibrary;
789 data.ulLogHistoryCount = mLogHistoryCount;
790
791 return S_OK;
792}
793
794/**
795 * Returns a medium format object corresponding to the given format
796 * identifier or null if no such format.
797 *
798 * @param aFormat Format identifier.
799 *
800 * @return ComObjPtr<MediumFormat>
801 */
802ComObjPtr<MediumFormat> SystemProperties::mediumFormat (CBSTR aFormat)
803{
804 ComObjPtr<MediumFormat> format;
805
806 AutoCaller autoCaller(this);
807 AssertComRCReturn (autoCaller.rc(), format);
808
809 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
810
811 for (MediumFormatList::const_iterator it = mMediumFormats.begin();
812 it != mMediumFormats.end(); ++ it)
813 {
814 /* MediumFormat is all const, no need to lock */
815
816 if ((*it)->id().compareIgnoreCase (aFormat) == 0)
817 {
818 format = *it;
819 break;
820 }
821 }
822
823 return format;
824}
825
826// private methods
827/////////////////////////////////////////////////////////////////////////////
828
829HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
830{
831 Utf8Str path(aPath);
832 if (path.isEmpty())
833 path = "Machines";
834
835 /* get the full file name */
836 Utf8Str folder;
837 int vrc = mParent->calculateFullPath(path, folder);
838 if (RT_FAILURE(vrc))
839 return setError(E_FAIL,
840 tr("Invalid default machine folder '%s' (%Rrc)"),
841 path.raw(),
842 vrc);
843
844 m_strDefaultMachineFolder = path;
845 m_strDefaultMachineFolderFull = folder;
846
847 return S_OK;
848}
849
850HRESULT SystemProperties::setDefaultHardDiskFolder(const Utf8Str &aPath)
851{
852 Utf8Str path(aPath);
853 if (path.isEmpty())
854 path = "HardDisks";
855
856 /* get the full file name */
857 Utf8Str folder;
858 int vrc = mParent->calculateFullPath(path, folder);
859 if (RT_FAILURE(vrc))
860 return setError(E_FAIL,
861 tr("Invalid default hard disk folder '%s' (%Rrc)"),
862 path.raw(),
863 vrc);
864
865 m_strDefaultHardDiskFolder = path;
866 m_strDefaultHardDiskFolderFull = folder;
867
868 return S_OK;
869}
870
871HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
872{
873 if (!aFormat.isEmpty())
874 m_strDefaultHardDiskFormat = aFormat;
875 else
876 m_strDefaultHardDiskFormat = "VDI";
877
878 return S_OK;
879}
880
881HRESULT SystemProperties::setRemoteDisplayAuthLibrary(const Utf8Str &aPath)
882{
883 if (!aPath.isEmpty())
884 m_strRemoteDisplayAuthLibrary = aPath;
885 else
886 m_strRemoteDisplayAuthLibrary = "VRDPAuth";
887
888 return S_OK;
889}
890
891HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
892{
893 if (!aPath.isEmpty())
894 m_strWebServiceAuthLibrary = aPath;
895 else
896 m_strWebServiceAuthLibrary = "VRDPAuth";
897
898 return S_OK;
899}
900
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use