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