VirtualBox

source: vbox/trunk/src/VBox/Main/DVDDriveImpl.cpp@ 2042

Last change on this file since 2042 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include "DVDDriveImpl.h"
23#include "MachineImpl.h"
24#include "Logging.h"
25
26#include <iprt/string.h>
27
28// defines
29////////////////////////////////////////////////////////////////////////////////
30
31// constructor / destructor
32////////////////////////////////////////////////////////////////////////////////
33
34HRESULT DVDDrive::FinalConstruct()
35{
36 return S_OK;
37}
38
39void DVDDrive::FinalRelease()
40{
41 if (isReady())
42 uninit ();
43}
44
45// public initializer/uninitializer for internal purposes only
46////////////////////////////////////////////////////////////////////////////////
47
48/**
49 * Initializes the DVD drive object.
50 *
51 * @param parent handle of our parent object
52 * @return COM result indicator
53 */
54HRESULT DVDDrive::init (Machine *parent)
55{
56 LogFlowMember (("DVDDrive::init (%p)\n", parent));
57
58 ComAssertRet (parent, E_INVALIDARG);
59
60 AutoLock alock (this);
61 ComAssertRet (!isReady(), E_UNEXPECTED);
62
63 mParent = parent;
64 // mPeer is left null
65
66 mData.allocate();
67
68 setReady (true);
69 return S_OK;
70}
71
72/**
73 * Initializes the DVD drive object given another DVD drive object
74 * (a kind of copy constructor). This object shares data with
75 * the object passed as an argument.
76 *
77 * @note This object must be destroyed before the original object
78 * it shares data with is destroyed.
79 */
80HRESULT DVDDrive::init (Machine *parent, DVDDrive *that)
81{
82 LogFlowMember (("DVDDrive::init (%p, %p)\n", parent, that));
83
84 ComAssertRet (parent && that, E_INVALIDARG);
85
86 AutoLock alock (this);
87 ComAssertRet (!isReady(), E_UNEXPECTED);
88
89 mParent = parent;
90 mPeer = that;
91
92 AutoLock thatlock (that);
93 mData.share (that->mData);
94
95 setReady (true);
96 return S_OK;
97}
98
99/**
100 * Initializes the guest object given another guest object
101 * (a kind of copy constructor). This object makes a private copy of data
102 * of the original object passed as an argument.
103 */
104HRESULT DVDDrive::initCopy (Machine *parent, DVDDrive *that)
105{
106 LogFlowMember (("DVDDrive::initCopy (%p, %p)\n", parent, that));
107
108 ComAssertRet (parent && that, E_INVALIDARG);
109
110 AutoLock alock (this);
111 ComAssertRet (!isReady(), E_UNEXPECTED);
112
113 mParent = parent;
114 // mPeer is left null
115
116 AutoLock thatlock (that);
117 mData.attachCopy (that->mData);
118
119 setReady (true);
120 return S_OK;
121}
122
123/**
124 * Uninitializes the instance and sets the ready flag to FALSE.
125 * Called either from FinalRelease() or by the parent when it gets destroyed.
126 */
127void DVDDrive::uninit()
128{
129 LogFlowMember (("DVDDrive::uninit()\n"));
130
131 AutoLock alock (this);
132
133 AssertReturn (isReady(), (void) 0);
134
135 mData.free();
136
137 mPeer.setNull();
138 mParent.setNull();
139
140 setReady (false);
141}
142
143// IDVDDrive properties
144////////////////////////////////////////////////////////////////////////////////
145
146STDMETHODIMP DVDDrive::COMGETTER(State) (DriveState_T *driveState)
147{
148 if (!driveState)
149 return E_POINTER;
150
151 AutoLock alock (this);
152 CHECK_READY();
153
154 *driveState = mData->mDriveState;
155 return S_OK;
156}
157
158STDMETHODIMP DVDDrive::COMGETTER(Passthrough) (BOOL *passthrough)
159{
160 if (!passthrough)
161 return E_POINTER;
162
163 AutoLock alock(this);
164 CHECK_READY();
165
166 *passthrough = mData->mPassthrough;
167 return S_OK;
168}
169
170STDMETHODIMP DVDDrive::COMSETTER(Passthrough) (BOOL passthrough)
171{
172 AutoLock alock(this);
173 CHECK_READY();
174 CHECK_MACHINE_MUTABILITY (mParent);
175
176 if (mData->mPassthrough != passthrough)
177 {
178 mData.backup();
179 mData->mPassthrough = passthrough;
180 }
181 return S_OK;
182}
183
184// IDVDDrive methods
185////////////////////////////////////////////////////////////////////////////////
186
187STDMETHODIMP DVDDrive::MountImage(INPTR GUIDPARAM imageId)
188{
189 if (Guid::isEmpty(imageId))
190 return E_INVALIDARG;
191
192 AutoLock alock (this);
193 CHECK_READY();
194
195 CHECK_MACHINE_MUTABILITY (mParent);
196
197 HRESULT rc = E_FAIL;
198
199 // find the image in the collection
200 ComPtr <IVirtualBox> vbox;
201 rc = mParent->COMGETTER(Parent) (vbox.asOutParam());
202 AssertComRCReturn (rc, rc);
203
204 ComPtr <IDVDImage> image;
205 rc = vbox->GetDVDImage (imageId, image.asOutParam());
206 if (SUCCEEDED (rc))
207 {
208 if (mData->mDriveState != DriveState_ImageMounted ||
209 !mData->mDVDImage.equalsTo (image))
210 {
211 mData.backup();
212 unmount();
213 mData->mDVDImage = image;
214 mData->mDriveState = DriveState_ImageMounted;
215
216 alock.unlock();
217 mParent->onDVDDriveChange();
218 }
219 }
220
221 return rc;
222}
223
224STDMETHODIMP DVDDrive::CaptureHostDrive(IHostDVDDrive *hostDVDDrive)
225{
226 if (!hostDVDDrive)
227 return E_INVALIDARG;
228
229 AutoLock alock (this);
230 CHECK_READY();
231
232 CHECK_MACHINE_MUTABILITY (mParent);
233
234 if (mData->mDriveState != DriveState_HostDriveCaptured ||
235 !mData->mHostDrive.equalsTo (hostDVDDrive))
236 {
237 mData.backup();
238 unmount();
239 mData->mHostDrive = hostDVDDrive;
240 mData->mDriveState = DriveState_HostDriveCaptured;
241
242 alock.unlock();
243 mParent->onDVDDriveChange();
244 }
245
246 return S_OK;
247}
248
249STDMETHODIMP DVDDrive::Unmount()
250{
251 AutoLock alock (this);
252 CHECK_READY();
253
254 CHECK_MACHINE_MUTABILITY (mParent);
255
256 if (mData->mDriveState != DriveState_NotMounted)
257 {
258 mData.backup();
259 unmount();
260 mData->mDriveState = DriveState_NotMounted;
261
262 alock.unlock();
263 mParent->onDVDDriveChange();
264 }
265
266 return S_OK;
267}
268
269STDMETHODIMP DVDDrive::GetImage(IDVDImage **dvdImage)
270{
271 if (!dvdImage)
272 return E_POINTER;
273
274 AutoLock alock (this);
275 CHECK_READY();
276
277 mData->mDVDImage.queryInterfaceTo (dvdImage);
278 return S_OK;
279}
280
281STDMETHODIMP DVDDrive::GetHostDrive(IHostDVDDrive **hostDrive)
282{
283 if (!hostDrive)
284 return E_POINTER;
285
286 AutoLock alock (this);
287 CHECK_READY();
288
289 mData->mHostDrive.queryInterfaceTo (hostDrive);
290 return S_OK;
291}
292
293// public methods only for internal purposes
294////////////////////////////////////////////////////////////////////////////////
295
296bool DVDDrive::rollback()
297{
298 AutoLock alock (this);
299
300 bool changed = false;
301
302 if (mData.isBackedUp())
303 {
304 // we need to check all data to see whether anything will be changed
305 // after rollback
306 changed = mData.hasActualChanges();
307 mData.rollback();
308 }
309
310 return changed;
311}
312
313void DVDDrive::commit()
314{
315 AutoLock alock (this);
316 if (mData.isBackedUp())
317 {
318 mData.commit();
319 if (mPeer)
320 {
321 // attach new data to the peer and reshare it
322 AutoLock peerlock (mPeer);
323 mPeer->mData.attach (mData);
324 }
325 }
326}
327
328void DVDDrive::copyFrom (DVDDrive *aThat)
329{
330 AutoLock alock (this);
331
332 // this will back up current data
333 mData.assignCopy (aThat->mData);
334}
335
336// private methods
337////////////////////////////////////////////////////////////////////////////////
338
339/**
340 * Helper to unmount a drive
341 *
342 * @returns COM status code
343 *
344 */
345HRESULT DVDDrive::unmount()
346{
347 if (mData->mDVDImage)
348 mData->mDVDImage.setNull();
349 if (mData->mHostDrive)
350 mData->mHostDrive.setNull();
351 return S_OK;
352}
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