VirtualBox

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

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

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.1 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2023 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 aUSBControllerTypes[] =
1815 {
1816 USBControllerType_OHCI,
1817 USBControllerType_EHCI,
1818 USBControllerType_XHCI,
1819 };
1820 aSupportedUSBControllerTypes.assign(aUSBControllerTypes,
1821 aUSBControllerTypes + RT_ELEMENTS(aUSBControllerTypes));
1822 return S_OK;
1823}
1824
1825HRESULT SystemProperties::getSupportedAudioDriverTypes(std::vector<AudioDriverType_T> &aSupportedAudioDriverTypes)
1826{
1827 static const AudioDriverType_T aAudioDriverTypes[] =
1828 {
1829 AudioDriverType_Default,
1830#ifdef RT_OS_WINDOWS
1831# if 0 /* deprecated for many years now */
1832 AudioDriverType_WinMM,
1833# endif
1834 AudioDriverType_WAS,
1835 AudioDriverType_DirectSound,
1836#endif
1837#ifdef RT_OS_DARWIN
1838 AudioDriverType_CoreAudio,
1839#endif
1840#ifdef RT_OS_OS2
1841 AudioDriverType_MMPM,
1842#endif
1843#ifdef RT_OS_SOLARIS
1844# if 0 /* deprecated for many years now */
1845 AudioDriverType_SolAudio,
1846# endif
1847#endif
1848#ifdef VBOX_WITH_AUDIO_ALSA
1849 AudioDriverType_ALSA,
1850#endif
1851#ifdef VBOX_WITH_AUDIO_OSS
1852 AudioDriverType_OSS,
1853#endif
1854#ifdef VBOX_WITH_AUDIO_PULSE
1855 AudioDriverType_Pulse,
1856#endif
1857 AudioDriverType_Null,
1858 };
1859 aSupportedAudioDriverTypes.assign(aAudioDriverTypes,
1860 aAudioDriverTypes + RT_ELEMENTS(aAudioDriverTypes));
1861 return S_OK;
1862}
1863
1864HRESULT SystemProperties::getSupportedAudioControllerTypes(std::vector<AudioControllerType_T> &aSupportedAudioControllerTypes)
1865{
1866 static const AudioControllerType_T aAudioControllerTypes[] =
1867 {
1868 AudioControllerType_AC97,
1869 AudioControllerType_SB16,
1870 AudioControllerType_HDA,
1871 };
1872 aSupportedAudioControllerTypes.assign(aAudioControllerTypes,
1873 aAudioControllerTypes + RT_ELEMENTS(aAudioControllerTypes));
1874 return S_OK;
1875}
1876
1877HRESULT SystemProperties::getSupportedStorageBuses(std::vector<StorageBus_T> &aSupportedStorageBuses)
1878{
1879 static const StorageBus_T aStorageBuses[] =
1880 {
1881 StorageBus_SATA,
1882 StorageBus_IDE,
1883 StorageBus_SCSI,
1884 StorageBus_Floppy,
1885 StorageBus_SAS,
1886 StorageBus_USB,
1887 StorageBus_PCIe,
1888 StorageBus_VirtioSCSI,
1889 };
1890 aSupportedStorageBuses.assign(aStorageBuses,
1891 aStorageBuses + RT_ELEMENTS(aStorageBuses));
1892 return S_OK;
1893}
1894
1895HRESULT SystemProperties::getSupportedStorageControllerTypes(std::vector<StorageControllerType_T> &aSupportedStorageControllerTypes)
1896{
1897 static const StorageControllerType_T aStorageControllerTypes[] =
1898 {
1899 StorageControllerType_IntelAhci,
1900 StorageControllerType_PIIX4,
1901 StorageControllerType_PIIX3,
1902 StorageControllerType_ICH6,
1903 StorageControllerType_LsiLogic,
1904 StorageControllerType_BusLogic,
1905 StorageControllerType_I82078,
1906 StorageControllerType_LsiLogicSas,
1907 StorageControllerType_USB,
1908 StorageControllerType_NVMe,
1909 StorageControllerType_VirtioSCSI,
1910 };
1911 aSupportedStorageControllerTypes.assign(aStorageControllerTypes,
1912 aStorageControllerTypes + RT_ELEMENTS(aStorageControllerTypes));
1913 return S_OK;
1914}
1915
1916HRESULT SystemProperties::getSupportedChipsetTypes(std::vector<ChipsetType_T> &aSupportedChipsetTypes)
1917{
1918 static const ChipsetType_T aChipsetTypes[] =
1919 {
1920 ChipsetType_PIIX3,
1921 ChipsetType_ICH9,
1922 };
1923 aSupportedChipsetTypes.assign(aChipsetTypes,
1924 aChipsetTypes + RT_ELEMENTS(aChipsetTypes));
1925 return S_OK;
1926}
1927
1928HRESULT SystemProperties::getSupportedIommuTypes(std::vector<IommuType_T> &aSupportedIommuTypes)
1929{
1930 static const IommuType_T aIommuTypes[] =
1931 {
1932 IommuType_None,
1933 IommuType_Automatic,
1934 IommuType_AMD,
1935 /** @todo Add Intel when it's supported. */
1936 };
1937 aSupportedIommuTypes.assign(aIommuTypes,
1938 aIommuTypes + RT_ELEMENTS(aIommuTypes));
1939 return S_OK;
1940}
1941
1942HRESULT SystemProperties::getSupportedTpmTypes(std::vector<TpmType_T> &aSupportedTpmTypes)
1943{
1944 static const TpmType_T aTpmTypes[] =
1945 {
1946 TpmType_None,
1947 TpmType_v1_2,
1948 TpmType_v2_0
1949 };
1950 aSupportedTpmTypes.assign(aTpmTypes,
1951 aTpmTypes + RT_ELEMENTS(aTpmTypes));
1952 return S_OK;
1953}
1954
1955
1956// public methods only for internal purposes
1957/////////////////////////////////////////////////////////////////////////////
1958
1959HRESULT SystemProperties::i_loadSettings(const settings::SystemProperties &data)
1960{
1961 AutoCaller autoCaller(this);
1962 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1963
1964 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1965 HRESULT rc = S_OK;
1966 rc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
1967 if (FAILED(rc)) return rc;
1968
1969 rc = i_setLoggingLevel(data.strLoggingLevel);
1970 if (FAILED(rc)) return rc;
1971
1972 rc = i_setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
1973 if (FAILED(rc)) return rc;
1974
1975 rc = i_setVRDEAuthLibrary(data.strVRDEAuthLibrary);
1976 if (FAILED(rc)) return rc;
1977
1978 rc = i_setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
1979 if (FAILED(rc)) return rc;
1980
1981 rc = i_setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
1982 if (FAILED(rc)) return rc;
1983
1984 rc = i_setDefaultCryptoExtPack(data.strDefaultCryptoExtPack);
1985 if (FAILED(rc)) return rc;
1986
1987 m->uLogHistoryCount = data.uLogHistoryCount;
1988 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
1989 m->uProxyMode = data.uProxyMode;
1990 m->strProxyUrl = data.strProxyUrl;
1991
1992 m->strLanguageId = data.strLanguageId;
1993
1994 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
1995 if (FAILED(rc)) return rc;
1996
1997 {
1998 /* must ignore errors signalled here, because the guest additions
1999 * file may not exist, and in this case keep the empty string */
2000 ErrorInfoKeeper eik;
2001 (void)i_setDefaultAdditionsISO(data.strDefaultAdditionsISO);
2002 }
2003
2004 rc = i_setDefaultFrontend(data.strDefaultFrontend);
2005 if (FAILED(rc)) return rc;
2006
2007 return S_OK;
2008}
2009
2010HRESULT SystemProperties::i_saveSettings(settings::SystemProperties &data)
2011{
2012 AutoCaller autoCaller(this);
2013 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2014
2015 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2016
2017 data = *m;
2018
2019 return S_OK;
2020}
2021
2022/**
2023 * Returns a medium format object corresponding to the given format
2024 * identifier or null if no such format.
2025 *
2026 * @param aFormat Format identifier.
2027 *
2028 * @return ComObjPtr<MediumFormat>
2029 */
2030ComObjPtr<MediumFormat> SystemProperties::i_mediumFormat(const Utf8Str &aFormat)
2031{
2032 ComObjPtr<MediumFormat> format;
2033
2034 AutoCaller autoCaller(this);
2035 AssertComRCReturn (autoCaller.rc(), format);
2036
2037 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2038
2039 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
2040 it != m_llMediumFormats.end();
2041 ++ it)
2042 {
2043 /* MediumFormat is all const, no need to lock */
2044
2045 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
2046 {
2047 format = *it;
2048 break;
2049 }
2050 }
2051
2052 return format;
2053}
2054
2055/**
2056 * Returns a medium format object corresponding to the given file extension or
2057 * null if no such format.
2058 *
2059 * @param aExt File extension.
2060 *
2061 * @return ComObjPtr<MediumFormat>
2062 */
2063ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt)
2064{
2065 ComObjPtr<MediumFormat> format;
2066
2067 AutoCaller autoCaller(this);
2068 AssertComRCReturn (autoCaller.rc(), format);
2069
2070 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2071
2072 bool fFound = false;
2073 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
2074 it != m_llMediumFormats.end() && !fFound;
2075 ++it)
2076 {
2077 /* MediumFormat is all const, no need to lock */
2078 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
2079 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
2080 it1 != aFileList.end();
2081 ++it1)
2082 {
2083 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
2084 {
2085 format = *it;
2086 fFound = true;
2087 break;
2088 }
2089 }
2090 }
2091
2092 return format;
2093}
2094
2095
2096/**
2097 * VD plugin load
2098 */
2099int SystemProperties::i_loadVDPlugin(const char *pszPluginLibrary)
2100{
2101 int vrc = VDPluginLoadFromFilename(pszPluginLibrary);
2102 LogFlowFunc(("pszPluginLibrary='%s' -> %Rrc\n", pszPluginLibrary, vrc));
2103 return vrc;
2104}
2105
2106/**
2107 * VD plugin unload
2108 */
2109int SystemProperties::i_unloadVDPlugin(const char *pszPluginLibrary)
2110{
2111 int vrc = VDPluginUnloadFromFilename(pszPluginLibrary);
2112 LogFlowFunc(("pszPluginLibrary='%s' -> %Rrc\n", pszPluginLibrary, vrc));
2113 return vrc;
2114}
2115
2116/**
2117 * Internally usable version of getDefaultAdditionsISO.
2118 */
2119HRESULT SystemProperties::i_getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
2120{
2121 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2122 if (m->strDefaultAdditionsISO.isNotEmpty())
2123 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
2124 else
2125 {
2126 /* no guest additions, check if it showed up in the mean time */
2127 alock.release();
2128 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
2129 if (m->strDefaultAdditionsISO.isEmpty())
2130 {
2131 ErrorInfoKeeper eik;
2132 (void)i_setDefaultAdditionsISO("");
2133 }
2134 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
2135 }
2136 return S_OK;
2137}
2138
2139// private methods
2140/////////////////////////////////////////////////////////////////////////////
2141
2142/**
2143 * Returns the user's home directory. Wrapper around RTPathUserHome().
2144 * @param strPath
2145 * @return
2146 */
2147HRESULT SystemProperties::i_getUserHomeDirectory(Utf8Str &strPath)
2148{
2149 char szHome[RTPATH_MAX];
2150 int vrc = RTPathUserHome(szHome, sizeof(szHome));
2151 if (RT_FAILURE(vrc))
2152 return setErrorBoth(E_FAIL, vrc,
2153 tr("Cannot determine user home directory (%Rrc)"),
2154 vrc);
2155 strPath = szHome;
2156 return S_OK;
2157}
2158
2159/**
2160 * Internal implementation to set the default machine folder. Gets called
2161 * from the public attribute setter as well as loadSettings(). With 4.0,
2162 * the "default default" machine folder has changed, and we now require
2163 * a full path always.
2164 * @param strPath
2165 * @return
2166 */
2167HRESULT SystemProperties::i_setDefaultMachineFolder(const Utf8Str &strPath)
2168{
2169 Utf8Str path(strPath); // make modifiable
2170 if ( path.isEmpty() // used by API calls to reset the default
2171 || path == "Machines" // this value (exactly like this, without path) is stored
2172 // in VirtualBox.xml if user upgrades from before 4.0 and
2173 // has not changed the default machine folder
2174 )
2175 {
2176 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
2177 HRESULT rc = i_getUserHomeDirectory(path);
2178 if (FAILED(rc)) return rc;
2179 path += RTPATH_SLASH_STR "VirtualBox VMs";
2180 }
2181
2182 if (!RTPathStartsWithRoot(path.c_str()))
2183 return setError(E_INVALIDARG,
2184 tr("Given default machine folder '%s' is not fully qualified"),
2185 path.c_str());
2186
2187 m->strDefaultMachineFolder = path;
2188
2189 return S_OK;
2190}
2191
2192HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
2193{
2194 Utf8Str useLoggingLevel(aLoggingLevel);
2195 if (useLoggingLevel.isEmpty())
2196 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
2197 int rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), useLoggingLevel.c_str());
2198 // If failed and not the default logging level - try to use the default logging level.
2199 if (RT_FAILURE(rc))
2200 {
2201 // If failed write message to the release log.
2202 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
2203 // If attempted logging level not the default one then try the default one.
2204 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
2205 {
2206 rc = RTLogGroupSettings(RTLogRelGetDefaultInstance(), VBOXSVC_LOG_DEFAULT);
2207 // If failed report this to the release log.
2208 if (RT_FAILURE(rc))
2209 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
2210 }
2211 // On any failure - set default level as the one to be stored.
2212 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
2213 }
2214 // Set to passed value or if default used/attempted (even if error condition) use empty string.
2215 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
2216 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
2217}
2218
2219HRESULT SystemProperties::i_setDefaultHardDiskFormat(const com::Utf8Str &aFormat)
2220{
2221 if (!aFormat.isEmpty())
2222 m->strDefaultHardDiskFormat = aFormat;
2223 else
2224 m->strDefaultHardDiskFormat = "VDI";
2225
2226 return S_OK;
2227}
2228
2229HRESULT SystemProperties::i_setVRDEAuthLibrary(const com::Utf8Str &aPath)
2230{
2231 if (!aPath.isEmpty())
2232 m->strVRDEAuthLibrary = aPath;
2233 else
2234 m->strVRDEAuthLibrary = "VBoxAuth";
2235
2236 return S_OK;
2237}
2238
2239HRESULT SystemProperties::i_setWebServiceAuthLibrary(const com::Utf8Str &aPath)
2240{
2241 if (!aPath.isEmpty())
2242 m->strWebServiceAuthLibrary = aPath;
2243 else
2244 m->strWebServiceAuthLibrary = "VBoxAuth";
2245
2246 return S_OK;
2247}
2248
2249HRESULT SystemProperties::i_setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
2250{
2251 m->strDefaultVRDEExtPack = aExtPack;
2252
2253 return S_OK;
2254}
2255
2256HRESULT SystemProperties::i_setDefaultCryptoExtPack(const com::Utf8Str &aExtPack)
2257{
2258 m->strDefaultCryptoExtPack = aExtPack;
2259
2260 return S_OK;
2261}
2262
2263HRESULT SystemProperties::i_setAutostartDatabasePath(const com::Utf8Str &aPath)
2264{
2265 HRESULT rc = S_OK;
2266 AutostartDb *autostartDb = this->mParent->i_getAutostartDb();
2267
2268 if (!aPath.isEmpty())
2269 {
2270 /* Update path in the autostart database. */
2271 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
2272 if (RT_SUCCESS(vrc))
2273 m->strAutostartDatabasePath = aPath;
2274 else
2275 rc = setErrorBoth(E_FAIL, vrc,
2276 tr("Cannot set the autostart database path (%Rrc)"),
2277 vrc);
2278 }
2279 else
2280 {
2281 int vrc = autostartDb->setAutostartDbPath(NULL);
2282 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
2283 m->strAutostartDatabasePath = "";
2284 else
2285 rc = setErrorBoth(E_FAIL, vrc,
2286 tr("Deleting the autostart database path failed (%Rrc)"),
2287 vrc);
2288 }
2289
2290 return rc;
2291}
2292
2293HRESULT SystemProperties::i_setDefaultAdditionsISO(const com::Utf8Str &aPath)
2294{
2295 com::Utf8Str path(aPath);
2296 if (path.isEmpty())
2297 {
2298 char strTemp[RTPATH_MAX];
2299 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
2300 AssertRC(vrc);
2301 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
2302
2303 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
2304 AssertRC(vrc);
2305 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
2306
2307 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
2308 AssertRC(vrc);
2309 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%s.iso", strTemp, VirtualBox::i_getVersionNormalized().c_str());
2310
2311 /* Check the standard image locations */
2312 if (RTFileExists(strSrc1.c_str()))
2313 path = strSrc1;
2314 else if (RTFileExists(strSrc2.c_str()))
2315 path = strSrc2;
2316 else if (RTFileExists(strSrc3.c_str()))
2317 path = strSrc3;
2318 else
2319 return setError(E_FAIL,
2320 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
2321 }
2322
2323 if (!RTPathStartsWithRoot(path.c_str()))
2324 return setError(E_INVALIDARG,
2325 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
2326 path.c_str());
2327
2328 if (!RTFileExists(path.c_str()))
2329 return setError(E_INVALIDARG,
2330 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
2331 path.c_str());
2332
2333 m->strDefaultAdditionsISO = path;
2334
2335 return S_OK;
2336}
2337
2338HRESULT SystemProperties::i_setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
2339{
2340 m->strDefaultFrontend = aDefaultFrontend;
2341
2342 return S_OK;
2343}
2344
2345HRESULT SystemProperties::getLanguageId(com::Utf8Str &aLanguageId)
2346{
2347#ifdef VBOX_WITH_MAIN_NLS
2348 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2349 aLanguageId = m->strLanguageId;
2350 alock.release();
2351
2352 HRESULT hrc = S_OK;
2353 if (aLanguageId.isEmpty())
2354 {
2355 char szLocale[256];
2356 memset(szLocale, 0, sizeof(szLocale));
2357 int vrc = RTLocaleQueryNormalizedBaseLocaleName(szLocale, sizeof(szLocale));
2358 if (RT_SUCCESS(vrc))
2359 aLanguageId = szLocale;
2360 else
2361 hrc = Global::vboxStatusCodeToCOM(vrc);
2362 }
2363 return hrc;
2364#else
2365 aLanguageId = "C";
2366 return S_OK;
2367#endif
2368}
2369
2370HRESULT SystemProperties::setLanguageId(const com::Utf8Str &aLanguageId)
2371{
2372#ifdef VBOX_WITH_MAIN_NLS
2373 VirtualBoxTranslator *pTranslator = VirtualBoxTranslator::instance();
2374 if (!pTranslator)
2375 return E_FAIL;
2376
2377 HRESULT hrc = S_OK;
2378 int vrc = pTranslator->i_loadLanguage(aLanguageId.c_str());
2379 if (RT_SUCCESS(vrc))
2380 {
2381 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2382 m->strLanguageId = aLanguageId;
2383 alock.release();
2384
2385 // VirtualBox::i_saveSettings() needs vbox write lock
2386 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
2387 hrc = mParent->i_saveSettings();
2388 }
2389 else
2390 hrc = Global::vboxStatusCodeToCOM(vrc);
2391
2392 pTranslator->release();
2393
2394 if (SUCCEEDED(hrc))
2395 mParent->i_onLanguageChanged(aLanguageId);
2396
2397 return hrc;
2398#else
2399 NOREF(aLanguageId);
2400 return E_NOTIMPL;
2401#endif
2402}
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