HardDiskAttachmentImpl.cpp revision 26d2a42f095ded346df2e41cc4837cb426b4753a
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync/** @file
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * VirtualBox COM class implementation
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * available from http://www.virtualbox.org. This file is free software;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * you can redistribute it and/or modify it under the terms of the GNU
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * General Public License (GPL) as published by the Free Software
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * additional information or have any questions.
f41e2072ec8320014565f76f4905e47f80b17262vboxsync */
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync#include "HardDiskAttachmentImpl.h"
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync#include "Logging.h"
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync// constructor / destructor
f41e2072ec8320014565f76f4905e47f80b17262vboxsync/////////////////////////////////////////////////////////////////////////////
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsyncHRESULT HardDisk2Attachment::FinalConstruct()
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync{
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync return S_OK;
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync}
820e4bc68518ef74f801cc055cb6d1522b3eddf4vboxsync
820e4bc68518ef74f801cc055cb6d1522b3eddf4vboxsyncvoid HardDisk2Attachment::FinalRelease()
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync{
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync uninit();
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync}
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync// public initializer/uninitializer for internal purposes only
f41e2072ec8320014565f76f4905e47f80b17262vboxsync/////////////////////////////////////////////////////////////////////////////
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync/**
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * Initializes the hard disk attachment object.
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * @param aHD Hard disk object.
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * @param aBus Bus type.
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * @param aChannel Channel number.
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * @param aDevice Device number on the channel.
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * @param aImplicit Wether the attachment contains an implicitly created diff.
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsyncHRESULT HardDisk2Attachment::init (HardDisk2 *aHD, StorageBus_T aBus, LONG aChannel,
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync LONG aDevice, bool aImplicit /*= false*/)
f41e2072ec8320014565f76f4905e47f80b17262vboxsync{
f41e2072ec8320014565f76f4905e47f80b17262vboxsync AssertReturn (aHD, E_INVALIDARG);
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync /* Enclose the state transition NotReady->InInit->Ready */
f41e2072ec8320014565f76f4905e47f80b17262vboxsync AutoInitSpan autoInitSpan (this);
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync AssertReturn (autoInitSpan.isOk(), E_FAIL);
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync m.hardDisk = aHD;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync unconst (m.bus) = aBus;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync unconst (m.channel) = aChannel;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync unconst (m.device) = aDevice;
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync m.implicit = aImplicit;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync /* Confirm a successful initialization when it's the case */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync autoInitSpan.setSucceeded();
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync return S_OK;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync}
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync/**
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync * Uninitializes the instance.
f41e2072ec8320014565f76f4905e47f80b17262vboxsync * Called from FinalRelease().
f41e2072ec8320014565f76f4905e47f80b17262vboxsync */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsyncvoid HardDisk2Attachment::uninit()
f41e2072ec8320014565f76f4905e47f80b17262vboxsync{
f41e2072ec8320014565f76f4905e47f80b17262vboxsync /* Enclose the state transition Ready->InUninit->NotReady */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync AutoUninitSpan autoUninitSpan (this);
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync if (autoUninitSpan.uninitDone())
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync return;
da34f630cce680921b71c5f024533113106d4f04vboxsync}
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync// IHardDisk2Attachment properties
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync/////////////////////////////////////////////////////////////////////////////
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsyncSTDMETHODIMP HardDisk2Attachment::COMGETTER(HardDisk) (IHardDisk2 **aHardDisk)
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync{
f41e2072ec8320014565f76f4905e47f80b17262vboxsync if (!aHardDisk)
f41e2072ec8320014565f76f4905e47f80b17262vboxsync return E_POINTER;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync AutoCaller autoCaller (this);
f41e2072ec8320014565f76f4905e47f80b17262vboxsync CheckComRCReturnRC (autoCaller.rc());
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync AutoReadLock alock (this);
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync m.hardDisk.queryInterfaceTo (aHardDisk);
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync return S_OK;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync}
f41e2072ec8320014565f76f4905e47f80b17262vboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsyncSTDMETHODIMP HardDisk2Attachment::COMGETTER(Bus) (StorageBus_T *aBus)
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync{
f41e2072ec8320014565f76f4905e47f80b17262vboxsync if (!aBus)
f41e2072ec8320014565f76f4905e47f80b17262vboxsync return E_POINTER;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
f41e2072ec8320014565f76f4905e47f80b17262vboxsync AutoCaller autoCaller (this);
f41e2072ec8320014565f76f4905e47f80b17262vboxsync CheckComRCReturnRC (autoCaller.rc());
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync /* m.bus is constant during life time, no need to lock */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *aBus = m.bus;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync return S_OK;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync}
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsyncSTDMETHODIMP HardDisk2Attachment::COMGETTER(Channel) (LONG *aChannel)
670b83d458bceb92123155b5b47a39b9d24e3266vboxsync{
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync if (!aChannel)
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync return E_INVALIDARG;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync AutoCaller autoCaller (this);
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync CheckComRCReturnRC (autoCaller.rc());
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync /* m.channel is constant during life time, no need to lock */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *aChannel = m.channel;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync return S_OK;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync}
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsyncSTDMETHODIMP HardDisk2Attachment::COMGETTER(Device) (LONG *aDevice)
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync{
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync if (!aDevice)
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync return E_INVALIDARG;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync AutoCaller autoCaller (this);
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync CheckComRCReturnRC (autoCaller.rc());
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync /* m.device is constant during life time, no need to lock */
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync *aDevice = m.device;
da34f630cce680921b71c5f024533113106d4f04vboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync return S_OK;
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync}
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync
261a4578c86ef14d89385dde78f0139b41a0cb8evboxsync