VirtualBox

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

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

Main/SystemPropertiesImpl.cpp: Log VDPlugIn load/unload results. bugref:9898

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