VirtualBox

source: vbox/trunk/src/VBox/Main/src-all/PCIDeviceAttachmentImpl.cpp@ 67954

Last change on this file since 67954 was 66046, checked in by vboxsync, 8 years ago

Main/Snapshot: When creating a snapshot it's necessary to copy the medium attachment objects (and not use the same ones) to separate the new snapshot from current state. Otherwise changing a removable medium (DVD/floppy) will show up in 'fresh' snapshots, i.e. the ones taken since VBoxSVC was started. Same issue for PCI device attachments (which isn't used as much). Apart from that a lot of error checking cleanup, for consistency reasons.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: PCIDeviceAttachmentImpl.cpp 66046 2017-03-10 16:58:36Z vboxsync $ */
2
3/** @file
4 *
5 * PCI attachment information implmentation.
6 */
7
8/*
9 * Copyright (C) 2010-2016 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "PCIDeviceAttachmentImpl.h"
21#include "AutoCaller.h"
22#include "Global.h"
23#include "Logging.h"
24
25#include <VBox/settings.h>
26
27struct PCIDeviceAttachment::Data
28{
29 Data(const Utf8Str &aDevName,
30 LONG aHostAddress,
31 LONG aGuestAddress,
32 BOOL afPhysical) :
33 DevName(aDevName),
34 HostAddress(aHostAddress),
35 GuestAddress(aGuestAddress),
36 fPhysical(afPhysical)
37 {
38 }
39
40 Utf8Str DevName;
41 LONG HostAddress;
42 LONG GuestAddress;
43 BOOL fPhysical;
44};
45
46// constructor / destructor
47/////////////////////////////////////////////////////////////////////////////
48DEFINE_EMPTY_CTOR_DTOR(PCIDeviceAttachment)
49
50HRESULT PCIDeviceAttachment::FinalConstruct()
51{
52 LogFlowThisFunc(("\n"));
53 return BaseFinalConstruct();
54}
55
56void PCIDeviceAttachment::FinalRelease()
57{
58 LogFlowThisFunc(("\n"));
59 uninit();
60 BaseFinalRelease();
61}
62
63// public initializer/uninitializer for internal purposes only
64/////////////////////////////////////////////////////////////////////////////
65HRESULT PCIDeviceAttachment::init(IMachine *aParent,
66 const Utf8Str &aDevName,
67 LONG aHostAddress,
68 LONG aGuestAddress,
69 BOOL fPhysical)
70{
71 NOREF(aParent);
72
73 /* Enclose the state transition NotReady->InInit->Ready */
74 AutoInitSpan autoInitSpan(this);
75 AssertReturn(autoInitSpan.isOk(), E_FAIL);
76
77 m = new Data(aDevName, aHostAddress, aGuestAddress, fPhysical);
78
79 /* Confirm a successful initialization */
80 autoInitSpan.setSucceeded();
81
82 return S_OK;
83}
84
85HRESULT PCIDeviceAttachment::initCopy(IMachine *aParent, PCIDeviceAttachment *aThat)
86{
87 LogFlowThisFunc(("aParent=%p, aThat=%p\n", aParent, aThat));
88
89 ComAssertRet(aParent && aThat, E_INVALIDARG);
90
91 return init(aParent, aThat->m->DevName, aThat->m->HostAddress, aThat->m->GuestAddress, aThat->m->fPhysical);
92}
93
94HRESULT PCIDeviceAttachment::i_loadSettings(IMachine *aParent,
95 const settings::HostPCIDeviceAttachment &hpda)
96{
97 return init(aParent, hpda.strDeviceName, hpda.uHostAddress, hpda.uGuestAddress, TRUE);
98}
99
100
101HRESULT PCIDeviceAttachment::i_saveSettings(settings::HostPCIDeviceAttachment &data)
102{
103 Assert(m);
104 data.uHostAddress = m->HostAddress;
105 data.uGuestAddress = m->GuestAddress;
106 data.strDeviceName = m->DevName;
107
108 return S_OK;
109}
110
111/**
112 * Uninitializes the instance.
113 * Called from FinalRelease().
114 */
115void PCIDeviceAttachment::uninit()
116{
117 /* Enclose the state transition Ready->InUninit->NotReady */
118 AutoUninitSpan autoUninitSpan(this);
119 if (autoUninitSpan.uninitDone())
120 return;
121
122 delete m;
123 m = NULL;
124}
125
126// IPCIDeviceAttachment properties
127/////////////////////////////////////////////////////////////////////////////
128HRESULT PCIDeviceAttachment::getName(com::Utf8Str &aName)
129{
130 aName = m->DevName;
131 return S_OK;
132}
133
134HRESULT PCIDeviceAttachment::getIsPhysicalDevice(BOOL *aIsPhysicalDevice)
135{
136 *aIsPhysicalDevice = m->fPhysical;
137 return S_OK;
138}
139
140HRESULT PCIDeviceAttachment::getHostAddress(LONG *aHostAddress)
141{
142 *aHostAddress = m->HostAddress;
143 return S_OK;
144}
145HRESULT PCIDeviceAttachment::getGuestAddress(LONG *aGuestAddress)
146{
147 *aGuestAddress = m->GuestAddress;
148 return S_OK;
149}
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