MediumImpl.h revision eeab73cfabc939c13e9e2491035489cf2a027570
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * VirtualBox COM class implementation
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
fcae7923a3c756b333f1e33eba002edf4448fb54vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
fcae7923a3c756b333f1e33eba002edf4448fb54vboxsync * available from http://www.virtualbox.org. This file is free software;
fcae7923a3c756b333f1e33eba002edf4448fb54vboxsync * you can redistribute it and/or modify it under the terms of the GNU
fcae7923a3c756b333f1e33eba002edf4448fb54vboxsync * General Public License (GPL) as published by the Free Software
fcae7923a3c756b333f1e33eba002edf4448fb54vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
fcae7923a3c756b333f1e33eba002edf4448fb54vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f001425d2b0a661d4cd1f7ea07b4e7454538c829vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f001425d2b0a661d4cd1f7ea07b4e7454538c829vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f001425d2b0a661d4cd1f7ea07b4e7454538c829vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
f001425d2b0a661d4cd1f7ea07b4e7454538c829vboxsync * additional information or have any questions.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync////////////////////////////////////////////////////////////////////////////////
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Base component class for all media types.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Provides the basic implementation of the IMedium interface.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * @note Subclasses must initialize the mVirtualBox data member in their init()
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * implementations with the valid VirtualBox instance because some
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * MediaBase methods call its methods.
691076bd437d5cd23673a24c5ba7d4cd77127354vboxsync /** Describes how a machine refers to this image. */
691076bd437d5cd23673a24c5ba7d4cd77127354vboxsync /** Equality predicate for stdc++. */
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync struct EqualsTo : public std::unary_function <BackRef, bool>
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync explicit EqualsTo (const Guid &aMachineId) : machineId (aMachineId) {}
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync BackRef (const Guid &aMachineId, const Guid &aSnapshotId = Guid::Empty)
6479169ec893c18a646cec595e4e214492d180f0vboxsync // IMedium properties
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync STDMETHOD(COMSETTER(Description)) (IN_BSTR aDescription);
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync STDMETHOD(COMGETTER(State)) (MediaState_T *aState);
a2907076474e923411cc5046492a88787ba377fevboxsync STDMETHOD(COMSETTER(Location)) (IN_BSTR aLocation);
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync STDMETHOD(COMGETTER(LastAccessError)) (BSTR *aLastAccessError);
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync STDMETHOD(COMGETTER(MachineIds)) (ComSafeArrayOut (BSTR, aMachineIds));
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // IMedium methods
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // public methods for internal purposes only
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync HRESULT updatePath (const char *aOldPath, const char *aNewPath);
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // unsafe inline public methods for internal purposes only (ensure there is
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // a caller and a read lock before calling them!)
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync const Bstr &location() const { return m.location; }
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync const Bstr &locationFull() const { return m.locationFull; }
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync const BackRefList &backRefs() const { return m.backRefs; }
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync std::find_if (m.backRefs.begin(), m.backRefs.end(),
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Performs extra checks if the medium can be closed and returns S_OK in
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * this case. Otherwise, returns a respective error message. Called by
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Close() from within this object's AutoMayUninitSpan and from under
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * mVirtualBox write lock.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Performs extra checks if the medium can be attached to the specified
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * VM and shapshot at the given time and returns S_OK in this case.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Otherwise, returns a respective error message. Called by attachTo() from
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * within this object's AutoWriteLock.
f48c3167a0f99da174686b66dc4e666f38ecae46vboxsync virtual HRESULT canAttach (const Guid & /* aMachineId */,
f48c3167a0f99da174686b66dc4e666f38ecae46vboxsync { return S_OK; }
f48c3167a0f99da174686b66dc4e666f38ecae46vboxsync * Unregisters this medium with mVirtualBox. Called by Close() from within
f48c3167a0f99da174686b66dc4e666f38ecae46vboxsync * this object's AutoMayUninitSpan and from under mVirtualBox write lock.
6479169ec893c18a646cec595e4e214492d180f0vboxsync /** weak VirtualBox parent */
6479169ec893c18a646cec595e4e214492d180f0vboxsync const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
6479169ec893c18a646cec595e4e214492d180f0vboxsync Data() : state (MediaState_NotCreated), size (0), readers (0)
f48c3167a0f99da174686b66dc4e666f38ecae46vboxsync , queryInfoCallers (0), accessibleInLock (false) {}
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync////////////////////////////////////////////////////////////////////////////////
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Base component class for simple image file based media such as CD/DVD ISO
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * images or Floppy images.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * Adds specific protectedInit() and saveSettings() methods that can load image
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * data from the settings files.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // protected initializer/uninitializer for internal purposes only
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync HRESULT protectedInit (VirtualBox *aVirtualBox, CBSTR aLocation,
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync HRESULT protectedInit (VirtualBox *aVirtualBox, const settings::Key &aImageNode);
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // public methods for internal purposes only
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync////////////////////////////////////////////////////////////////////////////////
6479169ec893c18a646cec595e4e214492d180f0vboxsync * The DVDImage component class implements the IDVDImage interface.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync : public com::SupportErrorInfoDerived<ImageMediumBase, DVDImage, IDVDImage>
6479169ec893c18a646cec595e4e214492d180f0vboxsync // public initializer/uninitializer for internal purposes only
6479169ec893c18a646cec595e4e214492d180f0vboxsync HRESULT init (VirtualBox *aParent, CBSTR aFilePath,
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync HRESULT init (VirtualBox *aParent, const settings::Key &aImageNode)
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync /** For com::SupportErrorInfoImpl. */
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync static const char *ComponentName() { return "DVDImage"; }
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync////////////////////////////////////////////////////////////////////////////////
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync * The FloppyImage component class implements the IFloppyImage interface.
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync : public com::SupportErrorInfoDerived<ImageMediumBase, FloppyImage, IFloppyImage>
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (FloppyImage)
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync // public initializer/uninitializer for internal purposes only
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync HRESULT init (VirtualBox *aParent, CBSTR aFilePath,
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync HRESULT init (VirtualBox *aParent, const settings::Key &aImageNode)
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync /** For com::SupportErrorInfoImpl. */
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync static const char *ComponentName() { return "FloppyImage"; }
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync#endif /* ____H_MEDIUMIMPL */
1403063c7e0c0a072d59e323b66068b06278fb9avboxsync/* vi: set tabstop=4 shiftwidth=4 expandtab: */