VirtualBox

source: vbox/trunk/src/VBox/Main/HardDiskAttachmentImpl.cpp@ 8083

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

Main: Renamed AutoLock => AutoWriteLock; AutoReaderLock => AutoReadLock.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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 (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.
16 */
17
18#include "HardDiskAttachmentImpl.h"
19#include "HardDiskImpl.h"
20
21#include "Logging.h"
22
23// constructor / destructor
24/////////////////////////////////////////////////////////////////////////////
25
26DEFINE_EMPTY_CTOR_DTOR (HardDiskAttachment)
27
28HRESULT HardDiskAttachment::FinalConstruct()
29{
30 mBus = StorageBus_Null;
31 mChannel = 0;
32 mDevice = 0;
33
34 return S_OK;
35}
36
37void HardDiskAttachment::FinalRelease()
38{
39}
40
41// public initializer/uninitializer for internal purposes only
42/////////////////////////////////////////////////////////////////////////////
43
44/**
45 * Initializes the hard disk attachment object.
46 * The initialized object becomes immediately dirty
47 *
48 * @param aHD hard disk object
49 * @param aBus bus type
50 * @param aChannel channel number
51 * @param aDevice device number on the channel
52 * @param aDirty whether the attachment is initially dirty or not
53 */
54HRESULT HardDiskAttachment::init (HardDisk *aHD, StorageBus_T aBus, LONG aChannel, LONG aDevice,
55 BOOL aDirty)
56{
57 ComAssertRet (aHD, E_INVALIDARG);
58
59 if (aBus == StorageBus_IDE)
60 {
61 if (aChannel < 0 || aChannel > 1)
62 return setError (E_FAIL,
63 tr ("Invalid IDE channel for hard disk '%ls': %d. "
64 "IDE channel number must be in range [0,1]"),
65 aHD->toString().raw(), aChannel);
66 if (aDevice < 0 || aDevice > 1 || (aChannel == 1 && aDevice == 0))
67 return setError (E_FAIL,
68 tr ("Invalid IDE device slot for hard disk '%ls': %d. "
69 "IDE device slot number must be in range [0,1] for "
70 "channel 0 and always 1 for channel 1"),
71 aHD->toString().raw(), aDevice);
72 }
73
74 AutoWriteLock alock (this);
75
76 mDirty = aDirty;
77
78 mHardDisk = aHD;
79 mBus = aBus;
80 mChannel = aChannel;
81 mDevice = aDevice;
82
83 setReady (true);
84 return S_OK;
85}
86
87// IHardDiskAttachment properties
88/////////////////////////////////////////////////////////////////////////////
89
90STDMETHODIMP HardDiskAttachment::COMGETTER(HardDisk) (IHardDisk **aHardDisk)
91{
92 if (!aHardDisk)
93 return E_POINTER;
94
95 AutoWriteLock alock (this);
96 CHECK_READY();
97
98 ComAssertRet (!!mHardDisk, E_FAIL);
99
100 mHardDisk.queryInterfaceTo (aHardDisk);
101 return S_OK;
102}
103
104STDMETHODIMP HardDiskAttachment::COMGETTER(Bus) (StorageBus_T *aBus)
105{
106 if (!aBus)
107 return E_POINTER;
108
109 AutoWriteLock alock (this);
110 CHECK_READY();
111
112 *aBus = mBus;
113 return S_OK;
114}
115
116STDMETHODIMP HardDiskAttachment::COMGETTER(Channel) (LONG *aChannel)
117{
118 if (!aChannel)
119 return E_INVALIDARG;
120
121 AutoWriteLock alock (this);
122 CHECK_READY();
123
124 *aChannel = mChannel;
125 return S_OK;
126}
127
128STDMETHODIMP HardDiskAttachment::COMGETTER(Device) (LONG *aDevice)
129{
130 if (!aDevice)
131 return E_INVALIDARG;
132
133 AutoWriteLock alock (this);
134 CHECK_READY();
135
136 *aDevice = mDevice;
137 return S_OK;
138}
139
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use