VirtualBox

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

Last change on this file since 42178 was 42178, checked in by vboxsync, 12 years ago

Autostart: Make the path to the autostart database configurable

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.9 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 42178 2012-07-17 12:35:07Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2011 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "SystemPropertiesImpl.h"
20#include "VirtualBoxImpl.h"
21#include "MachineImpl.h"
22#ifdef VBOX_WITH_EXTPACK
23# include "ExtPackManagerImpl.h"
24#endif
25#include "AutoCaller.h"
26#include "Global.h"
27#include "Logging.h"
28#include "AutostartDb.h"
29
30// generated header
31#include "SchemaDefs.h"
32
33#include <iprt/dir.h>
34#include <iprt/ldr.h>
35#include <iprt/path.h>
36#include <iprt/string.h>
37#include <iprt/cpp/utils.h>
38
39#include <VBox/err.h>
40#include <VBox/param.h>
41#include <VBox/settings.h>
42#include <VBox/vd.h>
43
44// defines
45/////////////////////////////////////////////////////////////////////////////
46
47// constructor / destructor
48/////////////////////////////////////////////////////////////////////////////
49
50SystemProperties::SystemProperties()
51 : mParent(NULL),
52 m(new settings::SystemProperties)
53{
54}
55
56SystemProperties::~SystemProperties()
57{
58 delete m;
59}
60
61
62HRESULT SystemProperties::FinalConstruct()
63{
64 return BaseFinalConstruct();
65}
66
67void SystemProperties::FinalRelease()
68{
69 uninit();
70 BaseFinalRelease();
71}
72
73// public methods only for internal purposes
74/////////////////////////////////////////////////////////////////////////////
75
76/**
77 * Initializes the system information object.
78 *
79 * @returns COM result indicator
80 */
81HRESULT SystemProperties::init(VirtualBox *aParent)
82{
83 LogFlowThisFunc(("aParent=%p\n", aParent));
84
85 ComAssertRet(aParent, E_FAIL);
86
87 /* Enclose the state transition NotReady->InInit->Ready */
88 AutoInitSpan autoInitSpan(this);
89 AssertReturn(autoInitSpan.isOk(), E_FAIL);
90
91 unconst(mParent) = aParent;
92
93 setDefaultMachineFolder(Utf8Str::Empty);
94 setDefaultHardDiskFormat(Utf8Str::Empty);
95
96 setVRDEAuthLibrary(Utf8Str::Empty);
97 setDefaultVRDEExtPack(Utf8Str::Empty);
98
99 m->ulLogHistoryCount = 3;
100
101 HRESULT rc = S_OK;
102
103 /* Fetch info of all available hd backends. */
104
105 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
106 /// any number of backends
107
108 VDBACKENDINFO aVDInfo[100];
109 unsigned cEntries;
110 int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
111 AssertRC(vrc);
112 if (RT_SUCCESS(vrc))
113 {
114 for (unsigned i = 0; i < cEntries; ++ i)
115 {
116 ComObjPtr<MediumFormat> hdf;
117 rc = hdf.createObject();
118 if (FAILED(rc)) break;
119
120 rc = hdf->init(&aVDInfo[i]);
121 if (FAILED(rc)) break;
122
123 m_llMediumFormats.push_back(hdf);
124 }
125 }
126
127 /* Confirm a successful initialization */
128 if (SUCCEEDED(rc))
129 autoInitSpan.setSucceeded();
130
131 return rc;
132}
133
134/**
135 * Uninitializes the instance and sets the ready flag to FALSE.
136 * Called either from FinalRelease() or by the parent when it gets destroyed.
137 */
138void SystemProperties::uninit()
139{
140 LogFlowThisFunc(("\n"));
141
142 /* Enclose the state transition Ready->InUninit->NotReady */
143 AutoUninitSpan autoUninitSpan(this);
144 if (autoUninitSpan.uninitDone())
145 return;
146
147 unconst(mParent) = NULL;
148}
149
150// ISystemProperties properties
151/////////////////////////////////////////////////////////////////////////////
152
153
154STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
155{
156 CheckComArgOutPointerValid(minRAM);
157
158 AutoCaller autoCaller(this);
159 if (FAILED(autoCaller.rc())) return autoCaller.rc();
160
161 /* no need to lock, this is const */
162 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
163 *minRAM = MM_RAM_MIN_IN_MB;
164
165 return S_OK;
166}
167
168STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
169{
170 CheckComArgOutPointerValid(maxRAM);
171
172 AutoCaller autoCaller(this);
173 if (FAILED(autoCaller.rc())) return autoCaller.rc();
174
175 /* no need to lock, this is const */
176 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
177 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
178 ULONG maxRAMArch = maxRAMSys;
179 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
180
181 return S_OK;
182}
183
184STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
185{
186 CheckComArgOutPointerValid(minVRAM);
187
188 AutoCaller autoCaller(this);
189 if (FAILED(autoCaller.rc())) return autoCaller.rc();
190
191 /* no need to lock, this is const */
192 *minVRAM = SchemaDefs::MinGuestVRAM;
193
194 return S_OK;
195}
196
197STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
198{
199 CheckComArgOutPointerValid(maxVRAM);
200
201 AutoCaller autoCaller(this);
202 if (FAILED(autoCaller.rc())) return autoCaller.rc();
203
204 /* no need to lock, this is const */
205 *maxVRAM = SchemaDefs::MaxGuestVRAM;
206
207 return S_OK;
208}
209
210STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
211{
212 CheckComArgOutPointerValid(minCPUCount);
213
214 AutoCaller autoCaller(this);
215 if (FAILED(autoCaller.rc())) return autoCaller.rc();
216
217 /* no need to lock, this is const */
218 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
219
220 return S_OK;
221}
222
223STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
224{
225 CheckComArgOutPointerValid(maxCPUCount);
226
227 AutoCaller autoCaller(this);
228 if (FAILED(autoCaller.rc())) return autoCaller.rc();
229
230 /* no need to lock, this is const */
231 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
232
233 return S_OK;
234}
235
236STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
237{
238 CheckComArgOutPointerValid(maxMonitors);
239
240 AutoCaller autoCaller(this);
241 if (FAILED(autoCaller.rc())) return autoCaller.rc();
242
243 /* no need to lock, this is const */
244 *maxMonitors = SchemaDefs::MaxGuestMonitors;
245
246 return S_OK;
247}
248
249STDMETHODIMP SystemProperties::COMGETTER(InfoVDSize)(LONG64 *infoVDSize)
250{
251 CheckComArgOutPointerValid(infoVDSize);
252
253 AutoCaller autoCaller(this);
254 if (FAILED(autoCaller.rc())) return autoCaller.rc();
255
256 /*
257 * The BIOS supports currently 32 bit LBA numbers (implementing the full
258 * 48 bit range is in theory trivial, but the crappy compiler makes things
259 * more difficult). This translates to almost 2 TiBytes (to be on the safe
260 * side, the reported limit is 1 MiByte less than that, as the total number
261 * of sectors should fit in 32 bits, too), which should be enough for the
262 * moment. Since the MBR partition tables support only 32bit sector numbers
263 * and thus the BIOS can only boot from disks smaller than 2T this is a
264 * rather hard limit.
265 *
266 * The virtual ATA/SATA disks support complete LBA48, and SCSI supports
267 * LBA64 (almost, more like LBA55 in practice), so the theoretical maximum
268 * disk size is 128 PiByte/16 EiByte. The GUI works nicely with 6 orders
269 * of magnitude, but not with 11..13 orders of magnitude.
270 */
271 /* no need to lock, this is const */
272 *infoVDSize = 2 * _1T - _1M;
273
274 return S_OK;
275}
276
277STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
278{
279 CheckComArgOutPointerValid(count);
280
281 AutoCaller autoCaller(this);
282 if (FAILED(autoCaller.rc())) return autoCaller.rc();
283
284 /* no need to lock, this is const */
285 *count = SchemaDefs::SerialPortCount;
286
287 return S_OK;
288}
289
290STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
291{
292 CheckComArgOutPointerValid(count);
293
294 AutoCaller autoCaller(this);
295 if (FAILED(autoCaller.rc())) return autoCaller.rc();
296
297 /* no need to lock, this is const */
298 *count = SchemaDefs::ParallelPortCount;
299
300 return S_OK;
301}
302
303STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
304{
305 CheckComArgOutPointerValid(aMaxBootPosition);
306
307 AutoCaller autoCaller(this);
308 if (FAILED(autoCaller.rc())) return autoCaller.rc();
309
310 /* no need to lock, this is const */
311 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
312
313 return S_OK;
314}
315
316
317STDMETHODIMP SystemProperties::GetMaxNetworkAdapters(ChipsetType_T aChipset, ULONG *count)
318{
319 CheckComArgOutPointerValid(count);
320
321 AutoCaller autoCaller(this);
322 if (FAILED(autoCaller.rc())) return autoCaller.rc();
323
324 /* no need for locking, no state */
325 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
326 if (uResult == 0)
327 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
328
329 *count = uResult;
330
331 return S_OK;
332}
333
334STDMETHODIMP SystemProperties::GetMaxNetworkAdaptersOfType(ChipsetType_T aChipset, NetworkAttachmentType_T aType, ULONG *count)
335{
336 CheckComArgOutPointerValid(count);
337
338 AutoCaller autoCaller(this);
339 if (FAILED(autoCaller.rc())) return autoCaller.rc();
340
341 /* no need for locking, no state */
342 uint32_t uResult = Global::getMaxNetworkAdapters(aChipset);
343 if (uResult == 0)
344 AssertMsgFailed(("Invalid chipset type %d\n", aChipset));
345
346 switch (aType)
347 {
348 case NetworkAttachmentType_NAT:
349 case NetworkAttachmentType_Internal:
350 /* chipset default is OK */
351 break;
352 case NetworkAttachmentType_Bridged:
353 /* Maybe use current host interface count here? */
354 break;
355 case NetworkAttachmentType_HostOnly:
356 uResult = RT_MIN(uResult, 8);
357 break;
358 default:
359 AssertMsgFailed(("Unhandled attachment type %d\n", aType));
360 }
361
362 *count = uResult;
363
364 return S_OK;
365}
366
367
368STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
369 ULONG *aMaxDevicesPerPort)
370{
371 CheckComArgOutPointerValid(aMaxDevicesPerPort);
372
373 AutoCaller autoCaller(this);
374 if (FAILED(autoCaller.rc())) return autoCaller.rc();
375
376 /* no need to lock, this is const */
377 switch (aBus)
378 {
379 case StorageBus_SATA:
380 case StorageBus_SCSI:
381 case StorageBus_SAS:
382 {
383 /* SATA and both SCSI controllers only support one device per port. */
384 *aMaxDevicesPerPort = 1;
385 break;
386 }
387 case StorageBus_IDE:
388 case StorageBus_Floppy:
389 {
390 /* The IDE and Floppy controllers support 2 devices. One as master
391 * and one as slave (or floppy drive 0 and 1). */
392 *aMaxDevicesPerPort = 2;
393 break;
394 }
395 default:
396 AssertMsgFailed(("Invalid bus type %d\n", aBus));
397 }
398
399 return S_OK;
400}
401
402STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
403 ULONG *aMinPortCount)
404{
405 CheckComArgOutPointerValid(aMinPortCount);
406
407 AutoCaller autoCaller(this);
408 if (FAILED(autoCaller.rc())) return autoCaller.rc();
409
410 /* no need to lock, this is const */
411 switch (aBus)
412 {
413 case StorageBus_SATA:
414 {
415 *aMinPortCount = 1;
416 break;
417 }
418 case StorageBus_SCSI:
419 {
420 *aMinPortCount = 16;
421 break;
422 }
423 case StorageBus_IDE:
424 {
425 *aMinPortCount = 2;
426 break;
427 }
428 case StorageBus_Floppy:
429 {
430 *aMinPortCount = 1;
431 break;
432 }
433 case StorageBus_SAS:
434 {
435 *aMinPortCount = 8;
436 break;
437 }
438 default:
439 AssertMsgFailed(("Invalid bus type %d\n", aBus));
440 }
441
442 return S_OK;
443}
444
445STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
446 ULONG *aMaxPortCount)
447{
448 CheckComArgOutPointerValid(aMaxPortCount);
449
450 AutoCaller autoCaller(this);
451 if (FAILED(autoCaller.rc())) return autoCaller.rc();
452
453 /* no need to lock, this is const */
454 switch (aBus)
455 {
456 case StorageBus_SATA:
457 {
458 *aMaxPortCount = 30;
459 break;
460 }
461 case StorageBus_SCSI:
462 {
463 *aMaxPortCount = 16;
464 break;
465 }
466 case StorageBus_IDE:
467 {
468 *aMaxPortCount = 2;
469 break;
470 }
471 case StorageBus_Floppy:
472 {
473 *aMaxPortCount = 1;
474 break;
475 }
476 case StorageBus_SAS:
477 {
478 *aMaxPortCount = 8;
479 break;
480 }
481 default:
482 AssertMsgFailed(("Invalid bus type %d\n", aBus));
483 }
484
485 return S_OK;
486}
487
488STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(ChipsetType_T aChipset,
489 StorageBus_T aBus,
490 ULONG *aMaxInstances)
491{
492 CheckComArgOutPointerValid(aMaxInstances);
493
494 AutoCaller autoCaller(this);
495 if (FAILED(autoCaller.rc())) return autoCaller.rc();
496
497 ULONG cCtrs = 0;
498
499 /* no need to lock, this is const */
500 switch (aBus)
501 {
502 case StorageBus_SATA:
503 case StorageBus_SCSI:
504 case StorageBus_SAS:
505 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
506 break;
507 case StorageBus_IDE:
508 case StorageBus_Floppy:
509 {
510 cCtrs = 1;
511 break;
512 }
513 default:
514 AssertMsgFailed(("Invalid bus type %d\n", aBus));
515 }
516
517 *aMaxInstances = cCtrs;
518
519 return S_OK;
520}
521
522STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
523 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
524{
525 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
526
527 AutoCaller autoCaller(this);
528 if (FAILED(autoCaller.rc())) return autoCaller.rc();
529
530 /* no need to lock, this is const */
531 switch (aBus)
532 {
533 case StorageBus_IDE:
534 case StorageBus_SATA:
535 {
536 com::SafeArray<DeviceType_T> saDeviceTypes(2);
537 saDeviceTypes[0] = DeviceType_DVD;
538 saDeviceTypes[1] = DeviceType_HardDisk;
539 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
540 break;
541 }
542 case StorageBus_SCSI:
543 case StorageBus_SAS:
544 {
545 com::SafeArray<DeviceType_T> saDeviceTypes(1);
546 saDeviceTypes[0] = DeviceType_HardDisk;
547 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
548 break;
549 }
550 case StorageBus_Floppy:
551 {
552 com::SafeArray<DeviceType_T> saDeviceTypes(1);
553 saDeviceTypes[0] = DeviceType_Floppy;
554 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
555 break;
556 }
557 default:
558 AssertMsgFailed(("Invalid bus type %d\n", aBus));
559 }
560
561 return S_OK;
562}
563
564STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
565{
566 CheckComArgOutPointerValid(aEnabled);
567
568 AutoCaller autoCaller(this);
569 if (FAILED(autoCaller.rc())) return autoCaller.rc();
570
571 /* no need to lock, this is const */
572 switch (aControllerType)
573 {
574 case StorageControllerType_LsiLogic:
575 case StorageControllerType_BusLogic:
576 case StorageControllerType_IntelAhci:
577 case StorageControllerType_LsiLogicSas:
578 *aEnabled = false;
579 break;
580 case StorageControllerType_PIIX3:
581 case StorageControllerType_PIIX4:
582 case StorageControllerType_ICH6:
583 case StorageControllerType_I82078:
584 *aEnabled = true;
585 break;
586 default:
587 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
588 }
589 return S_OK;
590}
591
592STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
593{
594 CheckComArgOutPointerValid(aDefaultMachineFolder);
595
596 AutoCaller autoCaller(this);
597 if (FAILED(autoCaller.rc())) return autoCaller.rc();
598
599 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
600
601 m->strDefaultMachineFolder.cloneTo(aDefaultMachineFolder);
602
603 return S_OK;
604}
605
606STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
607{
608 AutoCaller autoCaller(this);
609 if (FAILED(autoCaller.rc())) return autoCaller.rc();
610
611 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
612 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
613 alock.release();
614
615 if (SUCCEEDED(rc))
616 {
617 // VirtualBox::saveSettings() needs vbox write lock
618 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
619 rc = mParent->saveSettings();
620 }
621
622 return rc;
623}
624
625STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
626{
627 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
628
629 AutoCaller autoCaller(this);
630 if (FAILED(autoCaller.rc())) return autoCaller.rc();
631
632 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
633
634 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
635 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
636
637 return S_OK;
638}
639
640STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
641{
642 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
643
644 AutoCaller autoCaller(this);
645 if (FAILED(autoCaller.rc())) return autoCaller.rc();
646
647 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
648
649 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
650
651 return S_OK;
652}
653
654STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
655{
656 AutoCaller autoCaller(this);
657 if (FAILED(autoCaller.rc())) return autoCaller.rc();
658
659 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
660 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
661 alock.release();
662
663 if (SUCCEEDED(rc))
664 {
665 // VirtualBox::saveSettings() needs vbox write lock
666 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
667 rc = mParent->saveSettings();
668 }
669
670 return rc;
671}
672
673STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
674{
675 CheckComArgOutPointerValid(aFreeSpace);
676
677 ReturnComNotImplemented();
678}
679
680STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
681{
682 ReturnComNotImplemented();
683}
684
685STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
686{
687 CheckComArgOutPointerValid(aFreeSpacePercent);
688
689 ReturnComNotImplemented();
690}
691
692STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
693{
694 ReturnComNotImplemented();
695}
696
697STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
698{
699 CheckComArgOutPointerValid(aFreeSpace);
700
701 ReturnComNotImplemented();
702}
703
704STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
705{
706 ReturnComNotImplemented();
707}
708
709STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
710{
711 CheckComArgOutPointerValid(aFreeSpacePercent);
712
713 ReturnComNotImplemented();
714}
715
716STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
717{
718 ReturnComNotImplemented();
719}
720
721STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
722{
723 CheckComArgOutPointerValid(aVRDEAuthLibrary);
724
725 AutoCaller autoCaller(this);
726 if (FAILED(autoCaller.rc())) return autoCaller.rc();
727
728 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
729
730 m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
731
732 return S_OK;
733}
734
735STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
736{
737 AutoCaller autoCaller(this);
738 if (FAILED(autoCaller.rc())) return autoCaller.rc();
739
740 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
741 HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
742 alock.release();
743
744 if (SUCCEEDED(rc))
745 {
746 // VirtualBox::saveSettings() needs vbox write lock
747 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
748 rc = mParent->saveSettings();
749 }
750
751 return rc;
752}
753
754STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
755{
756 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
757
758 AutoCaller autoCaller(this);
759 if (FAILED(autoCaller.rc())) return autoCaller.rc();
760
761 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
762
763 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
764
765 return S_OK;
766}
767
768STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
769{
770 AutoCaller autoCaller(this);
771 if (FAILED(autoCaller.rc())) return autoCaller.rc();
772
773 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
774 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
775 alock.release();
776
777 if (SUCCEEDED(rc))
778 {
779 // VirtualBox::saveSettings() needs vbox write lock
780 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
781 rc = mParent->saveSettings();
782 }
783
784 return rc;
785}
786
787STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDEExtPack)(BSTR *aExtPack)
788{
789 CheckComArgOutPointerValid(aExtPack);
790
791 AutoCaller autoCaller(this);
792 HRESULT hrc = autoCaller.rc();
793 if (SUCCEEDED(hrc))
794 {
795 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
796 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
797 if (strExtPack.isNotEmpty())
798 {
799 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
800 hrc = S_OK;
801 else
802#ifdef VBOX_WITH_EXTPACK
803 hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
804#else
805 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
806#endif
807 }
808 else
809 {
810#ifdef VBOX_WITH_EXTPACK
811 hrc = mParent->getExtPackManager()->getDefaultVrdeExtPack(&strExtPack);
812#endif
813 if (strExtPack.isEmpty())
814 {
815 /*
816 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
817 * This is hardcoded uglyness, sorry.
818 */
819 char szPath[RTPATH_MAX];
820 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
821 if (RT_SUCCESS(vrc))
822 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
823 if (RT_SUCCESS(vrc))
824 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
825 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
826 {
827 /* Illegal extpack name, so no conflict. */
828 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
829 }
830 }
831 }
832
833 if (SUCCEEDED(hrc))
834 strExtPack.cloneTo(aExtPack);
835 }
836
837 return S_OK;
838}
839
840STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDEExtPack)(IN_BSTR aExtPack)
841{
842 CheckComArgNotNull(aExtPack);
843 Utf8Str strExtPack(aExtPack);
844
845 AutoCaller autoCaller(this);
846 HRESULT hrc = autoCaller.rc();
847 if (SUCCEEDED(hrc))
848 {
849 if (strExtPack.isNotEmpty())
850 {
851 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
852 hrc = S_OK;
853 else
854#ifdef VBOX_WITH_EXTPACK
855 hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
856#else
857 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
858#endif
859 }
860 if (SUCCEEDED(hrc))
861 {
862 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
863 hrc = setDefaultVRDEExtPack(aExtPack);
864 if (SUCCEEDED(hrc))
865 {
866 /* VirtualBox::saveSettings() needs the VirtualBox write lock. */
867 alock.release();
868 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
869 hrc = mParent->saveSettings();
870 }
871 }
872 }
873
874 return hrc;
875}
876
877STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
878{
879 CheckComArgOutPointerValid(count);
880
881 AutoCaller autoCaller(this);
882 if (FAILED(autoCaller.rc())) return autoCaller.rc();
883
884 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
885
886 *count = m->ulLogHistoryCount;
887
888 return S_OK;
889}
890
891STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
892{
893 AutoCaller autoCaller(this);
894 if (FAILED(autoCaller.rc())) return autoCaller.rc();
895
896 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
897 m->ulLogHistoryCount = count;
898 alock.release();
899
900 // VirtualBox::saveSettings() needs vbox write lock
901 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
902 HRESULT rc = mParent->saveSettings();
903
904 return rc;
905}
906
907STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
908{
909 CheckComArgOutPointerValid(aAudioDriver);
910
911 AutoCaller autoCaller(this);
912 if (FAILED(autoCaller.rc())) return autoCaller.rc();
913
914 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
915
916 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
917
918 return S_OK;
919}
920
921STDMETHODIMP SystemProperties::COMGETTER(AutostartDatabasePath)(BSTR *aAutostartDbPath)
922{
923 CheckComArgOutPointerValid(aAutostartDbPath);
924
925 AutoCaller autoCaller(this);
926 if (FAILED(autoCaller.rc())) return autoCaller.rc();
927
928 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
929
930 m->strAutostartDatabasePath.cloneTo(aAutostartDbPath);
931
932 return S_OK;
933}
934
935STDMETHODIMP SystemProperties::COMSETTER(AutostartDatabasePath)(IN_BSTR aAutostartDbPath)
936{
937 AutoCaller autoCaller(this);
938 if (FAILED(autoCaller.rc())) return autoCaller.rc();
939
940 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
941 HRESULT rc = setAutostartDatabasePath(aAutostartDbPath);
942 alock.release();
943
944 if (SUCCEEDED(rc))
945 {
946 // VirtualBox::saveSettings() needs vbox write lock
947 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
948 rc = mParent->saveSettings();
949 }
950
951 return rc;
952}
953
954// public methods only for internal purposes
955/////////////////////////////////////////////////////////////////////////////
956
957HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
958{
959 AutoCaller autoCaller(this);
960 if (FAILED(autoCaller.rc())) return autoCaller.rc();
961
962 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
963
964 HRESULT rc = S_OK;
965
966 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
967 if (FAILED(rc)) return rc;
968
969 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
970 if (FAILED(rc)) return rc;
971
972 rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
973 if (FAILED(rc)) return rc;
974
975 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
976 if (FAILED(rc)) return rc;
977
978 rc = setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
979 if (FAILED(rc)) return rc;
980
981 m->ulLogHistoryCount = data.ulLogHistoryCount;
982
983 rc = setAutostartDatabasePath(data.strAutostartDatabasePath);
984 if (FAILED(rc)) return rc;
985
986 return S_OK;
987}
988
989HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
990{
991 AutoCaller autoCaller(this);
992 if (FAILED(autoCaller.rc())) return autoCaller.rc();
993
994 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
995
996 data = *m;
997
998 return S_OK;
999}
1000
1001/**
1002 * Returns a medium format object corresponding to the given format
1003 * identifier or null if no such format.
1004 *
1005 * @param aFormat Format identifier.
1006 *
1007 * @return ComObjPtr<MediumFormat>
1008 */
1009ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
1010{
1011 ComObjPtr<MediumFormat> format;
1012
1013 AutoCaller autoCaller(this);
1014 AssertComRCReturn (autoCaller.rc(), format);
1015
1016 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1017
1018 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1019 it != m_llMediumFormats.end();
1020 ++ it)
1021 {
1022 /* MediumFormat is all const, no need to lock */
1023
1024 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
1025 {
1026 format = *it;
1027 break;
1028 }
1029 }
1030
1031 return format;
1032}
1033
1034/**
1035 * Returns a medium format object corresponding to the given file extension or
1036 * null if no such format.
1037 *
1038 * @param aExt File extension.
1039 *
1040 * @return ComObjPtr<MediumFormat>
1041 */
1042ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
1043{
1044 ComObjPtr<MediumFormat> format;
1045
1046 AutoCaller autoCaller(this);
1047 AssertComRCReturn (autoCaller.rc(), format);
1048
1049 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1050
1051 bool fFound = false;
1052 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
1053 it != m_llMediumFormats.end() && !fFound;
1054 ++it)
1055 {
1056 /* MediumFormat is all const, no need to lock */
1057 MediumFormat::StrList aFileList = (*it)->getFileExtensions();
1058 for (MediumFormat::StrList::const_iterator it1 = aFileList.begin();
1059 it1 != aFileList.end();
1060 ++it1)
1061 {
1062 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
1063 {
1064 format = *it;
1065 fFound = true;
1066 break;
1067 }
1068 }
1069 }
1070
1071 return format;
1072}
1073
1074// private methods
1075/////////////////////////////////////////////////////////////////////////////
1076
1077/**
1078 * Returns the user's home directory. Wrapper around RTPathUserHome().
1079 * @param strPath
1080 * @return
1081 */
1082HRESULT SystemProperties::getUserHomeDirectory(Utf8Str &strPath)
1083{
1084 char szHome[RTPATH_MAX];
1085 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1086 if (RT_FAILURE(vrc))
1087 return setError(E_FAIL,
1088 tr("Cannot determine user home directory (%Rrc)"),
1089 vrc);
1090 strPath = szHome;
1091 return S_OK;
1092}
1093
1094/**
1095 * Internal implementation to set the default machine folder. Gets called
1096 * from the public attribute setter as well as loadSettings(). With 4.0,
1097 * the "default default" machine folder has changed, and we now require
1098 * a full path always.
1099 * @param aPath
1100 * @return
1101 */
1102HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &strPath)
1103{
1104 Utf8Str path(strPath); // make modifiable
1105 if ( path.isEmpty() // used by API calls to reset the default
1106 || path == "Machines" // this value (exactly like this, without path) is stored
1107 // in VirtualBox.xml if user upgrades from before 4.0 and
1108 // has not changed the default machine folder
1109 )
1110 {
1111 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1112 HRESULT rc = getUserHomeDirectory(path);
1113 if (FAILED(rc)) return rc;
1114 path += RTPATH_SLASH_STR "VirtualBox VMs";
1115 }
1116
1117 if (!RTPathStartsWithRoot(path.c_str()))
1118 return setError(E_INVALIDARG,
1119 tr("Given default machine folder '%s' is not fully qualified"),
1120 path.c_str());
1121
1122 m->strDefaultMachineFolder = path;
1123
1124 return S_OK;
1125}
1126
1127HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
1128{
1129 if (!aFormat.isEmpty())
1130 m->strDefaultHardDiskFormat = aFormat;
1131 else
1132 m->strDefaultHardDiskFormat = "VDI";
1133
1134 return S_OK;
1135}
1136
1137HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
1138{
1139 if (!aPath.isEmpty())
1140 m->strVRDEAuthLibrary = aPath;
1141 else
1142 m->strVRDEAuthLibrary = "VBoxAuth";
1143
1144 return S_OK;
1145}
1146
1147HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
1148{
1149 if (!aPath.isEmpty())
1150 m->strWebServiceAuthLibrary = aPath;
1151 else
1152 m->strWebServiceAuthLibrary = "VBoxAuth";
1153
1154 return S_OK;
1155}
1156
1157HRESULT SystemProperties::setDefaultVRDEExtPack(const Utf8Str &aExtPack)
1158{
1159 m->strDefaultVRDEExtPack = aExtPack;
1160
1161 return S_OK;
1162}
1163
1164HRESULT SystemProperties::setAutostartDatabasePath(const Utf8Str &aPath)
1165{
1166 HRESULT rc = S_OK;
1167 AutostartDb *autostartDb = this->mParent->getAutostartDb();
1168
1169 if (!aPath.isEmpty())
1170 {
1171 /* Update path in the autostart database. */
1172 int vrc = autostartDb->setAutostartDbPath(aPath.c_str());
1173 if (RT_SUCCESS(vrc))
1174 m->strAutostartDatabasePath = aPath;
1175 else
1176 rc = setError(E_FAIL,
1177 tr("Cannot set the autostart database path (%Rrc)"),
1178 vrc);
1179 }
1180 else
1181 {
1182 int vrc = autostartDb->setAutostartDbPath(NULL);
1183 AssertRC(vrc);
1184 m->strAutostartDatabasePath = "";
1185 }
1186
1187 return rc;
1188}
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