VirtualBox

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

Last change on this file since 49644 was 49644, checked in by vboxsync, 11 years ago

stage 1/8 of 6813 changes

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