VirtualBox

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

Last change on this file since 35638 was 35638, checked in by vboxsync, 14 years ago

Main. QT/FE: fix long standing COM issue

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 29.1 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 35638 2011-01-19 19:10:49Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "SystemPropertiesImpl.h"
21#include "VirtualBoxImpl.h"
22#include "MachineImpl.h"
23#ifdef VBOX_WITH_EXTPACK
24# include "ExtPackManagerImpl.h"
25#endif
26#include "AutoCaller.h"
27#include "Global.h"
28#include "Logging.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(NetworkAdapterCount)(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::NetworkAdapterCount;
286
287 return S_OK;
288}
289
290STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(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::SerialPortCount;
299
300 return S_OK;
301}
302
303STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
304{
305 CheckComArgOutPointerValid(count);
306
307 AutoCaller autoCaller(this);
308 if (FAILED(autoCaller.rc())) return autoCaller.rc();
309
310 /* no need to lock, this is const */
311 *count = SchemaDefs::ParallelPortCount;
312
313 return S_OK;
314}
315
316STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
317{
318 CheckComArgOutPointerValid(aMaxBootPosition);
319
320 AutoCaller autoCaller(this);
321 if (FAILED(autoCaller.rc())) return autoCaller.rc();
322
323 /* no need to lock, this is const */
324 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
325
326 return S_OK;
327}
328
329STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
330 ULONG *aMaxDevicesPerPort)
331{
332 CheckComArgOutPointerValid(aMaxDevicesPerPort);
333
334 AutoCaller autoCaller(this);
335 if (FAILED(autoCaller.rc())) return autoCaller.rc();
336
337 /* no need to lock, this is const */
338 switch (aBus)
339 {
340 case StorageBus_SATA:
341 case StorageBus_SCSI:
342 case StorageBus_SAS:
343 {
344 /* SATA and both SCSI controllers only support one device per port. */
345 *aMaxDevicesPerPort = 1;
346 break;
347 }
348 case StorageBus_IDE:
349 case StorageBus_Floppy:
350 {
351 /* The IDE and Floppy controllers support 2 devices. One as master
352 * and one as slave (or floppy drive 0 and 1). */
353 *aMaxDevicesPerPort = 2;
354 break;
355 }
356 default:
357 AssertMsgFailed(("Invalid bus type %d\n", aBus));
358 }
359
360 return S_OK;
361}
362
363STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
364 ULONG *aMinPortCount)
365{
366 CheckComArgOutPointerValid(aMinPortCount);
367
368 AutoCaller autoCaller(this);
369 if (FAILED(autoCaller.rc())) return autoCaller.rc();
370
371 /* no need to lock, this is const */
372 switch (aBus)
373 {
374 case StorageBus_SATA:
375 {
376 *aMinPortCount = 1;
377 break;
378 }
379 case StorageBus_SCSI:
380 {
381 *aMinPortCount = 16;
382 break;
383 }
384 case StorageBus_IDE:
385 {
386 *aMinPortCount = 2;
387 break;
388 }
389 case StorageBus_Floppy:
390 {
391 *aMinPortCount = 1;
392 break;
393 }
394 case StorageBus_SAS:
395 {
396 *aMinPortCount = 8;
397 break;
398 }
399 default:
400 AssertMsgFailed(("Invalid bus type %d\n", aBus));
401 }
402
403 return S_OK;
404}
405
406STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
407 ULONG *aMaxPortCount)
408{
409 CheckComArgOutPointerValid(aMaxPortCount);
410
411 AutoCaller autoCaller(this);
412 if (FAILED(autoCaller.rc())) return autoCaller.rc();
413
414 /* no need to lock, this is const */
415 switch (aBus)
416 {
417 case StorageBus_SATA:
418 {
419 *aMaxPortCount = 30;
420 break;
421 }
422 case StorageBus_SCSI:
423 {
424 *aMaxPortCount = 16;
425 break;
426 }
427 case StorageBus_IDE:
428 {
429 *aMaxPortCount = 2;
430 break;
431 }
432 case StorageBus_Floppy:
433 {
434 *aMaxPortCount = 1;
435 break;
436 }
437 case StorageBus_SAS:
438 {
439 *aMaxPortCount = 8;
440 break;
441 }
442 default:
443 AssertMsgFailed(("Invalid bus type %d\n", aBus));
444 }
445
446 return S_OK;
447}
448
449STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(ChipsetType_T aChipset,
450 StorageBus_T aBus,
451 ULONG *aMaxInstances)
452{
453 CheckComArgOutPointerValid(aMaxInstances);
454
455 AutoCaller autoCaller(this);
456 if (FAILED(autoCaller.rc())) return autoCaller.rc();
457
458 ULONG cCtrs = 0;
459
460 /* no need to lock, this is const */
461 switch (aBus)
462 {
463 case StorageBus_SATA:
464 case StorageBus_SCSI:
465 case StorageBus_SAS:
466 cCtrs = aChipset == ChipsetType_ICH9 ? 8 : 1;
467 break;
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
483STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
484 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
485{
486 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
487
488 AutoCaller autoCaller(this);
489 if (FAILED(autoCaller.rc())) return autoCaller.rc();
490
491 /* no need to lock, this is const */
492 switch (aBus)
493 {
494 case StorageBus_IDE:
495 case StorageBus_SATA:
496 {
497 com::SafeArray<DeviceType_T> saDeviceTypes(2);
498 saDeviceTypes[0] = DeviceType_DVD;
499 saDeviceTypes[1] = DeviceType_HardDisk;
500 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
501 break;
502 }
503 case StorageBus_SCSI:
504 case StorageBus_SAS:
505 {
506 com::SafeArray<DeviceType_T> saDeviceTypes(1);
507 saDeviceTypes[0] = DeviceType_HardDisk;
508 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
509 break;
510 }
511 case StorageBus_Floppy:
512 {
513 com::SafeArray<DeviceType_T> saDeviceTypes(1);
514 saDeviceTypes[0] = DeviceType_Floppy;
515 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
516 break;
517 }
518 default:
519 AssertMsgFailed(("Invalid bus type %d\n", aBus));
520 }
521
522 return S_OK;
523}
524
525STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
526{
527 CheckComArgOutPointerValid(aEnabled);
528
529 AutoCaller autoCaller(this);
530 if (FAILED(autoCaller.rc())) return autoCaller.rc();
531
532 /* no need to lock, this is const */
533 switch (aControllerType)
534 {
535 case StorageControllerType_LsiLogic:
536 case StorageControllerType_BusLogic:
537 case StorageControllerType_IntelAhci:
538 case StorageControllerType_LsiLogicSas:
539 *aEnabled = false;
540 break;
541 case StorageControllerType_PIIX3:
542 case StorageControllerType_PIIX4:
543 case StorageControllerType_ICH6:
544 case StorageControllerType_I82078:
545 *aEnabled = true;
546 break;
547 default:
548 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
549 }
550 return S_OK;
551}
552
553STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
554{
555 CheckComArgOutPointerValid(aDefaultMachineFolder);
556
557 AutoCaller autoCaller(this);
558 if (FAILED(autoCaller.rc())) return autoCaller.rc();
559
560 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
561
562 m->strDefaultMachineFolder.cloneTo(aDefaultMachineFolder);
563
564 return S_OK;
565}
566
567STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
568{
569 AutoCaller autoCaller(this);
570 if (FAILED(autoCaller.rc())) return autoCaller.rc();
571
572 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
573 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
574 alock.release();
575
576 if (SUCCEEDED(rc))
577 {
578 // VirtualBox::saveSettings() needs vbox write lock
579 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
580 rc = mParent->saveSettings();
581 }
582
583 return rc;
584}
585
586STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
587{
588 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
589
590 AutoCaller autoCaller(this);
591 if (FAILED(autoCaller.rc())) return autoCaller.rc();
592
593 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
594
595 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
596 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
597
598 return S_OK;
599}
600
601STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
602{
603 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
604
605 AutoCaller autoCaller(this);
606 if (FAILED(autoCaller.rc())) return autoCaller.rc();
607
608 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
609
610 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
611
612 return S_OK;
613}
614
615STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
616{
617 AutoCaller autoCaller(this);
618 if (FAILED(autoCaller.rc())) return autoCaller.rc();
619
620 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
621 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
622 alock.release();
623
624 if (SUCCEEDED(rc))
625 {
626 // VirtualBox::saveSettings() needs vbox write lock
627 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
628 rc = mParent->saveSettings();
629 }
630
631 return rc;
632}
633
634STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
635{
636 CheckComArgOutPointerValid(aFreeSpace);
637
638 ReturnComNotImplemented();
639}
640
641STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
642{
643 ReturnComNotImplemented();
644}
645
646STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
647{
648 CheckComArgOutPointerValid(aFreeSpacePercent);
649
650 ReturnComNotImplemented();
651}
652
653STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
654{
655 ReturnComNotImplemented();
656}
657
658STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
659{
660 CheckComArgOutPointerValid(aFreeSpace);
661
662 ReturnComNotImplemented();
663}
664
665STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
666{
667 ReturnComNotImplemented();
668}
669
670STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
671{
672 CheckComArgOutPointerValid(aFreeSpacePercent);
673
674 ReturnComNotImplemented();
675}
676
677STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
678{
679 ReturnComNotImplemented();
680}
681
682STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
683{
684 CheckComArgOutPointerValid(aVRDEAuthLibrary);
685
686 AutoCaller autoCaller(this);
687 if (FAILED(autoCaller.rc())) return autoCaller.rc();
688
689 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
690
691 m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
692
693 return S_OK;
694}
695
696STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
697{
698 AutoCaller autoCaller(this);
699 if (FAILED(autoCaller.rc())) return autoCaller.rc();
700
701 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
702 HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
703 alock.release();
704
705 if (SUCCEEDED(rc))
706 {
707 // VirtualBox::saveSettings() needs vbox write lock
708 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
709 rc = mParent->saveSettings();
710 }
711
712 return rc;
713}
714
715STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
716{
717 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
718
719 AutoCaller autoCaller(this);
720 if (FAILED(autoCaller.rc())) return autoCaller.rc();
721
722 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
723
724 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
725
726 return S_OK;
727}
728
729STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
730{
731 AutoCaller autoCaller(this);
732 if (FAILED(autoCaller.rc())) return autoCaller.rc();
733
734 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
735 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
736 alock.release();
737
738 if (SUCCEEDED(rc))
739 {
740 // VirtualBox::saveSettings() needs vbox write lock
741 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
742 rc = mParent->saveSettings();
743 }
744
745 return rc;
746}
747
748STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDEExtPack)(BSTR *aExtPack)
749{
750 CheckComArgOutPointerValid(aExtPack);
751
752 AutoCaller autoCaller(this);
753 HRESULT hrc = autoCaller.rc();
754 if (SUCCEEDED(hrc))
755 {
756 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
757 Utf8Str strExtPack(m->strDefaultVRDEExtPack);
758 if (strExtPack.isNotEmpty())
759 {
760 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
761 hrc = S_OK;
762 else
763#ifdef VBOX_WITH_EXTPACK
764 hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
765#else
766 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
767#endif
768 }
769 else
770 {
771#ifdef VBOX_WITH_EXTPACK
772 hrc = mParent->getExtPackManager()->getDefaultVrdeExtPack(&strExtPack);
773#endif
774 if (strExtPack.isEmpty())
775 {
776 /*
777 * Klugde - check if VBoxVRDP.dll/.so/.dylib is installed.
778 * This is hardcoded uglyness, sorry.
779 */
780 char szPath[RTPATH_MAX];
781 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath));
782 if (RT_SUCCESS(vrc))
783 vrc = RTPathAppend(szPath, sizeof(szPath), "VBoxVRDP");
784 if (RT_SUCCESS(vrc))
785 vrc = RTStrCat(szPath, sizeof(szPath), RTLdrGetSuff());
786 if (RT_SUCCESS(vrc) && RTFileExists(szPath))
787 {
788 /* Illegal extpack name, so no conflict. */
789 strExtPack = VBOXVRDP_KLUDGE_EXTPACK_NAME;
790 }
791 }
792 }
793
794 if (SUCCEEDED(hrc))
795 strExtPack.cloneTo(aExtPack);
796 }
797
798 return S_OK;
799}
800
801STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDEExtPack)(IN_BSTR aExtPack)
802{
803 CheckComArgNotNull(aExtPack);
804 Utf8Str strExtPack(aExtPack);
805
806 AutoCaller autoCaller(this);
807 HRESULT hrc = autoCaller.rc();
808 if (SUCCEEDED(hrc))
809 {
810 if (strExtPack.isNotEmpty())
811 {
812 if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
813 hrc = S_OK;
814 else
815#ifdef VBOX_WITH_EXTPACK
816 hrc = mParent->getExtPackManager()->checkVrdeExtPack(&strExtPack);
817#else
818 hrc = setError(E_FAIL, tr("The extension pack '%s' does not exist"), strExtPack.c_str());
819#endif
820 }
821 if (SUCCEEDED(hrc))
822 {
823 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
824 hrc = setDefaultVRDEExtPack(aExtPack);
825 if (SUCCEEDED(hrc))
826 {
827 /* VirtualBox::saveSettings() needs the VirtualBox write lock. */
828 alock.release();
829 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
830 hrc = mParent->saveSettings();
831 }
832 }
833 }
834
835 return hrc;
836}
837
838STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
839{
840 CheckComArgOutPointerValid(count);
841
842 AutoCaller autoCaller(this);
843 if (FAILED(autoCaller.rc())) return autoCaller.rc();
844
845 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
846
847 *count = m->ulLogHistoryCount;
848
849 return S_OK;
850}
851
852STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
853{
854 AutoCaller autoCaller(this);
855 if (FAILED(autoCaller.rc())) return autoCaller.rc();
856
857 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
858 m->ulLogHistoryCount = count;
859 alock.release();
860
861 // VirtualBox::saveSettings() needs vbox write lock
862 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
863 HRESULT rc = mParent->saveSettings();
864
865 return rc;
866}
867
868STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
869{
870 CheckComArgOutPointerValid(aAudioDriver);
871
872 AutoCaller autoCaller(this);
873 if (FAILED(autoCaller.rc())) return autoCaller.rc();
874
875 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
876
877 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
878
879 return S_OK;
880}
881
882// public methods only for internal purposes
883/////////////////////////////////////////////////////////////////////////////
884
885HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
886{
887 AutoCaller autoCaller(this);
888 if (FAILED(autoCaller.rc())) return autoCaller.rc();
889
890 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
891
892 HRESULT rc = S_OK;
893
894 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
895 if (FAILED(rc)) return rc;
896
897 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
898 if (FAILED(rc)) return rc;
899
900 rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
901 if (FAILED(rc)) return rc;
902
903 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
904 if (FAILED(rc)) return rc;
905
906 rc = setDefaultVRDEExtPack(data.strDefaultVRDEExtPack);
907 if (FAILED(rc)) return rc;
908
909 m->ulLogHistoryCount = data.ulLogHistoryCount;
910
911 return S_OK;
912}
913
914HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
915{
916 AutoCaller autoCaller(this);
917 if (FAILED(autoCaller.rc())) return autoCaller.rc();
918
919 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
920
921 data = *m;
922
923 return S_OK;
924}
925
926/**
927 * Returns a medium format object corresponding to the given format
928 * identifier or null if no such format.
929 *
930 * @param aFormat Format identifier.
931 *
932 * @return ComObjPtr<MediumFormat>
933 */
934ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
935{
936 ComObjPtr<MediumFormat> format;
937
938 AutoCaller autoCaller(this);
939 AssertComRCReturn (autoCaller.rc(), format);
940
941 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
942
943 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
944 it != m_llMediumFormats.end();
945 ++ it)
946 {
947 /* MediumFormat is all const, no need to lock */
948
949 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
950 {
951 format = *it;
952 break;
953 }
954 }
955
956 return format;
957}
958
959/**
960 * Returns a medium format object corresponding to the given file extension or
961 * null if no such format.
962 *
963 * @param aExt File extension.
964 *
965 * @return ComObjPtr<MediumFormat>
966 */
967ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
968{
969 ComObjPtr<MediumFormat> format;
970
971 AutoCaller autoCaller(this);
972 AssertComRCReturn (autoCaller.rc(), format);
973
974 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
975
976 bool fFound = false;
977 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
978 it != m_llMediumFormats.end() && !fFound;
979 ++it)
980 {
981 /* MediumFormat is all const, no need to lock */
982 MediumFormat::StrList aFileList = (*it)->getFileExtensions();
983 for (MediumFormat::StrList::const_iterator it1 = aFileList.begin();
984 it1 != aFileList.end();
985 ++it1)
986 {
987 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
988 {
989 format = *it;
990 fFound = true;
991 break;
992 }
993 }
994 }
995
996 return format;
997}
998
999// private methods
1000/////////////////////////////////////////////////////////////////////////////
1001
1002/**
1003 * Returns the user's home directory. Wrapper around RTPathUserHome().
1004 * @param strPath
1005 * @return
1006 */
1007HRESULT SystemProperties::getUserHomeDirectory(Utf8Str &strPath)
1008{
1009 char szHome[RTPATH_MAX];
1010 int vrc = RTPathUserHome(szHome, sizeof(szHome));
1011 if (RT_FAILURE(vrc))
1012 return setError(E_FAIL,
1013 tr("Cannot determine user home directory (%Rrc)"),
1014 vrc);
1015 strPath = szHome;
1016 return S_OK;
1017}
1018
1019/**
1020 * Internal implementation to set the default machine folder. Gets called
1021 * from the public attribute setter as well as loadSettings(). With 4.0,
1022 * the "default default" machine folder has changed, and we now require
1023 * a full path always.
1024 * @param aPath
1025 * @return
1026 */
1027HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &strPath)
1028{
1029 Utf8Str path(strPath); // make modifiable
1030 if ( path.isEmpty() // used by API calls to reset the default
1031 || path == "Machines" // this value (exactly like this, without path) is stored
1032 // in VirtualBox.xml if user upgrades from before 4.0 and
1033 // has not changed the default machine folder
1034 )
1035 {
1036 // new default with VirtualBox 4.0: "$HOME/VirtualBox VMs"
1037 HRESULT rc = getUserHomeDirectory(path);
1038 if (FAILED(rc)) return rc;
1039 path += RTPATH_SLASH_STR "VirtualBox VMs";
1040 }
1041
1042 if (!RTPathStartsWithRoot(path.c_str()))
1043 return setError(E_INVALIDARG,
1044 tr("Given default machine folder '%s' is not fully qualified"),
1045 path.c_str());
1046
1047 m->strDefaultMachineFolder = path;
1048
1049 return S_OK;
1050}
1051
1052HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
1053{
1054 if (!aFormat.isEmpty())
1055 m->strDefaultHardDiskFormat = aFormat;
1056 else
1057 m->strDefaultHardDiskFormat = "VDI";
1058
1059 return S_OK;
1060}
1061
1062HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
1063{
1064 if (!aPath.isEmpty())
1065 m->strVRDEAuthLibrary = aPath;
1066 else
1067 m->strVRDEAuthLibrary = "VBoxAuth";
1068
1069 return S_OK;
1070}
1071
1072HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
1073{
1074 if (!aPath.isEmpty())
1075 m->strWebServiceAuthLibrary = aPath;
1076 else
1077 m->strWebServiceAuthLibrary = "VBoxAuth";
1078
1079 return S_OK;
1080}
1081
1082HRESULT SystemProperties::setDefaultVRDEExtPack(const Utf8Str &aExtPack)
1083{
1084 m->strDefaultVRDEExtPack = aExtPack;
1085
1086 return S_OK;
1087}
1088
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette