1 | /* $Id: SystemPropertiesImpl.cpp 21446 2009-07-09 15:09:57Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2008 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #include "SystemPropertiesImpl.h"
|
---|
25 | #include "VirtualBoxImpl.h"
|
---|
26 | #include "MachineImpl.h"
|
---|
27 | #include "Logging.h"
|
---|
28 |
|
---|
29 | // generated header
|
---|
30 | #include "SchemaDefs.h"
|
---|
31 |
|
---|
32 | #include <iprt/path.h>
|
---|
33 | #include <iprt/dir.h>
|
---|
34 | #include <iprt/process.h>
|
---|
35 | #include <iprt/ldr.h>
|
---|
36 |
|
---|
37 | #include <VBox/err.h>
|
---|
38 | #include <VBox/param.h>
|
---|
39 | #include <VBox/settings.h>
|
---|
40 |
|
---|
41 | // defines
|
---|
42 | /////////////////////////////////////////////////////////////////////////////
|
---|
43 |
|
---|
44 | // constructor / destructor
|
---|
45 | /////////////////////////////////////////////////////////////////////////////
|
---|
46 |
|
---|
47 | DEFINE_EMPTY_CTOR_DTOR (SystemProperties)
|
---|
48 |
|
---|
49 | HRESULT SystemProperties::FinalConstruct()
|
---|
50 | {
|
---|
51 | return S_OK;
|
---|
52 | }
|
---|
53 |
|
---|
54 | void SystemProperties::FinalRelease()
|
---|
55 | {
|
---|
56 | uninit ();
|
---|
57 | }
|
---|
58 |
|
---|
59 | // public methods only for internal purposes
|
---|
60 | /////////////////////////////////////////////////////////////////////////////
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Initializes the system information object.
|
---|
64 | *
|
---|
65 | * @returns COM result indicator
|
---|
66 | */
|
---|
67 | HRESULT SystemProperties::init (VirtualBox *aParent)
|
---|
68 | {
|
---|
69 | LogFlowThisFunc (("aParent=%p\n", aParent));
|
---|
70 |
|
---|
71 | ComAssertRet (aParent, E_FAIL);
|
---|
72 |
|
---|
73 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
74 | AutoInitSpan autoInitSpan (this);
|
---|
75 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
76 |
|
---|
77 | unconst (mParent) = aParent;
|
---|
78 |
|
---|
79 | setDefaultMachineFolder (NULL);
|
---|
80 | setDefaultHardDiskFolder (NULL);
|
---|
81 | setDefaultHardDiskFormat (NULL);
|
---|
82 |
|
---|
83 | setRemoteDisplayAuthLibrary (NULL);
|
---|
84 |
|
---|
85 | mLogHistoryCount = 3;
|
---|
86 |
|
---|
87 | HRESULT rc = S_OK;
|
---|
88 |
|
---|
89 | /* Fetch info of all available hd backends. */
|
---|
90 |
|
---|
91 | /// @todo NEWMEDIA VDBackendInfo needs to be improved to let us enumerate
|
---|
92 | /// any number of backends
|
---|
93 |
|
---|
94 | /// @todo We currently leak memory because it's not actually clear what to
|
---|
95 | /// free in structures returned by VDBackendInfo. Must be fixed ASAP!
|
---|
96 |
|
---|
97 | VDBACKENDINFO aVDInfo [100];
|
---|
98 | unsigned cEntries;
|
---|
99 | int vrc = VDBackendInfo (RT_ELEMENTS (aVDInfo), aVDInfo, &cEntries);
|
---|
100 | AssertRC (vrc);
|
---|
101 | if (RT_SUCCESS (vrc))
|
---|
102 | {
|
---|
103 | for (unsigned i = 0; i < cEntries; ++ i)
|
---|
104 | {
|
---|
105 | ComObjPtr <HardDiskFormat> hdf;
|
---|
106 | rc = hdf.createObject();
|
---|
107 | CheckComRCBreakRC (rc);
|
---|
108 |
|
---|
109 | rc = hdf->init (&aVDInfo [i]);
|
---|
110 | CheckComRCBreakRC (rc);
|
---|
111 |
|
---|
112 | mHardDiskFormats.push_back (hdf);
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | /* Driver defaults which are OS specific */
|
---|
117 | #if defined (RT_OS_WINDOWS)
|
---|
118 | # ifdef VBOX_WITH_WINMM
|
---|
119 | mDefaultAudioDriver = AudioDriverType_WinMM;
|
---|
120 | # else /* VBOX_WITH_WINMM */
|
---|
121 | mDefaultAudioDriver = AudioDriverType_DirectSound;
|
---|
122 | # endif /* !VBOX_WITH_WINMM */
|
---|
123 | #elif defined (RT_OS_SOLARIS)
|
---|
124 | mDefaultAudioDriver = AudioDriverType_SolAudio;
|
---|
125 | #elif defined (RT_OS_LINUX)
|
---|
126 | # if defined (VBOX_WITH_PULSE)
|
---|
127 | /* Check for the pulse library & that the pulse audio daemon is running. */
|
---|
128 | if (RTProcIsRunningByName ("pulseaudio") &&
|
---|
129 | RTLdrIsLoadable ("libpulse.so.0"))
|
---|
130 | mDefaultAudioDriver = AudioDriverType_Pulse;
|
---|
131 | else
|
---|
132 | # endif /* VBOX_WITH_PULSE */
|
---|
133 | # if defined (VBOX_WITH_ALSA)
|
---|
134 | /* Check if we can load the ALSA library */
|
---|
135 | if (RTLdrIsLoadable ("libasound.so.2"))
|
---|
136 | mDefaultAudioDriver = AudioDriverType_ALSA;
|
---|
137 | else
|
---|
138 | # endif /* VBOX_WITH_ALSA */
|
---|
139 | mDefaultAudioDriver = AudioDriverType_OSS;
|
---|
140 | #elif defined (RT_OS_DARWIN)
|
---|
141 | mDefaultAudioDriver = AudioDriverType_CoreAudio;
|
---|
142 | #elif defined (RT_OS_OS2)
|
---|
143 | mDefaultAudioDriver = AudioDriverType_MMP;
|
---|
144 | #elif defined (RT_OS_FREEBSD)
|
---|
145 | mDefaultAudioDriver = AudioDriverType_OSS;
|
---|
146 | #else
|
---|
147 | mDefaultAudioDriver = AudioDriverType_Null;
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | /* Confirm a successful initialization */
|
---|
151 | if (SUCCEEDED (rc))
|
---|
152 | autoInitSpan.setSucceeded();
|
---|
153 |
|
---|
154 | return rc;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
159 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
160 | */
|
---|
161 | void SystemProperties::uninit()
|
---|
162 | {
|
---|
163 | LogFlowThisFunc (("\n"));
|
---|
164 |
|
---|
165 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
166 | AutoUninitSpan autoUninitSpan (this);
|
---|
167 | if (autoUninitSpan.uninitDone())
|
---|
168 | return;
|
---|
169 |
|
---|
170 | unconst (mParent).setNull();
|
---|
171 | }
|
---|
172 |
|
---|
173 | // ISystemProperties properties
|
---|
174 | /////////////////////////////////////////////////////////////////////////////
|
---|
175 |
|
---|
176 |
|
---|
177 | STDMETHODIMP SystemProperties::COMGETTER(MinGuestRAM)(ULONG *minRAM)
|
---|
178 | {
|
---|
179 | if (!minRAM)
|
---|
180 | return E_POINTER;
|
---|
181 |
|
---|
182 | AutoCaller autoCaller (this);
|
---|
183 | CheckComRCReturnRC (autoCaller.rc());
|
---|
184 |
|
---|
185 | /* no need to lock, this is const */
|
---|
186 | AssertCompile(MM_RAM_MIN_IN_MB >= SchemaDefs::MinGuestRAM);
|
---|
187 | *minRAM = MM_RAM_MIN_IN_MB;
|
---|
188 |
|
---|
189 | return S_OK;
|
---|
190 | }
|
---|
191 |
|
---|
192 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestRAM)(ULONG *maxRAM)
|
---|
193 | {
|
---|
194 | if (!maxRAM)
|
---|
195 | return E_POINTER;
|
---|
196 |
|
---|
197 | AutoCaller autoCaller (this);
|
---|
198 | CheckComRCReturnRC (autoCaller.rc());
|
---|
199 |
|
---|
200 | /* no need to lock, this is const */
|
---|
201 | AssertCompile(MM_RAM_MAX_IN_MB <= SchemaDefs::MaxGuestRAM);
|
---|
202 | *maxRAM = MM_RAM_MAX_IN_MB;
|
---|
203 |
|
---|
204 | return S_OK;
|
---|
205 | }
|
---|
206 |
|
---|
207 | STDMETHODIMP SystemProperties::COMGETTER(MinGuestVRAM)(ULONG *minVRAM)
|
---|
208 | {
|
---|
209 | if (!minVRAM)
|
---|
210 | return E_POINTER;
|
---|
211 |
|
---|
212 | AutoCaller autoCaller (this);
|
---|
213 | CheckComRCReturnRC (autoCaller.rc());
|
---|
214 |
|
---|
215 | /* no need to lock, this is const */
|
---|
216 | *minVRAM = SchemaDefs::MinGuestVRAM;
|
---|
217 |
|
---|
218 | return S_OK;
|
---|
219 | }
|
---|
220 |
|
---|
221 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestVRAM)(ULONG *maxVRAM)
|
---|
222 | {
|
---|
223 | if (!maxVRAM)
|
---|
224 | return E_POINTER;
|
---|
225 |
|
---|
226 | AutoCaller autoCaller (this);
|
---|
227 | CheckComRCReturnRC (autoCaller.rc());
|
---|
228 |
|
---|
229 | /* no need to lock, this is const */
|
---|
230 | *maxVRAM = SchemaDefs::MaxGuestVRAM;
|
---|
231 |
|
---|
232 | return S_OK;
|
---|
233 | }
|
---|
234 |
|
---|
235 | STDMETHODIMP SystemProperties::COMGETTER(MinGuestCPUCount)(ULONG *minCPUCount)
|
---|
236 | {
|
---|
237 | if (!minCPUCount)
|
---|
238 | return E_POINTER;
|
---|
239 |
|
---|
240 | AutoCaller autoCaller (this);
|
---|
241 | CheckComRCReturnRC (autoCaller.rc());
|
---|
242 |
|
---|
243 | /* no need to lock, this is const */
|
---|
244 | *minCPUCount = SchemaDefs::MinCPUCount; // VMM_MIN_CPU_COUNT
|
---|
245 |
|
---|
246 | return S_OK;
|
---|
247 | }
|
---|
248 |
|
---|
249 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestCPUCount)(ULONG *maxCPUCount)
|
---|
250 | {
|
---|
251 | if (!maxCPUCount)
|
---|
252 | return E_POINTER;
|
---|
253 |
|
---|
254 | AutoCaller autoCaller (this);
|
---|
255 | CheckComRCReturnRC (autoCaller.rc());
|
---|
256 |
|
---|
257 | /* no need to lock, this is const */
|
---|
258 | *maxCPUCount = SchemaDefs::MaxCPUCount; // VMM_MAX_CPU_COUNT
|
---|
259 |
|
---|
260 | return S_OK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | STDMETHODIMP SystemProperties::COMGETTER(MaxGuestMonitors)(ULONG *maxMonitors)
|
---|
264 | {
|
---|
265 | if (!maxMonitors)
|
---|
266 | return E_POINTER;
|
---|
267 |
|
---|
268 | AutoCaller autoCaller (this);
|
---|
269 | CheckComRCReturnRC (autoCaller.rc());
|
---|
270 |
|
---|
271 | /* no need to lock, this is const */
|
---|
272 | *maxMonitors = SchemaDefs::MaxGuestMonitors;
|
---|
273 |
|
---|
274 | return S_OK;
|
---|
275 | }
|
---|
276 |
|
---|
277 | STDMETHODIMP SystemProperties::COMGETTER(MaxVDISize)(ULONG64 *maxVDISize)
|
---|
278 | {
|
---|
279 | if (!maxVDISize)
|
---|
280 | return E_POINTER;
|
---|
281 |
|
---|
282 | AutoCaller autoCaller (this);
|
---|
283 | CheckComRCReturnRC (autoCaller.rc());
|
---|
284 |
|
---|
285 | /** The BIOS supports currently 32 bit LBA numbers (implementing the full
|
---|
286 | * 48 bit range is in theory trivial, but the crappy compiler makes things
|
---|
287 | * more difficult). This translates to almost 2 TBytes (to be on the safe
|
---|
288 | * side, the reported limit is 1 MiByte less than that, as the total number
|
---|
289 | * of sectors should fit in 32 bits, too), which should bei enough for
|
---|
290 | * the moment. The virtual ATA disks support complete LBA48 (although for
|
---|
291 | * example iSCSI is also currently limited to 32 bit LBA), so the
|
---|
292 | * theoretical maximum disk size is 128 PiByte. The user interface cannot
|
---|
293 | * cope with this in a reasonable way yet. */
|
---|
294 | /* no need to lock, this is const */
|
---|
295 | *maxVDISize = 2048 * 1024 - 1;
|
---|
296 |
|
---|
297 | return S_OK;
|
---|
298 | }
|
---|
299 |
|
---|
300 | STDMETHODIMP SystemProperties::COMGETTER(NetworkAdapterCount)(ULONG *count)
|
---|
301 | {
|
---|
302 | if (!count)
|
---|
303 | return E_POINTER;
|
---|
304 |
|
---|
305 | AutoCaller autoCaller (this);
|
---|
306 | CheckComRCReturnRC (autoCaller.rc());
|
---|
307 |
|
---|
308 | /* no need to lock, this is const */
|
---|
309 | *count = SchemaDefs::NetworkAdapterCount;
|
---|
310 |
|
---|
311 | return S_OK;
|
---|
312 | }
|
---|
313 |
|
---|
314 | STDMETHODIMP SystemProperties::COMGETTER(SerialPortCount)(ULONG *count)
|
---|
315 | {
|
---|
316 | if (!count)
|
---|
317 | return E_POINTER;
|
---|
318 |
|
---|
319 | AutoCaller autoCaller (this);
|
---|
320 | CheckComRCReturnRC (autoCaller.rc());
|
---|
321 |
|
---|
322 | /* no need to lock, this is const */
|
---|
323 | *count = SchemaDefs::SerialPortCount;
|
---|
324 |
|
---|
325 | return S_OK;
|
---|
326 | }
|
---|
327 |
|
---|
328 | STDMETHODIMP SystemProperties::COMGETTER(ParallelPortCount)(ULONG *count)
|
---|
329 | {
|
---|
330 | if (!count)
|
---|
331 | return E_POINTER;
|
---|
332 |
|
---|
333 | AutoCaller autoCaller (this);
|
---|
334 | CheckComRCReturnRC (autoCaller.rc());
|
---|
335 |
|
---|
336 | /* no need to lock, this is const */
|
---|
337 | *count = SchemaDefs::ParallelPortCount;
|
---|
338 |
|
---|
339 | return S_OK;
|
---|
340 | }
|
---|
341 |
|
---|
342 | STDMETHODIMP SystemProperties::COMGETTER(MaxBootPosition)(ULONG *aMaxBootPosition)
|
---|
343 | {
|
---|
344 | CheckComArgOutPointerValid(aMaxBootPosition);
|
---|
345 |
|
---|
346 | AutoCaller autoCaller (this);
|
---|
347 | CheckComRCReturnRC (autoCaller.rc());
|
---|
348 |
|
---|
349 | /* no need to lock, this is const */
|
---|
350 | *aMaxBootPosition = SchemaDefs::MaxBootPosition;
|
---|
351 |
|
---|
352 | return S_OK;
|
---|
353 | }
|
---|
354 |
|
---|
355 | STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
|
---|
356 | {
|
---|
357 | CheckComArgOutPointerValid(aDefaultMachineFolder);
|
---|
358 |
|
---|
359 | AutoCaller autoCaller (this);
|
---|
360 | CheckComRCReturnRC (autoCaller.rc());
|
---|
361 |
|
---|
362 | AutoReadLock alock (this);
|
---|
363 |
|
---|
364 | mDefaultMachineFolderFull.cloneTo (aDefaultMachineFolder);
|
---|
365 |
|
---|
366 | return S_OK;
|
---|
367 | }
|
---|
368 |
|
---|
369 | STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
|
---|
370 | {
|
---|
371 | AutoCaller autoCaller (this);
|
---|
372 | CheckComRCReturnRC (autoCaller.rc());
|
---|
373 |
|
---|
374 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
375 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
376 |
|
---|
377 | HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
|
---|
378 | if (SUCCEEDED (rc))
|
---|
379 | rc = mParent->saveSettings();
|
---|
380 |
|
---|
381 | return rc;
|
---|
382 | }
|
---|
383 |
|
---|
384 | STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder) (BSTR *aDefaultHardDiskFolder)
|
---|
385 | {
|
---|
386 | CheckComArgOutPointerValid(aDefaultHardDiskFolder);
|
---|
387 |
|
---|
388 | AutoCaller autoCaller (this);
|
---|
389 | CheckComRCReturnRC (autoCaller.rc());
|
---|
390 |
|
---|
391 | AutoReadLock alock (this);
|
---|
392 |
|
---|
393 | mDefaultHardDiskFolderFull.cloneTo (aDefaultHardDiskFolder);
|
---|
394 |
|
---|
395 | return S_OK;
|
---|
396 | }
|
---|
397 |
|
---|
398 | STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder) (IN_BSTR aDefaultHardDiskFolder)
|
---|
399 | {
|
---|
400 | AutoCaller autoCaller (this);
|
---|
401 | CheckComRCReturnRC (autoCaller.rc());
|
---|
402 |
|
---|
403 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
404 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
405 |
|
---|
406 | HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
|
---|
407 | if (SUCCEEDED (rc))
|
---|
408 | rc = mParent->saveSettings();
|
---|
409 |
|
---|
410 | return rc;
|
---|
411 | }
|
---|
412 |
|
---|
413 | STDMETHODIMP SystemProperties::
|
---|
414 | COMGETTER(HardDiskFormats) (ComSafeArrayOut (IHardDiskFormat *, aHardDiskFormats))
|
---|
415 | {
|
---|
416 | if (ComSafeArrayOutIsNull (aHardDiskFormats))
|
---|
417 | return E_POINTER;
|
---|
418 |
|
---|
419 | AutoCaller autoCaller (this);
|
---|
420 | CheckComRCReturnRC (autoCaller.rc());
|
---|
421 |
|
---|
422 | AutoReadLock alock (this);
|
---|
423 |
|
---|
424 | SafeIfaceArray <IHardDiskFormat> hardDiskFormats (mHardDiskFormats);
|
---|
425 | hardDiskFormats.detachTo (ComSafeArrayOutArg (aHardDiskFormats));
|
---|
426 |
|
---|
427 | return S_OK;
|
---|
428 | }
|
---|
429 |
|
---|
430 | STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
|
---|
431 | {
|
---|
432 | CheckComArgOutPointerValid(aDefaultHardDiskFormat);
|
---|
433 |
|
---|
434 | AutoCaller autoCaller (this);
|
---|
435 | CheckComRCReturnRC (autoCaller.rc());
|
---|
436 |
|
---|
437 | AutoReadLock alock (this);
|
---|
438 |
|
---|
439 | mDefaultHardDiskFormat.cloneTo (aDefaultHardDiskFormat);
|
---|
440 |
|
---|
441 | return S_OK;
|
---|
442 | }
|
---|
443 |
|
---|
444 | STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
|
---|
445 | {
|
---|
446 | AutoCaller autoCaller (this);
|
---|
447 | CheckComRCReturnRC (autoCaller.rc());
|
---|
448 |
|
---|
449 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
450 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
451 |
|
---|
452 | HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
|
---|
453 | if (SUCCEEDED (rc))
|
---|
454 | rc = mParent->saveSettings();
|
---|
455 |
|
---|
456 | return rc;
|
---|
457 | }
|
---|
458 |
|
---|
459 | STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
|
---|
460 | {
|
---|
461 | CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
|
---|
462 |
|
---|
463 | AutoCaller autoCaller (this);
|
---|
464 | CheckComRCReturnRC (autoCaller.rc());
|
---|
465 |
|
---|
466 | AutoReadLock alock (this);
|
---|
467 |
|
---|
468 | mRemoteDisplayAuthLibrary.cloneTo (aRemoteDisplayAuthLibrary);
|
---|
469 |
|
---|
470 | return S_OK;
|
---|
471 | }
|
---|
472 |
|
---|
473 | STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
|
---|
474 | {
|
---|
475 | AutoCaller autoCaller (this);
|
---|
476 | CheckComRCReturnRC (autoCaller.rc());
|
---|
477 |
|
---|
478 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
479 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
480 |
|
---|
481 | HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
|
---|
482 | if (SUCCEEDED (rc))
|
---|
483 | rc = mParent->saveSettings();
|
---|
484 |
|
---|
485 | return rc;
|
---|
486 | }
|
---|
487 |
|
---|
488 | STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
|
---|
489 | {
|
---|
490 | CheckComArgOutPointerValid(aWebServiceAuthLibrary);
|
---|
491 |
|
---|
492 | AutoCaller autoCaller (this);
|
---|
493 | CheckComRCReturnRC (autoCaller.rc());
|
---|
494 |
|
---|
495 | AutoReadLock alock (this);
|
---|
496 |
|
---|
497 | mWebServiceAuthLibrary.cloneTo (aWebServiceAuthLibrary);
|
---|
498 |
|
---|
499 | return S_OK;
|
---|
500 | }
|
---|
501 |
|
---|
502 | STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
|
---|
503 | {
|
---|
504 | AutoCaller autoCaller (this);
|
---|
505 | CheckComRCReturnRC (autoCaller.rc());
|
---|
506 |
|
---|
507 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
508 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
509 |
|
---|
510 | HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
|
---|
511 | if (SUCCEEDED (rc))
|
---|
512 | rc = mParent->saveSettings();
|
---|
513 |
|
---|
514 | return rc;
|
---|
515 | }
|
---|
516 |
|
---|
517 | STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
|
---|
518 | {
|
---|
519 | if (!count)
|
---|
520 | return E_POINTER;
|
---|
521 |
|
---|
522 | AutoCaller autoCaller (this);
|
---|
523 | CheckComRCReturnRC (autoCaller.rc());
|
---|
524 |
|
---|
525 | AutoReadLock alock (this);
|
---|
526 |
|
---|
527 | *count = mLogHistoryCount;
|
---|
528 |
|
---|
529 | return S_OK;
|
---|
530 | }
|
---|
531 |
|
---|
532 | STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
|
---|
533 | {
|
---|
534 | AutoCaller autoCaller (this);
|
---|
535 | CheckComRCReturnRC (autoCaller.rc());
|
---|
536 |
|
---|
537 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
538 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
539 |
|
---|
540 | mLogHistoryCount = count;
|
---|
541 |
|
---|
542 | HRESULT rc = mParent->saveSettings();
|
---|
543 |
|
---|
544 | return rc;
|
---|
545 | }
|
---|
546 |
|
---|
547 | STDMETHODIMP SystemProperties::COMGETTER(DefaultAudioDriver) (AudioDriverType_T *aAudioDriver)
|
---|
548 | {
|
---|
549 | if (!aAudioDriver)
|
---|
550 | return E_POINTER;
|
---|
551 |
|
---|
552 | AutoCaller autoCaller (this);
|
---|
553 | CheckComRCReturnRC (autoCaller.rc());
|
---|
554 |
|
---|
555 | AutoReadLock alock (this);
|
---|
556 |
|
---|
557 | *aAudioDriver = mDefaultAudioDriver;
|
---|
558 |
|
---|
559 | return S_OK;
|
---|
560 | }
|
---|
561 |
|
---|
562 | // public methods only for internal purposes
|
---|
563 | /////////////////////////////////////////////////////////////////////////////
|
---|
564 |
|
---|
565 | HRESULT SystemProperties::loadSettings (const settings::Key &aGlobal)
|
---|
566 | {
|
---|
567 | using namespace settings;
|
---|
568 |
|
---|
569 | AutoCaller autoCaller (this);
|
---|
570 | CheckComRCReturnRC (autoCaller.rc());
|
---|
571 |
|
---|
572 | AutoWriteLock alock (this);
|
---|
573 |
|
---|
574 | AssertReturn (!aGlobal.isNull(), E_FAIL);
|
---|
575 |
|
---|
576 | HRESULT rc = S_OK;
|
---|
577 |
|
---|
578 | Key properties = aGlobal.key ("SystemProperties");
|
---|
579 |
|
---|
580 | Bstr bstr;
|
---|
581 |
|
---|
582 | bstr = properties.stringValue ("defaultMachineFolder");
|
---|
583 | rc = setDefaultMachineFolder (bstr);
|
---|
584 | CheckComRCReturnRC (rc);
|
---|
585 |
|
---|
586 | bstr = properties.stringValue ("defaultHardDiskFolder");
|
---|
587 | rc = setDefaultHardDiskFolder (bstr);
|
---|
588 | CheckComRCReturnRC (rc);
|
---|
589 |
|
---|
590 | bstr = properties.stringValue ("defaultHardDiskFormat");
|
---|
591 | rc = setDefaultHardDiskFormat (bstr);
|
---|
592 | CheckComRCReturnRC (rc);
|
---|
593 |
|
---|
594 | bstr = properties.stringValue ("remoteDisplayAuthLibrary");
|
---|
595 | rc = setRemoteDisplayAuthLibrary (bstr);
|
---|
596 | CheckComRCReturnRC (rc);
|
---|
597 |
|
---|
598 | bstr = properties.stringValue ("webServiceAuthLibrary");
|
---|
599 | rc = setWebServiceAuthLibrary (bstr);
|
---|
600 | CheckComRCReturnRC (rc);
|
---|
601 |
|
---|
602 | mLogHistoryCount = properties.valueOr <ULONG> ("LogHistoryCount", 3);
|
---|
603 |
|
---|
604 | return S_OK;
|
---|
605 | }
|
---|
606 |
|
---|
607 | HRESULT SystemProperties::saveSettings (settings::Key &aGlobal)
|
---|
608 | {
|
---|
609 | using namespace settings;
|
---|
610 |
|
---|
611 | AutoCaller autoCaller (this);
|
---|
612 | CheckComRCReturnRC (autoCaller.rc());
|
---|
613 |
|
---|
614 | AutoReadLock alock (this);
|
---|
615 |
|
---|
616 | ComAssertRet (!aGlobal.isNull(), E_FAIL);
|
---|
617 |
|
---|
618 | /* first, delete the entry */
|
---|
619 | Key properties = aGlobal.findKey ("SystemProperties");
|
---|
620 | if (!properties.isNull())
|
---|
621 | properties.zap();
|
---|
622 | /* then, recreate it */
|
---|
623 | properties = aGlobal.createKey ("SystemProperties");
|
---|
624 |
|
---|
625 | if (mDefaultMachineFolder)
|
---|
626 | properties.setValue <Bstr> ("defaultMachineFolder", mDefaultMachineFolder);
|
---|
627 |
|
---|
628 | if (mDefaultHardDiskFolder)
|
---|
629 | properties.setValue <Bstr> ("defaultHardDiskFolder", mDefaultHardDiskFolder);
|
---|
630 |
|
---|
631 | if (mDefaultHardDiskFormat)
|
---|
632 | properties.setValue <Bstr> ("defaultHardDiskFormat", mDefaultHardDiskFormat);
|
---|
633 |
|
---|
634 | if (mRemoteDisplayAuthLibrary)
|
---|
635 | properties.setValue <Bstr> ("remoteDisplayAuthLibrary", mRemoteDisplayAuthLibrary);
|
---|
636 |
|
---|
637 | if (mWebServiceAuthLibrary)
|
---|
638 | properties.setValue <Bstr> ("webServiceAuthLibrary", mWebServiceAuthLibrary);
|
---|
639 |
|
---|
640 | properties.setValue <ULONG> ("LogHistoryCount", mLogHistoryCount);
|
---|
641 |
|
---|
642 | return S_OK;
|
---|
643 | }
|
---|
644 |
|
---|
645 | /**
|
---|
646 | * Rerurns a hard disk format object corresponding to the given format
|
---|
647 | * identifier or null if no such format.
|
---|
648 | *
|
---|
649 | * @param aFormat Format identifier.
|
---|
650 | *
|
---|
651 | * @return ComObjPtr<HardDiskFormat>
|
---|
652 | */
|
---|
653 | ComObjPtr <HardDiskFormat> SystemProperties::hardDiskFormat (CBSTR aFormat)
|
---|
654 | {
|
---|
655 | ComObjPtr <HardDiskFormat> format;
|
---|
656 |
|
---|
657 | AutoCaller autoCaller (this);
|
---|
658 | AssertComRCReturn (autoCaller.rc(), format);
|
---|
659 |
|
---|
660 | AutoReadLock alock (this);
|
---|
661 |
|
---|
662 | for (HardDiskFormatList::const_iterator it = mHardDiskFormats.begin();
|
---|
663 | it != mHardDiskFormats.end(); ++ it)
|
---|
664 | {
|
---|
665 | /* HardDiskFormat is all const, no need to lock */
|
---|
666 |
|
---|
667 | if ((*it)->id().compareIgnoreCase (aFormat) == 0)
|
---|
668 | {
|
---|
669 | format = *it;
|
---|
670 | break;
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | return format;
|
---|
675 | }
|
---|
676 |
|
---|
677 | // private methods
|
---|
678 | /////////////////////////////////////////////////////////////////////////////
|
---|
679 |
|
---|
680 | HRESULT SystemProperties::setDefaultMachineFolder (CBSTR aPath)
|
---|
681 | {
|
---|
682 | Utf8Str path;
|
---|
683 | if (aPath && *aPath)
|
---|
684 | path = aPath;
|
---|
685 | else
|
---|
686 | path = "Machines";
|
---|
687 |
|
---|
688 | /* get the full file name */
|
---|
689 | Utf8Str folder;
|
---|
690 | int vrc = mParent->calculateFullPath (path, folder);
|
---|
691 | if (RT_FAILURE (vrc))
|
---|
692 | return setError (E_FAIL,
|
---|
693 | tr ("Invalid default machine folder '%ls' (%Rrc)"),
|
---|
694 | path.raw(), vrc);
|
---|
695 |
|
---|
696 | mDefaultMachineFolder = path;
|
---|
697 | mDefaultMachineFolderFull = folder;
|
---|
698 |
|
---|
699 | return S_OK;
|
---|
700 | }
|
---|
701 |
|
---|
702 | HRESULT SystemProperties::setDefaultHardDiskFolder (CBSTR aPath)
|
---|
703 | {
|
---|
704 | Utf8Str path;
|
---|
705 | if (aPath && *aPath)
|
---|
706 | path = aPath;
|
---|
707 | else
|
---|
708 | path = "HardDisks";
|
---|
709 |
|
---|
710 | /* get the full file name */
|
---|
711 | Utf8Str folder;
|
---|
712 | int vrc = mParent->calculateFullPath (path, folder);
|
---|
713 | if (RT_FAILURE (vrc))
|
---|
714 | return setError (E_FAIL,
|
---|
715 | tr ("Invalid default hard disk folder '%ls' (%Rrc)"),
|
---|
716 | path.raw(), vrc);
|
---|
717 |
|
---|
718 | mDefaultHardDiskFolder = path;
|
---|
719 | mDefaultHardDiskFolderFull = folder;
|
---|
720 |
|
---|
721 | return S_OK;
|
---|
722 | }
|
---|
723 |
|
---|
724 | HRESULT SystemProperties::setDefaultHardDiskFormat (CBSTR aFormat)
|
---|
725 | {
|
---|
726 | if (aFormat && *aFormat)
|
---|
727 | mDefaultHardDiskFormat = aFormat;
|
---|
728 | else
|
---|
729 | mDefaultHardDiskFormat = "VDI";
|
---|
730 |
|
---|
731 | return S_OK;
|
---|
732 | }
|
---|
733 |
|
---|
734 | HRESULT SystemProperties::setRemoteDisplayAuthLibrary (CBSTR aPath)
|
---|
735 | {
|
---|
736 | if (aPath && *aPath)
|
---|
737 | mRemoteDisplayAuthLibrary = aPath;
|
---|
738 | else
|
---|
739 | mRemoteDisplayAuthLibrary = "VRDPAuth";
|
---|
740 |
|
---|
741 | return S_OK;
|
---|
742 | }
|
---|
743 |
|
---|
744 | HRESULT SystemProperties::setWebServiceAuthLibrary (CBSTR aPath)
|
---|
745 | {
|
---|
746 | if (aPath && *aPath)
|
---|
747 | mWebServiceAuthLibrary = aPath;
|
---|
748 | else
|
---|
749 | mWebServiceAuthLibrary = "VRDPAuth";
|
---|
750 |
|
---|
751 | return S_OK;
|
---|
752 | }
|
---|
753 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|