VirtualBox

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

Last change on this file since 30787 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.5 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 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 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 unconst(m->pMachine) = aParent;
115 m->pPeer = that;
116
117 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
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 unconst(m->pMachine) = aParent;
145 // mPeer is left null
146
147 AutoWriteLock thatlock(that COMMA_LOCKVAL_SRC_POS);
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 unconst(m->pPeer) = NULL;
172 unconst(m->pMachine) = NULL;
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 COMMA_LOCKVAL_SRC_POS);
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 AutoMutableStateDependency adep(m->pMachine);
205 if (FAILED(adep.rc())) return adep.rc();
206
207 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
208
209 m->bd.backup();
210 m->bd->fLogoFadeIn = !!enable;
211
212 alock.release();
213 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
214 m->pMachine->setModified(Machine::IsModified_BIOS);
215
216 return S_OK;
217}
218
219STDMETHODIMP BIOSSettings::COMGETTER(LogoFadeOut)(BOOL *enabled)
220{
221 if (!enabled)
222 return E_POINTER;
223
224 AutoCaller autoCaller(this);
225 if (FAILED(autoCaller.rc())) return autoCaller.rc();
226
227 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
228
229 *enabled = m->bd->fLogoFadeOut;
230
231 return S_OK;
232}
233
234STDMETHODIMP BIOSSettings::COMSETTER(LogoFadeOut)(BOOL enable)
235{
236 AutoCaller autoCaller(this);
237 if (FAILED(autoCaller.rc())) return autoCaller.rc();
238
239 /* the machine needs to be mutable */
240 AutoMutableStateDependency adep(m->pMachine);
241 if (FAILED(adep.rc())) return adep.rc();
242
243 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
244
245 m->bd.backup();
246 m->bd->fLogoFadeOut = !!enable;
247
248 alock.release();
249 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
250 m->pMachine->setModified(Machine::IsModified_BIOS);
251
252 return S_OK;
253}
254
255STDMETHODIMP BIOSSettings::COMGETTER(LogoDisplayTime)(ULONG *displayTime)
256{
257 if (!displayTime)
258 return E_POINTER;
259
260 AutoCaller autoCaller(this);
261 if (FAILED(autoCaller.rc())) return autoCaller.rc();
262
263 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
264
265 *displayTime = m->bd->ulLogoDisplayTime;
266
267 return S_OK;
268}
269
270STDMETHODIMP BIOSSettings::COMSETTER(LogoDisplayTime)(ULONG displayTime)
271{
272 AutoCaller autoCaller(this);
273 if (FAILED(autoCaller.rc())) return autoCaller.rc();
274
275 /* the machine needs to be mutable */
276 AutoMutableStateDependency adep(m->pMachine);
277 if (FAILED(adep.rc())) return adep.rc();
278
279 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
280
281 m->bd.backup();
282 m->bd->ulLogoDisplayTime = displayTime;
283
284 alock.release();
285 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
286 m->pMachine->setModified(Machine::IsModified_BIOS);
287
288 return S_OK;
289}
290
291STDMETHODIMP BIOSSettings::COMGETTER(LogoImagePath)(BSTR *imagePath)
292{
293 if (!imagePath)
294 return E_POINTER;
295
296 AutoCaller autoCaller(this);
297 if (FAILED(autoCaller.rc())) return autoCaller.rc();
298
299 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
300
301 m->bd->strLogoImagePath.cloneTo(imagePath);
302 return S_OK;
303}
304
305STDMETHODIMP BIOSSettings::COMSETTER(LogoImagePath)(IN_BSTR imagePath)
306{
307 /* NULL strings are not allowed */
308 if (!imagePath)
309 return E_INVALIDARG;
310
311 AutoCaller autoCaller(this);
312 if (FAILED(autoCaller.rc())) return autoCaller.rc();
313
314 /* the machine needs to be mutable */
315 AutoMutableStateDependency adep(m->pMachine);
316 if (FAILED(adep.rc())) return adep.rc();
317
318 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
319
320 m->bd.backup();
321 m->bd->strLogoImagePath = imagePath;
322
323 alock.release();
324 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
325 m->pMachine->setModified(Machine::IsModified_BIOS);
326
327 return S_OK;
328}
329
330STDMETHODIMP BIOSSettings::COMGETTER(BootMenuMode)(BIOSBootMenuMode_T *bootMenuMode)
331{
332 if (!bootMenuMode)
333 return E_POINTER;
334
335 AutoCaller autoCaller(this);
336 if (FAILED(autoCaller.rc())) return autoCaller.rc();
337
338 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
339
340 *bootMenuMode = m->bd->biosBootMenuMode;
341 return S_OK;
342}
343
344STDMETHODIMP BIOSSettings::COMSETTER(BootMenuMode)(BIOSBootMenuMode_T bootMenuMode)
345{
346 AutoCaller autoCaller(this);
347 if (FAILED(autoCaller.rc())) return autoCaller.rc();
348
349 /* the machine needs to be mutable */
350 AutoMutableStateDependency adep(m->pMachine);
351 if (FAILED(adep.rc())) return adep.rc();
352
353 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
354
355 m->bd.backup();
356 m->bd->biosBootMenuMode = bootMenuMode;
357
358 alock.release();
359 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
360 m->pMachine->setModified(Machine::IsModified_BIOS);
361
362 return S_OK;
363}
364
365STDMETHODIMP BIOSSettings::COMGETTER(ACPIEnabled)(BOOL *enabled)
366{
367 if (!enabled)
368 return E_POINTER;
369
370 AutoCaller autoCaller(this);
371 if (FAILED(autoCaller.rc())) return autoCaller.rc();
372
373 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
374
375 *enabled = m->bd->fACPIEnabled;
376
377 return S_OK;
378}
379
380STDMETHODIMP BIOSSettings::COMSETTER(ACPIEnabled)(BOOL enable)
381{
382 AutoCaller autoCaller(this);
383 if (FAILED(autoCaller.rc())) return autoCaller.rc();
384
385 /* the machine needs to be mutable */
386 AutoMutableStateDependency adep(m->pMachine);
387 if (FAILED(adep.rc())) return adep.rc();
388
389 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
390
391 m->bd.backup();
392 m->bd->fACPIEnabled = !!enable;
393
394 alock.release();
395 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
396 m->pMachine->setModified(Machine::IsModified_BIOS);
397
398 return S_OK;
399}
400
401STDMETHODIMP BIOSSettings::COMGETTER(IOAPICEnabled)(BOOL *enabled)
402{
403 if (!enabled)
404 return E_POINTER;
405
406 AutoCaller autoCaller(this);
407 if (FAILED(autoCaller.rc())) return autoCaller.rc();
408
409 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
410
411 *enabled = m->bd->fIOAPICEnabled;
412
413 return S_OK;
414}
415
416STDMETHODIMP BIOSSettings::COMSETTER(IOAPICEnabled)(BOOL enable)
417{
418 AutoCaller autoCaller(this);
419 if (FAILED(autoCaller.rc())) return autoCaller.rc();
420
421 /* the machine needs to be mutable */
422 AutoMutableStateDependency adep(m->pMachine);
423 if (FAILED(adep.rc())) return adep.rc();
424
425 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
426
427 m->bd.backup();
428 m->bd->fIOAPICEnabled = !!enable;
429
430 alock.release();
431 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
432 m->pMachine->setModified(Machine::IsModified_BIOS);
433
434 return S_OK;
435}
436
437STDMETHODIMP BIOSSettings::COMGETTER(PXEDebugEnabled)(BOOL *enabled)
438{
439 if (!enabled)
440 return E_POINTER;
441
442 AutoCaller autoCaller(this);
443 if (FAILED(autoCaller.rc())) return autoCaller.rc();
444
445 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
446
447 *enabled = m->bd->fPXEDebugEnabled;
448
449 return S_OK;
450}
451
452STDMETHODIMP BIOSSettings::COMSETTER(PXEDebugEnabled)(BOOL enable)
453{
454 AutoCaller autoCaller(this);
455 if (FAILED(autoCaller.rc())) return autoCaller.rc();
456
457 /* the machine needs to be mutable */
458 AutoMutableStateDependency adep(m->pMachine);
459 if (FAILED(adep.rc())) return adep.rc();
460
461 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
462
463 m->bd.backup();
464 m->bd->fPXEDebugEnabled = !!enable;
465
466 alock.release();
467 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
468 m->pMachine->setModified(Machine::IsModified_BIOS);
469
470 return S_OK;
471}
472
473STDMETHODIMP BIOSSettings::COMGETTER(TimeOffset)(LONG64 *offset)
474{
475 if (!offset)
476 return E_POINTER;
477
478 AutoCaller autoCaller(this);
479 if (FAILED(autoCaller.rc())) return autoCaller.rc();
480
481 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
482
483 *offset = m->bd->llTimeOffset;
484
485 return S_OK;
486}
487
488STDMETHODIMP BIOSSettings::COMSETTER(TimeOffset)(LONG64 offset)
489{
490 AutoCaller autoCaller(this);
491 if (FAILED(autoCaller.rc())) return autoCaller.rc();
492
493 /* the machine needs to be mutable */
494 AutoMutableStateDependency adep(m->pMachine);
495 if (FAILED(adep.rc())) return adep.rc();
496
497 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
498
499 m->bd.backup();
500 m->bd->llTimeOffset = offset;
501
502 alock.release();
503 AutoWriteLock mlock(m->pMachine COMMA_LOCKVAL_SRC_POS); // mParent is const, needs no locking
504 m->pMachine->setModified(Machine::IsModified_BIOS);
505
506 return S_OK;
507}
508
509
510// IBIOSSettings methods
511/////////////////////////////////////////////////////////////////////////////
512
513// public methods only for internal purposes
514/////////////////////////////////////////////////////////////////////////////
515
516/**
517 * Loads settings from the given machine node.
518 * May be called once right after this object creation.
519 *
520 * @param aMachineNode <Machine> node.
521 *
522 * @note Locks this object for writing.
523 */
524HRESULT BIOSSettings::loadSettings(const settings::BIOSSettings &data)
525{
526 AutoCaller autoCaller(this);
527 AssertComRCReturnRC(autoCaller.rc());
528
529 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
530
531 // simply copy
532 *m->bd.data() = data;
533
534 return S_OK;
535}
536
537/**
538 * Saves settings to the given machine node.
539 *
540 * @param aMachineNode <Machine> node.
541 *
542 * @note Locks this object for reading.
543 */
544HRESULT BIOSSettings::saveSettings(settings::BIOSSettings &data)
545{
546 AutoCaller autoCaller(this);
547 AssertComRCReturnRC(autoCaller.rc());
548
549 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
550
551 data = *m->bd.data();
552
553 return S_OK;
554}
555
556void BIOSSettings::rollback()
557{
558 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
559 m->bd.rollback();
560}
561
562void BIOSSettings::commit()
563{
564 /* sanity */
565 AutoCaller autoCaller(this);
566 AssertComRCReturnVoid(autoCaller.rc());
567
568 /* sanity too */
569 AutoCaller peerCaller(m->pPeer);
570 AssertComRCReturnVoid(peerCaller.rc());
571
572 /* lock both for writing since we modify both (mPeer is "master" so locked
573 * first) */
574 AutoMultiWriteLock2 alock(m->pPeer, this COMMA_LOCKVAL_SRC_POS);
575
576 if (m->bd.isBackedUp())
577 {
578 m->bd.commit();
579 if (m->pPeer)
580 {
581 /* attach new data to the peer and reshare it */
582 AutoWriteLock peerlock(m->pPeer COMMA_LOCKVAL_SRC_POS);
583 m->pPeer->m->bd.attach(m->bd);
584 }
585 }
586}
587
588void BIOSSettings::copyFrom (BIOSSettings *aThat)
589{
590 AssertReturnVoid (aThat != NULL);
591
592 /* sanity */
593 AutoCaller autoCaller(this);
594 AssertComRCReturnVoid (autoCaller.rc());
595
596 /* sanity too */
597 AutoCaller thatCaller (aThat);
598 AssertComRCReturnVoid (thatCaller.rc());
599
600 /* peer is not modified, lock it for reading (aThat is "master" so locked
601 * first) */
602 AutoReadLock rl(aThat COMMA_LOCKVAL_SRC_POS);
603 AutoWriteLock wl(this COMMA_LOCKVAL_SRC_POS);
604
605 /* this will back up current data */
606 m->bd.assignCopy(aThat->m->bd);
607}
608
609void BIOSSettings::applyDefaults (GuestOSType *aOsType)
610{
611 AssertReturnVoid (aOsType != NULL);
612
613 /* sanity */
614 AutoCaller autoCaller(this);
615 AssertComRCReturnVoid (autoCaller.rc());
616
617 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
618
619 /* Initialize default BIOS settings here */
620 m->bd->fIOAPICEnabled = aOsType->recommendedIOAPIC();
621}
622
623/* 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