VirtualBox

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

Last change on this file since 25414 was 25310, checked in by vboxsync, 15 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
RevLine 
[13607]1/* $Id: SystemPropertiesImpl.cpp 25310 2009-12-10 17:06:44Z vboxsync $ */
[13606]2
[1]3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
[13606]9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
[1]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
[5999]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.
[8155]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.
[1]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>
[20260]34#include <iprt/process.h>
[20262]35#include <iprt/ldr.h>
[16560]36
37#include <VBox/err.h>
[16558]38#include <VBox/param.h>
[16560]39#include <VBox/settings.h>
[23257]40#include <VBox/VBoxHDD.h>
[1]41
42// defines
43/////////////////////////////////////////////////////////////////////////////
44
45// constructor / destructor
46/////////////////////////////////////////////////////////////////////////////
47
[13606]48DEFINE_EMPTY_CTOR_DTOR (SystemProperties)
49
[1]50HRESULT SystemProperties::FinalConstruct()
51{
52 return S_OK;
53}
54
55void SystemProperties::FinalRelease()
56{
[13606]57 uninit ();
[1]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{
[21878]70 LogFlowThisFunc(("aParent=%p\n", aParent));
[1]71
72 ComAssertRet (aParent, E_FAIL);
73
[13606]74 /* Enclose the state transition NotReady->InInit->Ready */
[21878]75 AutoInitSpan autoInitSpan(this);
76 AssertReturn(autoInitSpan.isOk(), E_FAIL);
[1]77
[21878]78 unconst(mParent) = aParent;
[1]79
[22173]80 setDefaultMachineFolder(Utf8Str::Null);
81 setDefaultHardDiskFolder(Utf8Str::Null);
82 setDefaultHardDiskFormat(Utf8Str::Null);
[14224]83
[22173]84 setRemoteDisplayAuthLibrary(Utf8Str::Null);
[1]85
[5150]86 mLogHistoryCount = 3;
[1]87
[13580]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);
[21878]102 if (RT_SUCCESS(vrc))
[13580]103 {
104 for (unsigned i = 0; i < cEntries; ++ i)
105 {
[23223]106 ComObjPtr<MediumFormat> hdf;
[13580]107 rc = hdf.createObject();
[25149]108 if (FAILED(rc)) break;
[13580]109
110 rc = hdf->init (&aVDInfo [i]);
[25149]111 if (FAILED(rc)) break;
[13580]112
[23223]113 mMediumFormats.push_back (hdf);
[13580]114 }
115 }
116
[20260]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
[13606]151 /* Confirm a successful initialization */
[21878]152 if (SUCCEEDED(rc))
[13606]153 autoInitSpan.setSucceeded();
[13580]154
155 return rc;
[1]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{
[21878]164 LogFlowThisFunc(("\n"));
[1]165
[13606]166 /* Enclose the state transition Ready->InUninit->NotReady */
[21878]167 AutoUninitSpan autoUninitSpan(this);
[13606]168 if (autoUninitSpan.uninitDone())
169 return;
[1]170
[21878]171 unconst(mParent).setNull();
[1]172}
173
174// ISystemProperties properties
175/////////////////////////////////////////////////////////////////////////////
176
177
178STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
179{
180 if (!minRAM)
181 return E_POINTER;
182
[21878]183 AutoCaller autoCaller(this);
[25149]184 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]185
186 /* no need to lock, this is const */
[18263]187 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
188 *minRAM = MM_RAM_MIN_IN_MB;
[1]189
190 return S_OK;
191}
192
193STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
194{
195 if (!maxRAM)
196 return E_POINTER;
197
[21878]198 AutoCaller autoCaller(this);
[25149]199 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]200
201 /* no need to lock, this is const */
[18263]202 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
[22595]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);
[1]213
214 return S_OK;
215}
216
217STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
218{
219 if (!minVRAM)
220 return E_POINTER;
221
[21878]222 AutoCaller autoCaller(this);
[25149]223 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]224
225 /* no need to lock, this is const */
[1]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
[21878]236 AutoCaller autoCaller(this);
[25149]237 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]238
239 /* no need to lock, this is const */
[1]240 *maxVRAM = SchemaDefs::MaxGuestVRAM;
241
242 return S_OK;
243}
244
[16569]245STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
246{
247 if (!minCPUCount)
248 return E_POINTER;
249
[21878]250 AutoCaller autoCaller(this);
[25149]251 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[16569]252
253 /* no need to lock, this is const */
[19403]254 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
[16569]255
256 return S_OK;
257}
258
259STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
260{
261 if (!maxCPUCount)
262 return E_POINTER;
263
[21878]264 AutoCaller autoCaller(this);
[25149]265 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[16569]266
267 /* no need to lock, this is const */
[19727]268 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
[16569]269
270 return S_OK;
271}
272
[1721]273STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
274{
275 if (!maxMonitors)
276 return E_POINTER;
277
[21878]278 AutoCaller autoCaller(this);
[25149]279 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]280
281 /* no need to lock, this is const */
[1721]282 *maxMonitors = SchemaDefs::MaxGuestMonitors;
283
284 return S_OK;
285}
286
[1]287STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
288{
289 if (!maxVDISize)
290 return E_POINTER;
291
[21878]292 AutoCaller autoCaller(this);
[25149]293 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]294
[1]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. */
[13606]304 /* no need to lock, this is const */
[1]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
[21878]315 AutoCaller autoCaller(this);
[25149]316 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]317
318 /* no need to lock, this is const */
[1]319 *count = SchemaDefs::NetworkAdapterCount;
320
321 return S_OK;
322}
323
[3494]324STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
325{
326 if (!count)
327 return E_POINTER;
[1]328
[21878]329 AutoCaller autoCaller(this);
[25149]330 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]331
332 /* no need to lock, this is const */
[3494]333 *count = SchemaDefs::SerialPortCount;
334
335 return S_OK;
336}
337
[3652]338STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
339{
340 if (!count)
341 return E_POINTER;
342
[21878]343 AutoCaller autoCaller(this);
[25149]344 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]345
346 /* no need to lock, this is const */
[3652]347 *count = SchemaDefs::ParallelPortCount;
348
349 return S_OK;
350}
351
[1]352STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
353{
[14972]354 CheckComArgOutPointerValid(aMaxBootPosition);
[1]355
[21878]356 AutoCaller autoCaller(this);
[25149]357 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]358
359 /* no need to lock, this is const */
[1]360 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
361
362 return S_OK;
363}
364
[23223]365STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus (StorageBus_T aBus, ULONG *aMaxDevicesPerPort)
366{
367 CheckComArgOutPointerValid(aMaxDevicesPerPort);
368
369 AutoCaller autoCaller(this);
[25149]370 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[23223]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);
[25149]402 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[23223]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);
[25149]439 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[23223]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
[23560]471STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus, ULONG *aMaxInstances)
472{
473 CheckComArgOutPointerValid(aMaxInstances);
474
475 AutoCaller autoCaller(this);
[25149]476 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[23560]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
[24346]497STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
498 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
499{
500 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
501
502 AutoCaller autoCaller(this);
[25149]503 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[24346]504
505 /* no need to lock, this is const */
506 switch (aBus)
507 {
508 case StorageBus_IDE:
509 {
[24438]510 com::SafeArray<DeviceType_T> saDeviceTypes(2);
511 saDeviceTypes[0] = DeviceType_DVD;
512 saDeviceTypes[1] = DeviceType_HardDisk;
[24346]513 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
514 break;
515 }
[24438]516 case StorageBus_SATA:
[24346]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
[13580]538STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
[1]539{
[14972]540 CheckComArgOutPointerValid(aDefaultMachineFolder);
[1]541
[21878]542 AutoCaller autoCaller(this);
[25149]543 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]544
[25310]545 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]546
[22173]547 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
[1]548
549 return S_OK;
550}
551
[15051]552STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
[1]553{
[21878]554 AutoCaller autoCaller(this);
[25149]555 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]556
[13606]557 /* VirtualBox::saveSettings() needs a write lock */
[25310]558 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
[13606]559
[13580]560 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
[21878]561 if (SUCCEEDED(rc))
[13606]562 rc = mParent->saveSettings();
[1]563
[13606]564 return rc;
[1]565}
566
[13580]567STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder) (BSTR *aDefaultHardDiskFolder)
[1]568{
[14972]569 CheckComArgOutPointerValid(aDefaultHardDiskFolder);
[1]570
[21878]571 AutoCaller autoCaller(this);
[25149]572 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]573
[25310]574 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]575
[22173]576 m_strDefaultHardDiskFolderFull.cloneTo(aDefaultHardDiskFolder);
[1]577
578 return S_OK;
579}
580
[15051]581STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder) (IN_BSTR aDefaultHardDiskFolder)
[1]582{
[21878]583 AutoCaller autoCaller(this);
[25149]584 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]585
[13606]586 /* VirtualBox::saveSettings() needs a write lock */
[25310]587 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
[13606]588
[13580]589 HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
[21878]590 if (SUCCEEDED(rc))
[13606]591 rc = mParent->saveSettings();
[1]592
[13606]593 return rc;
[1]594}
595
[13580]596STDMETHODIMP SystemProperties::
[23223]597COMGETTER(MediumFormats) (ComSafeArrayOut(IMediumFormat *, aMediumFormats))
[13580]598{
[23223]599 if (ComSafeArrayOutIsNull(aMediumFormats))
[13580]600 return E_POINTER;
601
[21878]602 AutoCaller autoCaller(this);
[25149]603 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13580]604
[25310]605 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]606
[23223]607 SafeIfaceArray<IMediumFormat> mediumFormats (mMediumFormats);
608 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
[13580]609
610 return S_OK;
611}
612
[14224]613STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
614{
[14972]615 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
[14224]616
[21878]617 AutoCaller autoCaller(this);
[25149]618 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[14224]619
[25310]620 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[14224]621
[22173]622 m_strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
[14224]623
624 return S_OK;
625}
626
[15051]627STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
[14224]628{
[21878]629 AutoCaller autoCaller(this);
[25149]630 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[14224]631
632 /* VirtualBox::saveSettings() needs a write lock */
[25310]633 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
[14224]634
635 HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
[21878]636 if (SUCCEEDED(rc))
[14224]637 rc = mParent->saveSettings();
638
639 return rc;
640}
641
[1]642STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
643{
[14972]644 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
[1]645
[21878]646 AutoCaller autoCaller(this);
[25149]647 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]648
[25310]649 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]650
[22173]651 m_strRemoteDisplayAuthLibrary.cloneTo(aRemoteDisplayAuthLibrary);
[1]652
653 return S_OK;
654}
655
[15051]656STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
[1]657{
[21878]658 AutoCaller autoCaller(this);
[25149]659 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]660
[13606]661 /* VirtualBox::saveSettings() needs a write lock */
[25310]662 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
[13606]663
[1]664 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
[21878]665 if (SUCCEEDED(rc))
[13606]666 rc = mParent->saveSettings();
[1]667
[13606]668 return rc;
[1]669}
670
[5771]671STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
672{
[14972]673 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
[5771]674
[21878]675 AutoCaller autoCaller(this);
[25149]676 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5771]677
[25310]678 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]679
[22173]680 m_strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
[5771]681
682 return S_OK;
683}
684
[15051]685STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
[5771]686{
[21878]687 AutoCaller autoCaller(this);
[25149]688 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5771]689
[13606]690 /* VirtualBox::saveSettings() needs a write lock */
[25310]691 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
[13606]692
[5771]693 HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
[21878]694 if (SUCCEEDED(rc))
[13606]695 rc = mParent->saveSettings();
[5771]696
[13606]697 return rc;
[5771]698}
699
[5150]700STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
701{
702 if (!count)
703 return E_POINTER;
704
[21878]705 AutoCaller autoCaller(this);
[25149]706 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5150]707
[25310]708 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]709
[5150]710 *count = mLogHistoryCount;
711
712 return S_OK;
713}
714
715STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
716{
[21878]717 AutoCaller autoCaller(this);
[25149]718 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[5150]719
[13606]720 /* VirtualBox::saveSettings() needs a write lock */
[25310]721 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
[13606]722
[5150]723 mLogHistoryCount = count;
724
[13606]725 HRESULT rc = mParent->saveSettings();
726
727 return rc;
[5150]728}
729
[20260]730STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver) (AudioDriverType_T *aAudioDriver)
731{
732 if (!aAudioDriver)
733 return E_POINTER;
734
[21878]735 AutoCaller autoCaller(this);
[25149]736 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[20260]737
[25310]738 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[20260]739
740 *aAudioDriver = mDefaultAudioDriver;
741
742 return S_OK;
743}
744
[1]745// public methods only for internal purposes
746/////////////////////////////////////////////////////////////////////////////
747
[22173]748HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
[1]749{
[21878]750 AutoCaller autoCaller(this);
[25149]751 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[13606]752
[25310]753 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
[1]754
[6076]755 HRESULT rc = S_OK;
[1]756
[22173]757 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
[25149]758 if (FAILED(rc)) return rc;
[1]759
[22173]760 rc = setDefaultHardDiskFolder(data.strDefaultHardDiskFolder);
[25149]761 if (FAILED(rc)) return rc;
[13580]762
[22173]763 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
[25149]764 if (FAILED(rc)) return rc;
[14224]765
[22173]766 rc = setRemoteDisplayAuthLibrary(data.strRemoteDisplayAuthLibrary);
[25149]767 if (FAILED(rc)) return rc;
[1]768
[22173]769 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
[25149]770 if (FAILED(rc)) return rc;
[5771]771
[22173]772 mLogHistoryCount = data.ulLogHistoryCount;
[1]773
[6076]774 return S_OK;
[1]775}
776
[22173]777HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
[1]778{
[21878]779 AutoCaller autoCaller(this);
[25149]780 if (FAILED(autoCaller.rc())) return autoCaller.rc();
[1]781
[25310]782 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[13606]783
[22173]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;
[1]790
791 return S_OK;
792}
793
[14225]794/**
[23223]795 * Returns a medium format object corresponding to the given format
[14225]796 * identifier or null if no such format.
797 *
798 * @param aFormat Format identifier.
799 *
[23223]800 * @return ComObjPtr<MediumFormat>
[14225]801 */
[23223]802ComObjPtr<MediumFormat> SystemProperties::mediumFormat (CBSTR aFormat)
[14225]803{
[23223]804 ComObjPtr<MediumFormat> format;
[14225]805
[21878]806 AutoCaller autoCaller(this);
[14225]807 AssertComRCReturn (autoCaller.rc(), format);
808
[25310]809 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
[14225]810
[23223]811 for (MediumFormatList::const_iterator it = mMediumFormats.begin();
812 it != mMediumFormats.end(); ++ it)
[14225]813 {
[23223]814 /* MediumFormat is all const, no need to lock */
[14225]815
[16081]816 if ((*it)->id().compareIgnoreCase (aFormat) == 0)
[14225]817 {
818 format = *it;
819 break;
820 }
821 }
822
823 return format;
824}
825
[1]826// private methods
827/////////////////////////////////////////////////////////////////////////////
828
[22173]829HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
[1]830{
[22173]831 Utf8Str path(aPath);
832 if (path.isEmpty())
[13580]833 path = "Machines";
[1]834
[13580]835 /* get the full file name */
836 Utf8Str folder;
[22173]837 int vrc = mParent->calculateFullPath(path, folder);
[21878]838 if (RT_FAILURE(vrc))
[22173]839 return setError(E_FAIL,
840 tr("Invalid default machine folder '%s' (%Rrc)"),
841 path.raw(),
842 vrc);
[1]843
[22173]844 m_strDefaultMachineFolder = path;
845 m_strDefaultMachineFolderFull = folder;
[1]846
847 return S_OK;
848}
849
[22173]850HRESULT SystemProperties::setDefaultHardDiskFolder(const Utf8Str &aPath)
[1]851{
[22173]852 Utf8Str path(aPath);
853 if (path.isEmpty())
[13580]854 path = "HardDisks";
[1]855
[13580]856 /* get the full file name */
857 Utf8Str folder;
[22173]858 int vrc = mParent->calculateFullPath(path, folder);
[21878]859 if (RT_FAILURE(vrc))
[22173]860 return setError(E_FAIL,
861 tr("Invalid default hard disk folder '%s' (%Rrc)"),
862 path.raw(),
863 vrc);
[1]864
[22173]865 m_strDefaultHardDiskFolder = path;
866 m_strDefaultHardDiskFolderFull = folder;
[1]867
868 return S_OK;
869}
870
[22173]871HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
[14224]872{
[22173]873 if (!aFormat.isEmpty())
874 m_strDefaultHardDiskFormat = aFormat;
[14224]875 else
[22173]876 m_strDefaultHardDiskFormat = "VDI";
[14224]877
878 return S_OK;
879}
880
[22173]881HRESULT SystemProperties::setRemoteDisplayAuthLibrary(const Utf8Str &aPath)
[1]882{
[22173]883 if (!aPath.isEmpty())
884 m_strRemoteDisplayAuthLibrary = aPath;
[1]885 else
[22173]886 m_strRemoteDisplayAuthLibrary = "VRDPAuth";
[1]887
888 return S_OK;
889}
890
[22173]891HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
[5771]892{
[22173]893 if (!aPath.isEmpty())
894 m_strWebServiceAuthLibrary = aPath;
[5771]895 else
[22173]896 m_strWebServiceAuthLibrary = "VRDPAuth";
[5771]897
898 return S_OK;
899}
[22173]900
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use