VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/BIOSSettingsImpl.cpp@ 55457

Last change on this file since 55457 was 55401, checked in by vboxsync, 10 years ago

added a couple of missing Id headers

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