VirtualBox

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

Last change on this file since 30832 was 30764, checked in by vboxsync, 14 years ago

back out r63543, r63544 until windows build problems can be solved properly

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