VirtualBox

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

Last change on this file since 25809 was 25589, checked in by vboxsync, 14 years ago

LsiLogic: Add SAS support for Main and Frontends

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.1 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 25589 2009-12-28 21:40:51Z 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 case StorageBus_SAS:
378 {
379 /* SATA and both SCSI controllers only support one device per port. */
380 *aMaxDevicesPerPort = 1;
381 break;
382 }
383 case StorageBus_IDE:
384 case StorageBus_Floppy:
385 {
386 /* The IDE and Floppy controllers support 2 devices. One as master
387 * and one as slave (or floppy drive 0 and 1). */
388 *aMaxDevicesPerPort = 2;
389 break;
390 }
391 default:
392 AssertMsgFailed(("Invalid bus type %d\n", aBus));
393 }
394
395 return S_OK;
396}
397
398STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus (StorageBus_T aBus, ULONG *aMinPortCount)
399{
400 CheckComArgOutPointerValid(aMinPortCount);
401
402 AutoCaller autoCaller(this);
403 if (FAILED(autoCaller.rc())) return autoCaller.rc();
404
405 /* no need to lock, this is const */
406 switch (aBus)
407 {
408 case StorageBus_SATA:
409 {
410 *aMinPortCount = 1;
411 break;
412 }
413 case StorageBus_SCSI:
414 {
415 *aMinPortCount = 16;
416 break;
417 }
418 case StorageBus_IDE:
419 {
420 *aMinPortCount = 2;
421 break;
422 }
423 case StorageBus_Floppy:
424 {
425 *aMinPortCount = 1;
426 break;
427 }
428 case StorageBus_SAS:
429 {
430 *aMinPortCount = 8;
431 break;
432 }
433 default:
434 AssertMsgFailed(("Invalid bus type %d\n", aBus));
435 }
436
437 return S_OK;
438}
439
440STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus (StorageBus_T aBus, ULONG *aMaxPortCount)
441{
442 CheckComArgOutPointerValid(aMaxPortCount);
443
444 AutoCaller autoCaller(this);
445 if (FAILED(autoCaller.rc())) return autoCaller.rc();
446
447 /* no need to lock, this is const */
448 switch (aBus)
449 {
450 case StorageBus_SATA:
451 {
452 *aMaxPortCount = 30;
453 break;
454 }
455 case StorageBus_SCSI:
456 {
457 *aMaxPortCount = 16;
458 break;
459 }
460 case StorageBus_IDE:
461 {
462 *aMaxPortCount = 2;
463 break;
464 }
465 case StorageBus_Floppy:
466 {
467 *aMaxPortCount = 1;
468 break;
469 }
470 case StorageBus_SAS:
471 {
472 *aMaxPortCount = 8;
473 break;
474 }
475 default:
476 AssertMsgFailed(("Invalid bus type %d\n", aBus));
477 }
478
479 return S_OK;
480}
481
482STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus, ULONG *aMaxInstances)
483{
484 CheckComArgOutPointerValid(aMaxInstances);
485
486 AutoCaller autoCaller(this);
487 if (FAILED(autoCaller.rc())) return autoCaller.rc();
488
489 /* no need to lock, this is const */
490 switch (aBus)
491 {
492 case StorageBus_SATA:
493 case StorageBus_SCSI:
494 case StorageBus_IDE:
495 case StorageBus_SAS:
496 case StorageBus_Floppy:
497 {
498 /** @todo raise the limits ASAP, per bus type */
499 *aMaxInstances = 1;
500 break;
501 }
502 default:
503 AssertMsgFailed(("Invalid bus type %d\n", aBus));
504 }
505
506 return S_OK;
507}
508
509STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
510 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
511{
512 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
513
514 AutoCaller autoCaller(this);
515 if (FAILED(autoCaller.rc())) return autoCaller.rc();
516
517 /* no need to lock, this is const */
518 switch (aBus)
519 {
520 case StorageBus_IDE:
521 {
522 com::SafeArray<DeviceType_T> saDeviceTypes(2);
523 saDeviceTypes[0] = DeviceType_DVD;
524 saDeviceTypes[1] = DeviceType_HardDisk;
525 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
526 break;
527 }
528 case StorageBus_SATA:
529 case StorageBus_SCSI:
530 case StorageBus_SAS:
531 {
532 com::SafeArray<DeviceType_T> saDeviceTypes(1);
533 saDeviceTypes[0] = DeviceType_HardDisk;
534 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
535 break;
536 }
537 case StorageBus_Floppy:
538 {
539 com::SafeArray<DeviceType_T> saDeviceTypes(1);
540 saDeviceTypes[0] = DeviceType_Floppy;
541 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
542 break;
543 }
544 default:
545 AssertMsgFailed(("Invalid bus type %d\n", aBus));
546 }
547
548 return S_OK;
549}
550
551STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
552{
553 CheckComArgOutPointerValid(aDefaultMachineFolder);
554
555 AutoCaller autoCaller(this);
556 if (FAILED(autoCaller.rc())) return autoCaller.rc();
557
558 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
559
560 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
561
562 return S_OK;
563}
564
565STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
566{
567 AutoCaller autoCaller(this);
568 if (FAILED(autoCaller.rc())) return autoCaller.rc();
569
570 /* VirtualBox::saveSettings() needs a write lock */
571 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
572
573 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
574 if (SUCCEEDED(rc))
575 rc = mParent->saveSettings();
576
577 return rc;
578}
579
580STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder) (BSTR *aDefaultHardDiskFolder)
581{
582 CheckComArgOutPointerValid(aDefaultHardDiskFolder);
583
584 AutoCaller autoCaller(this);
585 if (FAILED(autoCaller.rc())) return autoCaller.rc();
586
587 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
588
589 m_strDefaultHardDiskFolderFull.cloneTo(aDefaultHardDiskFolder);
590
591 return S_OK;
592}
593
594STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder) (IN_BSTR aDefaultHardDiskFolder)
595{
596 AutoCaller autoCaller(this);
597 if (FAILED(autoCaller.rc())) return autoCaller.rc();
598
599 /* VirtualBox::saveSettings() needs a write lock */
600 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
601
602 HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
603 if (SUCCEEDED(rc))
604 rc = mParent->saveSettings();
605
606 return rc;
607}
608
609STDMETHODIMP SystemProperties::
610COMGETTER(MediumFormats) (ComSafeArrayOut(IMediumFormat *, aMediumFormats))
611{
612 if (ComSafeArrayOutIsNull(aMediumFormats))
613 return E_POINTER;
614
615 AutoCaller autoCaller(this);
616 if (FAILED(autoCaller.rc())) return autoCaller.rc();
617
618 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
619
620 SafeIfaceArray<IMediumFormat> mediumFormats (mMediumFormats);
621 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
622
623 return S_OK;
624}
625
626STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
627{
628 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
629
630 AutoCaller autoCaller(this);
631 if (FAILED(autoCaller.rc())) return autoCaller.rc();
632
633 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
634
635 m_strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
636
637 return S_OK;
638}
639
640STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
641{
642 AutoCaller autoCaller(this);
643 if (FAILED(autoCaller.rc())) return autoCaller.rc();
644
645 /* VirtualBox::saveSettings() needs a write lock */
646 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
647
648 HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
649 if (SUCCEEDED(rc))
650 rc = mParent->saveSettings();
651
652 return rc;
653}
654
655STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
656{
657 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
658
659 AutoCaller autoCaller(this);
660 if (FAILED(autoCaller.rc())) return autoCaller.rc();
661
662 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
663
664 m_strRemoteDisplayAuthLibrary.cloneTo(aRemoteDisplayAuthLibrary);
665
666 return S_OK;
667}
668
669STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
670{
671 AutoCaller autoCaller(this);
672 if (FAILED(autoCaller.rc())) return autoCaller.rc();
673
674 /* VirtualBox::saveSettings() needs a write lock */
675 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
676
677 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
678 if (SUCCEEDED(rc))
679 rc = mParent->saveSettings();
680
681 return rc;
682}
683
684STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
685{
686 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
687
688 AutoCaller autoCaller(this);
689 if (FAILED(autoCaller.rc())) return autoCaller.rc();
690
691 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
692
693 m_strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
694
695 return S_OK;
696}
697
698STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
699{
700 AutoCaller autoCaller(this);
701 if (FAILED(autoCaller.rc())) return autoCaller.rc();
702
703 /* VirtualBox::saveSettings() needs a write lock */
704 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
705
706 HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
707 if (SUCCEEDED(rc))
708 rc = mParent->saveSettings();
709
710 return rc;
711}
712
713STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
714{
715 if (!count)
716 return E_POINTER;
717
718 AutoCaller autoCaller(this);
719 if (FAILED(autoCaller.rc())) return autoCaller.rc();
720
721 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
722
723 *count = mLogHistoryCount;
724
725 return S_OK;
726}
727
728STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
729{
730 AutoCaller autoCaller(this);
731 if (FAILED(autoCaller.rc())) return autoCaller.rc();
732
733 /* VirtualBox::saveSettings() needs a write lock */
734 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
735
736 mLogHistoryCount = count;
737
738 HRESULT rc = mParent->saveSettings();
739
740 return rc;
741}
742
743STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver) (AudioDriverType_T *aAudioDriver)
744{
745 if (!aAudioDriver)
746 return E_POINTER;
747
748 AutoCaller autoCaller(this);
749 if (FAILED(autoCaller.rc())) return autoCaller.rc();
750
751 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
752
753 *aAudioDriver = mDefaultAudioDriver;
754
755 return S_OK;
756}
757
758// public methods only for internal purposes
759/////////////////////////////////////////////////////////////////////////////
760
761HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
762{
763 AutoCaller autoCaller(this);
764 if (FAILED(autoCaller.rc())) return autoCaller.rc();
765
766 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
767
768 HRESULT rc = S_OK;
769
770 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
771 if (FAILED(rc)) return rc;
772
773 rc = setDefaultHardDiskFolder(data.strDefaultHardDiskFolder);
774 if (FAILED(rc)) return rc;
775
776 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
777 if (FAILED(rc)) return rc;
778
779 rc = setRemoteDisplayAuthLibrary(data.strRemoteDisplayAuthLibrary);
780 if (FAILED(rc)) return rc;
781
782 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
783 if (FAILED(rc)) return rc;
784
785 mLogHistoryCount = data.ulLogHistoryCount;
786
787 return S_OK;
788}
789
790HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
791{
792 AutoCaller autoCaller(this);
793 if (FAILED(autoCaller.rc())) return autoCaller.rc();
794
795 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
796
797 data.strDefaultMachineFolder = m_strDefaultMachineFolder;
798 data.strDefaultHardDiskFolder = m_strDefaultHardDiskFolder;
799 data.strDefaultHardDiskFormat = m_strDefaultHardDiskFormat;
800 data.strRemoteDisplayAuthLibrary = m_strRemoteDisplayAuthLibrary;
801 data.strWebServiceAuthLibrary = m_strWebServiceAuthLibrary;
802 data.ulLogHistoryCount = mLogHistoryCount;
803
804 return S_OK;
805}
806
807/**
808 * Returns a medium format object corresponding to the given format
809 * identifier or null if no such format.
810 *
811 * @param aFormat Format identifier.
812 *
813 * @return ComObjPtr<MediumFormat>
814 */
815ComObjPtr<MediumFormat> SystemProperties::mediumFormat (CBSTR aFormat)
816{
817 ComObjPtr<MediumFormat> format;
818
819 AutoCaller autoCaller(this);
820 AssertComRCReturn (autoCaller.rc(), format);
821
822 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
823
824 for (MediumFormatList::const_iterator it = mMediumFormats.begin();
825 it != mMediumFormats.end(); ++ it)
826 {
827 /* MediumFormat is all const, no need to lock */
828
829 if ((*it)->id().compareIgnoreCase (aFormat) == 0)
830 {
831 format = *it;
832 break;
833 }
834 }
835
836 return format;
837}
838
839// private methods
840/////////////////////////////////////////////////////////////////////////////
841
842HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
843{
844 Utf8Str path(aPath);
845 if (path.isEmpty())
846 path = "Machines";
847
848 /* get the full file name */
849 Utf8Str folder;
850 int vrc = mParent->calculateFullPath(path, folder);
851 if (RT_FAILURE(vrc))
852 return setError(E_FAIL,
853 tr("Invalid default machine folder '%s' (%Rrc)"),
854 path.raw(),
855 vrc);
856
857 m_strDefaultMachineFolder = path;
858 m_strDefaultMachineFolderFull = folder;
859
860 return S_OK;
861}
862
863HRESULT SystemProperties::setDefaultHardDiskFolder(const Utf8Str &aPath)
864{
865 Utf8Str path(aPath);
866 if (path.isEmpty())
867 path = "HardDisks";
868
869 /* get the full file name */
870 Utf8Str folder;
871 int vrc = mParent->calculateFullPath(path, folder);
872 if (RT_FAILURE(vrc))
873 return setError(E_FAIL,
874 tr("Invalid default hard disk folder '%s' (%Rrc)"),
875 path.raw(),
876 vrc);
877
878 m_strDefaultHardDiskFolder = path;
879 m_strDefaultHardDiskFolderFull = folder;
880
881 return S_OK;
882}
883
884HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
885{
886 if (!aFormat.isEmpty())
887 m_strDefaultHardDiskFormat = aFormat;
888 else
889 m_strDefaultHardDiskFormat = "VDI";
890
891 return S_OK;
892}
893
894HRESULT SystemProperties::setRemoteDisplayAuthLibrary(const Utf8Str &aPath)
895{
896 if (!aPath.isEmpty())
897 m_strRemoteDisplayAuthLibrary = aPath;
898 else
899 m_strRemoteDisplayAuthLibrary = "VRDPAuth";
900
901 return S_OK;
902}
903
904HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
905{
906 if (!aPath.isEmpty())
907 m_strWebServiceAuthLibrary = aPath;
908 else
909 m_strWebServiceAuthLibrary = "VRDPAuth";
910
911 return S_OK;
912}
913
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use