VirtualBox

source: vbox/trunk/src/VBox/Main/BIOSSettingsImpl.cpp@ 25881

Last change on this file since 25881 was 25860, checked in by vboxsync, 15 years ago

Main: cleanup: get rid of VirtualBoxBaseProto, move AutoCaller*/*Span* classes out of VirtualBoxBaseProto class scope and into separate header; move CombinedProgress into separate header (it's only used by Console any more)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include "BIOSSettingsImpl.h"
23#include "MachineImpl.h"
24#include "AutoCaller.h"
25#include "Logging.h"
26#include "GuestOSTypeImpl.h"
27
28#include <iprt/cpp/utils.h>
29#include <VBox/settings.h>
30
31////////////////////////////////////////////////////////////////////////////////
32//
33// BIOSSettings private data definition
34//
35////////////////////////////////////////////////////////////////////////////////
36
37struct BIOSSettings::Data
38{
39 Data()
40 { }
41
42 ComObjPtr<Machine, ComWeakRef> pMachine;
43 ComObjPtr<BIOSSettings> pPeer;
44
45 // use the XML settings structure in the members for simplicity
46 Backupable<settings::BIOSSettings> bd;
47};
48
49// constructor / destructor
50/////////////////////////////////////////////////////////////////////////////
51
52HRESULT BIOSSettings::FinalConstruct()
53{
54 return S_OK;
55}
56
57void BIOSSettings::FinalRelease()
58{
59 uninit ();
60}
61
62// public initializer/uninitializer for internal purposes only
63/////////////////////////////////////////////////////////////////////////////
64
65/**
66 * Initializes the audio adapter object.
67 *
68 * @returns COM result indicator
69 */
70HRESULT BIOSSettings::init(Machine *aParent)
71{
72 LogFlowThisFuncEnter();
73 LogFlowThisFunc(("aParent: %p\n", aParent));
74
75 ComAssertRet (aParent, E_INVALIDARG);
76
77 /* Enclose the state transition NotReady->InInit->Ready */
78 AutoInitSpan autoInitSpan(this);
79 AssertReturn(autoInitSpan.isOk(), E_FAIL);
80
81 m = new Data();
82
83 /* share the parent weakly */
84 unconst(m->pMachine) = aParent;
85
86 m->bd.allocate();
87
88 autoInitSpan.setSucceeded();
89
90 LogFlowThisFuncLeave();
91 return S_OK;
92}
93
94/**
95 * Initializes the audio adapter object given another audio adapter object
96 * (a kind of copy constructor). This object shares data with
97 * the object passed as an argument.
98 *
99 * @note This object must be destroyed before the original object
100 * it shares data with is destroyed.
101 */
102HRESULT BIOSSettings::init(Machine *aParent, BIOSSettings *that)
103{
104 LogFlowThisFuncEnter();
105 LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
106
107 ComAssertRet (aParent && that, E_INVALIDARG);
108
109 /* Enclose the state transition NotReady->InInit->Ready */
110 AutoInitSpan autoInitSpan(this);
111 AssertReturn(autoInitSpan.isOk(), E_FAIL);
112
113 m = new Data();
114
115 m->pMachine = aParent;
116 m->pPeer = that;
117
118 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
119 m->bd.share(that->m->bd);
120
121 autoInitSpan.setSucceeded();
122
123 LogFlowThisFuncLeave();
124 return S_OK;
125}
126
127/**
128 * Initializes the guest object given another guest object
129 * (a kind of copy constructor). This object makes a private copy of data
130 * of the original object passed as an argument.
131 */
132HRESULT BIOSSettings::initCopy(Machine *aParent, BIOSSettings *that)
133{
134 LogFlowThisFuncEnter();
135 LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
136
137 ComAssertRet (aParent && that, E_INVALIDARG);
138
139 /* Enclose the state transition NotReady->InInit->Ready */
140 AutoInitSpan autoInitSpan(this);
141 AssertReturn(autoInitSpan.isOk(), E_FAIL);
142
143 m = new Data();
144
145 m->pMachine = aParent;
146 // mPeer is left null
147
148 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
149 m->bd.attachCopy(that->m->bd);
150
151 autoInitSpan.setSucceeded();
152
153 LogFlowThisFuncLeave();
154 return S_OK;
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 */
161void BIOSSettings::uninit()
162{
163 LogFlowThisFuncEnter();
164
165 /* Enclose the state transition Ready->InUninit->NotReady */
166 AutoUninitSpan autoUninitSpan(this);
167 if (autoUninitSpan.uninitDone())
168 return;
169
170 m->bd.free();
171
172 m->pPeer.setNull();
173 m->pMachine.setNull();
174
175 delete m;
176 m = NULL;
177
178 LogFlowThisFuncLeave();
179}
180
181// IBIOSSettings properties
182/////////////////////////////////////////////////////////////////////////////
183
184STDMETHODIMP BIOSSettings::COMGETTER(LogoFadeIn)(BOOL *enabled)
185{
186 if (!enabled)
187 return E_POINTER;
188
189 AutoCaller autoCaller(this);
190 if (FAILED(autoCaller.rc())) return autoCaller.rc();
191
192 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
193
194 *enabled = m->bd->fLogoFadeIn;
195
196 return S_OK;
197}
198
199STDMETHODIMP BIOSSettings::COMSETTER(LogoFadeIn)(BOOL enable)
200{
201 AutoCaller autoCaller(this);
202 if (FAILED(autoCaller.rc())) return autoCaller.rc();
203
204 /* the machine needs to be mutable */
205 Machine::AutoMutableStateDependency adep(m->pMachine);
206 if (FAILED(adep.rc())) return adep.rc();
207
208 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
209
210 m->bd.backup();
211 m->bd->fLogoFadeIn = enable;
212
213 return S_OK;
214}
215
216STDMETHODIMP BIOSSettings::COMGETTER(LogoFadeOut)(BOOL *enabled)
217{
218 if (!enabled)
219 return E_POINTER;
220
221 AutoCaller autoCaller(this);
222 if (FAILED(autoCaller.rc())) return autoCaller.rc();
223
224 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
225
226 *enabled = m->bd->fLogoFadeOut;
227
228 return S_OK;
229}
230
231STDMETHODIMP BIOSSettings::COMSETTER(LogoFadeOut)(BOOL enable)
232{
233 AutoCaller autoCaller(this);
234 if (FAILED(autoCaller.rc())) return autoCaller.rc();
235
236 /* the machine needs to be mutable */
237 Machine::AutoMutableStateDependency adep(m->pMachine);
238 if (FAILED(adep.rc())) return adep.rc();
239
240 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
241
242 m->bd.backup();
243 m->bd->fLogoFadeOut = enable;
244
245 return S_OK;
246}
247
248STDMETHODIMP BIOSSettings::COMGETTER(LogoDisplayTime)(ULONG *displayTime)
249{
250 if (!displayTime)
251 return E_POINTER;
252
253 AutoCaller autoCaller(this);
254 if (FAILED(autoCaller.rc())) return autoCaller.rc();
255
256 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
257
258 *displayTime = m->bd->ulLogoDisplayTime;
259
260 return S_OK;
261}
262
263STDMETHODIMP BIOSSettings::COMSETTER(LogoDisplayTime)(ULONG displayTime)
264{
265 AutoCaller autoCaller(this);
266 if (FAILED(autoCaller.rc())) return autoCaller.rc();
267
268 /* the machine needs to be mutable */
269 Machine::AutoMutableStateDependency adep(m->pMachine);
270 if (FAILED(adep.rc())) return adep.rc();
271
272 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
273
274 m->bd.backup();
275 m->bd->ulLogoDisplayTime = displayTime;
276
277 return S_OK;
278}
279
280STDMETHODIMP BIOSSettings::COMGETTER(LogoImagePath)(BSTR *imagePath)
281{
282 if (!imagePath)
283 return E_POINTER;
284
285 AutoCaller autoCaller(this);
286 if (FAILED(autoCaller.rc())) return autoCaller.rc();
287
288 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
289
290 m->bd->strLogoImagePath.cloneTo(imagePath);
291 return S_OK;
292}
293
294STDMETHODIMP BIOSSettings::COMSETTER(LogoImagePath)(IN_BSTR imagePath)
295{
296 /* NULL strings are not allowed */
297 if (!imagePath)
298 return E_INVALIDARG;
299
300 AutoCaller autoCaller(this);
301 if (FAILED(autoCaller.rc())) return autoCaller.rc();
302
303 /* the machine needs to be mutable */
304 Machine::AutoMutableStateDependency adep(m->pMachine);
305 if (FAILED(adep.rc())) return adep.rc();
306
307 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
308
309 m->bd.backup();
310 m->bd->strLogoImagePath = imagePath;
311
312 return S_OK;
313}
314
315STDMETHODIMP BIOSSettings::COMGETTER(BootMenuMode)(BIOSBootMenuMode_T *bootMenuMode)
316{
317 if (!bootMenuMode)
318 return E_POINTER;
319
320 AutoCaller autoCaller(this);
321 if (FAILED(autoCaller.rc())) return autoCaller.rc();
322
323 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
324
325 *bootMenuMode = m->bd->biosBootMenuMode;
326 return S_OK;
327}
328
329STDMETHODIMP BIOSSettings::COMSETTER(BootMenuMode)(BIOSBootMenuMode_T bootMenuMode)
330{
331 AutoCaller autoCaller(this);
332 if (FAILED(autoCaller.rc())) return autoCaller.rc();
333
334 /* the machine needs to be mutable */
335 Machine::AutoMutableStateDependency adep(m->pMachine);
336 if (FAILED(adep.rc())) return adep.rc();
337
338 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
339
340 m->bd.backup();
341 m->bd->biosBootMenuMode = bootMenuMode;
342
343 return S_OK;
344}
345
346STDMETHODIMP BIOSSettings::COMGETTER(ACPIEnabled)(BOOL *enabled)
347{
348 if (!enabled)
349 return E_POINTER;
350
351 AutoCaller autoCaller(this);
352 if (FAILED(autoCaller.rc())) return autoCaller.rc();
353
354 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
355
356 *enabled = m->bd->fACPIEnabled;
357
358 return S_OK;
359}
360
361STDMETHODIMP BIOSSettings::COMSETTER(ACPIEnabled)(BOOL enable)
362{
363 AutoCaller autoCaller(this);
364 if (FAILED(autoCaller.rc())) return autoCaller.rc();
365
366 /* the machine needs to be mutable */
367 Machine::AutoMutableStateDependency adep(m->pMachine);
368 if (FAILED(adep.rc())) return adep.rc();
369
370 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
371
372 m->bd.backup();
373 m->bd->fACPIEnabled = enable;
374
375 return S_OK;
376}
377
378STDMETHODIMP BIOSSettings::COMGETTER(IOAPICEnabled)(BOOL *enabled)
379{
380 if (!enabled)
381 return E_POINTER;
382
383 AutoCaller autoCaller(this);
384 if (FAILED(autoCaller.rc())) return autoCaller.rc();
385
386 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
387
388 *enabled = m->bd->fIOAPICEnabled;
389
390 return S_OK;
391}
392
393STDMETHODIMP BIOSSettings::COMSETTER(IOAPICEnabled)(BOOL enable)
394{
395 AutoCaller autoCaller(this);
396 if (FAILED(autoCaller.rc())) return autoCaller.rc();
397
398 /* the machine needs to be mutable */
399 Machine::AutoMutableStateDependency adep(m->pMachine);
400 if (FAILED(adep.rc())) return adep.rc();
401
402 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
403
404 m->bd.backup();
405 m->bd->fIOAPICEnabled = enable;
406
407 return S_OK;
408}
409
410STDMETHODIMP BIOSSettings::COMGETTER(PXEDebugEnabled)(BOOL *enabled)
411{
412 if (!enabled)
413 return E_POINTER;
414
415 AutoCaller autoCaller(this);
416 if (FAILED(autoCaller.rc())) return autoCaller.rc();
417
418 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
419
420 *enabled = m->bd->fPXEDebugEnabled;
421
422 return S_OK;
423}
424
425STDMETHODIMP BIOSSettings::COMSETTER(PXEDebugEnabled)(BOOL enable)
426{
427 AutoCaller autoCaller(this);
428 if (FAILED(autoCaller.rc())) return autoCaller.rc();
429
430 /* the machine needs to be mutable */
431 Machine::AutoMutableStateDependency adep(m->pMachine);
432 if (FAILED(adep.rc())) return adep.rc();
433
434 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
435
436 m->bd.backup();
437 m->bd->fPXEDebugEnabled = enable;
438
439 return S_OK;
440}
441
442STDMETHODIMP BIOSSettings::COMGETTER(TimeOffset)(LONG64 *offset)
443{
444 if (!offset)
445 return E_POINTER;
446
447 AutoCaller autoCaller(this);
448 if (FAILED(autoCaller.rc())) return autoCaller.rc();
449
450 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
451
452 *offset = m->bd->llTimeOffset;
453
454 return S_OK;
455}
456
457STDMETHODIMP BIOSSettings::COMSETTER(TimeOffset)(LONG64 offset)
458{
459 AutoCaller autoCaller(this);
460 if (FAILED(autoCaller.rc())) return autoCaller.rc();
461
462 /* the machine needs to be mutable */
463 Machine::AutoMutableStateDependency adep(m->pMachine);
464 if (FAILED(adep.rc())) return adep.rc();
465
466 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
467
468 m->bd.backup();
469 m->bd->llTimeOffset = offset;
470
471 return S_OK;
472}
473
474
475// IBIOSSettings methods
476/////////////////////////////////////////////////////////////////////////////
477
478// public methods only for internal purposes
479/////////////////////////////////////////////////////////////////////////////
480
481/**
482 * Loads settings from the given machine node.
483 * May be called once right after this object creation.
484 *
485 * @param aMachineNode <Machine> node.
486 *
487 * @note Locks this object for writing.
488 */
489HRESULT BIOSSettings::loadSettings(const settings::BIOSSettings &data)
490{
491 AutoCaller autoCaller(this);
492 AssertComRCReturnRC(autoCaller.rc());
493
494 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
495
496 // simply copy
497 *m->bd.data() = data;
498
499 return S_OK;
500}
501
502/**
503 * Saves settings to the given machine node.
504 *
505 * @param aMachineNode <Machine> node.
506 *
507 * @note Locks this object for reading.
508 */
509HRESULT BIOSSettings::saveSettings(settings::BIOSSettings &data)
510{
511 AutoCaller autoCaller(this);
512 AssertComRCReturnRC(autoCaller.rc());
513
514 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
515
516 data = *m->bd.data();
517
518 return S_OK;
519}
520
521bool BIOSSettings::isModified()
522{
523 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
524 return m->bd.isBackedUp();
525}
526
527bool BIOSSettings::isReallyModified()
528{
529 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
530 return m->bd.hasActualChanges();
531}
532
533void BIOSSettings::rollback()
534{
535 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
536 m->bd.rollback();
537}
538
539void BIOSSettings::commit()
540{
541 /* sanity */
542 AutoCaller autoCaller(this);
543 AssertComRCReturnVoid(autoCaller.rc());
544
545 /* sanity too */
546 AutoCaller peerCaller(m->pPeer);
547 AssertComRCReturnVoid(peerCaller.rc());
548
549 /* lock both for writing since we modify both (mPeer is "master" so locked
550 * first) */
551 AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
552
553 if (m->bd.isBackedUp())
554 {
555 m->bd.commit();
556 if (m->pPeer)
557 {
558 /* attach new data to the peer and reshare it */
559 AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
560 m->pPeer->m->bd.attach(m->bd);
561 }
562 }
563}
564
565void BIOSSettings::copyFrom (BIOSSettings *aThat)
566{
567 AssertReturnVoid (aThat != NULL);
568
569 /* sanity */
570 AutoCaller autoCaller(this);
571 AssertComRCReturnVoid (autoCaller.rc());
572
573 /* sanity too */
574 AutoCaller thatCaller (aThat);
575 AssertComRCReturnVoid (thatCaller.rc());
576
577 /* peer is not modified, lock it for reading (aThat is "master" so locked
578 * first) */
579 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
580 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
581
582 /* this will back up current data */
583 m->bd.assignCopy(aThat->m->bd);
584}
585
586void BIOSSettings::applyDefaults (GuestOSType *aOsType)
587{
588 AssertReturnVoid (aOsType != NULL);
589
590 /* sanity */
591 AutoCaller autoCaller(this);
592 AssertComRCReturnVoid (autoCaller.rc());
593
594 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
595
596 /* Initialize default BIOS settings here */
597 m->bd->fIOAPICEnabled = aOsType->recommendedIOAPIC();
598}
599
600/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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