1 | /* $Id: SystemPropertiesImpl.cpp 15051 2008-12-05 17:20:00Z 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_FAIL);
|
---|
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 | CheckComArgOutPointerValid(aMaxBootPosition);
|
---|
278 |
|
---|
279 | AutoCaller autoCaller (this);
|
---|
280 | CheckComRCReturnRC (autoCaller.rc());
|
---|
281 |
|
---|
282 | /* no need to lock, this is const */
|
---|
283 | *aMaxBootPosition = SchemaDefs::MaxBootPosition;
|
---|
284 |
|
---|
285 | return S_OK;
|
---|
286 | }
|
---|
287 |
|
---|
288 | STDMETHODIMP SystemProperties::COMGETTER(DefaultMachineFolder) (BSTR *aDefaultMachineFolder)
|
---|
289 | {
|
---|
290 | CheckComArgOutPointerValid(aDefaultMachineFolder);
|
---|
291 |
|
---|
292 | AutoCaller autoCaller (this);
|
---|
293 | CheckComRCReturnRC (autoCaller.rc());
|
---|
294 |
|
---|
295 | AutoReadLock alock (this);
|
---|
296 |
|
---|
297 | mDefaultMachineFolderFull.cloneTo (aDefaultMachineFolder);
|
---|
298 |
|
---|
299 | return S_OK;
|
---|
300 | }
|
---|
301 |
|
---|
302 | STDMETHODIMP SystemProperties::COMSETTER(DefaultMachineFolder) (IN_BSTR aDefaultMachineFolder)
|
---|
303 | {
|
---|
304 | AutoCaller autoCaller (this);
|
---|
305 | CheckComRCReturnRC (autoCaller.rc());
|
---|
306 |
|
---|
307 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
308 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
309 |
|
---|
310 | HRESULT rc = setDefaultMachineFolder (aDefaultMachineFolder);
|
---|
311 | if (SUCCEEDED (rc))
|
---|
312 | rc = mParent->saveSettings();
|
---|
313 |
|
---|
314 | return rc;
|
---|
315 | }
|
---|
316 |
|
---|
317 | STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFolder) (BSTR *aDefaultHardDiskFolder)
|
---|
318 | {
|
---|
319 | CheckComArgOutPointerValid(aDefaultHardDiskFolder);
|
---|
320 |
|
---|
321 | AutoCaller autoCaller (this);
|
---|
322 | CheckComRCReturnRC (autoCaller.rc());
|
---|
323 |
|
---|
324 | AutoReadLock alock (this);
|
---|
325 |
|
---|
326 | mDefaultHardDiskFolderFull.cloneTo (aDefaultHardDiskFolder);
|
---|
327 |
|
---|
328 | return S_OK;
|
---|
329 | }
|
---|
330 |
|
---|
331 | STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFolder) (IN_BSTR aDefaultHardDiskFolder)
|
---|
332 | {
|
---|
333 | AutoCaller autoCaller (this);
|
---|
334 | CheckComRCReturnRC (autoCaller.rc());
|
---|
335 |
|
---|
336 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
337 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
338 |
|
---|
339 | HRESULT rc = setDefaultHardDiskFolder (aDefaultHardDiskFolder);
|
---|
340 | if (SUCCEEDED (rc))
|
---|
341 | rc = mParent->saveSettings();
|
---|
342 |
|
---|
343 | return rc;
|
---|
344 | }
|
---|
345 |
|
---|
346 | STDMETHODIMP SystemProperties::
|
---|
347 | COMGETTER(HardDiskFormats) (ComSafeArrayOut (IHardDiskFormat *, aHardDiskFormats))
|
---|
348 | {
|
---|
349 | if (ComSafeArrayOutIsNull (aHardDiskFormats))
|
---|
350 | return E_POINTER;
|
---|
351 |
|
---|
352 | AutoCaller autoCaller (this);
|
---|
353 | CheckComRCReturnRC (autoCaller.rc());
|
---|
354 |
|
---|
355 | AutoReadLock alock (this);
|
---|
356 |
|
---|
357 | SafeIfaceArray <IHardDiskFormat> hardDiskFormats (mHardDiskFormats);
|
---|
358 | hardDiskFormats.detachTo (ComSafeArrayOutArg (aHardDiskFormats));
|
---|
359 |
|
---|
360 | return S_OK;
|
---|
361 | }
|
---|
362 |
|
---|
363 | STDMETHODIMP SystemProperties::COMGETTER(DefaultHardDiskFormat) (BSTR *aDefaultHardDiskFormat)
|
---|
364 | {
|
---|
365 | CheckComArgOutPointerValid(aDefaultHardDiskFormat);
|
---|
366 |
|
---|
367 | AutoCaller autoCaller (this);
|
---|
368 | CheckComRCReturnRC (autoCaller.rc());
|
---|
369 |
|
---|
370 | AutoReadLock alock (this);
|
---|
371 |
|
---|
372 | mDefaultHardDiskFormat.cloneTo (aDefaultHardDiskFormat);
|
---|
373 |
|
---|
374 | return S_OK;
|
---|
375 | }
|
---|
376 |
|
---|
377 | STDMETHODIMP SystemProperties::COMSETTER(DefaultHardDiskFormat) (IN_BSTR aDefaultHardDiskFormat)
|
---|
378 | {
|
---|
379 | AutoCaller autoCaller (this);
|
---|
380 | CheckComRCReturnRC (autoCaller.rc());
|
---|
381 |
|
---|
382 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
383 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
384 |
|
---|
385 | HRESULT rc = setDefaultHardDiskFormat (aDefaultHardDiskFormat);
|
---|
386 | if (SUCCEEDED (rc))
|
---|
387 | rc = mParent->saveSettings();
|
---|
388 |
|
---|
389 | return rc;
|
---|
390 | }
|
---|
391 |
|
---|
392 | STDMETHODIMP SystemProperties::COMGETTER(RemoteDisplayAuthLibrary) (BSTR *aRemoteDisplayAuthLibrary)
|
---|
393 | {
|
---|
394 | CheckComArgOutPointerValid(aRemoteDisplayAuthLibrary);
|
---|
395 |
|
---|
396 | AutoCaller autoCaller (this);
|
---|
397 | CheckComRCReturnRC (autoCaller.rc());
|
---|
398 |
|
---|
399 | AutoReadLock alock (this);
|
---|
400 |
|
---|
401 | mRemoteDisplayAuthLibrary.cloneTo (aRemoteDisplayAuthLibrary);
|
---|
402 |
|
---|
403 | return S_OK;
|
---|
404 | }
|
---|
405 |
|
---|
406 | STDMETHODIMP SystemProperties::COMSETTER(RemoteDisplayAuthLibrary) (IN_BSTR aRemoteDisplayAuthLibrary)
|
---|
407 | {
|
---|
408 | AutoCaller autoCaller (this);
|
---|
409 | CheckComRCReturnRC (autoCaller.rc());
|
---|
410 |
|
---|
411 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
412 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
413 |
|
---|
414 | HRESULT rc = setRemoteDisplayAuthLibrary (aRemoteDisplayAuthLibrary);
|
---|
415 | if (SUCCEEDED (rc))
|
---|
416 | rc = mParent->saveSettings();
|
---|
417 |
|
---|
418 | return rc;
|
---|
419 | }
|
---|
420 |
|
---|
421 | STDMETHODIMP SystemProperties::COMGETTER(WebServiceAuthLibrary) (BSTR *aWebServiceAuthLibrary)
|
---|
422 | {
|
---|
423 | CheckComArgOutPointerValid(aWebServiceAuthLibrary);
|
---|
424 |
|
---|
425 | AutoCaller autoCaller (this);
|
---|
426 | CheckComRCReturnRC (autoCaller.rc());
|
---|
427 |
|
---|
428 | AutoReadLock alock (this);
|
---|
429 |
|
---|
430 | mWebServiceAuthLibrary.cloneTo (aWebServiceAuthLibrary);
|
---|
431 |
|
---|
432 | return S_OK;
|
---|
433 | }
|
---|
434 |
|
---|
435 | STDMETHODIMP SystemProperties::COMSETTER(WebServiceAuthLibrary) (IN_BSTR aWebServiceAuthLibrary)
|
---|
436 | {
|
---|
437 | AutoCaller autoCaller (this);
|
---|
438 | CheckComRCReturnRC (autoCaller.rc());
|
---|
439 |
|
---|
440 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
441 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
442 |
|
---|
443 | HRESULT rc = setWebServiceAuthLibrary (aWebServiceAuthLibrary);
|
---|
444 | if (SUCCEEDED (rc))
|
---|
445 | rc = mParent->saveSettings();
|
---|
446 |
|
---|
447 | return rc;
|
---|
448 | }
|
---|
449 |
|
---|
450 | STDMETHODIMP SystemProperties::COMGETTER(HWVirtExEnabled) (BOOL *enabled)
|
---|
451 | {
|
---|
452 | if (!enabled)
|
---|
453 | return E_POINTER;
|
---|
454 |
|
---|
455 | AutoCaller autoCaller (this);
|
---|
456 | CheckComRCReturnRC (autoCaller.rc());
|
---|
457 |
|
---|
458 | AutoReadLock alock (this);
|
---|
459 |
|
---|
460 | *enabled = mHWVirtExEnabled;
|
---|
461 |
|
---|
462 | return S_OK;
|
---|
463 | }
|
---|
464 |
|
---|
465 | STDMETHODIMP SystemProperties::COMSETTER(HWVirtExEnabled) (BOOL enabled)
|
---|
466 | {
|
---|
467 | AutoCaller autoCaller (this);
|
---|
468 | CheckComRCReturnRC (autoCaller.rc());
|
---|
469 |
|
---|
470 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
471 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
472 |
|
---|
473 | mHWVirtExEnabled = enabled;
|
---|
474 |
|
---|
475 | HRESULT rc = mParent->saveSettings();
|
---|
476 |
|
---|
477 | return rc;
|
---|
478 | }
|
---|
479 |
|
---|
480 | STDMETHODIMP SystemProperties::COMGETTER(LogHistoryCount) (ULONG *count)
|
---|
481 | {
|
---|
482 | if (!count)
|
---|
483 | return E_POINTER;
|
---|
484 |
|
---|
485 | AutoCaller autoCaller (this);
|
---|
486 | CheckComRCReturnRC (autoCaller.rc());
|
---|
487 |
|
---|
488 | AutoReadLock alock (this);
|
---|
489 |
|
---|
490 | *count = mLogHistoryCount;
|
---|
491 |
|
---|
492 | return S_OK;
|
---|
493 | }
|
---|
494 |
|
---|
495 | STDMETHODIMP SystemProperties::COMSETTER(LogHistoryCount) (ULONG count)
|
---|
496 | {
|
---|
497 | AutoCaller autoCaller (this);
|
---|
498 | CheckComRCReturnRC (autoCaller.rc());
|
---|
499 |
|
---|
500 | /* VirtualBox::saveSettings() needs a write lock */
|
---|
501 | AutoMultiWriteLock2 alock (mParent, this);
|
---|
502 |
|
---|
503 | mLogHistoryCount = count;
|
---|
504 |
|
---|
505 | HRESULT rc = mParent->saveSettings();
|
---|
506 |
|
---|
507 | return rc;
|
---|
508 | }
|
---|
509 |
|
---|
510 | // public methods only for internal purposes
|
---|
511 | /////////////////////////////////////////////////////////////////////////////
|
---|
512 |
|
---|
513 | HRESULT SystemProperties::loadSettings (const settings::Key &aGlobal)
|
---|
514 | {
|
---|
515 | using namespace settings;
|
---|
516 |
|
---|
517 | AutoCaller autoCaller (this);
|
---|
518 | CheckComRCReturnRC (autoCaller.rc());
|
---|
519 |
|
---|
520 | AutoWriteLock alock (this);
|
---|
521 |
|
---|
522 | AssertReturn (!aGlobal.isNull(), E_FAIL);
|
---|
523 |
|
---|
524 | HRESULT rc = S_OK;
|
---|
525 |
|
---|
526 | Key properties = aGlobal.key ("SystemProperties");
|
---|
527 |
|
---|
528 | Bstr bstr;
|
---|
529 |
|
---|
530 | bstr = properties.stringValue ("defaultMachineFolder");
|
---|
531 | rc = setDefaultMachineFolder (bstr);
|
---|
532 | CheckComRCReturnRC (rc);
|
---|
533 |
|
---|
534 | bstr = properties.stringValue ("defaultHardDiskFolder");
|
---|
535 | rc = setDefaultHardDiskFolder (bstr);
|
---|
536 | CheckComRCReturnRC (rc);
|
---|
537 |
|
---|
538 | bstr = properties.stringValue ("defaultHardDiskFormat");
|
---|
539 | rc = setDefaultHardDiskFormat (bstr);
|
---|
540 | CheckComRCReturnRC (rc);
|
---|
541 |
|
---|
542 | bstr = properties.stringValue ("remoteDisplayAuthLibrary");
|
---|
543 | rc = setRemoteDisplayAuthLibrary (bstr);
|
---|
544 | CheckComRCReturnRC (rc);
|
---|
545 |
|
---|
546 | bstr = properties.stringValue ("webServiceAuthLibrary");
|
---|
547 | rc = setWebServiceAuthLibrary (bstr);
|
---|
548 | CheckComRCReturnRC (rc);
|
---|
549 |
|
---|
550 | /* Note: not <BOOL> because Win32 defines BOOL as int */
|
---|
551 | mHWVirtExEnabled = properties.valueOr <bool> ("HWVirtExEnabled", false);
|
---|
552 |
|
---|
553 | mLogHistoryCount = properties.valueOr <ULONG> ("LogHistoryCount", 3);
|
---|
554 |
|
---|
555 | return S_OK;
|
---|
556 | }
|
---|
557 |
|
---|
558 | HRESULT SystemProperties::saveSettings (settings::Key &aGlobal)
|
---|
559 | {
|
---|
560 | using namespace settings;
|
---|
561 |
|
---|
562 | AutoCaller autoCaller (this);
|
---|
563 | CheckComRCReturnRC (autoCaller.rc());
|
---|
564 |
|
---|
565 | AutoReadLock alock (this);
|
---|
566 |
|
---|
567 | ComAssertRet (!aGlobal.isNull(), E_FAIL);
|
---|
568 |
|
---|
569 | /* first, delete the entry */
|
---|
570 | Key properties = aGlobal.findKey ("SystemProperties");
|
---|
571 | if (!properties.isNull())
|
---|
572 | properties.zap();
|
---|
573 | /* then, recreate it */
|
---|
574 | properties = aGlobal.createKey ("SystemProperties");
|
---|
575 |
|
---|
576 | if (mDefaultMachineFolder)
|
---|
577 | properties.setValue <Bstr> ("defaultMachineFolder", mDefaultMachineFolder);
|
---|
578 |
|
---|
579 | if (mDefaultHardDiskFolder)
|
---|
580 | properties.setValue <Bstr> ("defaultHardDiskFolder", mDefaultHardDiskFolder);
|
---|
581 |
|
---|
582 | if (mDefaultHardDiskFormat)
|
---|
583 | properties.setValue <Bstr> ("defaultHardDiskFormat", mDefaultHardDiskFormat);
|
---|
584 |
|
---|
585 | if (mRemoteDisplayAuthLibrary)
|
---|
586 | properties.setValue <Bstr> ("remoteDisplayAuthLibrary", mRemoteDisplayAuthLibrary);
|
---|
587 |
|
---|
588 | if (mWebServiceAuthLibrary)
|
---|
589 | properties.setValue <Bstr> ("webServiceAuthLibrary", mWebServiceAuthLibrary);
|
---|
590 |
|
---|
591 | properties.setValue <bool> ("HWVirtExEnabled", !!mHWVirtExEnabled);
|
---|
592 |
|
---|
593 | properties.setValue <ULONG> ("LogHistoryCount", mLogHistoryCount);
|
---|
594 |
|
---|
595 | return S_OK;
|
---|
596 | }
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * Rerurns a hard disk format object corresponding to the given format
|
---|
600 | * identifier or null if no such format.
|
---|
601 | *
|
---|
602 | * @param aFormat Format identifier.
|
---|
603 | *
|
---|
604 | * @return ComObjPtr<HardDiskFormat>
|
---|
605 | */
|
---|
606 | ComObjPtr <HardDiskFormat> SystemProperties::hardDiskFormat (CBSTR aFormat)
|
---|
607 | {
|
---|
608 | ComObjPtr <HardDiskFormat> format;
|
---|
609 |
|
---|
610 | AutoCaller autoCaller (this);
|
---|
611 | AssertComRCReturn (autoCaller.rc(), format);
|
---|
612 |
|
---|
613 | AutoReadLock alock (this);
|
---|
614 |
|
---|
615 | for (HardDiskFormatList::const_iterator it = mHardDiskFormats.begin();
|
---|
616 | it != mHardDiskFormats.end(); ++ it)
|
---|
617 | {
|
---|
618 | /* HardDiskFormat is all const, no need to lock */
|
---|
619 |
|
---|
620 | if ((*it)->id() == aFormat)
|
---|
621 | {
|
---|
622 | format = *it;
|
---|
623 | break;
|
---|
624 | }
|
---|
625 | }
|
---|
626 |
|
---|
627 | return format;
|
---|
628 | }
|
---|
629 |
|
---|
630 | // private methods
|
---|
631 | /////////////////////////////////////////////////////////////////////////////
|
---|
632 |
|
---|
633 | HRESULT SystemProperties::setDefaultMachineFolder (CBSTR aPath)
|
---|
634 | {
|
---|
635 | Utf8Str path;
|
---|
636 | if (aPath && *aPath)
|
---|
637 | path = aPath;
|
---|
638 | else
|
---|
639 | path = "Machines";
|
---|
640 |
|
---|
641 | /* get the full file name */
|
---|
642 | Utf8Str folder;
|
---|
643 | int vrc = mParent->calculateFullPath (path, folder);
|
---|
644 | if (RT_FAILURE (vrc))
|
---|
645 | return setError (E_FAIL,
|
---|
646 | tr ("Invalid default machine folder '%ls' (%Rrc)"),
|
---|
647 | path.raw(), vrc);
|
---|
648 |
|
---|
649 | mDefaultMachineFolder = path;
|
---|
650 | mDefaultMachineFolderFull = folder;
|
---|
651 |
|
---|
652 | return S_OK;
|
---|
653 | }
|
---|
654 |
|
---|
655 | HRESULT SystemProperties::setDefaultHardDiskFolder (CBSTR aPath)
|
---|
656 | {
|
---|
657 | Utf8Str path;
|
---|
658 | if (aPath && *aPath)
|
---|
659 | path = aPath;
|
---|
660 | else
|
---|
661 | path = "HardDisks";
|
---|
662 |
|
---|
663 | /* get the full file name */
|
---|
664 | Utf8Str folder;
|
---|
665 | int vrc = mParent->calculateFullPath (path, folder);
|
---|
666 | if (RT_FAILURE (vrc))
|
---|
667 | return setError (E_FAIL,
|
---|
668 | tr ("Invalid default hard disk folder '%ls' (%Rrc)"),
|
---|
669 | path.raw(), vrc);
|
---|
670 |
|
---|
671 | mDefaultHardDiskFolder = path;
|
---|
672 | mDefaultHardDiskFolderFull = folder;
|
---|
673 |
|
---|
674 | return S_OK;
|
---|
675 | }
|
---|
676 |
|
---|
677 | HRESULT SystemProperties::setDefaultHardDiskFormat (CBSTR aFormat)
|
---|
678 | {
|
---|
679 | if (aFormat && *aFormat)
|
---|
680 | mDefaultHardDiskFormat = aFormat;
|
---|
681 | else
|
---|
682 | mDefaultHardDiskFormat = "VDI";
|
---|
683 |
|
---|
684 | return S_OK;
|
---|
685 | }
|
---|
686 |
|
---|
687 | HRESULT SystemProperties::setRemoteDisplayAuthLibrary (CBSTR aPath)
|
---|
688 | {
|
---|
689 | if (aPath && *aPath)
|
---|
690 | mRemoteDisplayAuthLibrary = aPath;
|
---|
691 | else
|
---|
692 | mRemoteDisplayAuthLibrary = "VRDPAuth";
|
---|
693 |
|
---|
694 | return S_OK;
|
---|
695 | }
|
---|
696 |
|
---|
697 | HRESULT SystemProperties::setWebServiceAuthLibrary (CBSTR aPath)
|
---|
698 | {
|
---|
699 | if (aPath && *aPath)
|
---|
700 | mWebServiceAuthLibrary = aPath;
|
---|
701 | else
|
---|
702 | mWebServiceAuthLibrary = "VRDPAuth";
|
---|
703 |
|
---|
704 | return S_OK;
|
---|
705 | }
|
---|
706 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|