VirtualBox

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

Last change on this file since 85672 was 85574, checked in by vboxsync, 4 years ago

Main: Added ISystemProperties::getCPUProfiles.

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