VirtualBox

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

Last change on this file since 53390 was 52596, checked in by vboxsync, 10 years ago

Storage/VD + Main/ExtPackManager+VirtualBox+SystemProperties: restructure previous change to fit better into the extpack design (using existing hooks) by using two new extpack helper functions

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.3 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 52596 2014-09-04 16:45:50Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2014 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#include "SystemPropertiesImpl.h"
19#include "VirtualBoxImpl.h"
20#include "MachineImpl.h"
21#ifdef VBOX_WITH_EXTPACK
22# include "ExtPackManagerImpl.h"
23#endif
24#include "AutoCaller.h"
25#include "Global.h"
26#include "Logging.h"
27#include "AutostartDb.h"
28
29// generated header
30#include "SchemaDefs.h"
31
32#include <iprt/dir.h>
33#include <iprt/ldr.h>
34#include <iprt/path.h>
35#include <iprt/string.h>
36#include <iprt/cpp/utils.h>
37
38#include <VBox/err.h>
39#include <VBox/param.h>
40#include <VBox/settings.h>
41#include <VBox/vd.h>
42
43// defines
44/////////////////////////////////////////////////////////////////////////////
45
46// constructor / destructor
47/////////////////////////////////////////////////////////////////////////////
48
49SystemProperties::SystemProperties()
50 : mParent(NULL),
51 m(new settings::SystemProperties)
52{
53}
54
55SystemProperties::~SystemProperties()
56{
57 delete m;
58}
59
60
61HRESULT SystemProperties::FinalConstruct()
62{
63 return BaseFinalConstruct();
64}
65
66void SystemProperties::FinalRelease()
67{
68 uninit();
69 BaseFinalRelease();
70}
71
72// public methods only for internal purposes
73/////////////////////////////////////////////////////////////////////////////
74
75/**
76 * Initializes the system information object.
77 *
78 * @returns COM result indicator
79 */
80HRESULT SystemProperties::init(VirtualBox *aParent)
81{
82 LogFlowThisFunc(("aParent=%p\n", aParent));
83
84 ComAssertRet(aParent, E_FAIL);
85
86 /* Enclose the state transition NotReady->InInit->Ready */
87 AutoInitSpan autoInitSpan(this);
88 AssertReturn(autoInitSpan.isOk(), E_FAIL);
89
90 unconst(mParent) = aParent;
91
92 i_setDefaultMachineFolder(Utf8Str::Empty);
93 i_setLoggingLevel(Utf8Str::Empty);
94 i_setDefaultHardDiskFormat(Utf8Str::Empty);
95
96 i_setVRDEAuthLibrary(Utf8Str::Empty);
97 i_setDefaultVRDEExtPack(Utf8Str::Empty);
98
99 m->ulLogHistoryCount = 3;
100
101
102 /* On Windows and OS X, HW virtualization use isn't exclusive by
103 * default so that VT-x or AMD-V can be shared with other
104 * hypervisors without requiring user intervention.
105 * NB: See also SystemProperties constructor in settings.h
106 */
107#if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
108 m->fExclusiveHwVirt = false;
109#else
110 m->fExclusiveHwVirt = true;
111#endif
112
113 HRESULT rc = S_OK;
114
115 /* Fetch info of all available hd backends. */
116
117 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
118 /// any number of backends
119
120 VDBACKENDINFO aVDInfo[100];
121 unsigned cEntries;
122 int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
123 AssertRC(vrc);
124 if (RT_SUCCESS(vrc))
125 {
126 for (unsigned i = 0; i < cEntries; ++ i)
127 {
128 ComObjPtr<MediumFormat> hdf;
129 rc = hdf.createObject();
130 if (FAILED(rc)) break;
131
132 rc = hdf->init(&aVDInfo[i]);
133 if (FAILED(rc)) break;
134
135 m_llMediumFormats.push_back(hdf);
136 }
137 }
138
139 /* Confirm a successful initialization */
140 if (SUCCEEDED(rc))
141 autoInitSpan.setSucceeded();
142
143 return rc;
144}
145
146/**
147 * Uninitializes the instance and sets the ready flag to FALSE.
148 * Called either from FinalRelease() or by the parent when it gets destroyed.
149 */
150void SystemProperties::uninit()
151{
152 LogFlowThisFunc(("\n"));
153
154 /* Enclose the state transition Ready->InUninit->NotReady */
155 AutoUninitSpan autoUninitSpan(this);
156 if (autoUninitSpan.uninitDone())
157 return;
158
159 unconst(mParent) = NULL;
160}
161
162// wrapped ISystemProperties properties
163/////////////////////////////////////////////////////////////////////////////
164
165HRESULT SystemProperties::getMinGuestRAM(ULONG *minRAM)
166
167{
168 /* no need to lock, this is const */
169 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
170 *minRAM = MM_RAM_MIN_IN_MB;
171
172 return S_OK;
173}
174
175HRESULT SystemProperties::getMaxGuestRAM(ULONG *maxRAM)
176{
177 /* no need to lock, this is const */
178 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
179 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
180 ULONG maxRAMArch = maxRAMSys;
181 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
182
183 return S_OK;
184}
185
186HRESULT SystemProperties::getMinGuestVRAM(ULONG *minVRAM)
187{
188 /* no need to lock, this is const */
189 *minVRAM = SchemaDefs::MinGuestVRAM;
190
191 return S_OK;
192}
193
194HRESULT SystemProperties::getMaxGuestVRAM(ULONG *maxVRAM)
195{
196 /* no need to lock, this is const */
197 *maxVRAM = SchemaDefs::MaxGuestVRAM;
198
199 return S_OK;
200}
201
202HRESULT SystemProperties::getMinGuestCPUCount(ULONG *minCPUCount)
203{
204 /* no need to lock, this is const */
205 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
206
207 return S_OK;
208}
209
210HRESULT SystemProperties::getMaxGuestCPUCount(ULONG *maxCPUCount)
211{
212 /* no need to lock, this is const */
213 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
214
215 return S_OK;
216}
217
218HRESULT SystemProperties::getMaxGuestMonitors(ULONG *maxMonitors)
219{
220
221 /* no need to lock, this is const */
222 *maxMonitors = SchemaDefs::MaxGuestMonitors;
223
224 return S_OK;
225}
226
227
228HRESULT SystemProperties::getInfoVDSize(LONG64 *infoVDSize)
229{
230 /*
231 * The BIOS supports currently 32 bit LBA numbers (implementing the full
232 * 48 bit range is in theory trivial, but the crappy compiler makes things
233 * more difficult). This translates to almost 2 TiBytes (to be on the safe
234 * side, the reported limit is 1 MiByte less than that, as the total number
235 * of sectors should fit in 32 bits, too), which should be enough for the
236 * moment. Since the MBR partition tables support only 32bit sector numbers
237 * and thus the BIOS can only boot from disks smaller than 2T this is a
238 * rather hard limit.
239 *
240 * The virtual ATA/SATA disks support complete LBA48, and SCSI supports
241 * LBA64 (almost, more like LBA55 in practice), so the theoretical maximum
242 * disk size is 128 PiByte/16 EiByte. The GUI works nicely with 6 orders
243 * of magnitude, but not with 11..13 orders of magnitude.
244 */
245 /* no need to lock, this is const */
246 *infoVDSize = 2 * _1T - _1M;
247
248 return S_OK;
249}
250
251
252HRESULT SystemProperties::getSerialPortCount(ULONG *count)
253{
254 /* no need to lock, this is const */
255 *count = SchemaDefs::SerialPortCount;
256
257 return S_OK;
258}
259
260
261HRESULT SystemProperties::getParallelPortCount(ULONG *count)
262{
263 /* no need to lock, this is const */
264 *count = SchemaDefs::ParallelPortCount;
265
266 return S_OK;
267}
268
269
270HRESULT SystemProperties::getMaxBootPosition(ULONG *aMaxBootPosition)
271{
272 /* no need to lock, this is const */
273 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
274
275 return S_OK;
276}
277
278
279HRESULT SystemProperties::getExclusiveHwVirt(BOOL *aExclusiveHwVirt)
280{
281 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
282
283 *aExclusiveHwVirt = m->fExclusiveHwVirt;
284
285 return S_OK;
286}
287
288HRESULT SystemProperties::setExclusiveHwVirt(BOOL aExclusiveHwVirt)
289{
290 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
291 m->fExclusiveHwVirt = !!aExclusiveHwVirt;
292 alock.release();
293
294 // VirtualBox::i_saveSettings() needs vbox write lock
295 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
296 HRESULT rc = mParent->i_saveSettings();
297
298 return rc;
299}
300
301HRESULT SystemProperties::getMaxNetworkAdapters(ChipsetType_T aChipset, ULONG *aMaxNetworkAdapters)
302{
303 /* no need for locking, no state */
304 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
305 if (uResult == 0)
306 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
307 *aMaxNetworkAdapters = uResult;
308 return S_OK;
309}
310
311HRESULT SystemProperties::getMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType, ULONG *count)
312{
313 /* no need for locking, no state */
314 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
315 if (uResult == 0)
316 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
317
318 switch (aType)
319 {
320 case NetworkAttachmentType_NAT:
321 case NetworkAttachmentType_Internal:
322 case NetworkAttachmentType_NATNetwork:
323 /* chipset default is OK */
324 break;
325 case NetworkAttachmentType_Bridged:
326 /* Maybe use current host interface count here? */
327 break;
328 case NetworkAttachmentType_HostOnly:
329 uResult = RT_MIN(uResult, 8);
330 break;
331 default:
332 AssertMsgFailed(("Unhandled attachment type %d\n", aType));
333 }
334
335 *count = uResult;
336
337 return S_OK;
338}
339
340
341HRESULT SystemProperties::getMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
342 ULONG *aMaxDevicesPerPort)
343{
344 /* no need to lock, this is const */
345 switch (aBus)
346 {
347 case StorageBus_SATA:
348 case StorageBus_SCSI:
349 case StorageBus_SAS:
350 case StorageBus_USB:
351 {
352 /* SATA and both SCSI controllers only support one device per port. */
353 *aMaxDevicesPerPort = 1;
354 break;
355 }
356 case StorageBus_IDE:
357 case StorageBus_Floppy:
358 {
359 /* The IDE and Floppy controllers support 2 devices. One as master
360 * and one as slave (or floppy drive 0 and 1). */
361 *aMaxDevicesPerPort = 2;
362 break;
363 }
364 default:
365 AssertMsgFailed(("Invalid bus type %d\n", aBus));
366 }
367
368 return S_OK;
369}
370
371HRESULT SystemProperties::getMinPortCountForStorageBus(StorageBus_T aBus,
372 ULONG *aMinPortCount)
373{
374 /* no need to lock, this is const */
375 switch (aBus)
376 {
377 case StorageBus_SATA:
378 case StorageBus_SAS:
379 {
380 *aMinPortCount = 1;
381 break;
382 }
383 case StorageBus_SCSI:
384 {
385 *aMinPortCount = 16;
386 break;
387 }
388 case StorageBus_IDE:
389 {
390 *aMinPortCount = 2;
391 break;
392 }
393 case StorageBus_Floppy:
394 {
395 *aMinPortCount = 1;
396 break;
397 }
398 case StorageBus_USB:
399 {
400 *aMinPortCount = 8;
401 break;
402 }
403 default:
404 AssertMsgFailed(("Invalid bus type %d\n", aBus));
405 }
406
407 return S_OK;
408}
409
410HRESULT SystemProperties::getMaxPortCountForStorageBus(StorageBus_T aBus,
411 ULONG *aMaxPortCount)
412{
413 /* no need to lock, this is const */
414 switch (aBus)
415 {
416 case StorageBus_SATA:
417 {
418 *aMaxPortCount = 30;
419 break;
420 }
421 case StorageBus_SCSI:
422 {
423 *aMaxPortCount = 16;
424 break;
425 }
426 case StorageBus_IDE:
427 {
428 *aMaxPortCount = 2;
429 break;
430 }
431 case StorageBus_Floppy:
432 {
433 *aMaxPortCount = 1;
434 break;
435 }
436 case StorageBus_SAS:
437 {
438 *aMaxPortCount = 255;
439 break;
440 }
441 case StorageBus_USB:
442 {
443 *aMaxPortCount = 8;
444 break;
445 }
446 default:
447 AssertMsgFailed(("Invalid bus type %d\n", aBus));
448 }
449
450 return S_OK;
451}
452
453HRESULT SystemProperties::getMaxInstancesOfStorageBus(ChipsetType_T aChipset,
454 StorageBus_T aBus,
455 ULONG *aMaxInstances)
456{
457 ULONG cCtrs = 0;
458
459 /* no need to lock, this is const */
460 switch (aBus)
461 {
462 case StorageBus_SATA:
463 case StorageBus_SCSI:
464 case StorageBus_SAS:
465 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
466 break;
467 case StorageBus_USB:
468 case StorageBus_IDE:
469 case StorageBus_Floppy:
470 {
471 cCtrs = 1;
472 break;
473 }
474 default:
475 AssertMsgFailed(("Invalid bus type %d\n", aBus));
476 }
477
478 *aMaxInstances = cCtrs;
479
480 return S_OK;
481}
482
483HRESULT SystemProperties::getDeviceTypesForStorageBus(StorageBus_T aBus,
484 std::vector<DeviceType_T> &aDeviceTypes)
485{
486 aDeviceTypes.resize(0);
487
488 /* no need to lock, this is const */
489 switch (aBus)
490 {
491 case StorageBus_IDE:
492 case StorageBus_SATA:
493 case StorageBus_SCSI:
494 case StorageBus_SAS:
495 case StorageBus_USB:
496 {
497 aDeviceTypes.resize(2);
498 aDeviceTypes[0] = DeviceType_DVD;
499 aDeviceTypes[1] = DeviceType_HardDisk;
500 break;
501 }
502 case StorageBus_Floppy:
503 {
504 aDeviceTypes.resize(1);
505 aDeviceTypes[0] = DeviceType_Floppy;
506 break;
507 }
508 default:
509 AssertMsgFailed(("Invalid bus type %d\n", aBus));
510 }
511
512 return S_OK;
513}
514
515HRESULT SystemProperties::getDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType,
516 BOOL *aEnabled)
517{
518 /* no need to lock, this is const */
519 switch (aControllerType)
520 {
521 case StorageControllerType_LsiLogic:
522 case StorageControllerType_BusLogic:
523 case StorageControllerType_IntelAhci:
524 case StorageControllerType_LsiLogicSas:
525 case StorageControllerType_USB:
526 *aEnabled = false;
527 break;
528 case StorageControllerType_PIIX3:
529 case StorageControllerType_PIIX4:
530 case StorageControllerType_ICH6:
531 case StorageControllerType_I82078:
532 *aEnabled = true;
533 break;
534 default:
535 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
536 }
537 return S_OK;
538}
539
540HRESULT SystemProperties::getStorageControllerHotplugCapable(StorageControllerType_T aControllerType,
541 BOOL *aHotplugCapable)
542{
543 switch (aControllerType)
544 {
545 case StorageControllerType_IntelAhci:
546 case StorageControllerType_USB:
547 *aHotplugCapable = true;
548 break;
549 case StorageControllerType_LsiLogic:
550 case StorageControllerType_LsiLogicSas:
551 case StorageControllerType_BusLogic:
552 case StorageControllerType_PIIX3:
553 case StorageControllerType_PIIX4:
554 case StorageControllerType_ICH6:
555 case StorageControllerType_I82078:
556 *aHotplugCapable = false;
557 break;
558 default:
559 AssertMsgFailedReturn(("Invalid controller type %d\n", aControllerType), E_FAIL);
560 }
561
562 return S_OK;
563}
564
565HRESULT SystemProperties::getMaxInstancesOfUSBControllerType(ChipsetType_T aChipset,
566 USBControllerType_T aType,
567 ULONG *aMaxInstances)
568{
569 NOREF(aChipset);
570 ULONG cCtrs = 0;
571
572 /* no need to lock, this is const */
573 switch (aType)
574 {
575 case USBControllerType_OHCI:
576 case USBControllerType_EHCI:
577 case USBControllerType_XHCI:
578 {
579 cCtrs = 1;
580 break;
581 }
582 default:
583 AssertMsgFailed(("Invalid bus type %d\n", aType));
584 }
585
586 *aMaxInstances = cCtrs;
587
588 return S_OK;
589}
590
591HRESULT SystemProperties::getDefaultMachineFolder(com::Utf8Str &aDefaultMachineFolder)
592{
593 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
594 aDefaultMachineFolder = m->strDefaultMachineFolder;
595 return S_OK;
596}
597
598HRESULT SystemProperties::setDefaultMachineFolder(const com::Utf8Str &aDefaultMachineFolder)
599{
600 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
601 HRESULT rc = i_setDefaultMachineFolder(aDefaultMachineFolder);
602 alock.release();
603 if (SUCCEEDED(rc))
604 {
605 // VirtualBox::i_saveSettings() needs vbox write lock
606 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
607 rc = mParent->i_saveSettings();
608 }
609
610 return rc;
611}
612
613HRESULT SystemProperties::getLoggingLevel(com::Utf8Str &aLoggingLevel)
614{
615 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
616
617 aLoggingLevel = m->strLoggingLevel;
618
619 if (aLoggingLevel.isEmpty())
620 aLoggingLevel = VBOXSVC_LOG_DEFAULT;
621
622 return S_OK;
623}
624
625
626HRESULT SystemProperties::setLoggingLevel(const com::Utf8Str &aLoggingLevel)
627{
628 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
629 HRESULT rc = i_setLoggingLevel(aLoggingLevel);
630 alock.release();
631
632 if (SUCCEEDED(rc))
633 {
634 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
635 rc = mParent->i_saveSettings();
636 }
637 else
638 LogRel(("Cannot set passed logging level=%s, or the default one - Error=%Rhrc \n", aLoggingLevel.c_str(), rc));
639
640 return rc;
641}
642
643HRESULT SystemProperties::getMediumFormats(std::vector<ComPtr<IMediumFormat> > &aMediumFormats)
644{
645 MediumFormatList mediumFormats(m_llMediumFormats);
646 aMediumFormats.resize(mediumFormats.size());
647 size_t i = 0;
648 for (MediumFormatList::const_iterator it = mediumFormats.begin(); it != mediumFormats.end(); ++it, ++i)
649 (*it).queryInterfaceTo(aMediumFormats[i].asOutParam());
650 return S_OK;
651}
652
653HRESULT SystemProperties::getDefaultHardDiskFormat(com::Utf8Str &aDefaultHardDiskFormat)
654{
655 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
656 aDefaultHardDiskFormat = m->strDefaultHardDiskFormat;
657 return S_OK;
658}
659
660
661HRESULT SystemProperties::setDefaultHardDiskFormat(const com::Utf8Str &aDefaultHardDiskFormat)
662{
663 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
664 HRESULT rc = i_setDefaultHardDiskFormat(aDefaultHardDiskFormat);
665 alock.release();
666 if (SUCCEEDED(rc))
667 {
668 // VirtualBox::i_saveSettings() needs vbox write lock
669 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
670 rc = mParent->i_saveSettings();
671 }
672
673 return rc;
674}
675
676HRESULT SystemProperties::getFreeDiskSpaceWarning(LONG64 *aFreeSpace)
677{
678 NOREF(aFreeSpace);
679 ReturnComNotImplemented();
680}
681
682HRESULT SystemProperties::setFreeDiskSpaceWarning(LONG64 /* aFreeSpace */)
683{
684 ReturnComNotImplemented();
685}
686
687HRESULT SystemProperties::getFreeDiskSpacePercentWarning(ULONG *aFreeSpacePercent)
688{
689 NOREF(aFreeSpacePercent);
690 ReturnComNotImplemented();
691}
692
693HRESULT SystemProperties::setFreeDiskSpacePercentWarning(ULONG /* aFreeSpacePercent */)
694{
695 ReturnComNotImplemented();
696}
697
698HRESULT SystemProperties::getFreeDiskSpaceError(LONG64 *aFreeSpace)
699{
700 NOREF(aFreeSpace);
701 ReturnComNotImplemented();
702}
703
704HRESULT SystemProperties::setFreeDiskSpaceError(LONG64 /* aFreeSpace */)
705{
706 ReturnComNotImplemented();
707}
708
709HRESULT SystemProperties::getFreeDiskSpacePercentError(ULONG *aFreeSpacePercent)
710{
711 NOREF(aFreeSpacePercent);
712 ReturnComNotImplemented();
713}
714
715HRESULT SystemProperties::setFreeDiskSpacePercentError(ULONG /* aFreeSpacePercent */)
716{
717 ReturnComNotImplemented();
718}
719
720HRESULT SystemProperties::getVRDEAuthLibrary(com::Utf8Str &aVRDEAuthLibrary)
721{
722 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
723
724 aVRDEAuthLibrary = m->strVRDEAuthLibrary;
725
726 return S_OK;
727}
728
729HRESULT SystemProperties::setVRDEAuthLibrary(const com::Utf8Str &aVRDEAuthLibrary)
730{
731 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
732 HRESULT rc = i_setVRDEAuthLibrary(aVRDEAuthLibrary);
733 alock.release();
734 if (SUCCEEDED(rc))
735 {
736 // VirtualBox::i_saveSettings() needs vbox write lock
737 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
738 rc = mParent->i_saveSettings();
739 }
740
741 return rc;
742}
743
744HRESULT SystemProperties::getWebServiceAuthLibrary(com::Utf8Str &aWebServiceAuthLibrary)
745{
746 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
747
748 aWebServiceAuthLibrary = m->strWebServiceAuthLibrary;
749
750 return S_OK;
751}
752
753HRESULT SystemProperties::setWebServiceAuthLibrary(const com::Utf8Str &aWebServiceAuthLibrary)
754{
755 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
756 HRESULT rc = i_setWebServiceAuthLibrary(aWebServiceAuthLibrary);
757 alock.release();
758
759 if (SUCCEEDED(rc))
760 {
761 // VirtualBox::i_saveSettings() needs vbox write lock
762 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
763 rc = mParent->i_saveSettings();
764 }
765
766 return rc;
767}
768
769HRESULT SystemProperties::getDefaultVRDEExtPack(com::Utf8Str &aExtPack)
770{
771 HRESULT hrc = S_OK;
772 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
773 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
774 if (strExtPack.isNotEmpty())
775 {
776 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
777 hrc = S_OK;
778 else
779#ifdef VBOX_WITH_EXTPACK
780 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&strExtPack);
781#else
782 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
783#endif
784 }
785 else
786 {
787#ifdef VBOX_WITH_EXTPACK
788 hrc = mParent->i_getExtPackManager()->i_getDefaultVrdeExtPack(&strExtPack);
789#endif
790 if (strExtPack.isEmpty())
791 {
792 /*
793 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
794 * This is hardcoded uglyness, sorry.
795 */
796 char szPath[RTPATH_MAX];
797 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
798 if (RT_SUCCESS(vrc))
799 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
800 if (RT_SUCCESS(vrc))
801 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
802 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
803 {
804 /* Illegal extpack name, so no conflict. */
805 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
806 }
807 }
808 }
809
810 if (SUCCEEDED(hrc))
811 aExtPack = strExtPack;
812
813 return S_OK;
814}
815
816
817HRESULT SystemProperties::setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
818{
819 HRESULT hrc = S_OK;
820 if (aExtPack.isNotEmpty())
821 {
822 if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
823 hrc = S_OK;
824 else
825#ifdef VBOX_WITH_EXTPACK
826 hrc = mParent->i_getExtPackManager()->i_checkVrdeExtPack(&aExtPack);
827#else
828 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
829#endif
830 }
831 if (SUCCEEDED(hrc))
832 {
833 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
834 hrc = i_setDefaultVRDEExtPack(aExtPack);
835 if (SUCCEEDED(hrc))
836 {
837 /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
838 alock.release();
839 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
840 hrc = mParent->i_saveSettings();
841 }
842 }
843
844 return hrc;
845}
846
847
848HRESULT SystemProperties::getLogHistoryCount(ULONG *count)
849{
850 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
851
852 *count = m->ulLogHistoryCount;
853
854 return S_OK;
855}
856
857
858HRESULT SystemProperties::setLogHistoryCount(ULONG count)
859{
860 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
861 m->ulLogHistoryCount = count;
862 alock.release();
863
864 // VirtualBox::i_saveSettings() needs vbox write lock
865 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
866 HRESULT rc = mParent->i_saveSettings();
867
868 return rc;
869}
870
871HRESULT SystemProperties::getDefaultAudioDriver(AudioDriverType_T *aAudioDriver)
872{
873 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
874
875 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
876
877 return S_OK;
878}
879
880HRESULT SystemProperties::getAutostartDatabasePath(com::Utf8Str &aAutostartDbPath)
881{
882 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
883
884 aAutostartDbPath = m->strAutostartDatabasePath;
885
886 return S_OK;
887}
888
889HRESULT SystemProperties::setAutostartDatabasePath(const com::Utf8Str &aAutostartDbPath)
890{
891 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
892 HRESULT rc = i_setAutostartDatabasePath(aAutostartDbPath);
893 alock.release();
894
895 if (SUCCEEDED(rc))
896 {
897 // VirtualBox::i_saveSettings() needs vbox write lock
898 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
899 rc = mParent->i_saveSettings();
900 }
901
902 return rc;
903}
904
905HRESULT SystemProperties::getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
906{
907 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
908
909 if (m->strDefaultAdditionsISO.isEmpty())
910 {
911 /* no guest additions, check if it showed up in the mean time */
912 alock.release();
913 {
914 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
915 ErrorInfoKeeper eik;
916 (void)setDefaultAdditionsISO("");
917 }
918 alock.acquire();
919 }
920 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
921
922 return S_OK;
923}
924
925HRESULT SystemProperties::setDefaultAdditionsISO(const com::Utf8Str &aDefaultAdditionsISO)
926{
927 /** @todo not yet implemented, settings handling is missing */
928 ReturnComNotImplemented();
929
930 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
931 HRESULT rc = setDefaultAdditionsISO(aDefaultAdditionsISO);
932 alock.release();
933
934 if (SUCCEEDED(rc))
935 {
936 // VirtualBox::i_saveSettings() needs vbox write lock
937 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
938 rc = mParent->i_saveSettings();
939 }
940
941 return rc;
942}
943
944HRESULT SystemProperties::getDefaultFrontend(com::Utf8Str &aDefaultFrontend)
945{
946 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
947 aDefaultFrontend = m->strDefaultFrontend;
948 return S_OK;
949}
950
951HRESULT SystemProperties::setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
952{
953 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
954 if (m->strDefaultFrontend == Utf8Str(aDefaultFrontend))
955 return S_OK;
956 HRESULT rc = setDefaultFrontend(aDefaultFrontend);
957 alock.release();
958
959 if (SUCCEEDED(rc))
960 {
961 // VirtualBox::i_saveSettings() needs vbox write lock
962 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
963 rc = mParent->i_saveSettings();
964 }
965
966 return rc;
967}
968
969HRESULT SystemProperties::getScreenShotFormats(std::vector<BitmapFormat_T> &aBitmapFormats)
970{
971 aBitmapFormats.push_back(BitmapFormat_BGR0);
972 aBitmapFormats.push_back(BitmapFormat_BGRA);
973 aBitmapFormats.push_back(BitmapFormat_RGBA);
974 aBitmapFormats.push_back(BitmapFormat_PNG);
975 return S_OK;
976}
977
978// public methods only for internal purposes
979/////////////////////////////////////////////////////////////////////////////
980
981HRESULT SystemProperties::i_loadSettings(const settings::SystemProperties &data)
982{
983 AutoCaller autoCaller(this);
984 if (FAILED(autoCaller.rc())) return autoCaller.rc();
985
986 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
987 HRESULT rc = S_OK;
988 rc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
989 if (FAILED(rc)) return rc;
990
991 rc = i_setLoggingLevel(data.strLoggingLevel);
992 if (FAILED(rc)) return rc;
993
994 rc = i_setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
995 if (FAILED(rc)) return rc;
996
997 rc = i_setVRDEAuthLibrary(data.strVRDEAuthLibrary);
998 if (FAILED(rc)) return rc;
999
1000 rc = i_setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
1001 if (FAILED(rc)) return rc;
1002
1003 rc = i_setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
1004 if (FAILED(rc)) return rc;
1005
1006 m->ulLogHistoryCount = data.ulLogHistoryCount;
1007 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
1008
1009 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
1010 if (FAILED(rc)) return rc;
1011
1012 {
1013 /* must ignore errors signalled here, because the guest additions
1014 * file may not exist, and in this case keep the empty string */
1015 ErrorInfoKeeper eik;
1016 (void)i_setDefaultAdditionsISO(data.strDefaultAdditionsISO);
1017 }
1018
1019 rc = i_setDefaultFrontend(data.strDefaultFrontend);
1020 if (FAILED(rc)) return rc;
1021
1022 return S_OK;
1023}
1024
1025HRESULT SystemProperties::i_saveSettings(settings::SystemProperties &data)
1026{
1027 AutoCaller autoCaller(this);
1028 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1029
1030 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1031
1032 data = *m;
1033
1034 return S_OK;
1035}
1036
1037/**
1038 * Returns a medium format object corresponding to the given format
1039 * identifier or null if no such format.
1040 *
1041 * @param aFormat Format identifier.
1042 *
1043 * @return ComObjPtr<MediumFormat>
1044 */
1045ComObjPtr<MediumFormat> SystemProperties::i_mediumFormat(const Utf8Str &aFormat)
1046{
1047 ComObjPtr<MediumFormat> format;
1048
1049 AutoCaller autoCaller(this);
1050 AssertComRCReturn (autoCaller.rc(), format);
1051
1052 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1053
1054 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1055 it != m_llMediumFormats.end();
1056 ++ it)
1057 {
1058 /* MediumFormat is all const, no need to lock */
1059
1060 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
1061 {
1062 format = *it;
1063 break;
1064 }
1065 }
1066
1067 return format;
1068}
1069
1070/**
1071 * Returns a medium format object corresponding to the given file extension or
1072 * null if no such format.
1073 *
1074 * @param aExt File extension.
1075 *
1076 * @return ComObjPtr<MediumFormat>
1077 */
1078ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt)
1079{
1080 ComObjPtr<MediumFormat> format;
1081
1082 AutoCaller autoCaller(this);
1083 AssertComRCReturn (autoCaller.rc(), format);
1084
1085 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1086
1087 bool fFound = false;
1088 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1089 it != m_llMediumFormats.end() && !fFound;
1090 ++it)
1091 {
1092 /* MediumFormat is all const, no need to lock */
1093 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
1094 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
1095 it1 != aFileList.end();
1096 ++it1)
1097 {
1098 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
1099 {
1100 format = *it;
1101 fFound = true;
1102 break;
1103 }
1104 }
1105 }
1106
1107 return format;
1108}
1109
1110
1111/**
1112 * VD plugin load
1113 */
1114int SystemProperties::i_loadVDPlugin(const char *pszPluginLibrary)
1115{
1116 return VDPluginLoadFromFilename(pszPluginLibrary);
1117}
1118
1119/**
1120 * VD plugin unload
1121 */
1122int SystemProperties::i_unloadVDPlugin(const char *pszPluginLibrary)
1123{
1124 return VDPluginUnloadFromFilename(pszPluginLibrary);
1125}
1126
1127// private methods
1128/////////////////////////////////////////////////////////////////////////////
1129
1130/**
1131 * Returns the user's home directory. Wrapper around RTPathUserHome().
1132 * @param strPath
1133 * @return
1134 */
1135HRESULT SystemProperties::i_getUserHomeDirectory(Utf8Str &strPath)
1136{
1137 char szHome[RTPATH_MAX];
1138 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1139 if (RT_FAILURE(vrc))
1140 return setError(E_FAIL,
1141 tr("Cannot determine user home directory (%Rrc)"),
1142 vrc);
1143 strPath = szHome;
1144 return S_OK;
1145}
1146
1147/**
1148 * Internal implementation to set the default machine folder. Gets called
1149 * from the public attribute setter as well as loadSettings(). With 4.0,
1150 * the "default default" machine folder has changed, and we now require
1151 * a full path always.
1152 * @param aPath
1153 * @return
1154 */
1155HRESULT SystemProperties::i_setDefaultMachineFolder(const Utf8Str &strPath)
1156{
1157 Utf8Str path(strPath); // make modifiable
1158 if ( path.isEmpty() // used by API calls to reset the default
1159 || path == "Machines" // this value (exactly like this, without path) is stored
1160 // in VirtualBox.xml if user upgrades from before 4.0 and
1161 // has not changed the default machine folder
1162 )
1163 {
1164 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1165 HRESULT rc = i_getUserHomeDirectory(path);
1166 if (FAILED(rc)) return rc;
1167 path += RTPATH_SLASH_STR "VirtualBox VMs";
1168 }
1169
1170 if (!RTPathStartsWithRoot(path.c_str()))
1171 return setError(E_INVALIDARG,
1172 tr("Given default machine folder '%s' is not fully qualified"),
1173 path.c_str());
1174
1175 m->strDefaultMachineFolder = path;
1176
1177 return S_OK;
1178}
1179
1180HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
1181{
1182 Utf8Str useLoggingLevel(aLoggingLevel);
1183 int rc = RTLogGroupSettings(RTLogRelDefaultInstance(), useLoggingLevel.c_str());
1184 // If failed and not the default logging level - try to use the default logging level.
1185 if (RT_FAILURE(rc))
1186 {
1187 // If failed write message to the release log.
1188 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
1189 // If attempted logging level not the default one then try the default one.
1190 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
1191 {
1192 rc = RTLogGroupSettings(RTLogRelDefaultInstance(), VBOXSVC_LOG_DEFAULT);
1193 // If failed report this to the release log.
1194 if (RT_FAILURE(rc))
1195 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
1196 }
1197 // On any failure - set default level as the one to be stored.
1198 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1199 }
1200 // Set to passed value or if default used/attempted (even if error condition) use empty string.
1201 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
1202 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
1203}
1204
1205HRESULT SystemProperties::i_setDefaultHardDiskFormat(const com::Utf8Str &aFormat)
1206{
1207 if (!aFormat.isEmpty())
1208 m->strDefaultHardDiskFormat = aFormat;
1209 else
1210 m->strDefaultHardDiskFormat = "VDI";
1211
1212 return S_OK;
1213}
1214
1215HRESULT SystemProperties::i_setVRDEAuthLibrary(const com::Utf8Str &aPath)
1216{
1217 if (!aPath.isEmpty())
1218 m->strVRDEAuthLibrary = aPath;
1219 else
1220 m->strVRDEAuthLibrary = "VBoxAuth";
1221
1222 return S_OK;
1223}
1224
1225HRESULT SystemProperties::i_setWebServiceAuthLibrary(const com::Utf8Str &aPath)
1226{
1227 if (!aPath.isEmpty())
1228 m->strWebServiceAuthLibrary = aPath;
1229 else
1230 m->strWebServiceAuthLibrary = "VBoxAuth";
1231
1232 return S_OK;
1233}
1234
1235HRESULT SystemProperties::i_setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
1236{
1237 m->strDefaultVRDEExtPack = aExtPack;
1238
1239 return S_OK;
1240}
1241
1242HRESULT SystemProperties::i_setAutostartDatabasePath(const com::Utf8Str &aPath)
1243{
1244 HRESULT rc = S_OK;
1245 AutostartDb *autostartDb = this->mParent->i_getAutostartDb();
1246
1247 if (!aPath.isEmpty())
1248 {
1249 /* Update path in the autostart database. */
1250 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
1251 if (RT_SUCCESS(vrc))
1252 m->strAutostartDatabasePath = aPath;
1253 else
1254 rc = setError(E_FAIL,
1255 tr("Cannot set the autostart database path (%Rrc)"),
1256 vrc);
1257 }
1258 else
1259 {
1260 int vrc = autostartDb->setAutostartDbPath(NULL);
1261 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
1262 m->strAutostartDatabasePath = "";
1263 else
1264 rc = setError(E_FAIL,
1265 tr("Deleting the autostart database path failed (%Rrc)"),
1266 vrc);
1267 }
1268
1269 return rc;
1270}
1271
1272HRESULT SystemProperties::i_setDefaultAdditionsISO(const com::Utf8Str &aPath)
1273{
1274 com::Utf8Str path(aPath);
1275 if (path.isEmpty())
1276 {
1277 char strTemp[RTPATH_MAX];
1278 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
1279 AssertRC(vrc);
1280 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
1281
1282 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
1283 AssertRC(vrc);
1284 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
1285
1286 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
1287 AssertRC(vrc);
1288 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%s.iso", strTemp, VirtualBox::i_getVersionNormalized().c_str());
1289
1290 /* Check the standard image locations */
1291 if (RTFileExists(strSrc1.c_str()))
1292 path = strSrc1;
1293 else if (RTFileExists(strSrc2.c_str()))
1294 path = strSrc2;
1295 else if (RTFileExists(strSrc3.c_str()))
1296 path = strSrc3;
1297 else
1298 return setError(E_FAIL,
1299 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
1300 }
1301
1302 if (!RTPathStartsWithRoot(path.c_str()))
1303 return setError(E_INVALIDARG,
1304 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
1305 path.c_str());
1306
1307 if (!RTFileExists(path.c_str()))
1308 return setError(E_INVALIDARG,
1309 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
1310 path.c_str());
1311
1312 m->strDefaultAdditionsISO = path;
1313
1314 return S_OK;
1315}
1316
1317HRESULT SystemProperties::i_setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
1318{
1319 m->strDefaultFrontend = aDefaultFrontend;
1320
1321 return S_OK;
1322}
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