VirtualBox

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

Last change on this file since 67954 was 65063, checked in by vboxsync, 8 years ago

Main: doxygen fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.3 KB
Line 
1/* $Id: BIOSSettingsImpl.cpp 65063 2017-01-03 11:15:49Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2006-2016 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 = RT_BOOL(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 = RT_BOOL(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 = RT_BOOL(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 = RT_BOOL(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::getAPICMode(APICMode_T *aAPICMode)
391{
392 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
393
394 *aAPICMode = m->bd->apicMode;
395
396 return S_OK;
397}
398
399
400HRESULT BIOSSettings::setAPICMode(APICMode_T aAPICMode)
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
410 m->bd->apicMode = aAPICMode;
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
418
419HRESULT BIOSSettings::getPXEDebugEnabled(BOOL *enabled)
420{
421 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
422
423 *enabled = m->bd->fPXEDebugEnabled;
424
425 return S_OK;
426}
427
428
429HRESULT BIOSSettings::setPXEDebugEnabled(BOOL enable)
430{
431 /* the machine needs to be mutable */
432 AutoMutableStateDependency adep(m->pMachine);
433 if (FAILED(adep.rc())) return adep.rc();
434
435 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
436
437 m->bd.backup();
438 m->bd->fPXEDebugEnabled = RT_BOOL(enable);
439
440 alock.release();
441 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
442 m->pMachine->i_setModified(Machine::IsModified_BIOS);
443
444 return S_OK;
445}
446
447HRESULT BIOSSettings::getTimeOffset(LONG64 *offset)
448{
449 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
450
451 *offset = m->bd->llTimeOffset;
452
453 return S_OK;
454}
455
456
457HRESULT BIOSSettings::setTimeOffset(LONG64 offset)
458{
459 /* the machine needs to be mutable */
460 AutoMutableStateDependency adep(m->pMachine);
461 if (FAILED(adep.rc())) return adep.rc();
462
463 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
464
465 m->bd.backup();
466 m->bd->llTimeOffset = offset;
467
468 alock.release();
469 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
470 m->pMachine->i_setModified(Machine::IsModified_BIOS);
471
472 return S_OK;
473}
474
475HRESULT BIOSSettings::getNonVolatileStorageFile(com::Utf8Str &aNonVolatileStorageFile)
476{
477 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
478
479 aNonVolatileStorageFile = "";
480
481 return S_OK;
482}
483
484
485
486// IBIOSSettings methods
487/////////////////////////////////////////////////////////////////////////////
488
489// public methods only for internal purposes
490/////////////////////////////////////////////////////////////////////////////
491
492/**
493 * Loads settings from the given machine node.
494 * May be called once right after this object creation.
495 *
496 * @param data Configuration settings.
497 *
498 * @note Locks this object for writing.
499 */
500HRESULT BIOSSettings::i_loadSettings(const settings::BIOSSettings &data)
501{
502 AutoCaller autoCaller(this);
503 AssertComRCReturnRC(autoCaller.rc());
504
505 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
506
507 // simply copy
508 m->bd.assignCopy(&data);
509
510 return S_OK;
511}
512
513/**
514 * Saves settings to the given machine node.
515 *
516 * @param data Configuration settings.
517 *
518 * @note Locks this object for reading.
519 */
520HRESULT BIOSSettings::i_saveSettings(settings::BIOSSettings &data)
521{
522 AutoCaller autoCaller(this);
523 AssertComRCReturnRC(autoCaller.rc());
524
525 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
526
527 data = *m->bd.data();
528
529 return S_OK;
530}
531
532void BIOSSettings::i_rollback()
533{
534 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
535 m->bd.rollback();
536}
537
538void BIOSSettings::i_commit()
539{
540 /* sanity */
541 AutoCaller autoCaller(this);
542 AssertComRCReturnVoid(autoCaller.rc());
543
544 /* sanity too */
545 AutoCaller peerCaller(m->pPeer);
546 AssertComRCReturnVoid(peerCaller.rc());
547
548 /* lock both for writing since we modify both (mPeer is "master" so locked
549 * first) */
550 AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
551
552 if (m->bd.isBackedUp())
553 {
554 m->bd.commit();
555 if (m->pPeer)
556 {
557 /* attach new data to the peer and reshare it */
558 AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
559 m->pPeer->m->bd.attach(m->bd);
560 }
561 }
562}
563
564void BIOSSettings::i_copyFrom (BIOSSettings *aThat)
565{
566 AssertReturnVoid (aThat != NULL);
567
568 /* sanity */
569 AutoCaller autoCaller(this);
570 AssertComRCReturnVoid (autoCaller.rc());
571
572 /* sanity too */
573 AutoCaller thatCaller (aThat);
574 AssertComRCReturnVoid (thatCaller.rc());
575
576 /* peer is not modified, lock it for reading (aThat is "master" so locked
577 * first) */
578 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
579 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
580
581 /* this will back up current data */
582 m->bd.assignCopy(aThat->m->bd);
583}
584
585void BIOSSettings::i_applyDefaults (GuestOSType *aOsType)
586{
587 AssertReturnVoid (aOsType != NULL);
588
589 /* sanity */
590 AutoCaller autoCaller(this);
591 AssertComRCReturnVoid (autoCaller.rc());
592
593 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
594
595 /* Initialize default BIOS settings here */
596 m->bd->fIOAPICEnabled = aOsType->i_recommendedIOAPIC();
597}
598
599/* 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