VirtualBox

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

Last change on this file since 50447 was 50355, checked in by vboxsync, 11 years ago

6813 stage 7 VirtualBoxImpl.cpp etc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.6 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 50355 2014-02-06 17:55:07Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2013 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 {
578 cCtrs = 1;
579 break;
580 }
581 default:
582 AssertMsgFailed(("Invalid bus type %d\n", aType));
583 }
584
585 *aMaxInstances = cCtrs;
586
587 return S_OK;
588}
589
590HRESULT SystemProperties::getDefaultMachineFolder(com::Utf8Str &aDefaultMachineFolder)
591{
592 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
593 aDefaultMachineFolder = m->strDefaultMachineFolder;
594 return S_OK;
595}
596
597HRESULT SystemProperties::setDefaultMachineFolder(const com::Utf8Str &aDefaultMachineFolder)
598{
599 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
600 HRESULT rc = i_setDefaultMachineFolder(aDefaultMachineFolder);
601 alock.release();
602 if (SUCCEEDED(rc))
603 {
604 // VirtualBox::i_saveSettings() needs vbox write lock
605 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
606 rc = mParent->i_saveSettings();
607 }
608
609 return rc;
610}
611
612HRESULT SystemProperties::getLoggingLevel(com::Utf8Str &aLoggingLevel)
613{
614 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
615
616 aLoggingLevel = m->strLoggingLevel;
617
618 if (aLoggingLevel.isEmpty())
619 aLoggingLevel = VBOXSVC_LOG_DEFAULT;
620
621 return S_OK;
622}
623
624
625HRESULT SystemProperties::setLoggingLevel(const com::Utf8Str &aLoggingLevel)
626{
627 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
628 HRESULT rc = i_setLoggingLevel(aLoggingLevel);
629 alock.release();
630
631 if (SUCCEEDED(rc))
632 {
633 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
634 rc = mParent->i_saveSettings();
635 }
636 else
637 LogRel(("Cannot set passed logging level=%ls, or the default one - Error=%Rhrc \n", Bstr(aLoggingLevel).raw(), rc));
638
639 return rc;
640}
641
642HRESULT SystemProperties::getMediumFormats(std::vector<ComPtr<IMediumFormat> > &aMediumFormats)
643{
644 MediumFormatList mediumFormats(m_llMediumFormats);
645 aMediumFormats.resize(mediumFormats.size());
646 size_t i = 0;
647 for (MediumFormatList::const_iterator it = mediumFormats.begin(); it != mediumFormats.end(); ++it, ++i)
648 (*it).queryInterfaceTo(aMediumFormats[i].asOutParam());
649 return S_OK;
650}
651
652HRESULT SystemProperties::getDefaultHardDiskFormat(com::Utf8Str &aDefaultHardDiskFormat)
653{
654 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
655 aDefaultHardDiskFormat = m->strDefaultHardDiskFormat;
656 return S_OK;
657}
658
659
660HRESULT SystemProperties::setDefaultHardDiskFormat(const com::Utf8Str &aDefaultHardDiskFormat)
661{
662 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
663 HRESULT rc = i_setDefaultHardDiskFormat(aDefaultHardDiskFormat);
664 alock.release();
665 if (SUCCEEDED(rc))
666 {
667 // VirtualBox::i_saveSettings() needs vbox write lock
668 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
669 rc = mParent->i_saveSettings();
670 }
671
672 return rc;
673}
674
675HRESULT SystemProperties::getFreeDiskSpaceWarning(LONG64 *aFreeSpace)
676{
677 NOREF(aFreeSpace);
678 ReturnComNotImplemented();
679}
680
681HRESULT SystemProperties::setFreeDiskSpaceWarning(LONG64 /* aFreeSpace */)
682{
683 ReturnComNotImplemented();
684}
685
686HRESULT SystemProperties::getFreeDiskSpacePercentWarning(ULONG *aFreeSpacePercent)
687{
688 NOREF(aFreeSpacePercent);
689 ReturnComNotImplemented();
690}
691
692HRESULT SystemProperties::setFreeDiskSpacePercentWarning(ULONG /* aFreeSpacePercent */)
693{
694 ReturnComNotImplemented();
695}
696
697HRESULT SystemProperties::getFreeDiskSpaceError(LONG64 *aFreeSpace)
698{
699 NOREF(aFreeSpace);
700 ReturnComNotImplemented();
701}
702
703HRESULT SystemProperties::setFreeDiskSpaceError(LONG64 /* aFreeSpace */)
704{
705 ReturnComNotImplemented();
706}
707
708HRESULT SystemProperties::getFreeDiskSpacePercentError(ULONG *aFreeSpacePercent)
709{
710 NOREF(aFreeSpacePercent);
711 ReturnComNotImplemented();
712}
713
714HRESULT SystemProperties::setFreeDiskSpacePercentError(ULONG /* aFreeSpacePercent */)
715{
716 ReturnComNotImplemented();
717}
718
719HRESULT SystemProperties::getVRDEAuthLibrary(com::Utf8Str &aVRDEAuthLibrary)
720{
721 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
722
723 aVRDEAuthLibrary = m->strVRDEAuthLibrary;
724
725 return S_OK;
726}
727
728HRESULT SystemProperties::setVRDEAuthLibrary(const com::Utf8Str &aVRDEAuthLibrary)
729{
730 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
731 HRESULT rc = i_setVRDEAuthLibrary(aVRDEAuthLibrary);
732 alock.release();
733 if (SUCCEEDED(rc))
734 {
735 // VirtualBox::i_saveSettings() needs vbox write lock
736 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
737 rc = mParent->i_saveSettings();
738 }
739
740 return rc;
741}
742
743HRESULT SystemProperties::getWebServiceAuthLibrary(com::Utf8Str &aWebServiceAuthLibrary)
744{
745 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
746
747 aWebServiceAuthLibrary = m->strWebServiceAuthLibrary;
748
749 return S_OK;
750}
751
752HRESULT SystemProperties::setWebServiceAuthLibrary(const com::Utf8Str &aWebServiceAuthLibrary)
753{
754 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
755 HRESULT rc = i_setWebServiceAuthLibrary(aWebServiceAuthLibrary);
756 alock.release();
757
758 if (SUCCEEDED(rc))
759 {
760 // VirtualBox::i_saveSettings() needs vbox write lock
761 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
762 rc = mParent->i_saveSettings();
763 }
764
765 return rc;
766}
767
768HRESULT SystemProperties::getDefaultVRDEExtPack(com::Utf8Str &aExtPack)
769{
770 HRESULT hrc = S_OK;
771 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
772 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
773 if (strExtPack.isNotEmpty())
774 {
775 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
776 hrc = S_OK;
777 else
778#ifdef VBOX_WITH_EXTPACK
779 hrc = mParent->i_getExtPackManager()->checkVrdeExtPack(&strExtPack);
780#else
781 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
782#endif
783 }
784 else
785 {
786#ifdef VBOX_WITH_EXTPACK
787 hrc = mParent->i_getExtPackManager()->getDefaultVrdeExtPack(&strExtPack);
788#endif
789 if (strExtPack.isEmpty())
790 {
791 /*
792 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
793 * This is hardcoded uglyness, sorry.
794 */
795 char szPath[RTPATH_MAX];
796 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
797 if (RT_SUCCESS(vrc))
798 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
799 if (RT_SUCCESS(vrc))
800 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
801 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
802 {
803 /* Illegal extpack name, so no conflict. */
804 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
805 }
806 }
807 }
808
809 if (SUCCEEDED(hrc))
810 aExtPack = strExtPack;
811
812 return S_OK;
813}
814
815
816HRESULT SystemProperties::setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
817{
818 HRESULT hrc = S_OK;
819 if (aExtPack.isNotEmpty())
820 {
821 if (aExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
822 hrc = S_OK;
823 else
824#ifdef VBOX_WITH_EXTPACK
825 hrc = mParent->i_getExtPackManager()->checkVrdeExtPack(&aExtPack);
826#else
827 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), aExtPack.c_str());
828#endif
829 }
830 if (SUCCEEDED(hrc))
831 {
832 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
833 hrc = i_setDefaultVRDEExtPack(aExtPack);
834 if (SUCCEEDED(hrc))
835 {
836 /* VirtualBox::i_saveSettings() needs the VirtualBox write lock. */
837 alock.release();
838 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
839 hrc = mParent->i_saveSettings();
840 }
841 }
842
843 return hrc;
844}
845
846
847HRESULT SystemProperties::getLogHistoryCount(ULONG *count)
848{
849 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
850
851 *count = m->ulLogHistoryCount;
852
853 return S_OK;
854}
855
856
857HRESULT SystemProperties::setLogHistoryCount(ULONG count)
858{
859 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
860 m->ulLogHistoryCount = count;
861 alock.release();
862
863 // VirtualBox::i_saveSettings() needs vbox write lock
864 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
865 HRESULT rc = mParent->i_saveSettings();
866
867 return rc;
868}
869
870HRESULT SystemProperties::getDefaultAudioDriver(AudioDriverType_T *aAudioDriver)
871{
872 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
873
874 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
875
876 return S_OK;
877}
878
879HRESULT SystemProperties::getAutostartDatabasePath(com::Utf8Str &aAutostartDbPath)
880{
881 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
882
883 aAutostartDbPath = m->strAutostartDatabasePath;
884
885 return S_OK;
886}
887
888HRESULT SystemProperties::setAutostartDatabasePath(const com::Utf8Str &aAutostartDbPath)
889{
890 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
891 HRESULT rc = i_setAutostartDatabasePath(aAutostartDbPath);
892 alock.release();
893
894 if (SUCCEEDED(rc))
895 {
896 // VirtualBox::i_saveSettings() needs vbox write lock
897 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
898 rc = mParent->i_saveSettings();
899 }
900
901 return rc;
902}
903
904HRESULT SystemProperties::getDefaultAdditionsISO(com::Utf8Str &aDefaultAdditionsISO)
905{
906 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
907
908 if (m->strDefaultAdditionsISO.isEmpty())
909 {
910 /* no guest additions, check if it showed up in the mean time */
911 alock.release();
912 {
913 AutoWriteLock wlock(this COMMA_LOCKVAL_SRC_POS);
914 ErrorInfoKeeper eik;
915 (void)setDefaultAdditionsISO("");
916 }
917 alock.acquire();
918 }
919 aDefaultAdditionsISO = m->strDefaultAdditionsISO;
920
921 return S_OK;
922}
923
924HRESULT SystemProperties::setDefaultAdditionsISO(const com::Utf8Str &aDefaultAdditionsISO)
925{
926 /** @todo not yet implemented, settings handling is missing */
927 ReturnComNotImplemented();
928
929 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
930 HRESULT rc = setDefaultAdditionsISO(aDefaultAdditionsISO);
931 alock.release();
932
933 if (SUCCEEDED(rc))
934 {
935 // VirtualBox::i_saveSettings() needs vbox write lock
936 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
937 rc = mParent->i_saveSettings();
938 }
939
940 return rc;
941}
942
943HRESULT SystemProperties::getDefaultFrontend(com::Utf8Str &aDefaultFrontend)
944{
945 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
946 aDefaultFrontend = m->strDefaultFrontend;
947 return S_OK;
948}
949
950HRESULT SystemProperties::setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
951{
952 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
953 if (m->strDefaultFrontend == Utf8Str(aDefaultFrontend))
954 return S_OK;
955 HRESULT rc = setDefaultFrontend(aDefaultFrontend);
956 alock.release();
957
958 if (SUCCEEDED(rc))
959 {
960 // VirtualBox::i_saveSettings() needs vbox write lock
961 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
962 rc = mParent->i_saveSettings();
963 }
964
965 return rc;
966}
967
968// public methods only for internal purposes
969/////////////////////////////////////////////////////////////////////////////
970
971HRESULT SystemProperties::i_loadSettings(const settings::SystemProperties &data)
972{
973 AutoCaller autoCaller(this);
974 if (FAILED(autoCaller.rc())) return autoCaller.rc();
975
976 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
977 HRESULT rc = S_OK;
978 rc = i_setDefaultMachineFolder(data.strDefaultMachineFolder);
979 if (FAILED(rc)) return rc;
980
981 rc = i_setLoggingLevel(data.strLoggingLevel);
982 if (FAILED(rc)) return rc;
983
984 rc = i_setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
985 if (FAILED(rc)) return rc;
986
987 rc = i_setVRDEAuthLibrary(data.strVRDEAuthLibrary);
988 if (FAILED(rc)) return rc;
989
990 rc = i_setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
991 if (FAILED(rc)) return rc;
992
993 rc = i_setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
994 if (FAILED(rc)) return rc;
995
996 m->ulLogHistoryCount = data.ulLogHistoryCount;
997 m->fExclusiveHwVirt = data.fExclusiveHwVirt;
998
999 rc = i_setAutostartDatabasePath(data.strAutostartDatabasePath);
1000 if (FAILED(rc)) return rc;
1001
1002 {
1003 /* must ignore errors signalled here, because the guest additions
1004 * file may not exist, and in this case keep the empty string */
1005 ErrorInfoKeeper eik;
1006 (void)i_setDefaultAdditionsISO(data.strDefaultAdditionsISO);
1007 }
1008
1009 rc = i_setDefaultFrontend(data.strDefaultFrontend);
1010 if (FAILED(rc)) return rc;
1011
1012 return S_OK;
1013}
1014
1015HRESULT SystemProperties::i_saveSettings(settings::SystemProperties &data)
1016{
1017 AutoCaller autoCaller(this);
1018 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1019
1020 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1021
1022 data = *m;
1023
1024 return S_OK;
1025}
1026
1027/**
1028 * Returns a medium format object corresponding to the given format
1029 * identifier or null if no such format.
1030 *
1031 * @param aFormat Format identifier.
1032 *
1033 * @return ComObjPtr<MediumFormat>
1034 */
1035ComObjPtr<MediumFormat> SystemProperties::i_mediumFormat(const Utf8Str &aFormat)
1036{
1037 ComObjPtr<MediumFormat> format;
1038
1039 AutoCaller autoCaller(this);
1040 AssertComRCReturn (autoCaller.rc(), format);
1041
1042 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1043
1044 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1045 it != m_llMediumFormats.end();
1046 ++ it)
1047 {
1048 /* MediumFormat is all const, no need to lock */
1049
1050 if ((*it)->i_getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
1051 {
1052 format = *it;
1053 break;
1054 }
1055 }
1056
1057 return format;
1058}
1059
1060/**
1061 * Returns a medium format object corresponding to the given file extension or
1062 * null if no such format.
1063 *
1064 * @param aExt File extension.
1065 *
1066 * @return ComObjPtr<MediumFormat>
1067 */
1068ComObjPtr<MediumFormat> SystemProperties::i_mediumFormatFromExtension(const Utf8Str &aExt)
1069{
1070 ComObjPtr<MediumFormat> format;
1071
1072 AutoCaller autoCaller(this);
1073 AssertComRCReturn (autoCaller.rc(), format);
1074
1075 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1076
1077 bool fFound = false;
1078 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1079 it != m_llMediumFormats.end() && !fFound;
1080 ++it)
1081 {
1082 /* MediumFormat is all const, no need to lock */
1083 MediumFormat::StrArray aFileList = (*it)->i_getFileExtensions();
1084 for (MediumFormat::StrArray::const_iterator it1 = aFileList.begin();
1085 it1 != aFileList.end();
1086 ++it1)
1087 {
1088 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
1089 {
1090 format = *it;
1091 fFound = true;
1092 break;
1093 }
1094 }
1095 }
1096
1097 return format;
1098}
1099
1100// private methods
1101/////////////////////////////////////////////////////////////////////////////
1102
1103/**
1104 * Returns the user's home directory. Wrapper around RTPathUserHome().
1105 * @param strPath
1106 * @return
1107 */
1108HRESULT SystemProperties::i_getUserHomeDirectory(Utf8Str &strPath)
1109{
1110 char szHome[RTPATH_MAX];
1111 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1112 if (RT_FAILURE(vrc))
1113 return setError(E_FAIL,
1114 tr("Cannot determine user home directory (%Rrc)"),
1115 vrc);
1116 strPath = szHome;
1117 return S_OK;
1118}
1119
1120/**
1121 * Internal implementation to set the default machine folder. Gets called
1122 * from the public attribute setter as well as loadSettings(). With 4.0,
1123 * the "default default" machine folder has changed, and we now require
1124 * a full path always.
1125 * @param aPath
1126 * @return
1127 */
1128HRESULT SystemProperties::i_setDefaultMachineFolder(const Utf8Str &strPath)
1129{
1130 Utf8Str path(strPath); // make modifiable
1131 if ( path.isEmpty() // used by API calls to reset the default
1132 || path == "Machines" // this value (exactly like this, without path) is stored
1133 // in VirtualBox.xml if user upgrades from before 4.0 and
1134 // has not changed the default machine folder
1135 )
1136 {
1137 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1138 HRESULT rc = i_getUserHomeDirectory(path);
1139 if (FAILED(rc)) return rc;
1140 path += RTPATH_SLASH_STR "VirtualBox VMs";
1141 }
1142
1143 if (!RTPathStartsWithRoot(path.c_str()))
1144 return setError(E_INVALIDARG,
1145 tr("Given default machine folder '%s' is not fully qualified"),
1146 path.c_str());
1147
1148 m->strDefaultMachineFolder = path;
1149
1150 return S_OK;
1151}
1152
1153HRESULT SystemProperties::i_setLoggingLevel(const com::Utf8Str &aLoggingLevel)
1154{
1155 Utf8Str useLoggingLevel(aLoggingLevel);
1156 int rc = RTLogGroupSettings(RTLogRelDefaultInstance(), useLoggingLevel.c_str());
1157 // If failed and not the default logging level - try to use the default logging level.
1158 if (RT_FAILURE(rc))
1159 {
1160 // If failed write message to the release log.
1161 LogRel(("Cannot set passed logging level=%s Error=%Rrc \n", useLoggingLevel.c_str(), rc));
1162 // If attempted logging level not the default one then try the default one.
1163 if (!useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT))
1164 {
1165 rc = RTLogGroupSettings(RTLogRelDefaultInstance(), VBOXSVC_LOG_DEFAULT);
1166 // If failed report this to the release log.
1167 if (RT_FAILURE(rc))
1168 LogRel(("Cannot set default logging level Error=%Rrc \n", rc));
1169 }
1170 // On any failure - set default level as the one to be stored.
1171 useLoggingLevel = VBOXSVC_LOG_DEFAULT;
1172 }
1173 // Set to passed value or if default used/attempted (even if error condition) use empty string.
1174 m->strLoggingLevel = (useLoggingLevel.equals(VBOXSVC_LOG_DEFAULT) ? "" : useLoggingLevel);
1175 return RT_SUCCESS(rc) ? S_OK : E_FAIL;
1176}
1177
1178HRESULT SystemProperties::i_setDefaultHardDiskFormat(const com::Utf8Str &aFormat)
1179{
1180 if (!aFormat.isEmpty())
1181 m->strDefaultHardDiskFormat = aFormat;
1182 else
1183 m->strDefaultHardDiskFormat = "VDI";
1184
1185 return S_OK;
1186}
1187
1188HRESULT SystemProperties::i_setVRDEAuthLibrary(const com::Utf8Str &aPath)
1189{
1190 if (!aPath.isEmpty())
1191 m->strVRDEAuthLibrary = aPath;
1192 else
1193 m->strVRDEAuthLibrary = "VBoxAuth";
1194
1195 return S_OK;
1196}
1197
1198HRESULT SystemProperties::i_setWebServiceAuthLibrary(const com::Utf8Str &aPath)
1199{
1200 if (!aPath.isEmpty())
1201 m->strWebServiceAuthLibrary = aPath;
1202 else
1203 m->strWebServiceAuthLibrary = "VBoxAuth";
1204
1205 return S_OK;
1206}
1207
1208HRESULT SystemProperties::i_setDefaultVRDEExtPack(const com::Utf8Str &aExtPack)
1209{
1210 m->strDefaultVRDEExtPack = aExtPack;
1211
1212 return S_OK;
1213}
1214
1215HRESULT SystemProperties::i_setAutostartDatabasePath(const com::Utf8Str &aPath)
1216{
1217 HRESULT rc = S_OK;
1218 AutostartDb *autostartDb = this->mParent->i_getAutostartDb();
1219
1220 if (!aPath.isEmpty())
1221 {
1222 /* Update path in the autostart database. */
1223 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
1224 if (RT_SUCCESS(vrc))
1225 m->strAutostartDatabasePath = aPath;
1226 else
1227 rc = setError(E_FAIL,
1228 tr("Cannot set the autostart database path (%Rrc)"),
1229 vrc);
1230 }
1231 else
1232 {
1233 int vrc = autostartDb->setAutostartDbPath(NULL);
1234 if (RT_SUCCESS(vrc) || vrc == VERR_NOT_SUPPORTED)
1235 m->strAutostartDatabasePath = "";
1236 else
1237 rc = setError(E_FAIL,
1238 tr("Deleting the autostart database path failed (%Rrc)"),
1239 vrc);
1240 }
1241
1242 return rc;
1243}
1244
1245HRESULT SystemProperties::i_setDefaultAdditionsISO(const com::Utf8Str &aPath)
1246{
1247 com::Utf8Str path(aPath);
1248 if (path.isEmpty())
1249 {
1250 char strTemp[RTPATH_MAX];
1251 int vrc = RTPathAppPrivateNoArch(strTemp, sizeof(strTemp));
1252 AssertRC(vrc);
1253 Utf8Str strSrc1 = Utf8Str(strTemp).append("/VBoxGuestAdditions.iso");
1254
1255 vrc = RTPathExecDir(strTemp, sizeof(strTemp));
1256 AssertRC(vrc);
1257 Utf8Str strSrc2 = Utf8Str(strTemp).append("/additions/VBoxGuestAdditions.iso");
1258
1259 vrc = RTPathUserHome(strTemp, sizeof(strTemp));
1260 AssertRC(vrc);
1261 Utf8Str strSrc3 = Utf8StrFmt("%s/VBoxGuestAdditions_%ls.iso", strTemp, Bstr(VirtualBox::i_getVersionNormalized()).raw());
1262
1263 /* Check the standard image locations */
1264 if (RTFileExists(strSrc1.c_str()))
1265 path = strSrc1;
1266 else if (RTFileExists(strSrc2.c_str()))
1267 path = strSrc2;
1268 else if (RTFileExists(strSrc3.c_str()))
1269 path = strSrc3;
1270 else
1271 return setError(E_FAIL,
1272 tr("Cannot determine default Guest Additions ISO location. Most likely they are not available"));
1273 }
1274
1275 if (!RTPathStartsWithRoot(path.c_str()))
1276 return setError(E_INVALIDARG,
1277 tr("Given default machine Guest Additions ISO file '%s' is not fully qualified"),
1278 path.c_str());
1279
1280 if (!RTFileExists(path.c_str()))
1281 return setError(E_INVALIDARG,
1282 tr("Given default machine Guest Additions ISO file '%s' does not exist"),
1283 path.c_str());
1284
1285 m->strDefaultAdditionsISO = path;
1286
1287 return S_OK;
1288}
1289
1290HRESULT SystemProperties::i_setDefaultFrontend(const com::Utf8Str &aDefaultFrontend)
1291{
1292 m->strDefaultFrontend = aDefaultFrontend;
1293
1294 return S_OK;
1295}
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