3
* VirtualBox COM class implementation
7
* Copyright (C) 2006-2007 Oracle Corporation
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.
18
#include "BIOSSettingsImpl.h"
19
#include "MachineImpl.h"
20
#include "GuestOSTypeImpl.h"
22
#include <iprt/cpp/utils.h>
23
#include <VBox/settings.h>
25
#include "AutoStateDep.h"
26
#include "AutoCaller.h"
29
////////////////////////////////////////////////////////////////////////////////
31
// BIOSSettings private data definition
33
////////////////////////////////////////////////////////////////////////////////
35
struct BIOSSettings::Data
41
Machine * const pMachine;
42
ComObjPtr<BIOSSettings> pPeer;
44
// use the XML settings structure in the members for simplicity
45
Backupable<settings::BIOSSettings> bd;
48
// constructor / destructor
49
/////////////////////////////////////////////////////////////////////////////
51
HRESULT BIOSSettings::FinalConstruct()
56
void BIOSSettings::FinalRelease()
61
// public initializer/uninitializer for internal purposes only
62
/////////////////////////////////////////////////////////////////////////////
65
* Initializes the audio adapter object.
67
* @returns COM result indicator
69
HRESULT BIOSSettings::init(Machine *aParent)
71
LogFlowThisFuncEnter();
72
LogFlowThisFunc(("aParent: %p\n", aParent));
74
ComAssertRet(aParent, E_INVALIDARG);
76
/* Enclose the state transition NotReady->InInit->Ready */
77
AutoInitSpan autoInitSpan(this);
78
AssertReturn(autoInitSpan.isOk(), E_FAIL);
82
/* share the parent weakly */
83
unconst(m->pMachine) = aParent;
87
autoInitSpan.setSucceeded();
89
LogFlowThisFuncLeave();
94
* Initializes the audio adapter object given another audio adapter object
95
* (a kind of copy constructor). This object shares data with
96
* the object passed as an argument.
98
* @note This object must be destroyed before the original object
99
* it shares data with is destroyed.
101
HRESULT BIOSSettings::init(Machine *aParent, BIOSSettings *that)
103
LogFlowThisFuncEnter();
104
LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
106
ComAssertRet(aParent && that, E_INVALIDARG);
108
/* Enclose the state transition NotReady->InInit->Ready */
109
AutoInitSpan autoInitSpan(this);
110
AssertReturn(autoInitSpan.isOk(), E_FAIL);
114
unconst(m->pMachine) = aParent;
117
AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
118
m->bd.share(that->m->bd);
120
autoInitSpan.setSucceeded();
122
LogFlowThisFuncLeave();
127
* Initializes the guest object given another guest object
128
* (a kind of copy constructor). This object makes a private copy of data
129
* of the original object passed as an argument.
131
HRESULT BIOSSettings::initCopy(Machine *aParent, BIOSSettings *that)
133
LogFlowThisFuncEnter();
134
LogFlowThisFunc(("aParent: %p, that: %p\n", aParent, that));
136
ComAssertRet(aParent && that, E_INVALIDARG);
138
/* Enclose the state transition NotReady->InInit->Ready */
139
AutoInitSpan autoInitSpan(this);
140
AssertReturn(autoInitSpan.isOk(), E_FAIL);
144
unconst(m->pMachine) = aParent;
145
// mPeer is left null
147
AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
148
m->bd.attachCopy(that->m->bd);
150
autoInitSpan.setSucceeded();
152
LogFlowThisFuncLeave();
157
* Uninitializes the instance and sets the ready flag to FALSE.
158
* Called either from FinalRelease() or by the parent when it gets destroyed.
160
void BIOSSettings::uninit()
162
LogFlowThisFuncEnter();
164
/* Enclose the state transition Ready->InUninit->NotReady */
165
AutoUninitSpan autoUninitSpan(this);
166
if (autoUninitSpan.uninitDone())
171
unconst(m->pPeer) = NULL;
172
unconst(m->pMachine) = NULL;
177
LogFlowThisFuncLeave();
180
// IBIOSSettings properties
181
/////////////////////////////////////////////////////////////////////////////
183
STDMETHODIMP BIOSSettings::COMGETTER(LogoFadeIn)(BOOL *enabled)
188
AutoCaller autoCaller(this);
189
if (FAILED(autoCaller.rc())) return autoCaller.rc();
191
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
193
*enabled = m->bd->fLogoFadeIn;
198
STDMETHODIMP BIOSSettings::COMSETTER(LogoFadeIn)(BOOL enable)
200
AutoCaller autoCaller(this);
201
if (FAILED(autoCaller.rc())) return autoCaller.rc();
203
/* the machine needs to be mutable */
204
AutoMutableStateDependency adep(m->pMachine);
205
if (FAILED(adep.rc())) return adep.rc();
207
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
210
m->bd->fLogoFadeIn = !!enable;
213
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
214
m->pMachine->setModified(Machine::IsModified_BIOS);
219
STDMETHODIMP BIOSSettings::COMGETTER(LogoFadeOut)(BOOL *enabled)
224
AutoCaller autoCaller(this);
225
if (FAILED(autoCaller.rc())) return autoCaller.rc();
227
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
229
*enabled = m->bd->fLogoFadeOut;
234
STDMETHODIMP BIOSSettings::COMSETTER(LogoFadeOut)(BOOL enable)
236
AutoCaller autoCaller(this);
237
if (FAILED(autoCaller.rc())) return autoCaller.rc();
239
/* the machine needs to be mutable */
240
AutoMutableStateDependency adep(m->pMachine);
241
if (FAILED(adep.rc())) return adep.rc();
243
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
246
m->bd->fLogoFadeOut = !!enable;
249
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
250
m->pMachine->setModified(Machine::IsModified_BIOS);
255
STDMETHODIMP BIOSSettings::COMGETTER(LogoDisplayTime)(ULONG *displayTime)
260
AutoCaller autoCaller(this);
261
if (FAILED(autoCaller.rc())) return autoCaller.rc();
263
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
265
*displayTime = m->bd->ulLogoDisplayTime;
270
STDMETHODIMP BIOSSettings::COMSETTER(LogoDisplayTime)(ULONG displayTime)
272
AutoCaller autoCaller(this);
273
if (FAILED(autoCaller.rc())) return autoCaller.rc();
275
/* the machine needs to be mutable */
276
AutoMutableStateDependency adep(m->pMachine);
277
if (FAILED(adep.rc())) return adep.rc();
279
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
282
m->bd->ulLogoDisplayTime = displayTime;
285
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
286
m->pMachine->setModified(Machine::IsModified_BIOS);
291
STDMETHODIMP BIOSSettings::COMGETTER(LogoImagePath)(BSTR *imagePath)
296
AutoCaller autoCaller(this);
297
if (FAILED(autoCaller.rc())) return autoCaller.rc();
299
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
301
m->bd->strLogoImagePath.cloneTo(imagePath);
305
STDMETHODIMP BIOSSettings::COMSETTER(LogoImagePath)(IN_BSTR imagePath)
307
/* NULL strings are not allowed */
311
AutoCaller autoCaller(this);
312
if (FAILED(autoCaller.rc())) return autoCaller.rc();
314
/* the machine needs to be mutable */
315
AutoMutableStateDependency adep(m->pMachine);
316
if (FAILED(adep.rc())) return adep.rc();
318
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
321
m->bd->strLogoImagePath = imagePath;
324
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
325
m->pMachine->setModified(Machine::IsModified_BIOS);
330
STDMETHODIMP BIOSSettings::COMGETTER(BootMenuMode)(BIOSBootMenuMode_T *bootMenuMode)
335
AutoCaller autoCaller(this);
336
if (FAILED(autoCaller.rc())) return autoCaller.rc();
338
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
340
*bootMenuMode = m->bd->biosBootMenuMode;
344
STDMETHODIMP BIOSSettings::COMSETTER(BootMenuMode)(BIOSBootMenuMode_T bootMenuMode)
346
AutoCaller autoCaller(this);
347
if (FAILED(autoCaller.rc())) return autoCaller.rc();
349
/* the machine needs to be mutable */
350
AutoMutableStateDependency adep(m->pMachine);
351
if (FAILED(adep.rc())) return adep.rc();
353
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
356
m->bd->biosBootMenuMode = bootMenuMode;
359
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
360
m->pMachine->setModified(Machine::IsModified_BIOS);
365
STDMETHODIMP BIOSSettings::COMGETTER(ACPIEnabled)(BOOL *enabled)
370
AutoCaller autoCaller(this);
371
if (FAILED(autoCaller.rc())) return autoCaller.rc();
373
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
375
*enabled = m->bd->fACPIEnabled;
380
STDMETHODIMP BIOSSettings::COMSETTER(ACPIEnabled)(BOOL enable)
382
AutoCaller autoCaller(this);
383
if (FAILED(autoCaller.rc())) return autoCaller.rc();
385
/* the machine needs to be mutable */
386
AutoMutableStateDependency adep(m->pMachine);
387
if (FAILED(adep.rc())) return adep.rc();
389
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
392
m->bd->fACPIEnabled = !!enable;
395
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
396
m->pMachine->setModified(Machine::IsModified_BIOS);
401
STDMETHODIMP BIOSSettings::COMGETTER(IOAPICEnabled)(BOOL *enabled)
406
AutoCaller autoCaller(this);
407
if (FAILED(autoCaller.rc())) return autoCaller.rc();
409
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
411
*enabled = m->bd->fIOAPICEnabled;
416
STDMETHODIMP BIOSSettings::COMSETTER(IOAPICEnabled)(BOOL enable)
418
AutoCaller autoCaller(this);
419
if (FAILED(autoCaller.rc())) return autoCaller.rc();
421
/* the machine needs to be mutable */
422
AutoMutableStateDependency adep(m->pMachine);
423
if (FAILED(adep.rc())) return adep.rc();
425
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
428
m->bd->fIOAPICEnabled = !!enable;
431
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
432
m->pMachine->setModified(Machine::IsModified_BIOS);
437
STDMETHODIMP BIOSSettings::COMGETTER(PXEDebugEnabled)(BOOL *enabled)
442
AutoCaller autoCaller(this);
443
if (FAILED(autoCaller.rc())) return autoCaller.rc();
445
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
447
*enabled = m->bd->fPXEDebugEnabled;
452
STDMETHODIMP BIOSSettings::COMSETTER(PXEDebugEnabled)(BOOL enable)
454
AutoCaller autoCaller(this);
455
if (FAILED(autoCaller.rc())) return autoCaller.rc();
457
/* the machine needs to be mutable */
458
AutoMutableStateDependency adep(m->pMachine);
459
if (FAILED(adep.rc())) return adep.rc();
461
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
464
m->bd->fPXEDebugEnabled = !!enable;
467
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
468
m->pMachine->setModified(Machine::IsModified_BIOS);
473
STDMETHODIMP BIOSSettings::COMGETTER(TimeOffset)(LONG64 *offset)
478
AutoCaller autoCaller(this);
479
if (FAILED(autoCaller.rc())) return autoCaller.rc();
481
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
483
*offset = m->bd->llTimeOffset;
488
STDMETHODIMP BIOSSettings::COMSETTER(TimeOffset)(LONG64 offset)
490
AutoCaller autoCaller(this);
491
if (FAILED(autoCaller.rc())) return autoCaller.rc();
493
/* the machine needs to be mutable */
494
AutoMutableStateDependency adep(m->pMachine);
495
if (FAILED(adep.rc())) return adep.rc();
497
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
500
m->bd->llTimeOffset = offset;
503
AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
504
m->pMachine->setModified(Machine::IsModified_BIOS);
510
// IBIOSSettings methods
511
/////////////////////////////////////////////////////////////////////////////
513
// public methods only for internal purposes
514
/////////////////////////////////////////////////////////////////////////////
517
* Loads settings from the given machine node.
518
* May be called once right after this object creation.
520
* @param aMachineNode <Machine> node.
522
* @note Locks this object for writing.
524
HRESULT BIOSSettings::loadSettings(const settings::BIOSSettings &data)
526
AutoCaller autoCaller(this);
527
AssertComRCReturnRC(autoCaller.rc());
529
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
532
*m->bd.data() = data;
538
* Saves settings to the given machine node.
540
* @param aMachineNode <Machine> node.
542
* @note Locks this object for reading.
544
HRESULT BIOSSettings::saveSettings(settings::BIOSSettings &data)
546
AutoCaller autoCaller(this);
547
AssertComRCReturnRC(autoCaller.rc());
549
AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
551
data = *m->bd.data();
556
void BIOSSettings::rollback()
558
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
562
void BIOSSettings::commit()
565
AutoCaller autoCaller(this);
566
AssertComRCReturnVoid(autoCaller.rc());
569
AutoCaller peerCaller(m->pPeer);
570
AssertComRCReturnVoid(peerCaller.rc());
572
/* lock both for writing since we modify both (mPeer is "master" so locked
574
AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
576
if (m->bd.isBackedUp())
581
/* attach new data to the peer and reshare it */
582
AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
583
m->pPeer->m->bd.attach(m->bd);
588
void BIOSSettings::copyFrom (BIOSSettings *aThat)
590
AssertReturnVoid (aThat != NULL);
593
AutoCaller autoCaller(this);
594
AssertComRCReturnVoid (autoCaller.rc());
597
AutoCaller thatCaller (aThat);
598
AssertComRCReturnVoid (thatCaller.rc());
600
/* peer is not modified, lock it for reading (aThat is "master" so locked
602
AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
603
AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
605
/* this will back up current data */
606
m->bd.assignCopy(aThat->m->bd);
609
void BIOSSettings::applyDefaults (GuestOSType *aOsType)
611
AssertReturnVoid (aOsType != NULL);
614
AutoCaller autoCaller(this);
615
AssertComRCReturnVoid (autoCaller.rc());
617
AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
619
/* Initialize default BIOS settings here */
620
m->bd->fIOAPICEnabled = aOsType->recommendedIOAPIC();
623
/* vi: set tabstop=4 shiftwidth=4 expandtab: */