VirtualBox

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

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

Main: use settings struct for machine user data; remove iprt::MiniString::raw() and change all occurences to c_str()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.1 KB
Line 
1/* $Id: SystemPropertiesImpl.cpp 31539 2010-08-10 15:40:18Z 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/VBoxHDD.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 setDefaultHardDiskFolder(Utf8Str::Empty);
88 setDefaultHardDiskFormat(Utf8Str::Empty);
89
90 setRemoteDisplayAuthLibrary(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(MaxVDISize)(ULONG64 *maxVDISize)
243{
244 CheckComArgOutPointerValid(maxVDISize);
245
246 AutoCaller autoCaller(this);
247 if (FAILED(autoCaller.rc())) return autoCaller.rc();
248
249 /** The BIOS supports currently 32 bit LBA numbers (implementing the full
250 * 48 bit range is in theory trivial, but the crappy compiler makes things
251 * more difficult). This translates to almost 2 TBytes (to be on the safe
252 * side, the reported limit is 1 MiByte less than that, as the total number
253 * of sectors should fit in 32 bits, too), which should bei enough for
254 * the moment. The virtual ATA disks support complete LBA48 (although for
255 * example iSCSI is also currently limited to 32 bit LBA), so the
256 * theoretical maximum disk size is 128 PiByte. The user interface cannot
257 * cope with this in a reasonable way yet. */
258 /* no need to lock, this is const */
259 *maxVDISize = 2048 * 1024 - 1;
260
261 return S_OK;
262}
263
264STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
265{
266 CheckComArgOutPointerValid(count);
267
268 AutoCaller autoCaller(this);
269 if (FAILED(autoCaller.rc())) return autoCaller.rc();
270
271 /* no need to lock, this is const */
272 *count = SchemaDefs::NetworkAdapterCount;
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
316STDMETHODIMP SystemProperties::GetMaxDevicesPerPortForStorageBus(StorageBus_T aBus,
317 ULONG *aMaxDevicesPerPort)
318{
319 CheckComArgOutPointerValid(aMaxDevicesPerPort);
320
321 AutoCaller autoCaller(this);
322 if (FAILED(autoCaller.rc())) return autoCaller.rc();
323
324 /* no need to lock, this is const */
325 switch (aBus)
326 {
327 case StorageBus_SATA:
328 case StorageBus_SCSI:
329 case StorageBus_SAS:
330 {
331 /* SATA and both SCSI controllers only support one device per port. */
332 *aMaxDevicesPerPort = 1;
333 break;
334 }
335 case StorageBus_IDE:
336 case StorageBus_Floppy:
337 {
338 /* The IDE and Floppy controllers support 2 devices. One as master
339 * and one as slave (or floppy drive 0 and 1). */
340 *aMaxDevicesPerPort = 2;
341 break;
342 }
343 default:
344 AssertMsgFailed(("Invalid bus type %d\n", aBus));
345 }
346
347 return S_OK;
348}
349
350STDMETHODIMP SystemProperties::GetMinPortCountForStorageBus(StorageBus_T aBus,
351 ULONG *aMinPortCount)
352{
353 CheckComArgOutPointerValid(aMinPortCount);
354
355 AutoCaller autoCaller(this);
356 if (FAILED(autoCaller.rc())) return autoCaller.rc();
357
358 /* no need to lock, this is const */
359 switch (aBus)
360 {
361 case StorageBus_SATA:
362 {
363 *aMinPortCount = 1;
364 break;
365 }
366 case StorageBus_SCSI:
367 {
368 *aMinPortCount = 16;
369 break;
370 }
371 case StorageBus_IDE:
372 {
373 *aMinPortCount = 2;
374 break;
375 }
376 case StorageBus_Floppy:
377 {
378 *aMinPortCount = 1;
379 break;
380 }
381 case StorageBus_SAS:
382 {
383 *aMinPortCount = 8;
384 break;
385 }
386 default:
387 AssertMsgFailed(("Invalid bus type %d\n", aBus));
388 }
389
390 return S_OK;
391}
392
393STDMETHODIMP SystemProperties::GetMaxPortCountForStorageBus(StorageBus_T aBus,
394 ULONG *aMaxPortCount)
395{
396 CheckComArgOutPointerValid(aMaxPortCount);
397
398 AutoCaller autoCaller(this);
399 if (FAILED(autoCaller.rc())) return autoCaller.rc();
400
401 /* no need to lock, this is const */
402 switch (aBus)
403 {
404 case StorageBus_SATA:
405 {
406 *aMaxPortCount = 30;
407 break;
408 }
409 case StorageBus_SCSI:
410 {
411 *aMaxPortCount = 16;
412 break;
413 }
414 case StorageBus_IDE:
415 {
416 *aMaxPortCount = 2;
417 break;
418 }
419 case StorageBus_Floppy:
420 {
421 *aMaxPortCount = 1;
422 break;
423 }
424 case StorageBus_SAS:
425 {
426 *aMaxPortCount = 8;
427 break;
428 }
429 default:
430 AssertMsgFailed(("Invalid bus type %d\n", aBus));
431 }
432
433 return S_OK;
434}
435
436STDMETHODIMP SystemProperties::GetMaxInstancesOfStorageBus(StorageBus_T aBus,
437 ULONG *aMaxInstances)
438{
439 CheckComArgOutPointerValid(aMaxInstances);
440
441 AutoCaller autoCaller(this);
442 if (FAILED(autoCaller.rc())) return autoCaller.rc();
443
444 /* no need to lock, this is const */
445 switch (aBus)
446 {
447 case StorageBus_SATA:
448 case StorageBus_SCSI:
449 case StorageBus_IDE:
450 case StorageBus_SAS:
451 case StorageBus_Floppy:
452 {
453 /** @todo raise the limits ASAP, per bus type */
454 *aMaxInstances = 1;
455 break;
456 }
457 default:
458 AssertMsgFailed(("Invalid bus type %d\n", aBus));
459 }
460
461 return S_OK;
462}
463
464STDMETHODIMP SystemProperties::GetDeviceTypesForStorageBus(StorageBus_T aBus,
465 ComSafeArrayOut(DeviceType_T, aDeviceTypes))
466{
467 CheckComArgOutSafeArrayPointerValid(aDeviceTypes);
468
469 AutoCaller autoCaller(this);
470 if (FAILED(autoCaller.rc())) return autoCaller.rc();
471
472 /* no need to lock, this is const */
473 switch (aBus)
474 {
475 case StorageBus_IDE:
476 {
477 com::SafeArray<DeviceType_T> saDeviceTypes(2);
478 saDeviceTypes[0] = DeviceType_DVD;
479 saDeviceTypes[1] = DeviceType_HardDisk;
480 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
481 break;
482 }
483 case StorageBus_SATA:
484 case StorageBus_SCSI:
485 case StorageBus_SAS:
486 {
487 com::SafeArray<DeviceType_T> saDeviceTypes(1);
488 saDeviceTypes[0] = DeviceType_HardDisk;
489 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
490 break;
491 }
492 case StorageBus_Floppy:
493 {
494 com::SafeArray<DeviceType_T> saDeviceTypes(1);
495 saDeviceTypes[0] = DeviceType_Floppy;
496 saDeviceTypes.detachTo(ComSafeArrayOutArg(aDeviceTypes));
497 break;
498 }
499 default:
500 AssertMsgFailed(("Invalid bus type %d\n", aBus));
501 }
502
503 return S_OK;
504}
505
506STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder)(BSTR *aDefaultMachineFolder)
507{
508 CheckComArgOutPointerValid(aDefaultMachineFolder);
509
510 AutoCaller autoCaller(this);
511 if (FAILED(autoCaller.rc())) return autoCaller.rc();
512
513 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
514
515 m_strDefaultMachineFolderFull.cloneTo(aDefaultMachineFolder);
516
517 return S_OK;
518}
519
520STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder)(IN_BSTR aDefaultMachineFolder)
521{
522 AutoCaller autoCaller(this);
523 if (FAILED(autoCaller.rc())) return autoCaller.rc();
524
525 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
526 HRESULT rc = setDefaultMachineFolder(aDefaultMachineFolder);
527 alock.release();
528
529 if (SUCCEEDED(rc))
530 {
531 // VirtualBox::saveSettings() needs vbox write lock
532 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
533 rc = mParent->saveSettings();
534 }
535
536 return rc;
537}
538
539STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder)(BSTR *aDefaultHardDiskFolder)
540{
541 CheckComArgOutPointerValid(aDefaultHardDiskFolder);
542
543 AutoCaller autoCaller(this);
544 if (FAILED(autoCaller.rc())) return autoCaller.rc();
545
546 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
547
548 m_strDefaultHardDiskFolderFull.cloneTo(aDefaultHardDiskFolder);
549
550 return S_OK;
551}
552
553STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder)(IN_BSTR aDefaultHardDiskFolder)
554{
555 AutoCaller autoCaller(this);
556 if (FAILED(autoCaller.rc())) return autoCaller.rc();
557
558 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
559 HRESULT rc = setDefaultHardDiskFolder(aDefaultHardDiskFolder);
560 alock.release();
561
562 if (SUCCEEDED(rc))
563 {
564 // VirtualBox::saveSettings() needs vbox write lock
565 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
566 rc = mParent->saveSettings();
567 }
568
569 return rc;
570}
571
572STDMETHODIMP SystemProperties::COMGETTER(MediumFormats)(ComSafeArrayOut(IMediumFormat *, aMediumFormats))
573{
574 CheckComArgOutSafeArrayPointerValid(aMediumFormats);
575
576 AutoCaller autoCaller(this);
577 if (FAILED(autoCaller.rc())) return autoCaller.rc();
578
579 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
580
581 SafeIfaceArray<IMediumFormat> mediumFormats(m_llMediumFormats);
582 mediumFormats.detachTo(ComSafeArrayOutArg(aMediumFormats));
583
584 return S_OK;
585}
586
587STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat)(BSTR *aDefaultHardDiskFormat)
588{
589 CheckComArgOutPointerValid(aDefaultHardDiskFormat);
590
591 AutoCaller autoCaller(this);
592 if (FAILED(autoCaller.rc())) return autoCaller.rc();
593
594 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
595
596 m->strDefaultHardDiskFormat.cloneTo(aDefaultHardDiskFormat);
597
598 return S_OK;
599}
600
601STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat)(IN_BSTR aDefaultHardDiskFormat)
602{
603 AutoCaller autoCaller(this);
604 if (FAILED(autoCaller.rc())) return autoCaller.rc();
605
606 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
607 HRESULT rc = setDefaultHardDiskFormat(aDefaultHardDiskFormat);
608 alock.release();
609
610 if (SUCCEEDED(rc))
611 {
612 // VirtualBox::saveSettings() needs vbox write lock
613 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
614 rc = mParent->saveSettings();
615 }
616
617 return rc;
618}
619
620STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceWarning)(ULONG64 *aFreeSpace)
621{
622 CheckComArgOutPointerValid(aFreeSpace);
623
624 ReturnComNotImplemented();
625}
626
627STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceWarning)(ULONG64 /* aFreeSpace */)
628{
629 ReturnComNotImplemented();
630}
631
632STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentWarning)(ULONG *aFreeSpacePercent)
633{
634 CheckComArgOutPointerValid(aFreeSpacePercent);
635
636 ReturnComNotImplemented();
637}
638
639STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentWarning)(ULONG /* aFreeSpacePercent */)
640{
641 ReturnComNotImplemented();
642}
643
644STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpaceError)(ULONG64 *aFreeSpace)
645{
646 CheckComArgOutPointerValid(aFreeSpace);
647
648 ReturnComNotImplemented();
649}
650
651STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpaceError)(ULONG64 /* aFreeSpace */)
652{
653 ReturnComNotImplemented();
654}
655
656STDMETHODIMP SystemProperties::COMGETTER(FreeDiskSpacePercentError)(ULONG *aFreeSpacePercent)
657{
658 CheckComArgOutPointerValid(aFreeSpacePercent);
659
660 ReturnComNotImplemented();
661}
662
663STDMETHODIMP SystemProperties::COMSETTER(FreeDiskSpacePercentError)(ULONG /* aFreeSpacePercent */)
664{
665 ReturnComNotImplemented();
666}
667
668STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary)(BSTR *aRemoteDisplayAuthLibrary)
669{
670 CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
671
672 AutoCaller autoCaller(this);
673 if (FAILED(autoCaller.rc())) return autoCaller.rc();
674
675 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
676
677 m->strRemoteDisplayAuthLibrary.cloneTo(aRemoteDisplayAuthLibrary);
678
679 return S_OK;
680}
681
682STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary)(IN_BSTR aRemoteDisplayAuthLibrary)
683{
684 AutoCaller autoCaller(this);
685 if (FAILED(autoCaller.rc())) return autoCaller.rc();
686
687 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
688 HRESULT rc = setRemoteDisplayAuthLibrary(aRemoteDisplayAuthLibrary);
689 alock.release();
690
691 if (SUCCEEDED(rc))
692 {
693 // VirtualBox::saveSettings() needs vbox write lock
694 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
695 rc = mParent->saveSettings();
696 }
697
698 return rc;
699}
700
701STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary)(BSTR *aWebServiceAuthLibrary)
702{
703 CheckComArgOutPointerValid(aWebServiceAuthLibrary);
704
705 AutoCaller autoCaller(this);
706 if (FAILED(autoCaller.rc())) return autoCaller.rc();
707
708 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
709
710 m->strWebServiceAuthLibrary.cloneTo(aWebServiceAuthLibrary);
711
712 return S_OK;
713}
714
715STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary)(IN_BSTR aWebServiceAuthLibrary)
716{
717 AutoCaller autoCaller(this);
718 if (FAILED(autoCaller.rc())) return autoCaller.rc();
719
720 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
721 HRESULT rc = setWebServiceAuthLibrary(aWebServiceAuthLibrary);
722 alock.release();
723
724 if (SUCCEEDED(rc))
725 {
726 // VirtualBox::saveSettings() needs vbox write lock
727 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
728 rc = mParent->saveSettings();
729 }
730
731 return rc;
732}
733
734STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount)(ULONG *count)
735{
736 CheckComArgOutPointerValid(count);
737
738 AutoCaller autoCaller(this);
739 if (FAILED(autoCaller.rc())) return autoCaller.rc();
740
741 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
742
743 *count = m->ulLogHistoryCount;
744
745 return S_OK;
746}
747
748STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount)(ULONG count)
749{
750 AutoCaller autoCaller(this);
751 if (FAILED(autoCaller.rc())) return autoCaller.rc();
752
753 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
754 m->ulLogHistoryCount = count;
755 alock.release();
756
757 // VirtualBox::saveSettings() needs vbox write lock
758 AutoWriteLock vboxLock(mParent COMMA_LOCKVAL_SRC_POS);
759 HRESULT rc = mParent->saveSettings();
760
761 return rc;
762}
763
764STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver)(AudioDriverType_T *aAudioDriver)
765{
766 CheckComArgOutPointerValid(aAudioDriver);
767
768 AutoCaller autoCaller(this);
769 if (FAILED(autoCaller.rc())) return autoCaller.rc();
770
771 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
772
773 *aAudioDriver = settings::MachineConfigFile::getHostDefaultAudioDriver();
774
775 return S_OK;
776}
777
778// public methods only for internal purposes
779/////////////////////////////////////////////////////////////////////////////
780
781HRESULT SystemProperties::loadSettings(const settings::SystemProperties &data)
782{
783 AutoCaller autoCaller(this);
784 if (FAILED(autoCaller.rc())) return autoCaller.rc();
785
786 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
787
788 HRESULT rc = S_OK;
789
790 rc = setDefaultMachineFolder(data.strDefaultMachineFolder);
791 if (FAILED(rc)) return rc;
792
793 rc = setDefaultHardDiskFolder(data.strDefaultHardDiskFolder);
794 if (FAILED(rc)) return rc;
795
796 rc = setDefaultHardDiskFormat(data.strDefaultHardDiskFormat);
797 if (FAILED(rc)) return rc;
798
799 rc = setRemoteDisplayAuthLibrary(data.strRemoteDisplayAuthLibrary);
800 if (FAILED(rc)) return rc;
801
802 rc = setWebServiceAuthLibrary(data.strWebServiceAuthLibrary);
803 if (FAILED(rc)) return rc;
804
805 m->ulLogHistoryCount = data.ulLogHistoryCount;
806
807 return S_OK;
808}
809
810HRESULT SystemProperties::saveSettings(settings::SystemProperties &data)
811{
812 AutoCaller autoCaller(this);
813 if (FAILED(autoCaller.rc())) return autoCaller.rc();
814
815 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
816
817 data = *m;
818
819 return S_OK;
820}
821
822/**
823 * Returns a medium format object corresponding to the given format
824 * identifier or null if no such format.
825 *
826 * @param aFormat Format identifier.
827 *
828 * @return ComObjPtr<MediumFormat>
829 */
830ComObjPtr<MediumFormat> SystemProperties::mediumFormat(const Utf8Str &aFormat)
831{
832 ComObjPtr<MediumFormat> format;
833
834 AutoCaller autoCaller(this);
835 AssertComRCReturn (autoCaller.rc(), format);
836
837 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
838
839 for (MediumFormatList::const_iterator it = m_llMediumFormats.begin();
840 it != m_llMediumFormats.end();
841 ++ it)
842 {
843 /* MediumFormat is all const, no need to lock */
844
845 if ((*it)->getId().compare(aFormat, Utf8Str::CaseInsensitive) == 0)
846 {
847 format = *it;
848 break;
849 }
850 }
851
852 return format;
853}
854
855// private methods
856/////////////////////////////////////////////////////////////////////////////
857
858HRESULT SystemProperties::setDefaultMachineFolder(const Utf8Str &aPath)
859{
860 Utf8Str path(aPath);
861 if (path.isEmpty())
862 path = "Machines";
863
864 /* get the full file name */
865 Utf8Str folder;
866 int vrc = mParent->calculateFullPath(path, folder);
867 if (RT_FAILURE(vrc))
868 return setError(E_FAIL,
869 tr("Invalid default machine folder '%s' (%Rrc)"),
870 path.c_str(),
871 vrc);
872
873 m->strDefaultMachineFolder = path;
874 m_strDefaultMachineFolderFull = folder;
875
876 return S_OK;
877}
878
879HRESULT SystemProperties::setDefaultHardDiskFolder(const Utf8Str &aPath)
880{
881 Utf8Str path(aPath);
882 if (path.isEmpty())
883 path = "HardDisks";
884
885 /* get the full file name */
886 Utf8Str folder;
887 int vrc = mParent->calculateFullPath(path, folder);
888 if (RT_FAILURE(vrc))
889 return setError(E_FAIL,
890 tr("Invalid default hard disk folder '%s' (%Rrc)"),
891 path.c_str(),
892 vrc);
893
894 m->strDefaultHardDiskFolder = path;
895 m_strDefaultHardDiskFolderFull = folder;
896
897 return S_OK;
898}
899
900HRESULT SystemProperties::setDefaultHardDiskFormat(const Utf8Str &aFormat)
901{
902 if (!aFormat.isEmpty())
903 m->strDefaultHardDiskFormat = aFormat;
904 else
905 m->strDefaultHardDiskFormat = "VDI";
906
907 return S_OK;
908}
909
910HRESULT SystemProperties::setRemoteDisplayAuthLibrary(const Utf8Str &aPath)
911{
912 if (!aPath.isEmpty())
913 m->strRemoteDisplayAuthLibrary = aPath;
914 else
915 m->strRemoteDisplayAuthLibrary = "VRDPAuth";
916
917 return S_OK;
918}
919
920HRESULT SystemProperties::setWebServiceAuthLibrary(const Utf8Str &aPath)
921{
922 if (!aPath.isEmpty())
923 m->strWebServiceAuthLibrary = aPath;
924 else
925 m->strWebServiceAuthLibrary = "VRDPAuth";
926
927 return S_OK;
928}
929
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