VirtualBox

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

Last change on this file since 25275 was 25201, checked in by vboxsync, 14 years ago

Main: make BIOSSettings instance data private and make it use the XML settings struct for simplicity

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

© 2023 Oracle
ContactPrivacy policyTerms of Use