VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/SystemPropertiesImpl.cpp@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.4 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#define LOG_GROUP LOG_GROUP_MAIN_SYSTEMPROPERTIES
29#include "SystemPropertiesImpl.h"
30#include "VirtualBoxImpl.h"
31#include "MachineImpl.h"
32#ifdef VBOX_WITH_EXTPACK
33# include "ExtPackManagerImpl.h"
34#endif
35#include "CPUProfileImpl.h"
36#include "AutoCaller.h"
37#include "Global.h"
38#include "LoggingNew.h"
39#include "AutostartDb.h"
40#include "VirtualBoxTranslator.h"
41
42// generated header
43#include "SchemaDefs.h"
44
45#include <iprt/dir.h>
46#include <iprt/ldr.h>
47#include <iprt/locale.h>
48#include <iprt/path.h>
49#include <iprt/string.h>
50#include <iprt/uri.h>
51#include <iprt/cpp/utils.h>
52
53#include <iprt/errcore.h>
54#include <VBox/param.h>
55#include <VBox/settings.h>
56#include <VBox/vd.h>
57#include <VBox/vmm/cpum.h>
58
59// defines
60/////////////////////////////////////////////////////////////////////////////
61
62// constructor / destructor
63/////////////////////////////////////////////////////////////////////////////
64
65SystemProperties::SystemProperties()
66 : mParent(NULL)
67 , m(new settings::SystemProperties)
68 , m_fLoadedX86CPUProfiles(false)
69{
70}
71
72SystemProperties::~SystemProperties()
73{
74 delete m;
75}
76
77
78HRESULT SystemProperties::FinalConstruct()
79{
80 return BaseFinalConstruct();
81}
82
83void SystemProperties::FinalRelease()
84{
85 uninit();
86 BaseFinalRelease();
87}
88
89// public methods only for internal purposes
90/////////////////////////////////////////////////////////////////////////////
91
92/**
93 * Initializes the system information object.
94 *
95 * @returns COM result indicator
96 */
97HRESULT SystemProperties::init(VirtualBox *aParent)
98{
99 LogFlowThisFunc(("aParent=%p\n", aParent));
100
101 ComAssertRet(aParent, E_FAIL);
102
103 /* Enclose the state transition NotReady->InInit->Ready */
104 AutoInitSpan autoInitSpan(this);
105 AssertReturn(autoInitSpan.isOk(), E_FAIL);
106
107 unconst(mParent) = aParent;
108
109 i_setDefaultMachineFolder(Utf8Str::Empty);
110 i_setLoggingLevel(Utf8Str::Empty);
111 i_setDefaultHardDiskFormat(Utf8Str::Empty);
112
113 i_setVRDEAuthLibrary(Utf8Str::Empty);
114 i_setDefaultVRDEExtPack(Utf8Str::Empty);
115 i_setDefaultCryptoExtPack(Utf8Str::Empty);
116
117 m->uLogHistoryCount = 3;
118
119
120 /* On Windows, OS X and Solaris, HW virtualization use isn't exclusive
121 * by default so that VT-x or AMD-V can be shared with other
122 * hypervisors without requiring user intervention.
123 * NB: See also SystemProperties constructor in settings.h
124 */
125#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS)
126 m->fExclusiveHwVirt = false;
127#else
128 m->fExclusiveHwVirt = true;
129#endif
130
131 HRESULT rc = S_OK;
132
133 /* Fetch info of all available hd backends. */
134
135 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
136 /// any number of backends
137
138 VDBACKENDINFO aVDInfo[100];
139 unsigned cEntries;
140 int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
141 AssertRC(vrc);
142 if (RT_SUCCESS(vrc))
143 {
144 for (unsigned i = 0; i < cEntries; ++ i)
145 {
146 ComObjPtr<MediumFormat> hdf;
147 rc = hdf.createObject();
148 if (FAILED(rc)) break;
149
150 rc = hdf->init(&aVDInfo[i]);
151 if (FAILED(rc)) break;
152
153 m_llMediumFormats.push_back(hdf);
154 }
155 }
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// wrapped ISystemProperties properties
181/////////////////////////////////////////////////////////////////////////////
182
183HRESULT SystemProperties::getMinGuestRAM(ULONG *minRAM)
184
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
193HRESULT SystemProperties::getMaxGuestRAM(ULONG *maxRAM)
194{
195 /* no need to lock, this is const */
196 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
197 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
198 ULONG maxRAMArch = maxRAMSys;
199 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
200
201 return S_OK;
202}
203
204HRESULT SystemProperties::getMinGuestVRAM(ULONG *minVRAM)
205{
206 /* no need to lock, this is const */
207 *minVRAM = SchemaDefs::MinGuestVRAM;
208
209 return S_OK;
210}
211
212HRESULT SystemProperties::getMaxGuestVRAM(ULONG *maxVRAM)
213{
214 /* no need to lock, this is const */
215 *maxVRAM = SchemaDefs::MaxGuestVRAM;
216
217 return S_OK;
218}
219
220HRESULT SystemProperties::getMinGuestCPUCount(ULONG *minCPUCount)
221{
222 /* no need to lock, this is const */
223 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
224
225 return S_OK;
226}
227
228HRESULT SystemProperties::getMaxGuestCPUCount(ULONG *maxCPUCount)
229{
230 /* no need to lock, this is const */
231 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
232
233 return S_OK;
234}
235
236HRESULT SystemProperties::getMaxGuestMonitors(ULONG *maxMonitors)
237{
238
239 /* no need to lock, this is const */
240 *maxMonitors = SchemaDefs::MaxGuestMonitors;
241
242 return S_OK;
243}
244
245
246HRESULT SystemProperties::getInfoVDSize(LONG64 *infoVDSize)
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
269
270HRESULT SystemProperties::getSerialPortCount(ULONG *count)
271{
272 /* no need to lock, this is const */
273 *count = SchemaDefs::SerialPortCount;
274
275 return S_OK;
276}
277
278
279HRESULT SystemProperties::getParallelPortCount(ULONG *count)
280{
281 /* no need to lock, this is const */
282 *count = SchemaDefs::ParallelPortCount;
283
284 return S_OK;
285}
286
287
288HRESULT SystemProperties::getMaxBootPosition(ULONG *aMaxBootPosition)
289{
290 /* no need to lock, this is const */
291 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
292
293 return S_OK;
294}
295
296
297HRESULT SystemProperties::getRawModeSupported(BOOL *aRawModeSupported)
298{
299 *aRawModeSupported = FALSE;
300 return S_OK;
301}
302
303
304HRESULT SystemProperties::getExclusiveHwVirt(BOOL *aExclusiveHwVirt)
305{
306 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
307
308 *aExclusiveHwVirt = m->fExclusiveHwVirt;
309
310 return S_OK;
311}
312
313HRESULT SystemProperties::setExclusiveHwVirt(BOOL aExclusiveHwVirt)
314{
315 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
316 m->fExclusiveHwVirt = !!aExclusiveHwVirt;
317 alock.release();
318
319 // VirtualBox::i_saveSettings() needs vbox write lock
320 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
321 HRESULT rc = mParent->i_saveSettings();
322
323 return rc;
324}
325
326HRESULT SystemProperties::getMaxNetworkAdapters(ChipsetType_T aChipset, ULONG *aMaxNetworkAdapters)
327{
328 /* no need for locking, no state */
329 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
330 if (uResult == 0)
331 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
332 *aMaxNetworkAdapters = uResult;
333 return S_OK;
334}
335
336HRESULT SystemProperties::getMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType, ULONG *count)
337{
338 /* no need for locking, no state */
339 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
340 if (uResult == 0)
341 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
342
343 switch (aType)
344 {
345 case NetworkAttachmentType_NAT:
346 case NetworkAttachmentType_Internal:
347 case NetworkAttachmentType_NATNetwork:
348 /* chipset default is OK */
349 break;
350 case NetworkAttachmentType_Bridged:
351 /* Maybe use current host interface count here? */
352 break;
353 case NetworkAttachmentType_HostOnly:
354 uResult = RT_MIN(uResult, 8);
355 break;
356 default:
357 AssertMsgFailed(("Unhandled attachment type %d\n", aType));
358 }
359
360 *count = uResult;
361
362 return S_OK;
363}
364
365
366HRESULT SystemProperties::getMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
367 ULONG *aMaxDevicesPerPort)
368{
369 /* no need to lock, this is const */
370 switch (aBus)
371 {
372 case StorageBus_SATA:
373 case StorageBus_SCSI:
374 case StorageBus_SAS:
375 case StorageBus_USB:
376 case StorageBus_PCIe:
377 case StorageBus_VirtioSCSI:
378 {
379 /* SATA and both SCSI controllers only support one device per port. */
380 *aMaxDevicesPerPort = 1;
381 break;
382 }
383 case StorageBus_IDE:
384 case StorageBus_Floppy:
385 {
386 /* The IDE and Floppy controllers support 2 devices. One as master
387 * and one as slave (or floppy drive 0 and 1). */
388 *aMaxDevicesPerPort = 2;
389 break;
390 }
391 default:
392 AssertMsgFailed(("Invalid bus type %d\n", aBus));
393 }
394
395 return S_OK;
396}
397
398HRESULT SystemProperties::getMinPortCountForStorageBus(StorageBus_T aBus,
399 ULONG *aMinPortCount)
400{
401 /* no need to lock, this is const */
402 switch (aBus)
403 {
404 case StorageBus_SATA:
405 case StorageBus_SAS:
406 case StorageBus_PCIe:
407 case StorageBus_VirtioSCSI:
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 case StorageBus_USB:
428 {
429 *aMinPortCount = 8;
430 break;
431 }
432 default:
433 AssertMsgFailed(("Invalid bus type %d\n", aBus));
434 }
435
436 return S_OK;
437}
438
439HRESULT SystemProperties::getMaxPortCountForStorageBus(StorageBus_T aBus,
440 ULONG *aMaxPortCount)
441{
442 /* no need to lock, this is const */
443 switch (aBus)
444 {
445 case StorageBus_SATA:
446 {
447 *aMaxPortCount = 30;
448 break;
449 }
450 case StorageBus_SCSI:
451 {
452 *aMaxPortCount = 16;
453 break;
454 }
455 case StorageBus_IDE:
456 {
457 *aMaxPortCount = 2;
458 break;
459 }
460 case StorageBus_Floppy:
461 {
462 *aMaxPortCount = 1;
463 break;
464 }
465 case StorageBus_SAS:
466 case StorageBus_PCIe:
467 {
468 *aMaxPortCount = 255;
469 break;
470 }
471 case StorageBus_USB:
472 {
473 *aMaxPortCount = 8;
474 break;
475 }
476 case StorageBus_VirtioSCSI:
477 {
478 *aMaxPortCount = 256;
479 break;
480 }
481 default:
482 AssertMsgFailed(("Invalid bus type %d\n", aBus));
483 }
484
485 return S_OK;
486}
487
488HRESULT SystemProperties::getMaxInstancesOfStorageBus(ChipsetType_T aChipset,
489 StorageBus_T aBus,
490 ULONG *aMaxInstances)
491{
492 ULONG cCtrs = 0;
493
494 /* no need to lock, this is const */
495 switch (aBus)
496 {
497 case StorageBus_SATA:
498 case StorageBus_SCSI:
499 case StorageBus_SAS:
500 case StorageBus_PCIe:
501 case StorageBus_VirtioSCSI:
502 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
503 break;
504 case StorageBus_USB:
505 case StorageBus_IDE:
506 case StorageBus_Floppy:
507 {
508 cCtrs = 1;
509 break;
510 }
511 default:
512 AssertMsgFailed(("Invalid bus type %d\n", aBus));
513 }
514
515 *aMaxInstances = cCtrs;
516
517 return S_OK;
518}
519
520HRESULT SystemProperties::getDeviceTypesForStorageBus(StorageBus_T aBus,
521 std::vector<DeviceType_T> &aDeviceTypes)
522{
523 aDeviceTypes.resize(0);
524
525 /* no need to lock, this is const */
526 switch (aBus)
527 {
528 case StorageBus_IDE:
529 case StorageBus_SATA:
530 case StorageBus_SCSI:
531 case StorageBus_SAS:
532 case StorageBus_USB:
533 case StorageBus_VirtioSCSI:
534 {
535 aDeviceTypes.resize(2);
536 aDeviceTypes[0] = DeviceType_DVD;
537 aDeviceTypes[1] = DeviceType_HardDisk;
538 break;
539 }
540 case StorageBus_Floppy:
541 {
542 aDeviceTypes.resize(1);
543 aDeviceTypes[0] = DeviceType_Floppy;
544 break;
545 }
546 case StorageBus_PCIe:
547 {
548 aDeviceTypes.resize(1);
549 aDeviceTypes[0] = DeviceType_HardDisk;
550 break;
551 }
552 default:
553 AssertMsgFailed(("Invalid bus type %d\n", aBus));
554 }
555
556 return S_OK;
557}
558
559HRESULT SystemProperties::getStorageBusForStorageControllerType(StorageControllerType_T aStorageControllerType,
560 StorageBus_T *aStorageBus)
561{
562 /* no need to lock, this is const */
563 switch (aStorageControllerType)
564 {
565 case StorageControllerType_LsiLogic:
566 case StorageControllerType_BusLogic:
567 *aStorageBus = StorageBus_SCSI;
568 break;
569 case StorageControllerType_IntelAhci:
570 *aStorageBus = StorageBus_SATA;
571 break;
572 case StorageControllerType_PIIX3:
573 case StorageControllerType_PIIX4:
574 case StorageControllerType_ICH6:
575 *aStorageBus = StorageBus_IDE;
576 break;
577 case StorageControllerType_I82078:
578 *aStorageBus = StorageBus_Floppy;
579 break;
580 case StorageControllerType_LsiLogicSas:
581 *aStorageBus = StorageBus_SAS;
582 break;
583 case StorageControllerType_USB:
584 *aStorageBus = StorageBus_USB;
585 break;
586 case StorageControllerType_NVMe:
587 *aStorageBus = StorageBus_PCIe;
588 break;
589 case StorageControllerType_VirtioSCSI:
590 *aStorageBus = StorageBus_VirtioSCSI;
591 break;
592 default:
593 return setError(E_FAIL, tr("Invalid storage controller type %d\n"), aStorageBus);
594 }
595
596 return S_OK;
597}
598
599HRESULT SystemProperties::getStorageControllerTypesForStorageBus(StorageBus_T aStorageBus,
600 std::vector<StorageControllerType_T> &aStorageControllerTypes)
601{
602 aStorageControllerTypes.resize(0);
603
604 /* no need to lock, this is const */
605 switch (aStorageBus)
606 {
607 case StorageBus_IDE:
608 aStorageControllerTypes.resize(3);
609 aStorageControllerTypes[0] = StorageControllerType_PIIX4;
610 aStorageControllerTypes[1] = StorageControllerType_PIIX3;
611 aStorageControllerTypes[2] = StorageControllerType_ICH6;
612 break;
613 case StorageBus_SATA:
614 aStorageControllerTypes.resize(1);
615 aStorageControllerTypes[0] = StorageControllerType_IntelAhci;
616 break;
617 case StorageBus_SCSI:
618 aStorageControllerTypes.resize(2);
619 aStorageControllerTypes[0] = StorageControllerType_LsiLogic;
620 aStorageControllerTypes[1] = StorageControllerType_BusLogic;
621 break;
622 case StorageBus_Floppy:
623 aStorageControllerTypes.resize(1);
624 aStorageControllerTypes[0] = StorageControllerType_I82078;
625 break;
626 case StorageBus_SAS:
627 aStorageControllerTypes.resize(1);
628 aStorageControllerTypes[0] = StorageControllerType_LsiLogicSas;
629 break;
630 case StorageBus_USB:
631 aStorageControllerTypes.resize(1);
632 aStorageControllerTypes[0] = StorageControllerType_USB;
633 break;
634 case StorageBus_PCIe:
635 aStorageControllerTypes.resize(1);
636 aStorageControllerTypes[0] = StorageControllerType_NVMe;
637 break;
638 case StorageBus_VirtioSCSI:
639 aStorageControllerTypes.resize(1);
640 aStorageControllerTypes[0] = StorageControllerType_VirtioSCSI;
641 break;
642 default:
643 return setError(E_FAIL, tr("Invalid storage bus %d\n"), aStorageBus);
644 }
645
646 return S_OK;
647}
648
649HRESULT SystemProperties::getDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType,
650 BOOL *aEnabled)
651{
652 /* no need to lock, this is const */
653 switch (aControllerType)
654 {
655 case StorageControllerType_LsiLogic:
656 case StorageControllerType_BusLogic:
657 case StorageControllerType_IntelAhci:
658 case StorageControllerType_LsiLogicSas:
659 case StorageControllerType_USB:
660 case StorageControllerType_NVMe:
661 case StorageControllerType_VirtioSCSI:
662 *aEnabled = false;
663 break;
664 case StorageControllerType_PIIX3:
665 case StorageControllerType_PIIX4:
666 case StorageControllerType_ICH6:
667 case StorageControllerType_I82078:
668 *aEnabled = true;
669 break;
670 default:
671 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
672 }
673 return S_OK;
674}
675
676HRESULT SystemProperties::getStorageControllerHotplugCapable(StorageControllerType_T aControllerType,
677 BOOL *aHotplugCapable)
678{
679 switch (aControllerType)
680 {
681 case StorageControllerType_IntelAhci:
682 case StorageControllerType_USB:
683 *aHotplugCapable = true;
684 break;
685 case StorageControllerType_LsiLogic:
686 case StorageControllerType_LsiLogicSas:
687 case StorageControllerType_BusLogic:
688 case StorageControllerType_NVMe:
689 case StorageControllerType_VirtioSCSI:
690 case StorageControllerType_PIIX3:
691 case StorageControllerType_PIIX4:
692 case StorageControllerType_ICH6:
693 case StorageControllerType_I82078:
694 *aHotplugCapable = false;
695 break;
696 default:
697 AssertMsgFailedReturn(("Invalid controller type %d\n", aControllerType), E_FAIL);
698 }
699
700 return S_OK;
701}
702
703HRESULT SystemProperties::getMaxInstancesOfUSBControllerType(ChipsetType_T aChipset,
704 USBControllerType_T aType,
705 ULONG *aMaxInstances)
706{
707 NOREF(aChipset);
708 ULONG cCtrs = 0;
709
710 /* no need to lock, this is const */
711 switch (aType)
712 {
713 case USBControllerType_OHCI:
714 case USBControllerType_EHCI:
715 case USBControllerType_XHCI:
716 {
717 cCtrs = 1;
718 break;
719 }
720 default:
721 AssertMsgFailed(("Invalid bus type %d\n", aType));
722 }
723
724 *aMaxInstances = cCtrs;
725
726 return S_OK;
727}
728
729HRESULT SystemProperties::getCPUProfiles(CPUArchitecture_T aArchitecture, const com::Utf8Str &aNamePattern,
730 std::vector<ComPtr<ICPUProfile> > &aProfiles)
731{
732 /*
733 * Validate and adjust the architecture.
734 */
735 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
736 CPUArchitecture_T enmSecondaryArch = aArchitecture;
737 bool fLoaded;
738 switch (aArchitecture)
739 {
740 case CPUArchitecture_Any:
741 aArchitecture = CPUArchitecture_AMD64;
742 RT_FALL_THROUGH();
743 case CPUArchitecture_AMD64:
744 enmSecondaryArch = CPUArchitecture_x86;
745 RT_FALL_THROUGH();
746 case CPUArchitecture_x86:
747 fLoaded = m_fLoadedX86CPUProfiles;
748 break;
749 default:
750 return setError(E_INVALIDARG, tr("Invalid or unsupported architecture value: %d"), aArchitecture);
751 }
752
753 /*
754 * Do we need to load the profiles?
755 */
756 HRESULT hrc;
757 if (fLoaded)
758 hrc = S_OK;
759 else
760 {
761 alock.release();
762 AutoWriteLock alockWrite(this COMMA_LOCKVAL_SRC_POS);
763
764 /*
765 * Translate the architecture to a VMM module handle.
766 */
767 const char *pszVMM;
768 switch (aArchitecture)
769 {
770 case CPUArchitecture_AMD64:
771 case CPUArchitecture_x86:
772 pszVMM = "VBoxVMM";
773 fLoaded = m_fLoadedX86CPUProfiles;
774 break;
775 default:
776 AssertFailedReturn(E_INVALIDARG);
777 }
778 if (fLoaded)
779 hrc = S_OK;
780 else
781 {
782 char szPath[RTPATH_MAX];
783 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
784 if (RT_SUCCESS(vrc))
785 vrc = RTPathAppend(szPath, sizeof(szPath), pszVMM);
786 if (RT_SUCCESS(vrc))
787 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
788 if (RT_SUCCESS(vrc))
789 {
790 RTLDRMOD hMod = NIL_RTLDRMOD;
791 vrc = RTLdrLoad(szPath, &hMod);
792 if (RT_SUCCESS(vrc))
793 {
794 /*
795 * Resolve the CPUMDb APIs we need.
796 */
797 PFNCPUMDBGETENTRIES pfnGetEntries
798 = (PFNCPUMDBGETENTRIES)RTLdrGetFunction(hMod, "CPUMR3DbGetEntries");
799 PFNCPUMDBGETENTRYBYINDEX pfnGetEntryByIndex
800 = (PFNCPUMDBGETENTRYBYINDEX)RTLdrGetFunction(hMod, "CPUMR3DbGetEntryByIndex");
801 if (pfnGetEntries && pfnGetEntryByIndex)
802 {
803 size_t const cExistingProfiles = m_llCPUProfiles.size();
804
805 /*
806 * Instantate the profiles.
807 */
808 hrc = S_OK;
809 uint32_t const cEntries = pfnGetEntries();
810 for (uint32_t i = 0; i < cEntries; i++)
811 {
812 PCCPUMDBENTRY pDbEntry = pfnGetEntryByIndex(i);
813 AssertBreakStmt(pDbEntry, hrc = setError(E_UNEXPECTED, "CPUMR3DbGetEntryByIndex failed for %i", i));
814
815 ComObjPtr<CPUProfile> ptrProfile;
816 hrc = ptrProfile.createObject();
817 if (SUCCEEDED(hrc))
818 {
819 hrc = ptrProfile->initFromDbEntry(pDbEntry);
820 if (SUCCEEDED(hrc))
821 {
822 try
823 {
824 m_llCPUProfiles.push_back(ptrProfile);
825 continue;
826 }
827 catch (std::bad_alloc &)
828 {
829 hrc = E_OUTOFMEMORY;
830 }
831 }
832 }
833 break;
834 }
835
836 /*
837 * On success update the flag and retake the read lock.
838 * If we fail, drop the profiles we added to the list.
839 */
840 if (SUCCEEDED(hrc))
841 {
842 switch (aArchitecture)
843 {
844 case CPUArchitecture_AMD64:
845 case CPUArchitecture_x86:
846 m_fLoadedX86CPUProfiles = true;
847 break;
848 default:
849 AssertFailedStmt(hrc = E_INVALIDARG);
850 }
851
852 alockWrite.release();
853 alock.acquire();
854 }
855 else
856 m_llCPUProfiles.resize(cExistingProfiles);
857 }
858 else
859 hrc = setErrorVrc(VERR_SYMBOL_NOT_FOUND,
860 tr("'%s' is missing symbols: CPUMR3DbGetEntries, CPUMR3DbGetEntryByIndex"), szPath);
861 RTLdrClose(hMod);
862 }
863 else
864 hrc = setErrorVrc(vrc, tr("Failed to construct load '%s': %Rrc"), szPath, vrc);
865 }
866 else
867 hrc = setErrorVrc(vrc, tr("Failed to construct path to the VMM DLL/Dylib/SharedObject: %Rrc"), vrc);
868 }
869 }
870 if (SUCCEEDED(hrc))
871 {
872 /*
873 * Return the matching profiles.
874 */
875 /* Count matches: */
876 size_t cMatches = 0;
877 for (CPUProfileList_T::const_iterator it = m_llCPUProfiles.begin(); it != m_llCPUProfiles.end(); ++it)
878 if ((*it)->i_match(aArchitecture, enmSecondaryArch, aNamePattern))
879 cMatches++;
880
881 /* Resize the output array. */
882 try
883 {
884 aProfiles.resize(cMatches);
885 }
886 catch (std::bad_alloc &)
887 {
888 aProfiles.resize(0);
889 hrc = E_OUTOFMEMORY;
890 }
891
892 /* Get the return objects: */
893 if (SUCCEEDED(hrc) && cMatches > 0)
894 {
895 size_t iMatch = 0;
896 for (CPUProfileList_T::const_iterator it = m_llCPUProfiles.begin(); it != m_llCPUProfiles.end(); ++it)
897 if ((*it)->i_match(aArchitecture, enmSecondaryArch, aNamePattern))
898 {
899 AssertBreakStmt(iMatch < cMatches, hrc = E_UNEXPECTED);
900 hrc = (*it).queryInterfaceTo(aProfiles[iMatch].asOutParam());
901 if (SUCCEEDED(hrc))
902 iMatch++;
903 else
904 break;
905 }
906 AssertStmt(iMatch == cMatches || FAILED(hrc), hrc = E_UNEXPECTED);
907 }
908 }
909 return hrc;
910}
911
912
913HRESULT SystemProperties::getDefaultMachineFolder(com::Utf8Str &aDefaultMachineFolder)
914{
915 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
916 aDefaultMachineFolder = m->strDefaultMachineFolder;
917 return S_OK;
918}
919
920HRESULT SystemProperties::setDefaultMachineFolder(const com::Utf8Str &aDefaultMachineFolder)
921{
922 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
923 HRESULT rc = i_setDefaultMachineFolder(aDefaultMachineFolder);
924 alock.release();
925 if (SUCCEEDED(rc))
926 {
927 // VirtualBox::i_saveSettings() needs vbox write lock
928 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
929 rc = mParent->i_saveSettings();
930 }
931
932 return rc;
933}
934
935HRESULT SystemProperties::getLoggingLevel(com::Utf8Str &aLoggingLevel)
936{
937 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
938
939 aLoggingLevel = m->strLoggingLevel;
940
941 if (aLoggingLevel.isEmpty())
942 aLoggingLevel = VBOXSVC_LOG_DEFAULT;
943
944 return S_OK;
945}
946
947
948HRESULT SystemProperties::setLoggingLevel(const com::Utf8Str &aLoggingLevel)
949{
950 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
951 HRESULT rc = i_setLoggingLevel(aLoggingLevel);
952 alock.release();
953
954 if (SUCCEEDED(rc))
955 {
956 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
957 rc = mParent->i_saveSettings();
958 }
959 else
960 LogRel(("Cannot set passed logging level=%s, or the default one - Error=%Rhrc \n", aLoggingLevel.c_str(), rc));
961
962 return rc;
963}
964
965HRESULT SystemProperties::getMediumFormats(std::vector<ComPtr<IMediumFormat> > &aMediumFormats)
966{
967 MediumFormatList mediumFormats(m_llMediumFormats);
968 aMediumFormats.resize(mediumFormats.size());
969 size_t i = 0;
970 for (MediumFormatList::const_iterator it = mediumFormats.begin(); it != mediumFormats.end(); ++it, ++i)
971 (*it).queryInterfaceTo(aMediumFormats[i].asOutParam());
972 return S_OK;
973}
974
975HRESULT SystemProperties::getDefaultHardDiskFormat(com::Utf8Str &aDefaultHardDiskFormat)
976{
977 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
978 aDefaultHardDiskFormat = m->strDefaultHardDiskFormat;
979 return S_OK;
980}
981
982
983HRESULT SystemProperties::setDefaultHardDiskFormat(const com::Utf8Str &aDefaultHardDiskFormat)
984{
985 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
986 HRESULT rc = i_setDefaultHardDiskFormat(aDefaultHardDiskFormat);
987 alock.release();
988 if (SUCCEEDED(rc))
989 {
990 // VirtualBox::i_saveSettings() needs vbox write lock
991 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
992 rc = mParent->i_saveSettings();
993 }
994
995 return rc;
996}
997
998HRESULT SystemProperties::getFreeDiskSpaceWarning(LONG64 *aFreeSpace)
999{
1000 NOREF(aFreeSpace);
1001 ReturnComNotImplemented();
1002}
1003
1004HRESULT SystemProperties::setFreeDiskSpaceWarning(LONG64 /* aFreeSpace */)
1005{
1006 ReturnComNotImplemented();
1007}
1008
1009HRESULT SystemProperties::getFreeDiskSpacePercentWarning(ULONG *aFreeSpacePercent)
1010{
1011 NOREF(aFreeSpacePercent);
1012 ReturnComNotImplemented();
1013}
1014
1015HRESULT SystemProperties::setFreeDiskSpacePercentWarning(ULONG /* aFreeSpacePercent */)
1016{
1017 ReturnComNotImplemented();
1018}
1019
1020HRESULT SystemProperties::getFreeDiskSpaceError(LONG64 *aFreeSpace)
1021{
1022 NOREF(aFreeSpace);
1023 ReturnComNotImplemented();
1024}
1025
1026HRESULT SystemProperties::setFreeDiskSpaceError(LONG64 /* aFreeSpace */)
1027{
1028 ReturnComNotImplemented();
1029}
1030
1031HRESULT SystemProperties::getFreeDiskSpacePercentError(ULONG *aFreeSpacePercent)
1032{
1033 NOREF(aFreeSpacePercent);
1034 ReturnComNotImplemented();
1035}
1036
1037HRESULT SystemProperties::setFreeDiskSpacePercentError(ULONG /* aFreeSpacePercent */)
1038{
1039 ReturnComNotImplemented();
1040}
1041
1042HRESULT SystemProperties::getVRDEAuthLibrary(com::Utf8Str &aVRDEAuthLibrary)
1043{
1044 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1045
1046 aVRDEAuthLibrary = m->strVRDEAuthLibrary;
1047
1048 return S_OK;
1049}
1050
1051HRESULT SystemProperties::setVRDEAuthLibrary(const com::Utf8Str &aVRDEAuthLibrary)
1052{
1053 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1054 HRESULT rc = i_setVRDEAuthLibrary(aVRDEAuthLibrary);
1055 alock.release();
1056 if (SUCCEEDED(rc))
1057 {
1058 // VirtualBox::i_saveSettings() needs vbox write lock
1059 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1060 rc = mParent->i_saveSettings();
1061 }
1062
1063 return rc;
1064}
1065
1066HRESULT SystemProperties::getWebServiceAuthLibrary(com::Utf8Str &aWebServiceAuthLibrary)
1067{
1068 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1069
1070 aWebServiceAuthLibrary = m->strWebServiceAuthLibrary;
1071
1072 return S_OK;
1073}
1074
1075HRESULT SystemProperties::setWebServiceAuthLibrary(const com::Utf8Str &aWebServiceAuthLibrary)
1076{
1077 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1078 HRESULT rc = i_setWebServiceAuthLibrary(aWebServiceAuthLibrary);
1079 alock.release();
1080
1081 if (SUCCEEDED(rc))
1082 {
1083 // VirtualBox::i_saveSettings() needs vbox write lock
1084 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1085 rc = mParent->i_saveSettings();
1086 }
1087
1088 return rc;
1089}
1090
1091HRESULT SystemProperties::getDefaultVRDEExtPack(com::Utf8Str &aExtPack)
1092{
1093 HRESULT hrc = S_OK;
1094 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1095 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
1096 if (strExtPack.isNotEmpty())
1097 {
1098 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
1099 hrc = S_OK;
1100 else
1101#ifdef VBOX_WITH_EXTPACK
1102 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&strExtPack);
1103#else
1104 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
1105#endif
1106 }
1107 else
1108 {
1109#ifdef VBOX_WITH_EXTPACK
1110 hrc = mParent->i_getExtPackManager()->i_getDefaultVrdeExtPack(&strExtPack);
1111#endif
1112 if (strExtPack.isEmpty())
1113 {
1114 /*
1115 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
1116 * This is hardcoded uglyness, sorry.
1117 */
1118 char szPath[RTPATH_MAX];
1119 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
1120 if (RT_SUCCESS(vrc))
1121 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
1122 if (RT_SUCCESS(vrc))
1123 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
1124 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
1125 {
1126 /* Illegal extpack name, so no conflict. */
1127 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
1128 }
1129 }
1130 }
1131
1132 if (SUCCEEDED(hrc))
1133 aExtPack = strExtPack;
1134
1135 return S_OK;
1136}
1137
1138
1139HRESULT SystemProperties::setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
1140{
1141 HRESULT hrc = S_OK;
1142 if (aExtPack.isNotEmpty())
1143 {
1144 if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
1145 hrc = S_OK;
1146 else
1147#ifdef VBOX_WITH_EXTPACK
1148 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&aExtPack);
1149#else
1150 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
1151#endif
1152 }
1153 if (SUCCEEDED(hrc))
1154 {
1155 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1156 hrc = i_setDefaultVRDEExtPack(aExtPack);
1157 if (SUCCEEDED(hrc))
1158 {
1159 /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
1160 alock.release();
1161 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1162 hrc = mParent->i_saveSettings();
1163 }
1164 }
1165
1166 return hrc;
1167}
1168
1169
1170HRESULT SystemProperties::getDefaultCryptoExtPack(com::Utf8Str &aExtPack)
1171{
1172 HRESULT hrc = S_OK;
1173 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1174 Utf8Str strExtPack(m->strDefaultCryptoExtPack);
1175 if (strExtPack.isNotEmpty())
1176 {
1177 if (strExtPack.equals(VBOXPUELCRYPTO_KLUDGE_EXTPACK_NAME))
1178 hrc = S_OK;
1179 else
1180#ifdef VBOX_WITH_EXTPACK
1181 hrc = mParent->i_getExtPackManager()->i_checkCryptoExtPack(&strExtPack);
1182#else
1183 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
1184#endif
1185 }
1186 else
1187 {
1188#ifdef VBOX_WITH_EXTPACK
1189 hrc = mParent->i_getExtPackManager()->i_getDefaultCryptoExtPack(&strExtPack);
1190#endif
1191 if (strExtPack.isEmpty())
1192 {
1193 /*
1194 * Klugde - check if VBoxPuelCrypto.dll/.so/.dylib is installed.
1195 * This is hardcoded uglyness, sorry.
1196 */
1197 char szPath[RTPATH_MAX];
1198 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
1199 if (RT_SUCCESS(vrc))
1200 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxPuelCrypto");
1201 if (RT_SUCCESS(vrc))
1202 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
1203 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
1204 {
1205 /* Illegal extpack name, so no conflict. */
1206 strExtPack = VBOXPUELCRYPTO_KLUDGE_EXTPACK_NAME;
1207 }
1208 }
1209 }
1210
1211 if (SUCCEEDED(hrc))
1212 aExtPack = strExtPack;
1213
1214 return S_OK;
1215}
1216
1217
1218HRESULT SystemProperties::setDefaultCryptoExtPack(const com::Utf8Str &aExtPack)
1219{
1220 HRESULT hrc = S_OK;
1221 if (aExtPack.isNotEmpty())
1222 {
1223 if (aExtPack.equals(VBOXPUELCRYPTO_KLUDGE_EXTPACK_NAME))
1224 hrc = S_OK;
1225 else
1226#ifdef VBOX_WITH_EXTPACK
1227 hrc = mParent->i_getExtPackManager()->i_checkCryptoExtPack(&aExtPack);
1228#else
1229 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
1230#endif
1231 }
1232 if (SUCCEEDED(hrc))
1233 {
1234 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1235 hrc = i_setDefaultCryptoExtPack(aExtPack);
1236 if (SUCCEEDED(hrc))
1237 {
1238 /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
1239 alock.release();
1240 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1241 hrc = mParent->i_saveSettings();
1242 }
1243 }
1244
1245 return hrc;
1246}
1247
1248
1249HRESULT SystemProperties::getLogHistoryCount(ULONG *count)
1250{
1251 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1252
1253 *count = m->uLogHistoryCount;
1254
1255 return S_OK;
1256}
1257
1258
1259HRESULT SystemProperties::setLogHistoryCount(ULONG count)
1260{
1261 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1262 m->uLogHistoryCount = count;
1263 alock.release();
1264
1265 // VirtualBox::i_saveSettings() needs vbox write lock
1266 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1267 HRESULT rc = mParent->i_saveSettings();
1268
1269 return rc;
1270}
1271
1272HRESULT SystemProperties::getDefaultAudioDriver(AudioDriverType_T *aAudioDriver)
1273{
1274 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1275
1276 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
1277
1278 return S_OK;
1279}
1280
1281HRESULT SystemProperties::getAutostartDatabasePath(com::Utf8Str &aAutostartDbPath)
1282{
1283 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1284
1285 aAutostartDbPath = m->strAutostartDatabasePath;
1286
1287 return S_OK;
1288}
1289
1290HRESULT SystemProperties::setAutostartDatabasePath(const com::Utf8Str &aAutostartDbPath)
1291{
1292 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1293 HRESULT rc = i_setAutostartDatabasePath(aAutostartDbPath);
1294 alock.release();
1295
1296 if (SUCCEEDED(rc))
1297 {
1298 // VirtualBox::i_saveSettings() needs vbox write lock
1299 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1300 rc = mParent->i_saveSettings();
1301 }
1302
1303 return rc;
1304}
1305
1306HRESULT SystemProperties::getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
1307{
1308 return i_getDefaultAdditionsISO(aDefaultAdditionsISO);
1309}
1310
1311HRESULT SystemProperties::setDefaultAdditionsISO(const com::Utf8Str &aDefaultAdditionsISO)
1312{
1313 RT_NOREF(aDefaultAdditionsISO);
1314 /** @todo not yet implemented, settings handling is missing */
1315 ReturnComNotImplemented();
1316#if 0 /* not implemented */
1317 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1318 HRESULT rc = i_setDefaultAdditionsISO(aDefaultAdditionsISO);
1319 alock.release();
1320
1321 if (SUCCEEDED(rc))
1322 {
1323 // VirtualBox::i_saveSettings() needs vbox write lock
1324 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1325 rc = mParent->i_saveSettings();
1326 }
1327
1328 return rc;
1329#endif
1330}
1331
1332HRESULT SystemProperties::getDefaultFrontend(com::Utf8Str &aDefaultFrontend)
1333{
1334 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1335 aDefaultFrontend = m->strDefaultFrontend;
1336 return S_OK;
1337}
1338
1339HRESULT SystemProperties::setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
1340{
1341 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1342 if (m->strDefaultFrontend == aDefaultFrontend)
1343 return S_OK;
1344 HRESULT rc = i_setDefaultFrontend(aDefaultFrontend);
1345 alock.release();
1346
1347 if (SUCCEEDED(rc))
1348 {
1349 // VirtualBox::i_saveSettings() needs vbox write lock
1350 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
1351 rc = mParent->i_saveSettings();
1352 }
1353
1354 return rc;
1355}
1356
1357HRESULT SystemProperties::getScreenShotFormats(std::vector<BitmapFormat_T> &aBitmapFormats)
1358{
1359 aBitmapFormats.push_back(BitmapFormat_BGR0);
1360 aBitmapFormats.push_back(BitmapFormat_BGRA);
1361 aBitmapFormats.push_back(BitmapFormat_RGBA);
1362 aBitmapFormats.push_back(BitmapFormat_PNG);
1363 return S_OK;
1364}
1365
1366HRESULT SystemProperties::getProxyMode(ProxyMode_T *pProxyMode)
1367{
1368 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1369 ProxyMode_T enmMode = *pProxyMode = (ProxyMode_T)m->uProxyMode;
1370 AssertMsgReturn(enmMode == ProxyMode_System || enmMode == ProxyMode_NoProxy || enmMode == ProxyMode_Manual,
1371 ("enmMode=%d\n", enmMode), E_UNEXPECTED);
1372 return S_OK;
1373}
1374
1375HRESULT SystemProperties::setProxyMode(ProxyMode_T aProxyMode)
1376{
1377 /* Validate input. */
1378 switch (aProxyMode)
1379 {
1380 case ProxyMode_System:
1381 case ProxyMode_NoProxy:
1382 case ProxyMode_Manual:
1383 break;
1384 default:
1385 return setError(E_INVALIDARG, tr("Invalid ProxyMode value: %d"), (int)aProxyMode);
1386 }
1387
1388 /* Set and write out settings. */
1389 {
1390 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1391 m->uProxyMode = aProxyMode;
1392 }
1393 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */
1394 return mParent->i_saveSettings();
1395}
1396
1397HRESULT SystemProperties::getProxyURL(com::Utf8Str &aProxyURL)
1398{
1399 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1400 aProxyURL = m->strProxyUrl;
1401 return S_OK;
1402}
1403
1404HRESULT SystemProperties::setProxyURL(const com::Utf8Str &aProxyURL)
1405{
1406 /*
1407 * Validate input.
1408 */
1409 Utf8Str const *pStrProxyUrl = &aProxyURL;
1410 Utf8Str strTmp;
1411 if (pStrProxyUrl->isNotEmpty())
1412 {
1413 /* RTUriParse requires a scheme, so append 'http://' if none seems present: */
1414 if (pStrProxyUrl->find("://") == RTCString::npos)
1415 {
1416 strTmp.printf("http://%s", aProxyURL.c_str());
1417 pStrProxyUrl = &strTmp;
1418 }
1419
1420 /* Use RTUriParse to check the format. There must be a hostname, but nothing
1421 can follow it and the port. */
1422 RTURIPARSED Parsed;
1423 int vrc = RTUriParse(pStrProxyUrl->c_str(), &Parsed);
1424 if (RT_FAILURE(vrc))
1425 return setErrorBoth(E_INVALIDARG, vrc, tr("Failed to parse proxy URL: %Rrc"), vrc);
1426 if ( Parsed.cchAuthorityHost == 0
1427 && !RTUriIsSchemeMatch(pStrProxyUrl->c_str(), "direct"))
1428 return setError(E_INVALIDARG, tr("Proxy URL must include a hostname"));
1429 if (Parsed.cchPath > 0)
1430 return setError(E_INVALIDARG, tr("Proxy URL must not include a path component (%.*s)"),
1431 Parsed.cchPath, pStrProxyUrl->c_str() + Parsed.offPath);
1432 if (Parsed.cchQuery > 0)
1433 return setError(E_INVALIDARG, tr("Proxy URL must not include a query component (?%.*s)"),
1434 Parsed.cchQuery, pStrProxyUrl->c_str() + Parsed.offQuery);
1435 if (Parsed.cchFragment > 0)
1436 return setError(E_INVALIDARG, tr("Proxy URL must not include a fragment component (#%.*s)"),
1437 Parsed.cchFragment, pStrProxyUrl->c_str() + Parsed.offFragment);
1438 }
1439
1440 /*
1441 * Set and write out settings.
1442 */
1443 {
1444 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1445 m->strProxyUrl = *pStrProxyUrl;
1446 }
1447 AutoWriteLock alock(mParent COMMA_LOCKVAL_SRC_POS); /* required for saving. */
1448 return mParent->i_saveSettings();
1449}
1450
1451HRESULT SystemProperties::getSupportedParavirtProviders(std::vector<ParavirtProvider_T> &aSupportedParavirtProviders)
1452{
1453 static const ParavirtProvider_T aParavirtProviders[] =
1454 {
1455 ParavirtProvider_None,
1456 ParavirtProvider_Default,
1457 ParavirtProvider_Legacy,
1458 ParavirtProvider_Minimal,
1459 ParavirtProvider_HyperV,
1460 ParavirtProvider_KVM,
1461 };
1462 aSupportedParavirtProviders.assign(aParavirtProviders,
1463 aParavirtProviders + RT_ELEMENTS(aParavirtProviders));
1464 return S_OK;
1465}
1466
1467HRESULT SystemProperties::getSupportedClipboardModes(std::vector<ClipboardMode_T> &aSupportedClipboardModes)
1468{
1469 static const ClipboardMode_T aClipboardModes[] =
1470 {
1471 ClipboardMode_Disabled,
1472 ClipboardMode_HostToGuest,
1473 ClipboardMode_GuestToHost,
1474 ClipboardMode_Bidirectional,
1475 };
1476 aSupportedClipboardModes.assign(aClipboardModes,
1477 aClipboardModes + RT_ELEMENTS(aClipboardModes));
1478 return S_OK;
1479}
1480
1481HRESULT SystemProperties::getSupportedDnDModes(std::vector<DnDMode_T> &aSupportedDnDModes)
1482{
1483 static const DnDMode_T aDnDModes[] =
1484 {
1485 DnDMode_Disabled,
1486 DnDMode_HostToGuest,
1487 DnDMode_GuestToHost,
1488 DnDMode_Bidirectional,
1489 };
1490 aSupportedDnDModes.assign(aDnDModes,
1491 aDnDModes + RT_ELEMENTS(aDnDModes));
1492 return S_OK;
1493}
1494
1495HRESULT SystemProperties::getSupportedFirmwareTypes(std::vector<FirmwareType_T> &aSupportedFirmwareTypes)
1496{
1497 static const FirmwareType_T aFirmwareTypes[] =
1498 {
1499 FirmwareType_BIOS,
1500 FirmwareType_EFI,
1501 FirmwareType_EFI32,
1502 FirmwareType_EFI64,
1503 FirmwareType_EFIDUAL,
1504 };
1505 aSupportedFirmwareTypes.assign(aFirmwareTypes,
1506 aFirmwareTypes + RT_ELEMENTS(aFirmwareTypes));
1507 return S_OK;
1508}
1509
1510HRESULT SystemProperties::getSupportedPointingHIDTypes(std::vector<PointingHIDType_T> &aSupportedPointingHIDTypes)
1511{
1512 static const PointingHIDType_T aPointingHIDTypes[] =
1513 {
1514 PointingHIDType_PS2Mouse,
1515#ifdef DEBUG
1516 PointingHIDType_USBMouse,
1517#endif
1518 PointingHIDType_USBTablet,
1519#ifdef DEBUG
1520 PointingHIDType_ComboMouse,
1521#endif
1522 PointingHIDType_USBMultiTouch,
1523 PointingHIDType_USBMultiTouchScreenPlusPad,
1524 };
1525 aSupportedPointingHIDTypes.assign(aPointingHIDTypes,
1526 aPointingHIDTypes + RT_ELEMENTS(aPointingHIDTypes));
1527 return S_OK;
1528}
1529
1530HRESULT SystemProperties::getSupportedKeyboardHIDTypes(std::vector<KeyboardHIDType_T> &aSupportedKeyboardHIDTypes)
1531{
1532 static const KeyboardHIDType_T aKeyboardHIDTypes[] =
1533 {
1534 KeyboardHIDType_PS2Keyboard,
1535 KeyboardHIDType_USBKeyboard,
1536#ifdef DEBUG
1537 KeyboardHIDType_ComboKeyboard,
1538#endif
1539 };
1540 aSupportedKeyboardHIDTypes.assign(aKeyboardHIDTypes,
1541 aKeyboardHIDTypes + RT_ELEMENTS(aKeyboardHIDTypes));
1542 return S_OK;
1543}
1544
1545HRESULT SystemProperties::getSupportedVFSTypes(std::vector<VFSType_T> &aSupportedVFSTypes)
1546{
1547 static const VFSType_T aVFSTypes[] =
1548 {
1549 VFSType_File,
1550 VFSType_Cloud,
1551 VFSType_S3,
1552#ifdef DEBUG
1553 VFSType_WebDav,
1554#endif
1555 };
1556 aSupportedVFSTypes.assign(aVFSTypes,
1557 aVFSTypes + RT_ELEMENTS(aVFSTypes));
1558 return S_OK;
1559}
1560
1561HRESULT SystemProperties::getSupportedImportOptions(std::vector<ImportOptions_T> &aSupportedImportOptions)
1562{
1563 static const ImportOptions_T aImportOptions[] =
1564 {
1565 ImportOptions_KeepAllMACs,
1566 ImportOptions_KeepNATMACs,
1567 ImportOptions_ImportToVDI,
1568 };
1569 aSupportedImportOptions.assign(aImportOptions,
1570 aImportOptions + RT_ELEMENTS(aImportOptions));
1571 return S_OK;
1572}
1573
1574HRESULT SystemProperties::getSupportedExportOptions(std::vector<ExportOptions_T> &aSupportedExportOptions)
1575{
1576 static const ExportOptions_T aExportOptions[] =
1577 {
1578 ExportOptions_CreateManifest,
1579 ExportOptions_ExportDVDImages,
1580 ExportOptions_StripAllMACs,
1581 ExportOptions_StripAllNonNATMACs,
1582 };
1583 aSupportedExportOptions.assign(aExportOptions,
1584 aExportOptions + RT_ELEMENTS(aExportOptions));
1585 return S_OK;
1586}
1587
1588HRESULT SystemProperties::getSupportedRecordingFeatures(std::vector<RecordingFeature_T> &aSupportedRecordingFeatures)
1589{
1590#ifdef VBOX_WITH_RECORDING
1591 static const RecordingFeature_T aRecordingFeatures[] =
1592 {
1593# ifdef VBOX_WITH_AUDIO_RECORDING
1594 RecordingFeature_Audio,
1595# endif
1596 RecordingFeature_Video,
1597 };
1598 aSupportedRecordingFeatures.assign(aRecordingFeatures,
1599 aRecordingFeatures + RT_ELEMENTS(aRecordingFeatures));
1600#else /* !VBOX_WITH_RECORDING */
1601 aSupportedRecordingFeatures.clear();
1602#endif /* VBOX_WITH_RECORDING */
1603 return S_OK;
1604}
1605
1606HRESULT SystemProperties::getSupportedRecordingAudioCodecs(std::vector<RecordingAudioCodec_T> &aSupportedRecordingAudioCodecs)
1607{
1608 static const RecordingAudioCodec_T aRecordingAudioCodecs[] =
1609 {
1610 RecordingAudioCodec_None,
1611#ifdef DEBUG
1612 RecordingAudioCodec_WavPCM,
1613#endif
1614#ifdef VBOX_WITH_LIBVORBIS
1615 RecordingAudioCodec_OggVorbis,
1616#endif
1617 };
1618 aSupportedRecordingAudioCodecs.assign(aRecordingAudioCodecs,
1619 aRecordingAudioCodecs + RT_ELEMENTS(aRecordingAudioCodecs));
1620 return S_OK;
1621}
1622
1623HRESULT SystemProperties::getSupportedRecordingVideoCodecs(std::vector<RecordingVideoCodec_T> &aSupportedRecordingVideoCodecs)
1624{
1625 static const RecordingVideoCodec_T aRecordingVideoCodecs[] =
1626 {
1627 RecordingVideoCodec_None,
1628#ifdef VBOX_WITH_LIBVPX
1629 RecordingVideoCodec_VP8,
1630#endif
1631#ifdef DEBUG
1632 RecordingVideoCodec_VP9,
1633 RecordingVideoCodec_AV1,
1634#endif
1635 };
1636 aSupportedRecordingVideoCodecs.assign(aRecordingVideoCodecs,
1637 aRecordingVideoCodecs + RT_ELEMENTS(aRecordingVideoCodecs));
1638 return S_OK;
1639}
1640
1641HRESULT SystemProperties::getSupportedRecordingVSModes(std::vector<RecordingVideoScalingMode_T> &aSupportedRecordingVideoScalingModes)
1642{
1643 static const RecordingVideoScalingMode_T aRecordingVideoScalingModes[] =
1644 {
1645 RecordingVideoScalingMode_None,
1646#ifdef DEBUG
1647 RecordingVideoScalingMode_NearestNeighbor,
1648 RecordingVideoScalingMode_Bilinear,
1649 RecordingVideoScalingMode_Bicubic,
1650#endif
1651 };
1652 aSupportedRecordingVideoScalingModes.assign(aRecordingVideoScalingModes,
1653 aRecordingVideoScalingModes + RT_ELEMENTS(aRecordingVideoScalingModes));
1654 return S_OK;
1655}
1656
1657HRESULT SystemProperties::getSupportedRecordingARCModes(std::vector<RecordingRateControlMode_T> &aSupportedRecordingAudioRateControlModes)
1658{
1659 static const RecordingRateControlMode_T aRecordingAudioRateControlModes[] =
1660 {
1661#ifdef DEBUG
1662 RecordingRateControlMode_ABR,
1663 RecordingRateControlMode_CBR,
1664#endif
1665 RecordingRateControlMode_VBR
1666 };
1667 aSupportedRecordingAudioRateControlModes.assign(aRecordingAudioRateControlModes,
1668 aRecordingAudioRateControlModes + RT_ELEMENTS(aRecordingAudioRateControlModes));
1669 return S_OK;
1670}
1671
1672HRESULT SystemProperties::getSupportedRecordingVRCModes(std::vector<RecordingRateControlMode_T> &aSupportedRecordingVideoRateControlModes)
1673{
1674 static const RecordingRateControlMode_T aRecordingVideoRateControlModes[] =
1675 {
1676#ifdef DEBUG
1677 RecordingRateControlMode_ABR,
1678 RecordingRateControlMode_CBR,
1679#endif
1680 RecordingRateControlMode_VBR
1681 };
1682 aSupportedRecordingVideoRateControlModes.assign(aRecordingVideoRateControlModes,
1683 aRecordingVideoRateControlModes + RT_ELEMENTS(aRecordingVideoRateControlModes));
1684 return S_OK;
1685}
1686
1687HRESULT SystemProperties::getSupportedGraphicsControllerTypes(std::vector<GraphicsControllerType_T> &aSupportedGraphicsControllerTypes)
1688{
1689 static const GraphicsControllerType_T aGraphicsControllerTypes[] =
1690 {
1691 GraphicsControllerType_VBoxVGA,
1692 GraphicsControllerType_VMSVGA,
1693 GraphicsControllerType_VBoxSVGA,
1694 GraphicsControllerType_Null,
1695 };
1696 aSupportedGraphicsControllerTypes.assign(aGraphicsControllerTypes,
1697 aGraphicsControllerTypes + RT_ELEMENTS(aGraphicsControllerTypes));
1698 return S_OK;
1699}
1700
1701HRESULT SystemProperties::getSupportedCloneOptions(std::vector<CloneOptions_T> &aSupportedCloneOptions)
1702{
1703 static const CloneOptions_T aCloneOptions[] =
1704 {
1705 CloneOptions_Link,
1706 CloneOptions_KeepAllMACs,
1707 CloneOptions_KeepNATMACs,
1708 CloneOptions_KeepDiskNames,
1709 CloneOptions_KeepHwUUIDs,
1710 };
1711 aSupportedCloneOptions.assign(aCloneOptions,
1712 aCloneOptions + RT_ELEMENTS(aCloneOptions));
1713 return S_OK;
1714}
1715
1716HRESULT SystemProperties::getSupportedAutostopTypes(std::vector<AutostopType_T> &aSupportedAutostopTypes)
1717{
1718 static const AutostopType_T aAutostopTypes[] =
1719 {
1720 AutostopType_Disabled,
1721 AutostopType_SaveState,
1722 AutostopType_PowerOff,
1723 AutostopType_AcpiShutdown,
1724 };
1725 aSupportedAutostopTypes.assign(aAutostopTypes,
1726 aAutostopTypes + RT_ELEMENTS(aAutostopTypes));
1727 return S_OK;
1728}
1729
1730HRESULT SystemProperties::getSupportedVMProcPriorities(std::vector<VMProcPriority_T> &aSupportedVMProcPriorities)
1731{
1732 static const VMProcPriority_T aVMProcPriorities[] =
1733 {
1734 VMProcPriority_Default,
1735 VMProcPriority_Flat,
1736 VMProcPriority_Low,
1737 VMProcPriority_Normal,
1738 VMProcPriority_High,
1739 };
1740 aSupportedVMProcPriorities.assign(aVMProcPriorities,
1741 aVMProcPriorities + RT_ELEMENTS(aVMProcPriorities));
1742 return S_OK;
1743}
1744
1745HRESULT SystemProperties::getSupportedNetworkAttachmentTypes(std::vector<NetworkAttachmentType_T> &aSupportedNetworkAttachmentTypes)
1746{
1747 static const NetworkAttachmentType_T aNetworkAttachmentTypes[] =
1748 {
1749 NetworkAttachmentType_NAT,
1750 NetworkAttachmentType_Bridged,
1751 NetworkAttachmentType_Internal,
1752 NetworkAttachmentType_HostOnly,
1753#ifdef VBOX_WITH_VMNET
1754 NetworkAttachmentType_HostOnlyNetwork,
1755#endif /* VBOX_WITH_VMNET */
1756 NetworkAttachmentType_Generic,
1757 NetworkAttachmentType_NATNetwork,
1758#ifdef VBOX_WITH_CLOUD_NET
1759 NetworkAttachmentType_Cloud,
1760#endif
1761 NetworkAttachmentType_Null,
1762 };
1763 aSupportedNetworkAttachmentTypes.assign(aNetworkAttachmentTypes,
1764 aNetworkAttachmentTypes + RT_ELEMENTS(aNetworkAttachmentTypes));
1765 return S_OK;
1766}
1767
1768HRESULT SystemProperties::getSupportedNetworkAdapterTypes(std::vector<NetworkAdapterType_T> &aSupportedNetworkAdapterTypes)
1769{
1770 static const NetworkAdapterType_T aNetworkAdapterTypes[] =
1771 {
1772 NetworkAdapterType_Am79C970A,
1773 NetworkAdapterType_Am79C973,
1774 NetworkAdapterType_I82540EM,
1775 NetworkAdapterType_I82543GC,
1776 NetworkAdapterType_I82545EM,
1777 NetworkAdapterType_Virtio,
1778 };
1779 aSupportedNetworkAdapterTypes.assign(aNetworkAdapterTypes,
1780 aNetworkAdapterTypes + RT_ELEMENTS(aNetworkAdapterTypes));
1781 return S_OK;
1782}
1783
1784HRESULT SystemProperties::getSupportedPortModes(std::vector<PortMode_T> &aSupportedPortModes)
1785{
1786 static const PortMode_T aPortModes[] =
1787 {
1788 PortMode_Disconnected,
1789 PortMode_HostPipe,
1790 PortMode_HostDevice,
1791 PortMode_RawFile,
1792 PortMode_TCP,
1793 };
1794 aSupportedPortModes.assign(aPortModes,
1795 aPortModes + RT_ELEMENTS(aPortModes));
1796 return S_OK;
1797}
1798
1799HRESULT SystemProperties::getSupportedUartTypes(std::vector<UartType_T> &aSupportedUartTypes)
1800{
1801 static const UartType_T aUartTypes[] =
1802 {
1803 UartType_U16450,
1804 UartType_U16550A,
1805 UartType_U16750,
1806 };
1807 aSupportedUartTypes.assign(aUartTypes,
1808 aUartTypes + RT_ELEMENTS(aUartTypes));
1809 return S_OK;
1810}
1811
1812HRESULT SystemProperties::getSupportedUSBControllerTypes(std::vector<USBControllerType_T> &aSupportedUSBControllerTypes)
1813{
1814 static const USBControllerType_T aUSBControllerTypesWithoutExtPack[] =
1815 {
1816 USBControllerType_OHCI,
1817 };
1818 static const USBControllerType_T aUSBControllerTypesWithExtPack[] =
1819 {
1820 USBControllerType_OHCI,
1821 USBControllerType_EHCI,
1822 USBControllerType_XHCI,
1823 };
1824 bool fExtPack = false;
1825# ifdef VBOX_WITH_EXTPACK
1826 static const char *s_pszUsbExtPackName = "Oracle VM VirtualBox Extension Pack";
1827 if (mParent->i_getExtPackManager()->i_isExtPackUsable(s_pszUsbExtPackName))
1828# endif
1829 {
1830 fExtPack = true;
1831 }
1832
1833 if (fExtPack)
1834 aSupportedUSBControllerTypes.assign(aUSBControllerTypesWithExtPack,
1835 aUSBControllerTypesWithExtPack + RT_ELEMENTS(aUSBControllerTypesWithExtPack));
1836 else
1837 aSupportedUSBControllerTypes.assign(aUSBControllerTypesWithoutExtPack,
1838 aUSBControllerTypesWithoutExtPack + RT_ELEMENTS(aUSBControllerTypesWithoutExtPack));
1839 return S_OK;
1840}
1841
1842HRESULT SystemProperties::getSupportedAudioDriverTypes(std::vector<AudioDriverType_T> &aSupportedAudioDriverTypes)
1843{
1844 static const AudioDriverType_T aAudioDriverTypes[] =
1845 {
1846 AudioDriverType_Default,
1847#ifdef RT_OS_WINDOWS
1848# if 0 /* deprecated for many years now */
1849 AudioDriverType_WinMM,
1850# endif
1851 AudioDriverType_WAS,
1852 AudioDriverType_DirectSound,
1853#endif
1854#ifdef RT_OS_DARWIN
1855 AudioDriverType_CoreAudio,
1856#endif
1857#ifdef RT_OS_OS2
1858 AudioDriverType_MMPM,
1859#endif
1860#ifdef RT_OS_SOLARIS
1861# if 0 /* deprecated for many years now */
1862 AudioDriverType_SolAudio,
1863# endif
1864#endif
1865#ifdef VBOX_WITH_AUDIO_ALSA
1866 AudioDriverType_ALSA,
1867#endif
1868#ifdef VBOX_WITH_AUDIO_OSS
1869 AudioDriverType_OSS,
1870#endif
1871#ifdef VBOX_WITH_AUDIO_PULSE
1872 AudioDriverType_Pulse,
1873#endif
1874 AudioDriverType_Null,
1875 };
1876 aSupportedAudioDriverTypes.assign(aAudioDriverTypes,
1877 aAudioDriverTypes + RT_ELEMENTS(aAudioDriverTypes));
1878 return S_OK;
1879}
1880
1881HRESULT SystemProperties::getSupportedAudioControllerTypes(std::vector<AudioControllerType_T> &aSupportedAudioControllerTypes)
1882{
1883 static const AudioControllerType_T aAudioControllerTypes[] =
1884 {
1885 AudioControllerType_AC97,
1886 AudioControllerType_SB16,
1887 AudioControllerType_HDA,
1888 };
1889 aSupportedAudioControllerTypes.assign(aAudioControllerTypes,
1890 aAudioControllerTypes + RT_ELEMENTS(aAudioControllerTypes));
1891 return S_OK;
1892}
1893
1894HRESULT SystemProperties::getSupportedStorageBuses(std::vector<StorageBus_T> &aSupportedStorageBuses)
1895{
1896 static const StorageBus_T aStorageBuses[] =
1897 {
1898 StorageBus_SATA,
1899 StorageBus_IDE,
1900 StorageBus_SCSI,
1901 StorageBus_Floppy,
1902 StorageBus_SAS,
1903 StorageBus_USB,
1904 StorageBus_PCIe,
1905 StorageBus_VirtioSCSI,
1906 };
1907 aSupportedStorageBuses.assign(aStorageBuses,
1908 aStorageBuses + RT_ELEMENTS(aStorageBuses));
1909 return S_OK;
1910}
1911
1912HRESULT SystemProperties::getSupportedStorageControllerTypes(std::vector<StorageControllerType_T> &aSupportedStorageControllerTypes)
1913{
1914 static const StorageControllerType_T aStorageControllerTypes[] =
1915 {
1916 StorageControllerType_IntelAhci,
1917 StorageControllerType_PIIX4,
1918 StorageControllerType_PIIX3,
1919 StorageControllerType_ICH6,
1920 StorageControllerType_LsiLogic,
1921 StorageControllerType_BusLogic,
1922 StorageControllerType_I82078,
1923 StorageControllerType_LsiLogicSas,
1924 StorageControllerType_USB,
1925 StorageControllerType_NVMe,
1926 StorageControllerType_VirtioSCSI,
1927 };
1928 aSupportedStorageControllerTypes.assign(aStorageControllerTypes,
1929 aStorageControllerTypes + RT_ELEMENTS(aStorageControllerTypes));
1930 return S_OK;
1931}
1932
1933HRESULT SystemProperties::getSupportedChipsetTypes(std::vector<ChipsetType_T> &aSupportedChipsetTypes)
1934{
1935 static const ChipsetType_T aChipsetTypes[] =
1936 {
1937 ChipsetType_PIIX3,
1938 ChipsetType_ICH9,
1939 };
1940 aSupportedChipsetTypes.assign(aChipsetTypes,
1941 aChipsetTypes + RT_ELEMENTS(aChipsetTypes));
1942 return S_OK;
1943}
1944
1945HRESULT SystemProperties::getSupportedIommuTypes(std::vector<IommuType_T> &aSupportedIommuTypes)
1946{
1947 static const IommuType_T aIommuTypes[] =
1948 {
1949 IommuType_None,
1950 IommuType_Automatic,
1951 IommuType_AMD,
1952 /** @todo Add Intel when it's supported. */
1953 };
1954 aSupportedIommuTypes.assign(aIommuTypes,
1955 aIommuTypes + RT_ELEMENTS(aIommuTypes));
1956 return S_OK;
1957}
1958
1959
1960// public methods only for internal purposes
1961/////////////////////////////////////////////////////////////////////////////
1962
1963HRESULT SystemProperties::i_loadSettings(const settings::SystemProperties &data)
1964{
1965 AutoCaller autoCaller(this);
1966 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1967
1968 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1969 HRESULT rc = S_OK;
1970 rc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
1971 if (FAILED(rc)) return rc;
1972
1973 rc = i_setLoggingLevel(data.strLoggingLevel);
1974 if (FAILED(rc)) return rc;
1975
1976 rc = i_setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
1977 if (FAILED(rc)) return rc;
1978
1979 rc = i_setVRDEAuthLibrary(data.strVRDEAuthLibrary);
1980 if (FAILED(rc)) return rc;
1981
1982 rc = i_setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
1983 if (FAILED(rc)) return rc;
1984
1985 rc = i_setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
1986 if (FAILED(rc)) return rc;
1987
1988 rc = i_setDefaultCryptoExtPack(data.strDefaultCryptoExtPack);
1989 if (FAILED(rc)) return rc;
1990
1991 m->uLogHistoryCount = data.uLogHistoryCount;
1992 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
1993 m->uProxyMode = data.uProxyMode;
1994 m->strProxyUrl = data.strProxyUrl;
1995
1996 m->strLanguageId = data.strLanguageId;
1997
1998 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
1999 if (FAILED(rc)) return rc;
2000
2001 {
2002 /* must ignore errors signalled here, because the guest additions
2003 * file may not exist, and in this case keep the empty string */
2004 ErrorInfoKeeper eik;
2005 (void)i_setDefaultAdditionsISO(data.strDefaultAdditionsISO);
2006 }
2007
2008 rc = i_setDefaultFrontend(data.strDefaultFrontend);
2009 if (FAILED(rc)) return rc;
2010
2011 return S_OK;
2012}
2013
2014HRESULT SystemProperties::i_saveSettings(settings::SystemProperties &data)
2015{
2016 AutoCaller autoCaller(this);
2017 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2018
2019 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2020
2021 data = *m;
2022
2023 return S_OK;
2024}
2025
2026/**
2027 * Returns a medium format object corresponding to the given format
2028 * identifier or null if no such format.
2029 *
2030 * @param aFormat Format identifier.
2031 *
2032 * @return ComObjPtr<MediumFormat>
2033 */
2034ComObjPtr<MediumFormat> SystemProperties::i_mediumFormat(const Utf8Str &aFormat)
2035{
2036 ComObjPtr<MediumFormat> format;
2037
2038 AutoCaller autoCaller(this);
2039 AssertComRCReturn (autoCaller.rc(), format);
2040
2041 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2042
2043 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
2044 it != m_llMediumFormats.end();
2045 ++ it)
2046 {
2047 /* MediumFormat is all const, no need to lock */
2048
2049 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
2050 {
2051 format = *it;
2052 break;
2053 }
2054 }
2055
2056 return format;
2057}
2058
2059/**
2060 * Returns a medium format object corresponding to the given file extension or
2061 * null if no such format.
2062 *
2063 * @param aExt File extension.
2064 *
2065 * @return ComObjPtr<MediumFormat>
2066 */
2067ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt)
2068{
2069 ComObjPtr<MediumFormat> format;
2070
2071 AutoCaller autoCaller(this);
2072 AssertComRCReturn (autoCaller.rc(), format);
2073
2074 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2075
2076 bool fFound = false;
2077 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
2078 it != m_llMediumFormats.end() && !fFound;
2079 ++it)
2080 {
2081 /* MediumFormat is all const, no need to lock */
2082 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
2083 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
2084 it1 != aFileList.end();
2085 ++it1)
2086 {
2087 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
2088 {
2089 format = *it;
2090 fFound = true;
2091 break;
2092 }
2093 }
2094 }
2095
2096 return format;
2097}
2098
2099
2100/**
2101 * VD plugin load
2102 */
2103int SystemProperties::i_loadVDPlugin(const char *pszPluginLibrary)
2104{
2105 int vrc = VDPluginLoadFromFilename(pszPluginLibrary);
2106 LogFlowFunc(("pszPluginLibrary='%s' -> %Rrc\n", pszPluginLibrary, vrc));
2107 return vrc;
2108}
2109
2110/**
2111 * VD plugin unload
2112 */
2113int SystemProperties::i_unloadVDPlugin(const char *pszPluginLibrary)
2114{
2115 int vrc = VDPluginUnloadFromFilename(pszPluginLibrary);
2116 LogFlowFunc(("pszPluginLibrary='%s' -> %Rrc\n", pszPluginLibrary, vrc));
2117 return vrc;
2118}
2119
2120/**
2121 * Internally usable version of getDefaultAdditionsISO.
2122 */
2123HRESULT SystemProperties::i_getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
2124{
2125 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2126 if (m->strDefaultAdditionsISO.isNotEmpty())
2127 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
2128 else
2129 {
2130 /* no guest additions, check if it showed up in the mean time */
2131 alock.release();
2132 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
2133 if (m->strDefaultAdditionsISO.isEmpty())
2134 {
2135 ErrorInfoKeeper eik;
2136 (void)i_setDefaultAdditionsISO("");
2137 }
2138 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
2139 }
2140 return S_OK;
2141}
2142
2143// private methods
2144/////////////////////////////////////////////////////////////////////////////
2145
2146/**
2147 * Returns the user's home directory. Wrapper around RTPathUserHome().
2148 * @param strPath
2149 * @return
2150 */
2151HRESULT SystemProperties::i_getUserHomeDirectory(Utf8Str &strPath)
2152{
2153 char szHome[RTPATH_MAX];
2154 int vrc = RTPathUserHome(szHome, sizeof(szHome));
2155 if (RT_FAILURE(vrc))
2156 return setErrorBoth(E_FAIL, vrc,
2157 tr("Cannot determine user home directory (%Rrc)"),
2158 vrc);
2159 strPath = szHome;
2160 return S_OK;
2161}
2162
2163/**
2164 * Internal implementation to set the default machine folder. Gets called
2165 * from the public attribute setter as well as loadSettings(). With 4.0,
2166 * the "default default" machine folder has changed, and we now require
2167 * a full path always.
2168 * @param strPath
2169 * @return
2170 */
2171HRESULT SystemProperties::i_setDefaultMachineFolder(const Utf8Str &strPath)
2172{
2173 Utf8Str path(strPath); // make modifiable
2174 if ( path.isEmpty() // used by API calls to reset the default
2175 || path == "Machines" // this value (exactly like this, without path) is stored
2176 // in VirtualBox.xml if user upgrades from before 4.0 and
2177 // has not changed the default machine folder
2178 )
2179 {
2180 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
2181 HRESULT rc = i_getUserHomeDirectory(path);
2182 if (FAILED(rc)) return rc;
2183 path += RTPATH_SLASH_STR "VirtualBox VMs";
2184 }
2185
2186 if (!RTPathStartsWithRoot(path.c_str()))
2187 return setError(E_INVALIDARG,
2188 tr("Given default machine folder '%s' is not fully qualified"),
2189 path.c_str());
2190
2191 m->strDefaultMachineFolder = path;
2192
2193 return S_OK;
2194}
2195
2196HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
2197{
2198 Utf8Str useLoggingLevel(aLoggingLevel);
2199 if (useLoggingLevel.isEmpty())
2200 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
2201 int rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), useLoggingLevel.c_str());
2202 // If failed and not the default logging level - try to use the default logging level.
2203 if (RT_FAILURE(rc))
2204 {
2205 // If failed write message to the release log.
2206 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
2207 // If attempted logging level not the default one then try the default one.
2208 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
2209 {
2210 rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), VBOXSVC_LOG_DEFAULT);
2211 // If failed report this to the release log.
2212 if (RT_FAILURE(rc))
2213 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
2214 }
2215 // On any failure - set default level as the one to be stored.
2216 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
2217 }
2218 // Set to passed value or if default used/attempted (even if error condition) use empty string.
2219 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
2220 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
2221}
2222
2223HRESULT SystemProperties::i_setDefaultHardDiskFormat(const com::Utf8Str &aFormat)
2224{
2225 if (!aFormat.isEmpty())
2226 m->strDefaultHardDiskFormat = aFormat;
2227 else
2228 m->strDefaultHardDiskFormat = "VDI";
2229
2230 return S_OK;
2231}
2232
2233HRESULT SystemProperties::i_setVRDEAuthLibrary(const com::Utf8Str &aPath)
2234{
2235 if (!aPath.isEmpty())
2236 m->strVRDEAuthLibrary = aPath;
2237 else
2238 m->strVRDEAuthLibrary = "VBoxAuth";
2239
2240 return S_OK;
2241}
2242
2243HRESULT SystemProperties::i_setWebServiceAuthLibrary(const com::Utf8Str &aPath)
2244{
2245 if (!aPath.isEmpty())
2246 m->strWebServiceAuthLibrary = aPath;
2247 else
2248 m->strWebServiceAuthLibrary = "VBoxAuth";
2249
2250 return S_OK;
2251}
2252
2253HRESULT SystemProperties::i_setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
2254{
2255 m->strDefaultVRDEExtPack = aExtPack;
2256
2257 return S_OK;
2258}
2259
2260HRESULT SystemProperties::i_setDefaultCryptoExtPack(const com::Utf8Str &aExtPack)
2261{
2262 m->strDefaultCryptoExtPack = aExtPack;
2263
2264 return S_OK;
2265}
2266
2267HRESULT SystemProperties::i_setAutostartDatabasePath(const com::Utf8Str &aPath)
2268{
2269 HRESULT rc = S_OK;
2270 AutostartDb *autostartDb = this->mParent->i_getAutostartDb();
2271
2272 if (!aPath.isEmpty())
2273 {
2274 /* Update path in the autostart database. */
2275 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
2276 if (RT_SUCCESS(vrc))
2277 m->strAutostartDatabasePath = aPath;
2278 else
2279 rc = setErrorBoth(E_FAIL, vrc,
2280 tr("Cannot set the autostart database path (%Rrc)"),
2281 vrc);
2282 }
2283 else
2284 {
2285 int vrc = autostartDb->setAutostartDbPath(NULL);
2286 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
2287 m->strAutostartDatabasePath = "";
2288 else
2289 rc = setErrorBoth(E_FAIL, vrc,
2290 tr("Deleting the autostart database path failed (%Rrc)"),
2291 vrc);
2292 }
2293
2294 return rc;
2295}
2296
2297HRESULT SystemProperties::i_setDefaultAdditionsISO(const com::Utf8Str &aPath)
2298{
2299 com::Utf8Str path(aPath);
2300 if (path.isEmpty())
2301 {
2302 char strTemp[RTPATH_MAX];
2303 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
2304 AssertRC(vrc);
2305 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
2306
2307 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
2308 AssertRC(vrc);
2309 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
2310
2311 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
2312 AssertRC(vrc);
2313 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%s.iso", strTemp, VirtualBox::i_getVersionNormalized().c_str());
2314
2315 /* Check the standard image locations */
2316 if (RTFileExists(strSrc1.c_str()))
2317 path = strSrc1;
2318 else if (RTFileExists(strSrc2.c_str()))
2319 path = strSrc2;
2320 else if (RTFileExists(strSrc3.c_str()))
2321 path = strSrc3;
2322 else
2323 return setError(E_FAIL,
2324 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
2325 }
2326
2327 if (!RTPathStartsWithRoot(path.c_str()))
2328 return setError(E_INVALIDARG,
2329 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
2330 path.c_str());
2331
2332 if (!RTFileExists(path.c_str()))
2333 return setError(E_INVALIDARG,
2334 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
2335 path.c_str());
2336
2337 m->strDefaultAdditionsISO = path;
2338
2339 return S_OK;
2340}
2341
2342HRESULT SystemProperties::i_setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
2343{
2344 m->strDefaultFrontend = aDefaultFrontend;
2345
2346 return S_OK;
2347}
2348
2349HRESULT SystemProperties::getLanguageId(com::Utf8Str &aLanguageId)
2350{
2351#ifdef VBOX_WITH_MAIN_NLS
2352 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2353 aLanguageId = m->strLanguageId;
2354 alock.release();
2355
2356 HRESULT hrc = S_OK;
2357 if (aLanguageId.isEmpty())
2358 {
2359 char szLocale[256];
2360 memset(szLocale, 0, sizeof(szLocale));
2361 int vrc = RTLocaleQueryNormalizedBaseLocaleName(szLocale, sizeof(szLocale));
2362 if (RT_SUCCESS(vrc))
2363 aLanguageId = szLocale;
2364 else
2365 hrc = Global::vboxStatusCodeToCOM(vrc);
2366 }
2367 return hrc;
2368#else
2369 aLanguageId = "C";
2370 return S_OK;
2371#endif
2372}
2373
2374HRESULT SystemProperties::setLanguageId(const com::Utf8Str &aLanguageId)
2375{
2376#ifdef VBOX_WITH_MAIN_NLS
2377 VirtualBoxTranslator *pTranslator = VirtualBoxTranslator::instance();
2378 if (!pTranslator)
2379 return E_FAIL;
2380
2381 HRESULT hrc = S_OK;
2382 int vrc = pTranslator->i_loadLanguage(aLanguageId.c_str());
2383 if (RT_SUCCESS(vrc))
2384 {
2385 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2386 m->strLanguageId = aLanguageId;
2387 alock.release();
2388
2389 // VirtualBox::i_saveSettings() needs vbox write lock
2390 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
2391 hrc = mParent->i_saveSettings();
2392 }
2393 else
2394 hrc = Global::vboxStatusCodeToCOM(vrc);
2395
2396 pTranslator->release();
2397
2398 if (SUCCEEDED(hrc))
2399 mParent->i_onLanguageChanged(aLanguageId);
2400
2401 return hrc;
2402#else
2403 NOREF(aLanguageId);
2404 return E_NOTIMPL;
2405#endif
2406}
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