VirtualBox

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

Last change on this file since 30430 was 30423, checked in by vboxsync, 14 years ago

Compile fixes

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