VirtualBox

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

Last change on this file since 26163 was 26156, checked in by vboxsync, 15 years ago

Main: get rid of isReallyChanged() voodoo in Machine and subclasses; instead check in the XML classes whether things really changed via operator==; documentation, cleanup

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette