VirtualBox

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

Last change on this file since 23575 was 23560, checked in by vboxsync, 15 years ago

API/SystemProperties: new method to query the maximum instance count for each storage bus

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