VirtualBox

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

Last change on this file since 98351 was 98262, checked in by vboxsync, 23 months ago

Main: rc() -> hrc()/vrc(). bugref:10223

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