VirtualBox

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

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

Main-OVF: Select the target format out of the available formats.

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