VirtualBox

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

Last change on this file since 95741 was 95741, checked in by vboxsync, 3 years ago

Main/Recording: Added ISystemProperties::getRecordingFeatures to allow clients querying for enabled recording features at runtime. Also added IRecordingScreenSettings::videoDeadline + audioDeadline attributes to allow specifying the video/audio codec's (encoding) deadlines. bugref:10244

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette