VirtualBox

source: vbox/trunk/src/VBox/Main/SystemPropertiesImpl.cpp@ 33595

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

VD: Move the generic virtual disk framework + backends to src/VBox/Storage and rename the files to get rid of the HDD part because it supports floppy and DVD images too

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.2 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 33567 2010-10-28 15:37:21Z 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.virtualbox.org. 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#include "AutoCaller.h"
24#include "Logging.h"
25
26// generated header
27#include "SchemaDefs.h"
28
29#include <iprt/path.h>
30#include <iprt/dir.h>
31#include <iprt/cpp/utils.h>
32
33#include <VBox/err.h>
34#include <VBox/param.h>
35#include <VBox/settings.h>
36#include <VBox/vd.h>
37
38// defines
39/////////////////////////////////////////////////////////////////////////////
40
41// constructor / destructor
42/////////////////////////////////////////////////////////////////////////////
43
44SystemProperties::SystemProperties()
45 : mParent(NULL),
46 m(new settings::SystemProperties)
47{
48}
49
50SystemProperties::~SystemProperties()
51{
52 delete m;
53}
54
55
56HRESULT SystemProperties::FinalConstruct()
57{
58 return S_OK;
59}
60
61void SystemProperties::FinalRelease()
62{
63 uninit();
64}
65
66// public methods only for internal purposes
67/////////////////////////////////////////////////////////////////////////////
68
69/**
70 * Initializes the system information object.
71 *
72 * @returns COM result indicator
73 */
74HRESULT SystemProperties::init(VirtualBox *aParent)
75{
76 LogFlowThisFunc(("aParent=%p\n", aParent));
77
78 ComAssertRet(aParent, E_FAIL);
79
80 /* Enclose the state transition NotReady->InInit->Ready */
81 AutoInitSpan autoInitSpan(this);
82 AssertReturn(autoInitSpan.isOk(), E_FAIL);
83
84 unconst(mParent) = aParent;
85
86 setDefaultMachineFolder(Utf8Str::Empty);
87 setDefaultHardDiskFormat(Utf8Str::Empty);
88
89 setVRDEAuthLibrary(Utf8Str::Empty);
90 setDefaultVRDELibrary(Utf8Str::Empty);
91
92 m->ulLogHistoryCount = 3;
93
94 HRESULT rc = S_OK;
95
96 /* Fetch info of all available hd backends. */
97
98 /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
99 /// any number of backends
100
101 VDBACKENDINFO aVDInfo[100];
102 unsigned cEntries;
103 int vrc = VDBackendInfo(RT_ELEMENTS(aVDInfo), aVDInfo, &cEntries);
104 AssertRC(vrc);
105 if (RT_SUCCESS(vrc))
106 {
107 for (unsigned i = 0; i < cEntries; ++ i)
108 {
109 ComObjPtr<MediumFormat> hdf;
110 rc = hdf.createObject();
111 if (FAILED(rc)) break;
112
113 rc = hdf->init(&aVDInfo[i]);
114 if (FAILED(rc)) break;
115
116 m_llMediumFormats.push_back(hdf);
117 }
118 }
119
120 /* Confirm a successful initialization */
121 if (SUCCEEDED(rc))
122 autoInitSpan.setSucceeded();
123
124 return rc;
125}
126
127/**
128 * Uninitializes the instance and sets the ready flag to FALSE.
129 * Called either from FinalRelease() or by the parent when it gets destroyed.
130 */
131void SystemProperties::uninit()
132{
133 LogFlowThisFunc(("\n"));
134
135 /* Enclose the state transition Ready->InUninit->NotReady */
136 AutoUninitSpan autoUninitSpan(this);
137 if (autoUninitSpan.uninitDone())
138 return;
139
140 unconst(mParent) = NULL;
141}
142
143// ISystemProperties properties
144/////////////////////////////////////////////////////////////////////////////
145
146
147STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
148{
149 CheckComArgOutPointerValid(minRAM);
150
151 AutoCaller autoCaller(this);
152 if (FAILED(autoCaller.rc())) return autoCaller.rc();
153
154 /* no need to lock, this is const */
155 AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
156 *minRAM = MM_RAM_MIN_IN_MB;
157
158 return S_OK;
159}
160
161STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
162{
163 CheckComArgOutPointerValid(maxRAM);
164
165 AutoCaller autoCaller(this);
166 if (FAILED(autoCaller.rc())) return autoCaller.rc();
167
168 /* no need to lock, this is const */
169 AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
170 ULONG maxRAMSys = MM_RAM_MAX_IN_MB;
171 ULONG maxRAMArch = maxRAMSys;
172 *maxRAM = RT_MIN(maxRAMSys, maxRAMArch);
173
174 return S_OK;
175}
176
177STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
178{
179 CheckComArgOutPointerValid(minVRAM);
180
181 AutoCaller autoCaller(this);
182 if (FAILED(autoCaller.rc())) return autoCaller.rc();
183
184 /* no need to lock, this is const */
185 *minVRAM = SchemaDefs::MinGuestVRAM;
186
187 return S_OK;
188}
189
190STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
191{
192 CheckComArgOutPointerValid(maxVRAM);
193
194 AutoCaller autoCaller(this);
195 if (FAILED(autoCaller.rc())) return autoCaller.rc();
196
197 /* no need to lock, this is const */
198 *maxVRAM = SchemaDefs::MaxGuestVRAM;
199
200 return S_OK;
201}
202
203STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
204{
205 CheckComArgOutPointerValid(minCPUCount);
206
207 AutoCaller autoCaller(this);
208 if (FAILED(autoCaller.rc())) return autoCaller.rc();
209
210 /* no need to lock, this is const */
211 *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
212
213 return S_OK;
214}
215
216STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
217{
218 CheckComArgOutPointerValid(maxCPUCount);
219
220 AutoCaller autoCaller(this);
221 if (FAILED(autoCaller.rc())) return autoCaller.rc();
222
223 /* no need to lock, this is const */
224 *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
225
226 return S_OK;
227}
228
229STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
230{
231 CheckComArgOutPointerValid(maxMonitors);
232
233 AutoCaller autoCaller(this);
234 if (FAILED(autoCaller.rc())) return autoCaller.rc();
235
236 /* no need to lock, this is const */
237 *maxMonitors = SchemaDefs::MaxGuestMonitors;
238
239 return S_OK;
240}
241
242STDMETHODIMP SystemProperties::COMGETTER(InfoVDSize)(LONG64 *infoVDSize)
243{
244 CheckComArgOutPointerValid(infoVDSize);
245
246 AutoCaller autoCaller(this);
247 if (FAILED(autoCaller.rc())) return autoCaller.rc();
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
270STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
271{
272 CheckComArgOutPointerValid(count);
273
274 AutoCaller autoCaller(this);
275 if (FAILED(autoCaller.rc())) return autoCaller.rc();
276
277 /* no need to lock, this is const */
278 *count = SchemaDefs::NetworkAdapterCount;
279
280 return S_OK;
281}
282
283STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
284{
285 CheckComArgOutPointerValid(count);
286
287 AutoCaller autoCaller(this);
288 if (FAILED(autoCaller.rc())) return autoCaller.rc();
289
290 /* no need to lock, this is const */
291 *count = SchemaDefs::SerialPortCount;
292
293 return S_OK;
294}
295
296STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
297{
298 CheckComArgOutPointerValid(count);
299
300 AutoCaller autoCaller(this);
301 if (FAILED(autoCaller.rc())) return autoCaller.rc();
302
303 /* no need to lock, this is const */
304 *count = SchemaDefs::ParallelPortCount;
305
306 return S_OK;
307}
308
309STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
310{
311 CheckComArgOutPointerValid(aMaxBootPosition);
312
313 AutoCaller autoCaller(this);
314 if (FAILED(autoCaller.rc())) return autoCaller.rc();
315
316 /* no need to lock, this is const */
317 *aMaxBootPosition = SchemaDefs::MaxBootPosition;
318
319 return S_OK;
320}
321
322STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
323 ULONG *aMaxDevicesPerPort)
324{
325 CheckComArgOutPointerValid(aMaxDevicesPerPort);
326
327 AutoCaller autoCaller(this);
328 if (FAILED(autoCaller.rc())) return autoCaller.rc();
329
330 /* no need to lock, this is const */
331 switch (aBus)
332 {
333 case StorageBus_SATA:
334 case StorageBus_SCSI:
335 case StorageBus_SAS:
336 {
337 /* SATA and both SCSI controllers only support one device per port. */
338 *aMaxDevicesPerPort = 1;
339 break;
340 }
341 case StorageBus_IDE:
342 case StorageBus_Floppy:
343 {
344 /* The IDE and Floppy controllers support 2 devices. One as master
345 * and one as slave (or floppy drive 0 and 1). */
346 *aMaxDevicesPerPort = 2;
347 break;
348 }
349 default:
350 AssertMsgFailed(("Invalid bus type %d\n", aBus));
351 }
352
353 return S_OK;
354}
355
356STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
357 ULONG *aMinPortCount)
358{
359 CheckComArgOutPointerValid(aMinPortCount);
360
361 AutoCaller autoCaller(this);
362 if (FAILED(autoCaller.rc())) return autoCaller.rc();
363
364 /* no need to lock, this is const */
365 switch (aBus)
366 {
367 case StorageBus_SATA:
368 {
369 *aMinPortCount = 1;
370 break;
371 }
372 case StorageBus_SCSI:
373 {
374 *aMinPortCount = 16;
375 break;
376 }
377 case StorageBus_IDE:
378 {
379 *aMinPortCount = 2;
380 break;
381 }
382 case StorageBus_Floppy:
383 {
384 *aMinPortCount = 1;
385 break;
386 }
387 case StorageBus_SAS:
388 {
389 *aMinPortCount = 8;
390 break;
391 }
392 default:
393 AssertMsgFailed(("Invalid bus type %d\n", aBus));
394 }
395
396 return S_OK;
397}
398
399STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
400 ULONG *aMaxPortCount)
401{
402 CheckComArgOutPointerValid(aMaxPortCount);
403
404 AutoCaller autoCaller(this);
405 if (FAILED(autoCaller.rc())) return autoCaller.rc();
406
407 /* no need to lock, this is const */
408 switch (aBus)
409 {
410 case StorageBus_SATA:
411 {
412 *aMaxPortCount = 30;
413 break;
414 }
415 case StorageBus_SCSI:
416 {
417 *aMaxPortCount = 16;
418 break;
419 }
420 case StorageBus_IDE:
421 {
422 *aMaxPortCount = 2;
423 break;
424 }
425 case StorageBus_Floppy:
426 {
427 *aMaxPortCount = 1;
428 break;
429 }
430 case StorageBus_SAS:
431 {
432 *aMaxPortCount = 8;
433 break;
434 }
435 default:
436 AssertMsgFailed(("Invalid bus type %d\n", aBus));
437 }
438
439 return S_OK;
440}
441
442STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus,
443 ULONG *aMaxInstances)
444{
445 CheckComArgOutPointerValid(aMaxInstances);
446
447 AutoCaller autoCaller(this);
448 if (FAILED(autoCaller.rc())) return autoCaller.rc();
449
450 /* no need to lock, this is const */
451 switch (aBus)
452 {
453 case StorageBus_SATA:
454 case StorageBus_SCSI:
455 case StorageBus_IDE:
456 case StorageBus_SAS:
457 case StorageBus_Floppy:
458 {
459 /** @todo raise the limits ASAP, per bus type */
460 *aMaxInstances = 1;
461 break;
462 }
463 default:
464 AssertMsgFailed(("Invalid bus type %d\n", aBus));
465 }
466
467 return S_OK;
468}
469
470STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
471 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
472{
473 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
474
475 AutoCaller autoCaller(this);
476 if (FAILED(autoCaller.rc())) return autoCaller.rc();
477
478 /* no need to lock, this is const */
479 switch (aBus)
480 {
481 case StorageBus_IDE:
482 case StorageBus_SATA:
483 {
484 com::SafeArray<DeviceType_T> saDeviceTypes(2);
485 saDeviceTypes[0] = DeviceType_DVD;
486 saDeviceTypes[1] = DeviceType_HardDisk;
487 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
488 break;
489 }
490 case StorageBus_SCSI:
491 case StorageBus_SAS:
492 {
493 com::SafeArray<DeviceType_T> saDeviceTypes(1);
494 saDeviceTypes[0] = DeviceType_HardDisk;
495 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
496 break;
497 }
498 case StorageBus_Floppy:
499 {
500 com::SafeArray<DeviceType_T> saDeviceTypes(1);
501 saDeviceTypes[0] = DeviceType_Floppy;
502 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
503 break;
504 }
505 default:
506 AssertMsgFailed(("Invalid bus type %d\n", aBus));
507 }
508
509 return S_OK;
510}
511
512STDMETHODIMP SystemProperties::GetDefaultIoCacheSettingForStorageController(StorageControllerType_T aControllerType, BOOL *aEnabled)
513{
514 CheckComArgOutPointerValid(aEnabled);
515
516 AutoCaller autoCaller(this);
517 if (FAILED(autoCaller.rc())) return autoCaller.rc();
518
519 /* no need to lock, this is const */
520 switch (aControllerType)
521 {
522 case StorageControllerType_LsiLogic:
523 case StorageControllerType_BusLogic:
524 case StorageControllerType_IntelAhci:
525 case StorageControllerType_LsiLogicSas:
526 *aEnabled = false;
527 break;
528 case StorageControllerType_PIIX3:
529 case StorageControllerType_PIIX4:
530 case StorageControllerType_ICH6:
531 case StorageControllerType_I82078:
532 *aEnabled = true;
533 break;
534 default:
535 AssertMsgFailed(("Invalid controller type %d\n", aControllerType));
536 }
537 return S_OK;
538}
539
540STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
541{
542 CheckComArgOutPointerValid(aDefaultMachineFolder);
543
544 AutoCaller autoCaller(this);
545 if (FAILED(autoCaller.rc())) return autoCaller.rc();
546
547 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
548
549 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
550
551 return S_OK;
552}
553
554STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
555{
556 AutoCaller autoCaller(this);
557 if (FAILED(autoCaller.rc())) return autoCaller.rc();
558
559 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
560 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
561 alock.release();
562
563 if (SUCCEEDED(rc))
564 {
565 // VirtualBox::saveSettings() needs vbox write lock
566 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
567 rc = mParent->saveSettings();
568 }
569
570 return rc;
571}
572
573STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
574{
575 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
576
577 AutoCaller autoCaller(this);
578 if (FAILED(autoCaller.rc())) return autoCaller.rc();
579
580 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
581
582 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
583 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
584
585 return S_OK;
586}
587
588STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
589{
590 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
591
592 AutoCaller autoCaller(this);
593 if (FAILED(autoCaller.rc())) return autoCaller.rc();
594
595 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
596
597 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
598
599 return S_OK;
600}
601
602STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
603{
604 AutoCaller autoCaller(this);
605 if (FAILED(autoCaller.rc())) return autoCaller.rc();
606
607 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
608 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
609 alock.release();
610
611 if (SUCCEEDED(rc))
612 {
613 // VirtualBox::saveSettings() needs vbox write lock
614 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
615 rc = mParent->saveSettings();
616 }
617
618 return rc;
619}
620
621STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(LONG64 *aFreeSpace)
622{
623 CheckComArgOutPointerValid(aFreeSpace);
624
625 ReturnComNotImplemented();
626}
627
628STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(LONG64 /* aFreeSpace */)
629{
630 ReturnComNotImplemented();
631}
632
633STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
634{
635 CheckComArgOutPointerValid(aFreeSpacePercent);
636
637 ReturnComNotImplemented();
638}
639
640STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
641{
642 ReturnComNotImplemented();
643}
644
645STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(LONG64 *aFreeSpace)
646{
647 CheckComArgOutPointerValid(aFreeSpace);
648
649 ReturnComNotImplemented();
650}
651
652STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(LONG64 /* aFreeSpace */)
653{
654 ReturnComNotImplemented();
655}
656
657STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
658{
659 CheckComArgOutPointerValid(aFreeSpacePercent);
660
661 ReturnComNotImplemented();
662}
663
664STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
665{
666 ReturnComNotImplemented();
667}
668
669STDMETHODIMP SystemProperties::COMGETTER(VRDEAuthLibrary)(BSTR *aVRDEAuthLibrary)
670{
671 CheckComArgOutPointerValid(aVRDEAuthLibrary);
672
673 AutoCaller autoCaller(this);
674 if (FAILED(autoCaller.rc())) return autoCaller.rc();
675
676 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
677
678 m->strVRDEAuthLibrary.cloneTo(aVRDEAuthLibrary);
679
680 return S_OK;
681}
682
683STDMETHODIMP SystemProperties::COMSETTER(VRDEAuthLibrary)(IN_BSTR aVRDEAuthLibrary)
684{
685 AutoCaller autoCaller(this);
686 if (FAILED(autoCaller.rc())) return autoCaller.rc();
687
688 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
689 HRESULT rc = setVRDEAuthLibrary(aVRDEAuthLibrary);
690 alock.release();
691
692 if (SUCCEEDED(rc))
693 {
694 // VirtualBox::saveSettings() needs vbox write lock
695 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
696 rc = mParent->saveSettings();
697 }
698
699 return rc;
700}
701
702STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
703{
704 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
705
706 AutoCaller autoCaller(this);
707 if (FAILED(autoCaller.rc())) return autoCaller.rc();
708
709 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
710
711 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
712
713 return S_OK;
714}
715
716STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
717{
718 AutoCaller autoCaller(this);
719 if (FAILED(autoCaller.rc())) return autoCaller.rc();
720
721 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
722 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
723 alock.release();
724
725 if (SUCCEEDED(rc))
726 {
727 // VirtualBox::saveSettings() needs vbox write lock
728 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
729 rc = mParent->saveSettings();
730 }
731
732 return rc;
733}
734
735STDMETHODIMP SystemProperties::COMGETTER(DefaultVRDELibrary)(BSTR *aVRDELibrary)
736{
737 CheckComArgOutPointerValid(aVRDELibrary);
738
739 AutoCaller autoCaller(this);
740 if (FAILED(autoCaller.rc())) return autoCaller.rc();
741
742 BOOL fFound = FALSE;
743 HRESULT rc = mParent->VRDEIsLibraryRegistered(Bstr(m->strDefaultVRDELibrary).raw(), &fFound);
744
745 if (FAILED(rc)|| !fFound)
746 return setError(E_FAIL, "The library is not registered\n");
747
748 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
749
750 m->strDefaultVRDELibrary.cloneTo(aVRDELibrary);
751
752 return S_OK;
753}
754
755STDMETHODIMP SystemProperties::COMSETTER(DefaultVRDELibrary)(IN_BSTR aVRDELibrary)
756{
757 AutoCaller autoCaller(this);
758 if (FAILED(autoCaller.rc())) return autoCaller.rc();
759
760 HRESULT rc;
761
762 Bstr bstrLibrary(aVRDELibrary);
763
764 if (!bstrLibrary.isEmpty())
765 {
766 BOOL fFound = FALSE;
767 rc = mParent->VRDEIsLibraryRegistered(bstrLibrary.raw(), &fFound);
768
769 if (FAILED(rc) || !fFound)
770 return setError(E_FAIL, "The library is not registered\n");
771 }
772
773 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
774 rc = setDefaultVRDELibrary(bstrLibrary);
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(LogHistoryCount)(ULONG *count)
788{
789 CheckComArgOutPointerValid(count);
790
791 AutoCaller autoCaller(this);
792 if (FAILED(autoCaller.rc())) return autoCaller.rc();
793
794 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
795
796 *count = m->ulLogHistoryCount;
797
798 return S_OK;
799}
800
801STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
802{
803 AutoCaller autoCaller(this);
804 if (FAILED(autoCaller.rc())) return autoCaller.rc();
805
806 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
807 m->ulLogHistoryCount = count;
808 alock.release();
809
810 // VirtualBox::saveSettings() needs vbox write lock
811 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
812 HRESULT rc = mParent->saveSettings();
813
814 return rc;
815}
816
817STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
818{
819 CheckComArgOutPointerValid(aAudioDriver);
820
821 AutoCaller autoCaller(this);
822 if (FAILED(autoCaller.rc())) return autoCaller.rc();
823
824 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
825
826 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
827
828 return S_OK;
829}
830
831// public methods only for internal purposes
832/////////////////////////////////////////////////////////////////////////////
833
834HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
835{
836 AutoCaller autoCaller(this);
837 if (FAILED(autoCaller.rc())) return autoCaller.rc();
838
839 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
840
841 HRESULT rc = S_OK;
842
843 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
844 if (FAILED(rc)) return rc;
845
846 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
847 if (FAILED(rc)) return rc;
848
849 rc = setVRDEAuthLibrary(data.strVRDEAuthLibrary);
850 if (FAILED(rc)) return rc;
851
852 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
853 if (FAILED(rc)) return rc;
854
855 rc = setDefaultVRDELibrary(data.strDefaultVRDELibrary);
856 if (FAILED(rc)) return rc;
857
858 m->ulLogHistoryCount = data.ulLogHistoryCount;
859
860 return S_OK;
861}
862
863HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
864{
865 AutoCaller autoCaller(this);
866 if (FAILED(autoCaller.rc())) return autoCaller.rc();
867
868 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
869
870 data = *m;
871
872 return S_OK;
873}
874
875/**
876 * Returns a medium format object corresponding to the given format
877 * identifier or null if no such format.
878 *
879 * @param aFormat Format identifier.
880 *
881 * @return ComObjPtr<MediumFormat>
882 */
883ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
884{
885 ComObjPtr<MediumFormat> format;
886
887 AutoCaller autoCaller(this);
888 AssertComRCReturn (autoCaller.rc(), format);
889
890 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
891
892 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
893 it != m_llMediumFormats.end();
894 ++ it)
895 {
896 /* MediumFormat is all const, no need to lock */
897
898 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
899 {
900 format = *it;
901 break;
902 }
903 }
904
905 return format;
906}
907
908/**
909 * Returns a medium format object corresponding to the given file extension or
910 * null if no such format.
911 *
912 * @param aExt File extension.
913 *
914 * @return ComObjPtr<MediumFormat>
915 */
916ComObjPtr<MediumFormat> SystemProperties::mediumFormatFromExtension(const Utf8Str &aExt)
917{
918 ComObjPtr<MediumFormat> format;
919
920 AutoCaller autoCaller(this);
921 AssertComRCReturn (autoCaller.rc(), format);
922
923 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
924
925 bool fFound = false;
926 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
927 it != m_llMediumFormats.end() && !fFound;
928 ++it)
929 {
930 /* MediumFormat is all const, no need to lock */
931 MediumFormat::StrList aFileList = (*it)->getFileExtensions();
932 for (MediumFormat::StrList::const_iterator it1 = aFileList.begin();
933 it1 != aFileList.end();
934 ++it1)
935 {
936 if ((*it1).compare(aExt, Utf8Str::CaseInsensitive) == 0)
937 {
938 format = *it;
939 fFound = true;
940 break;
941 }
942 }
943 }
944
945 return format;
946}
947
948// private methods
949/////////////////////////////////////////////////////////////////////////////
950
951HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
952{
953 Utf8Str path(aPath);
954 if (path.isEmpty())
955 path = "Machines";
956
957 /* get the full file name */
958 Utf8Str folder;
959 int vrc = mParent->calculateFullPath(path, folder);
960 if (RT_FAILURE(vrc))
961 return setError(E_FAIL,
962 tr("Invalid default machine folder '%s' (%Rrc)"),
963 path.c_str(),
964 vrc);
965
966 m->strDefaultMachineFolder = path;
967 m_strDefaultMachineFolderFull = folder;
968
969 return S_OK;
970}
971
972HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
973{
974 if (!aFormat.isEmpty())
975 m->strDefaultHardDiskFormat = aFormat;
976 else
977 m->strDefaultHardDiskFormat = "VDI";
978
979 return S_OK;
980}
981
982HRESULT SystemProperties::setVRDEAuthLibrary(const Utf8Str &aPath)
983{
984 if (!aPath.isEmpty())
985 m->strVRDEAuthLibrary = aPath;
986 else
987 m->strVRDEAuthLibrary = "VRDPAuth";
988
989 return S_OK;
990}
991
992HRESULT SystemProperties::setDefaultVRDELibrary(const Utf8Str &aPath)
993{
994 m->strDefaultVRDELibrary = aPath;
995
996 return S_OK;
997}
998
999HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
1000{
1001 if (!aPath.isEmpty())
1002 m->strWebServiceAuthLibrary = aPath;
1003 else
1004 m->strWebServiceAuthLibrary = "VRDPAuth";
1005
1006 return S_OK;
1007}
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