VirtualBox

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

Last change on this file since 28292 was 27858, checked in by vboxsync, 15 years ago

Main: gcc warnings

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