VirtualBox

source: vbox/trunk/src/VBox/Main/DVDImageImpl.cpp@ 13538

Last change on this file since 13538 was 8155, checked in by vboxsync, 16 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
RevLine 
[1]1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
[8155]7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
[1]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
[5999]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.
[8155]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.
[1]20 */
21
22#include "DVDImageImpl.h"
23#include "VirtualBoxImpl.h"
24#include "Logging.h"
25
26#include <iprt/file.h>
27#include <iprt/path.h>
[3007]28#include <iprt/cpputils.h>
[3330]29
[1]30#include <VBox/err.h>
31#include <VBox/param.h>
32
33// constructor / destructor
34/////////////////////////////////////////////////////////////////////////////
35
[2567]36DEFINE_EMPTY_CTOR_DTOR (DVDImage)
37
[1]38HRESULT DVDImage::FinalConstruct()
39{
40 mAccessible = FALSE;
41 return S_OK;
42}
43
44void DVDImage::FinalRelease()
45{
46 uninit();
47}
48
49// public initializer/uninitializer for internal purposes only
50/////////////////////////////////////////////////////////////////////////////
51
52/**
53 * Initializes the DVD image object.
54 *
[2567]55 * @param aParent
[1]56 * parent object
[2567]57 * @param aFilePath
[1]58 * local file system path to the image file
59 * (can be relative to the VirtualBox config dir)
[2567]60 * @param aRegistered
[1]61 * whether this object is being initialized by the VirtualBox init code
62 * because it is present in the registry
[2567]63 * @param aId
[1]64 * ID of the DVD image to assign
65 *
66 * @return COM result indicator
67 */
[2567]68HRESULT DVDImage::init (VirtualBox *aParent, const BSTR aFilePath,
69 BOOL aRegistered, const Guid &aId)
[1]70{
[2567]71 LogFlowThisFunc (("aFilePath={%ls}, aId={%s}\n",
72 aFilePath, aId.toString().raw()));
[1]73
[2567]74 ComAssertRet (aParent && aFilePath && !!aId, E_INVALIDARG);
[1]75
[2567]76 /* Enclose the state transition NotReady->InInit->Ready */
77 AutoInitSpan autoInitSpan (this);
78 AssertReturn (autoInitSpan.isOk(), E_UNEXPECTED);
[1]79
80 HRESULT rc = S_OK;
81
[2567]82 /* share the parent weakly */
83 unconst (mParent) = aParent;
[1]84
[2567]85 /* register with parent early, since uninit() will unconditionally
86 * unregister on failure */
87 mParent->addDependentChild (this);
[1]88
[2567]89 unconst (mImageFile) = aFilePath;
90 unconst (mUuid) = aId;
91
[1]92 /* get the full file name */
93 char filePathFull [RTPATH_MAX];
[2567]94 int vrc = RTPathAbsEx (mParent->homeDir(), Utf8Str (aFilePath),
[1]95 filePathFull, sizeof (filePathFull));
96 if (VBOX_FAILURE (vrc))
[2567]97 return setError (E_FAIL,
98 tr ("Invalid image file path: '%ls' (%Vrc)"),
99 aFilePath, vrc);
[1]100
101 unconst (mImageFileFull) = filePathFull;
[2567]102 LogFlowThisFunc (("...filePathFull={%ls}\n", mImageFileFull.raw()));
[1]103
[2567]104 if (!aRegistered)
[1]105 {
106 /* check whether the given file exists or not */
107 RTFILE file;
108 vrc = RTFileOpen (&file, filePathFull,
109 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
110 if (VBOX_FAILURE (vrc))
111 {
112 /* here we come when the image was just opened by
113 * IVirtualBox::OpenDVDImage(). fail in this case */
114 rc = setError (E_FAIL,
115 tr ("Could not open the CD/DVD image '%ls' (%Vrc)"),
116 mImageFileFull.raw(), vrc);
117 }
118 else
119 RTFileClose (file);
120 }
121
[2567]122 /* Confirm a successful initialization when it's the case */
[1]123 if (SUCCEEDED (rc))
[2567]124 autoInitSpan.setSucceeded();
[1]125
126 return rc;
127}
128
129/**
130 * Uninitializes the instance and sets the ready flag to FALSE.
131 * Called either from FinalRelease() or by the parent when it gets destroyed.
132 */
133void DVDImage::uninit()
134{
[2567]135 LogFlowThisFunc (("\n"));
[1]136
[2567]137 /* Enclose the state transition Ready->InUninit->NotReady */
138 AutoUninitSpan autoUninitSpan (this);
139 if (autoUninitSpan.uninitDone())
[1]140 return;
141
[2567]142 LogFlowThisFunc (("initFailed()=%RTbool\n", autoUninitSpan.initFailed()));
[1]143
144 mParent->removeDependentChild (this);
145
[2567]146 unconst (mParent).setNull();
[1]147}
148
149// IDVDImage properties
150/////////////////////////////////////////////////////////////////////////////
151
[2567]152STDMETHODIMP DVDImage::COMGETTER(Id) (GUIDPARAMOUT aId)
[1]153{
[2567]154 if (!aId)
[1]155 return E_POINTER;
156
[2567]157 AutoCaller autoCaller (this);
158 CheckComRCReturnRC (autoCaller.rc());
[1]159
[2567]160 /* mUuid is constant during life time, no need to lock */
161 mUuid.cloneTo (aId);
162
[1]163 return S_OK;
164}
165
[2567]166STDMETHODIMP DVDImage::COMGETTER(FilePath) (BSTR *aFilePath)
[1]167{
[2567]168 if (!aFilePath)
[1]169 return E_POINTER;
170
[2567]171 AutoCaller autoCaller (this);
172 CheckComRCReturnRC (autoCaller.rc());
[1]173
[8083]174 AutoReadLock alock (this);
[2567]175
176 mImageFileFull.cloneTo (aFilePath);
177
[1]178 return S_OK;
179}
180
[2567]181STDMETHODIMP DVDImage::COMGETTER(Accessible) (BOOL *aAccessible)
[1]182{
[2567]183 if (!aAccessible)
[1]184 return E_POINTER;
185
[2567]186 AutoCaller autoCaller (this);
187 CheckComRCReturnRC (autoCaller.rc());
188
[8083]189 AutoWriteLock alock (this);
[1]190
191 HRESULT rc = S_OK;
192
193 /* check whether the given image file exists or not */
194 RTFILE file;
195 int vrc = RTFileOpen (&file, Utf8Str (mImageFileFull),
196 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
197 if (VBOX_FAILURE (vrc))
198 {
199 Log (("DVDImage::COMGETTER(Accessible): WARNING: '%ls' "
200 "is not accessible (%Vrc)\n", mImageFileFull.raw(), vrc));
201 mAccessible = FALSE;
202 }
203 else
204 {
205 mAccessible = TRUE;
206 RTFileClose (file);
207 }
208
[2567]209 *aAccessible = mAccessible;
[1]210
211 return rc;
212}
213
[2567]214STDMETHODIMP DVDImage::COMGETTER(Size) (ULONG64 *aSize)
[1]215{
[2567]216 if (!aSize)
[1]217 return E_POINTER;
218
219 HRESULT rc = S_OK;
220
[2567]221 AutoCaller autoCaller (this);
222 CheckComRCReturnRC (autoCaller.rc());
[1]223
[8083]224 AutoReadLock alock (this);
[2567]225
[1]226 RTFILE file;
227 int vrc = RTFileOpen (&file, Utf8Str (mImageFileFull),
228 RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
229
230 if (VBOX_FAILURE (vrc))
231 rc = setError (E_FAIL, tr("Failed to open ISO image '%ls' (%Vrc)\n"),
232 mImageFileFull.raw(), vrc);
233 else
234 {
[2110]235 AssertCompile (sizeof (uint64_t) == sizeof (ULONG64));
236
[1]237 uint64_t u64Size = 0;
238
239 vrc = RTFileGetSize (file, &u64Size);
240
241 if (VBOX_SUCCESS (vrc))
[2567]242 *aSize = u64Size;
[1]243 else
244 rc = setError (E_FAIL,
245 tr ("Failed to determine size of ISO image '%ls' (%Vrc)\n"),
246 mImageFileFull.raw(), vrc);
247
248 RTFileClose (file);
249 }
250
251 return rc;
252}
253
254// public methods for internal purposes only
255////////////////////////////////////////////////////////////////////////////////
256
257/**
258 * Changes the stored path values of this image to reflect the new location.
259 * Intended to be called only by VirtualBox::updateSettings() if a machine's
260 * name change causes directory renaming that affects this image.
261 *
262 * @param aNewFullPath new full path to this image file
263 * @param aNewPath new path to this image file relative to the VirtualBox
264 * settings directory (when possible)
265 *
266 * @note Locks this object for writing.
267 */
268void DVDImage::updatePath (const char *aNewFullPath, const char *aNewPath)
269{
270 AssertReturnVoid (aNewFullPath);
271 AssertReturnVoid (aNewPath);
272
[2567]273 AutoCaller autoCaller (this);
274 AssertComRCReturnVoid (autoCaller.rc());
275
[8083]276 AutoWriteLock alock (this);
[1]277
278 unconst (mImageFileFull) = aNewFullPath;
279 unconst (mImageFile) = aNewPath;
280}
281
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use