VirtualBox

source: vbox/trunk/src/VBox/Main/MediumAttachmentImpl.cpp@ 23880

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

Main/MediumAttachment: change return value of Controller getter to return a reference to the StorageController instead of just the name

File size: 6.9 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2009 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 "MediumAttachmentImpl.h"
23#include "MachineImpl.h"
24
25#include "Logging.h"
26
27// constructor / destructor
28/////////////////////////////////////////////////////////////////////////////
29
30DEFINE_EMPTY_CTOR_DTOR(MediumAttachment)
31
32HRESULT MediumAttachment::FinalConstruct()
33{
34 LogFlowThisFunc(("\n"));
35 return S_OK;
36}
37
38void MediumAttachment::FinalRelease()
39{
40 LogFlowThisFuncEnter();
41 uninit();
42 LogFlowThisFuncLeave();
43}
44
45// public initializer/uninitializer for internal purposes only
46/////////////////////////////////////////////////////////////////////////////
47
48/**
49 * Initializes the medium attachment object.
50 *
51 * @param aParent Machine object.
52 * @param aMedium Medium object.
53 * @param aController Controller the hard disk is attached to.
54 * @param aPort Port number.
55 * @param aDevice Device number on the port.
56 * @param aImplicit Wether the attachment contains an implicitly created diff.
57 */
58HRESULT MediumAttachment::init(Machine *aParent,
59 Medium *aMedium,
60 StorageController *aController,
61 LONG aPort,
62 LONG aDevice,
63 DeviceType_T aType,
64 bool aImplicit /*= false*/)
65{
66 LogFlowThisFuncEnter();
67 LogFlowThisFunc(("aParent=%p aMedium=%p aController=%ls aPort=%d aDevice=%d aType=%d aImplicit=%d\n", aParent, aMedium, aController, aPort, aDevice, aType, aImplicit));
68
69 if (aType == DeviceType_HardDisk)
70 AssertReturn(aMedium, E_INVALIDARG);
71
72 /* Enclose the state transition NotReady->InInit->Ready */
73 AutoInitSpan autoInitSpan(this);
74 AssertReturn(autoInitSpan.isOk(), E_FAIL);
75
76 unconst(mParent) = aParent;
77
78 m.allocate();
79 m->medium = aMedium;
80 unconst(m->controller) = aController;
81 unconst(m->port) = aPort;
82 unconst(m->device) = aDevice;
83 unconst(m->type) = aType;
84 unconst(m->passthrough) = false;
85
86 m->implicit = aImplicit;
87
88 /* Confirm a successful initialization when it's the case */
89 autoInitSpan.setSucceeded();
90
91 LogFlowThisFuncLeave();
92 return S_OK;
93}
94
95/**
96 * Uninitializes the instance.
97 * Called from FinalRelease().
98 */
99void MediumAttachment::uninit()
100{
101 LogFlowThisFuncEnter();
102
103 /* Enclose the state transition Ready->InUninit->NotReady */
104 AutoUninitSpan autoUninitSpan(this);
105 if (autoUninitSpan.uninitDone())
106 return;
107
108 m.free();
109
110 unconst(mParent).setNull();
111
112 LogFlowThisFuncLeave();
113}
114
115/**
116 * @note Locks this object for writing.
117 */
118bool MediumAttachment::rollback()
119{
120 LogFlowThisFuncEnter();
121
122 /* sanity */
123 AutoCaller autoCaller(this);
124 AssertComRCReturn (autoCaller.rc(), false);
125
126 AutoWriteLock alock(this);
127
128 bool changed = false;
129
130 if (m.isBackedUp())
131 {
132 /* we need to check all data to see whether anything will be changed
133 * after rollback */
134 changed = m.hasActualChanges();
135 m.rollback();
136 }
137
138 LogFlowThisFuncLeave();
139 return changed;
140}
141
142/**
143 * @note Locks this object for writing.
144 */
145void MediumAttachment::commit()
146{
147 LogFlowThisFuncEnter();
148
149 /* sanity */
150 AutoCaller autoCaller(this);
151 AssertComRCReturnVoid (autoCaller.rc());
152
153 AutoWriteLock alock(this);
154
155 if (m.isBackedUp())
156 m.commit();
157
158 LogFlowThisFuncLeave();
159}
160
161
162// IHardDiskAttachment properties
163/////////////////////////////////////////////////////////////////////////////
164
165STDMETHODIMP MediumAttachment::COMGETTER(Medium)(IMedium **aHardDisk)
166{
167 LogFlowThisFuncEnter();
168
169 CheckComArgOutPointerValid(aHardDisk);
170
171 AutoCaller autoCaller(this);
172 CheckComRCReturnRC(autoCaller.rc());
173
174 AutoReadLock alock(this);
175
176 m->medium.queryInterfaceTo(aHardDisk);
177
178 LogFlowThisFuncLeave();
179 return S_OK;
180}
181
182STDMETHODIMP MediumAttachment::COMGETTER(Controller)(IStorageController **aController)
183{
184 LogFlowThisFuncEnter();
185
186 CheckComArgOutPointerValid(aController);
187
188 AutoCaller autoCaller(this);
189 CheckComRCReturnRC(autoCaller.rc());
190
191 /* m->controller is constant during life time, no need to lock */
192 m->controller.queryInterfaceTo(aController);
193
194 LogFlowThisFuncLeave();
195 return S_OK;
196}
197
198STDMETHODIMP MediumAttachment::COMGETTER(Port)(LONG *aPort)
199{
200 LogFlowThisFuncEnter();
201
202 CheckComArgOutPointerValid(aPort);
203
204 AutoCaller autoCaller(this);
205 CheckComRCReturnRC(autoCaller.rc());
206
207 /* m->port is constant during life time, no need to lock */
208 *aPort = m->port;
209
210 LogFlowThisFuncLeave();
211 return S_OK;
212}
213
214STDMETHODIMP MediumAttachment::COMGETTER(Device)(LONG *aDevice)
215{
216 LogFlowThisFuncEnter();
217
218 CheckComArgOutPointerValid(aDevice);
219
220 AutoCaller autoCaller(this);
221 CheckComRCReturnRC(autoCaller.rc());
222
223 /* m->device is constant during life time, no need to lock */
224 *aDevice = m->device;
225
226 LogFlowThisFuncLeave();
227 return S_OK;
228}
229
230STDMETHODIMP MediumAttachment::COMGETTER(Type)(DeviceType_T *aType)
231{
232 LogFlowThisFuncEnter();
233
234 CheckComArgOutPointerValid(aType);
235
236 AutoCaller autoCaller(this);
237 CheckComRCReturnRC(autoCaller.rc());
238
239 /* m->type is constant during life time, no need to lock */
240 *aType = m->type;
241
242 LogFlowThisFuncLeave();
243 return S_OK;
244}
245
246STDMETHODIMP MediumAttachment::COMSETTER(Passthrough)(BOOL aPassthrough)
247{
248 LogFlowThisFuncEnter();
249
250 AutoCaller autoCaller(this);
251 CheckComRCReturnRC(autoCaller.rc());
252
253 /** @todo the entire passthrough handling can only be enabled after the
254 * MediumAttachment handling in Machine is fixed. */
255#if 0
256 /* the machine need to be mutable */
257 Machine::AutoMutableStateDependency adep(mParent);
258 CheckComRCReturnRC(adep.rc());
259
260 AutoWriteLock lock(this);
261
262 if (m->passthrough != !!aPassthrough)
263 {
264 m.backup();
265 m->passthrough = !!aPassthrough;
266 }
267#endif
268
269 LogFlowThisFuncLeave();
270 return S_OK;
271}
272
273STDMETHODIMP MediumAttachment::COMGETTER(Passthrough)(BOOL *aPassthrough)
274{
275 LogFlowThisFuncEnter();
276
277 CheckComArgOutPointerValid(aPassthrough);
278
279 AutoCaller autoCaller(this);
280 CheckComRCReturnRC(autoCaller.rc());
281
282 AutoReadLock lock(this);
283
284 *aPassthrough = m->passthrough;
285
286 LogFlowThisFuncLeave();
287 return S_OK;
288}
289
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