VirtualBox

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

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

Main,Frontends: TakeScreenShot API cleanup.

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