MediumAttachmentImpl.cpp revision d9dbe2e6150d8025f5ff837b11a95ca18b511fb8
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * VirtualBox COM class implementation
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * available from http://www.virtualbox.org. This file is free software;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * you can redistribute it and/or modify it under the terms of the GNU
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * General Public License (GPL) as published by the Free Software
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * additional information or have any questions.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync////////////////////////////////////////////////////////////////////////////////
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync// private member data definition
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync////////////////////////////////////////////////////////////////////////////////
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync bool operator==(const BackupableMediumAttachmentData &that) const
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync return this == &that
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync /* Since MediumAttachment is not a first class citizen when it
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * comes to managing settings, having a reference to the storage
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * controller will not work - when settings are changed it will point
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * to the old, uninitialized instance. Changing this requires
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync * substantial changes to MediumImpl.cpp. */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /** Reference to Machine object, for checking mutable state. */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* later: const ComObjPtr<MediumAttachment> mPeer; */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync// constructor / destructor
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync/////////////////////////////////////////////////////////////////////////////
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync// public initializer/uninitializer for internal purposes only
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync/////////////////////////////////////////////////////////////////////////////
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * Initializes the medium attachment object.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param aParent Machine object.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param aMedium Medium object.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param aController Controller the hard disk is attached to.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param aPort Port number.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param aDevice Device number on the port.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * @param aPassthrough Wether accesses are directly passed to the host drive.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync LogFlowThisFunc(("aParent=%p aMedium=%p aControllerName=%ls aPort=%d aDevice=%d aType=%d aPassthrough=%d\n", aParent, aMedium, aControllerName.raw(), aPort, aDevice, aType, aPassthrough));
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* Enclose the state transition NotReady->InInit->Ready */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync unconst(m->bd->bstrControllerName) = aControllerName;
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* Newly created attachments never have an implicitly created medium
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * associated with them. Implicit diff image creation happens later. */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* Confirm a successful initialization when it's the case */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* Construct a short log name for this attachment. */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync const char *psz = strpbrk(ctlName.c_str(), " \t:-");
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync aPort, aDevice, Global::stringifyDeviceType(aType),
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * Uninitializes the instance.
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync * Called from FinalRelease().
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* Enclose the state transition Ready->InUninit->NotReady */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync// IHardDiskAttachment properties
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync/////////////////////////////////////////////////////////////////////////////
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncSTDMETHODIMP MediumAttachment::COMGETTER(Medium)(IMedium **aHardDisk)
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsyncSTDMETHODIMP MediumAttachment::COMGETTER(Controller)(BSTR *aController)
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* m->controller is constant during life time, no need to lock */
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsyncSTDMETHODIMP MediumAttachment::COMGETTER(Port)(LONG *aPort)
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsync /* m->bd->port is constant during life time, no need to lock */
62184c10d4a848c16595c203aad10dcf3cb8cdaavboxsyncSTDMETHODIMP MediumAttachment::COMGETTER(Device)(LONG *aDevice)
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync /* m->bd->device is constant during life time, no need to lock */
71955773a7f477f9a159a491f765ba97e1f00e1avboxsyncSTDMETHODIMP MediumAttachment::COMGETTER(Type)(DeviceType_T *aType)
bf11cc8a816102c7f343cb5cc113e7a08fa129a0vboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsync /* m->bd->type is constant during life time, no need to lock */
2ebdf3d2131d683bde27a65eeef2450d8834fec9vboxsyncSTDMETHODIMP MediumAttachment::COMGETTER(Passthrough)(BOOL *aPassthrough)
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync if (FAILED(autoCaller.rc())) return autoCaller.rc();
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * @note Locks this object for writing.
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync /* sanity */
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync bool changed = false;
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync /* we need to check all data to see whether anything will be changed
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync * after rollback */
71955773a7f477f9a159a491f765ba97e1f00e1avboxsync LogFlowThisFunc(("LEAVE - %s - returning %RTbool\n", getLogName(), changed));