VirtualBox

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

Last change on this file since 27689 was 27607, checked in by vboxsync, 15 years ago

Main: remove templates for 'weak' com pointers which do nothing anyway

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.2 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 27607 2010-03-22 18:13:07Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "SystemPropertiesImpl.h"
25#include "VirtualBoxImpl.h"
26#include "MachineImpl.h"
27#include "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 /// @todo We currently leak memory because it's not actually clear what to
105 /// free in structures returned by VDBackendInfo. Must be fixed ASAP!
106
107 VDBACKENDINFO aVDInfo[100];
108 unsigned cEntries;
109 int vrc = VDBackendInfo(RT_ELEMENTS (aVDInfo), aVDInfo, &cEntries);
110 AssertRC(vrc);
111 if (RT_SUCCESS(vrc))
112 {
113 for (unsigned i = 0; i < cEntries; ++ i)
114 {
115 ComObjPtr<MediumFormat> hdf;
116 rc = hdf.createObject();
117 if (FAILED(rc)) break;
118
119 rc = hdf->init(&aVDInfo[i]);
120 if (FAILED(rc)) break;
121
122 mMediumFormats.push_back(hdf);
123 }
124 }
125
126 /* Driver defaults which are OS specific */
127#if defined (RT_OS_WINDOWS)
128# ifdef VBOX_WITH_WINMM
129 mDefaultAudioDriver = AudioDriverType_WinMM;
130# else /* VBOX_WITH_WINMM */
131 mDefaultAudioDriver = AudioDriverType_DirectSound;
132# endif /* !VBOX_WITH_WINMM */
133#elif defined (RT_OS_SOLARIS)
134 mDefaultAudioDriver = AudioDriverType_SolAudio;
135#elif defined (RT_OS_LINUX)
136# if defined (VBOX_WITH_PULSE)
137 /* Check for the pulse library & that the pulse audio daemon is running. */
138 if (RTProcIsRunningByName ("pulseaudio") &&
139 RTLdrIsLoadable ("libpulse.so.0"))
140 mDefaultAudioDriver = AudioDriverType_Pulse;
141 else
142# endif /* VBOX_WITH_PULSE */
143# if defined (VBOX_WITH_ALSA)
144 /* Check if we can load the ALSA library */
145 if (RTLdrIsLoadable ("libasound.so.2"))
146 mDefaultAudioDriver = AudioDriverType_ALSA;
147 else
148# endif /* VBOX_WITH_ALSA */
149 mDefaultAudioDriver = AudioDriverType_OSS;
150#elif defined (RT_OS_DARWIN)
151 mDefaultAudioDriver = AudioDriverType_CoreAudio;
152#elif defined (RT_OS_OS2)
153 mDefaultAudioDriver = AudioDriverType_MMP;
154#elif defined (RT_OS_FREEBSD)
155 mDefaultAudioDriver = AudioDriverType_OSS;
156#else
157 mDefaultAudioDriver = AudioDriverType_Null;
158#endif
159
160 /* Confirm a successful initialization */
161 if (SUCCEEDED(rc))
162 autoInitSpan.setSucceeded();
163
164 return rc;
165}
166
167/**
168 * Uninitializes the instance and sets the ready flag to FALSE.
169 * Called either from FinalRelease() or by the parent when it gets destroyed.
170 */
171void SystemProperties::uninit()
172{
173 LogFlowThisFunc(("\n"));
174
175 /* Enclose the state transition Ready->InUninit->NotReady */
176 AutoUninitSpan autoUninitSpan(this);
177 if (autoUninitSpan.uninitDone())
178 return;
179
180 unconst(mParent) = NULL;
181}
182
183// ISystemProperties properties
184/////////////////////////////////////////////////////////////////////////////
185
186
187STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
188{
189 if (!minRAM)
190 return E_POINTER;
191
192 AutoCaller autoCaller(this);
193 if (FAILED(autoCaller.rc())) return autoCaller.rc();
194
195 /* no need to lock, this is const */
196 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
197 *minRAM = MM_RAM_MIN_IN_MB;
198
199 return S_OK;
200}
201
202STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
203{
204 if (!maxRAM)
205 return E_POINTER;
206
207 AutoCaller autoCaller(this);
208 if (FAILED(autoCaller.rc())) return autoCaller.rc();
209
210 /* no need to lock, this is const */
211 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
212 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
213 ULONG maxRAMArch = maxRAMSys;
214#if HC_ARCH_BITS == 32 && !defined(RT_OS_DARWIN)
215# ifdef RT_OS_WINDOWS
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 if (!minVRAM)
229 return E_POINTER;
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 if (!maxVRAM)
243 return E_POINTER;
244
245 AutoCaller autoCaller(this);
246 if (FAILED(autoCaller.rc())) return autoCaller.rc();
247
248 /* no need to lock, this is const */
249 *maxVRAM = SchemaDefs::MaxGuestVRAM;
250
251 return S_OK;
252}
253
254STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
255{
256 if (!minCPUCount)
257 return E_POINTER;
258
259 AutoCaller autoCaller(this);
260 if (FAILED(autoCaller.rc())) return autoCaller.rc();
261
262 /* no need to lock, this is const */
263 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
264
265 return S_OK;
266}
267
268STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
269{
270 if (!maxCPUCount)
271 return E_POINTER;
272
273 AutoCaller autoCaller(this);
274 if (FAILED(autoCaller.rc())) return autoCaller.rc();
275
276 /* no need to lock, this is const */
277 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
278
279 return S_OK;
280}
281
282STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
283{
284 if (!maxMonitors)
285 return E_POINTER;
286
287 AutoCaller autoCaller(this);
288 if (FAILED(autoCaller.rc())) return autoCaller.rc();
289
290 /* no need to lock, this is const */
291 *maxMonitors = SchemaDefs::MaxGuestMonitors;
292
293 return S_OK;
294}
295
296STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
297{
298 if (!maxVDISize)
299 return E_POINTER;
300
301 AutoCaller autoCaller(this);
302 if (FAILED(autoCaller.rc())) return autoCaller.rc();
303
304 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
305 * 48 bit range is in theory trivial, but the crappy compiler makes things
306 * more difficult). This translates to almost 2 TBytes (to be on the safe
307 * side, the reported limit is 1 MiByte less than that, as the total number
308 * of sectors should fit in 32 bits, too), which should bei enough for
309 * the moment. The virtual ATA disks support complete LBA48 (although for
310 * example iSCSI is also currently limited to 32 bit LBA), so the
311 * theoretical maximum disk size is 128 PiByte. The user interface cannot
312 * cope with this in a reasonable way yet. */
313 /* no need to lock, this is const */
314 *maxVDISize = 2048 * 1024 - 1;
315
316 return S_OK;
317}
318
319STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
320{
321 if (!count)
322 return E_POINTER;
323
324 AutoCaller autoCaller(this);
325 if (FAILED(autoCaller.rc())) return autoCaller.rc();
326
327 /* no need to lock, this is const */
328 *count = SchemaDefs::NetworkAdapterCount;
329
330 return S_OK;
331}
332
333STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
334{
335 if (!count)
336 return E_POINTER;
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::SerialPortCount;
343
344 return S_OK;
345}
346
347STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
348{
349 if (!count)
350 return E_POINTER;
351
352 AutoCaller autoCaller(this);
353 if (FAILED(autoCaller.rc())) return autoCaller.rc();
354
355 /* no need to lock, this is const */
356 *count = SchemaDefs::ParallelPortCount;
357
358 return S_OK;
359}
360
361STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
362{
363 CheckComArgOutPointerValid(aMaxBootPosition);
364
365 AutoCaller autoCaller(this);
366 if (FAILED(autoCaller.rc())) return autoCaller.rc();
367
368 /* no need to lock, this is const */
369 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
370
371 return S_OK;
372}
373
374STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus (StorageBus_T aBus, ULONG *aMaxDevicesPerPort)
375{
376 CheckComArgOutPointerValid(aMaxDevicesPerPort);
377
378 AutoCaller autoCaller(this);
379 if (FAILED(autoCaller.rc())) return autoCaller.rc();
380
381 /* no need to lock, this is const */
382 switch (aBus)
383 {
384 case StorageBus_SATA:
385 case StorageBus_SCSI:
386 case StorageBus_SAS:
387 {
388 /* SATA and both SCSI controllers only support one device per port. */
389 *aMaxDevicesPerPort = 1;
390 break;
391 }
392 case StorageBus_IDE:
393 case StorageBus_Floppy:
394 {
395 /* The IDE and Floppy controllers support 2 devices. One as master
396 * and one as slave (or floppy drive 0 and 1). */
397 *aMaxDevicesPerPort = 2;
398 break;
399 }
400 default:
401 AssertMsgFailed(("Invalid bus type %d\n", aBus));
402 }
403
404 return S_OK;
405}
406
407STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus (StorageBus_T aBus, ULONG *aMinPortCount)
408{
409 CheckComArgOutPointerValid(aMinPortCount);
410
411 AutoCaller autoCaller(this);
412 if (FAILED(autoCaller.rc())) return autoCaller.rc();
413
414 /* no need to lock, this is const */
415 switch (aBus)
416 {
417 case StorageBus_SATA:
418 {
419 *aMinPortCount = 1;
420 break;
421 }
422 case StorageBus_SCSI:
423 {
424 *aMinPortCount = 16;
425 break;
426 }
427 case StorageBus_IDE:
428 {
429 *aMinPortCount = 2;
430 break;
431 }
432 case StorageBus_Floppy:
433 {
434 *aMinPortCount = 1;
435 break;
436 }
437 case StorageBus_SAS:
438 {
439 *aMinPortCount = 8;
440 break;
441 }
442 default:
443 AssertMsgFailed(("Invalid bus type %d\n", aBus));
444 }
445
446 return S_OK;
447}
448
449STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus (StorageBus_T aBus, ULONG *aMaxPortCount)
450{
451 CheckComArgOutPointerValid(aMaxPortCount);
452
453 AutoCaller autoCaller(this);
454 if (FAILED(autoCaller.rc())) return autoCaller.rc();
455
456 /* no need to lock, this is const */
457 switch (aBus)
458 {
459 case StorageBus_SATA:
460 {
461 *aMaxPortCount = 30;
462 break;
463 }
464 case StorageBus_SCSI:
465 {
466 *aMaxPortCount = 16;
467 break;
468 }
469 case StorageBus_IDE:
470 {
471 *aMaxPortCount = 2;
472 break;
473 }
474 case StorageBus_Floppy:
475 {
476 *aMaxPortCount = 1;
477 break;
478 }
479 case StorageBus_SAS:
480 {
481 *aMaxPortCount = 8;
482 break;
483 }
484 default:
485 AssertMsgFailed(("Invalid bus type %d\n", aBus));
486 }
487
488 return S_OK;
489}
490
491STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus, ULONG *aMaxInstances)
492{
493 CheckComArgOutPointerValid(aMaxInstances);
494
495 AutoCaller autoCaller(this);
496 if (FAILED(autoCaller.rc())) return autoCaller.rc();
497
498 /* no need to lock, this is const */
499 switch (aBus)
500 {
501 case StorageBus_SATA:
502 case StorageBus_SCSI:
503 case StorageBus_IDE:
504 case StorageBus_SAS:
505 case StorageBus_Floppy:
506 {
507 /** @todo raise the limits ASAP, per bus type */
508 *aMaxInstances = 1;
509 break;
510 }
511 default:
512 AssertMsgFailed(("Invalid bus type %d\n", aBus));
513 }
514
515 return S_OK;
516}
517
518STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
519 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
520{
521 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
522
523 AutoCaller autoCaller(this);
524 if (FAILED(autoCaller.rc())) return autoCaller.rc();
525
526 /* no need to lock, this is const */
527 switch (aBus)
528 {
529 case StorageBus_IDE:
530 {
531 com::SafeArray<DeviceType_T> saDeviceTypes(2);
532 saDeviceTypes[0] = DeviceType_DVD;
533 saDeviceTypes[1] = DeviceType_HardDisk;
534 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
535 break;
536 }
537 case StorageBus_SATA:
538 case StorageBus_SCSI:
539 case StorageBus_SAS:
540 {
541 com::SafeArray<DeviceType_T> saDeviceTypes(1);
542 saDeviceTypes[0] = DeviceType_HardDisk;
543 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
544 break;
545 }
546 case StorageBus_Floppy:
547 {
548 com::SafeArray<DeviceType_T> saDeviceTypes(1);
549 saDeviceTypes[0] = DeviceType_Floppy;
550 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
551 break;
552 }
553 default:
554 AssertMsgFailed(("Invalid bus type %d\n", aBus));
555 }
556
557 return S_OK;
558}
559
560STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
561{
562 CheckComArgOutPointerValid(aDefaultMachineFolder);
563
564 AutoCaller autoCaller(this);
565 if (FAILED(autoCaller.rc())) return autoCaller.rc();
566
567 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
568
569 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
570
571 return S_OK;
572}
573
574STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
575{
576 AutoCaller autoCaller(this);
577 if (FAILED(autoCaller.rc())) return autoCaller.rc();
578
579 /* VirtualBox::saveSettings() needs a write lock */
580 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
581
582 HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
583 if (SUCCEEDED(rc))
584 rc = mParent->saveSettings();
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 /* VirtualBox::saveSettings() needs a write lock */
609 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
610
611 HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
612 if (SUCCEEDED(rc))
613 rc = mParent->saveSettings();
614
615 return rc;
616}
617
618STDMETHODIMP SystemProperties::
619COMGETTER(MediumFormats) (ComSafeArrayOut(IMediumFormat *, aMediumFormats))
620{
621 if (ComSafeArrayOutIsNull(aMediumFormats))
622 return E_POINTER;
623
624 AutoCaller autoCaller(this);
625 if (FAILED(autoCaller.rc())) return autoCaller.rc();
626
627 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
628
629 SafeIfaceArray<IMediumFormat> mediumFormats (mMediumFormats);
630 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
631
632 return S_OK;
633}
634
635STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
636{
637 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
638
639 AutoCaller autoCaller(this);
640 if (FAILED(autoCaller.rc())) return autoCaller.rc();
641
642 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
643
644 m_strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
645
646 return S_OK;
647}
648
649STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
650{
651 AutoCaller autoCaller(this);
652 if (FAILED(autoCaller.rc())) return autoCaller.rc();
653
654 /* VirtualBox::saveSettings() needs a write lock */
655 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
656
657 HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
658 if (SUCCEEDED(rc))
659 rc = mParent->saveSettings();
660
661 return rc;
662}
663
664STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
665{
666 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
667
668 AutoCaller autoCaller(this);
669 if (FAILED(autoCaller.rc())) return autoCaller.rc();
670
671 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
672
673 m_strRemoteDisplayAuthLibrary.cloneTo(aRemoteDisplayAuthLibrary);
674
675 return S_OK;
676}
677
678STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
679{
680 AutoCaller autoCaller(this);
681 if (FAILED(autoCaller.rc())) return autoCaller.rc();
682
683 /* VirtualBox::saveSettings() needs a write lock */
684 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
685
686 HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
687 if (SUCCEEDED(rc))
688 rc = mParent->saveSettings();
689
690 return rc;
691}
692
693STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
694{
695 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
696
697 AutoCaller autoCaller(this);
698 if (FAILED(autoCaller.rc())) return autoCaller.rc();
699
700 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
701
702 m_strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
703
704 return S_OK;
705}
706
707STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
708{
709 AutoCaller autoCaller(this);
710 if (FAILED(autoCaller.rc())) return autoCaller.rc();
711
712 /* VirtualBox::saveSettings() needs a write lock */
713 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
714
715 HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
716 if (SUCCEEDED(rc))
717 rc = mParent->saveSettings();
718
719 return rc;
720}
721
722STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
723{
724 if (!count)
725 return E_POINTER;
726
727 AutoCaller autoCaller(this);
728 if (FAILED(autoCaller.rc())) return autoCaller.rc();
729
730 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
731
732 *count = mLogHistoryCount;
733
734 return S_OK;
735}
736
737STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
738{
739 AutoCaller autoCaller(this);
740 if (FAILED(autoCaller.rc())) return autoCaller.rc();
741
742 /* VirtualBox::saveSettings() needs a write lock */
743 AutoMultiWriteLock2 alock(mParent, this COMMA_LOCKVAL_SRC_POS);
744
745 mLogHistoryCount = count;
746
747 HRESULT rc = mParent->saveSettings();
748
749 return rc;
750}
751
752STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver) (AudioDriverType_T *aAudioDriver)
753{
754 if (!aAudioDriver)
755 return E_POINTER;
756
757 AutoCaller autoCaller(this);
758 if (FAILED(autoCaller.rc())) return autoCaller.rc();
759
760 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
761
762 *aAudioDriver = mDefaultAudioDriver;
763
764 return S_OK;
765}
766
767// public methods only for internal purposes
768/////////////////////////////////////////////////////////////////////////////
769
770HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
771{
772 AutoCaller autoCaller(this);
773 if (FAILED(autoCaller.rc())) return autoCaller.rc();
774
775 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
776
777 HRESULT rc = S_OK;
778
779 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
780 if (FAILED(rc)) return rc;
781
782 rc = setDefaultHardDiskFolder(data.strDefaultHardDiskFolder);
783 if (FAILED(rc)) return rc;
784
785 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
786 if (FAILED(rc)) return rc;
787
788 rc = setRemoteDisplayAuthLibrary(data.strRemoteDisplayAuthLibrary);
789 if (FAILED(rc)) return rc;
790
791 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
792 if (FAILED(rc)) return rc;
793
794 mLogHistoryCount = data.ulLogHistoryCount;
795
796 return S_OK;
797}
798
799HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
800{
801 AutoCaller autoCaller(this);
802 if (FAILED(autoCaller.rc())) return autoCaller.rc();
803
804 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
805
806 data.strDefaultMachineFolder = m_strDefaultMachineFolder;
807 data.strDefaultHardDiskFolder = m_strDefaultHardDiskFolder;
808 data.strDefaultHardDiskFormat = m_strDefaultHardDiskFormat;
809 data.strRemoteDisplayAuthLibrary = m_strRemoteDisplayAuthLibrary;
810 data.strWebServiceAuthLibrary = m_strWebServiceAuthLibrary;
811 data.ulLogHistoryCount = mLogHistoryCount;
812
813 return S_OK;
814}
815
816/**
817 * Returns a medium format object corresponding to the given format
818 * identifier or null if no such format.
819 *
820 * @param aFormat Format identifier.
821 *
822 * @return ComObjPtr<MediumFormat>
823 */
824ComObjPtr<MediumFormat> SystemProperties::mediumFormat (CBSTR aFormat)
825{
826 ComObjPtr<MediumFormat> format;
827
828 AutoCaller autoCaller(this);
829 AssertComRCReturn (autoCaller.rc(), format);
830
831 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
832
833 for (MediumFormatList::const_iterator it = mMediumFormats.begin();
834 it != mMediumFormats.end(); ++ it)
835 {
836 /* MediumFormat is all const, no need to lock */
837
838 if ((*it)->id().compare(aFormat, Bstr::CaseInsensitive) == 0)
839 {
840 format = *it;
841 break;
842 }
843 }
844
845 return format;
846}
847
848// private methods
849/////////////////////////////////////////////////////////////////////////////
850
851HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
852{
853 Utf8Str path(aPath);
854 if (path.isEmpty())
855 path = "Machines";
856
857 /* get the full file name */
858 Utf8Str folder;
859 int vrc = mParent->calculateFullPath(path, folder);
860 if (RT_FAILURE(vrc))
861 return setError(E_FAIL,
862 tr("Invalid default machine folder '%s' (%Rrc)"),
863 path.raw(),
864 vrc);
865
866 m_strDefaultMachineFolder = path;
867 m_strDefaultMachineFolderFull = folder;
868
869 return S_OK;
870}
871
872HRESULT SystemProperties::setDefaultHardDiskFolder(const Utf8Str &aPath)
873{
874 Utf8Str path(aPath);
875 if (path.isEmpty())
876 path = "HardDisks";
877
878 /* get the full file name */
879 Utf8Str folder;
880 int vrc = mParent->calculateFullPath(path, folder);
881 if (RT_FAILURE(vrc))
882 return setError(E_FAIL,
883 tr("Invalid default hard disk folder '%s' (%Rrc)"),
884 path.raw(),
885 vrc);
886
887 m_strDefaultHardDiskFolder = path;
888 m_strDefaultHardDiskFolderFull = folder;
889
890 return S_OK;
891}
892
893HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
894{
895 if (!aFormat.isEmpty())
896 m_strDefaultHardDiskFormat = aFormat;
897 else
898 m_strDefaultHardDiskFormat = "VDI";
899
900 return S_OK;
901}
902
903HRESULT SystemProperties::setRemoteDisplayAuthLibrary(const Utf8Str &aPath)
904{
905 if (!aPath.isEmpty())
906 m_strRemoteDisplayAuthLibrary = aPath;
907 else
908 m_strRemoteDisplayAuthLibrary = "VRDPAuth";
909
910 return S_OK;
911}
912
913HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
914{
915 if (!aPath.isEmpty())
916 m_strWebServiceAuthLibrary = aPath;
917 else
918 m_strWebServiceAuthLibrary = "VRDPAuth";
919
920 return S_OK;
921}
922
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