1 | /** @file
|
---|
2 | *
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * 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.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "HardDiskAttachmentImpl.h"
|
---|
23 |
|
---|
24 | #include "Logging.h"
|
---|
25 |
|
---|
26 | // constructor / destructor
|
---|
27 | /////////////////////////////////////////////////////////////////////////////
|
---|
28 |
|
---|
29 | HRESULT HardDiskAttachment::FinalConstruct()
|
---|
30 | {
|
---|
31 | return S_OK;
|
---|
32 | }
|
---|
33 |
|
---|
34 | void HardDiskAttachment::FinalRelease()
|
---|
35 | {
|
---|
36 | uninit();
|
---|
37 | }
|
---|
38 |
|
---|
39 | // public initializer/uninitializer for internal purposes only
|
---|
40 | /////////////////////////////////////////////////////////////////////////////
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Initializes the hard disk attachment object.
|
---|
44 | *
|
---|
45 | * @param aHD Hard disk object.
|
---|
46 | * @param aBus Bus type.
|
---|
47 | * @param aChannel Channel number.
|
---|
48 | * @param aDevice Device number on the channel.
|
---|
49 | * @param aImplicit Wether the attachment contains an implicitly created diff.
|
---|
50 | */
|
---|
51 | HRESULT HardDiskAttachment::init(HardDisk *aHD, StorageBus_T aBus, LONG aChannel,
|
---|
52 | LONG aDevice, bool aImplicit /*= false*/)
|
---|
53 | {
|
---|
54 | AssertReturn (aHD, E_INVALIDARG);
|
---|
55 |
|
---|
56 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
57 | AutoInitSpan autoInitSpan (this);
|
---|
58 | AssertReturn (autoInitSpan.isOk(), E_FAIL);
|
---|
59 |
|
---|
60 | m.hardDisk = aHD;
|
---|
61 | unconst (m.bus) = aBus;
|
---|
62 | unconst (m.channel) = aChannel;
|
---|
63 | unconst (m.device) = aDevice;
|
---|
64 |
|
---|
65 | m.implicit = aImplicit;
|
---|
66 |
|
---|
67 | /* Confirm a successful initialization when it's the case */
|
---|
68 | autoInitSpan.setSucceeded();
|
---|
69 |
|
---|
70 | return S_OK;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Uninitializes the instance.
|
---|
75 | * Called from FinalRelease().
|
---|
76 | */
|
---|
77 | void HardDiskAttachment::uninit()
|
---|
78 | {
|
---|
79 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
80 | AutoUninitSpan autoUninitSpan (this);
|
---|
81 | if (autoUninitSpan.uninitDone())
|
---|
82 | return;
|
---|
83 | }
|
---|
84 |
|
---|
85 | // IHardDiskAttachment properties
|
---|
86 | /////////////////////////////////////////////////////////////////////////////
|
---|
87 |
|
---|
88 | STDMETHODIMP HardDiskAttachment::COMGETTER(HardDisk) (IHardDisk **aHardDisk)
|
---|
89 | {
|
---|
90 | CheckComArgOutPointerValid(aHardDisk);
|
---|
91 |
|
---|
92 | AutoCaller autoCaller (this);
|
---|
93 | CheckComRCReturnRC (autoCaller.rc());
|
---|
94 |
|
---|
95 | AutoReadLock alock (this);
|
---|
96 |
|
---|
97 | m.hardDisk.queryInterfaceTo (aHardDisk);
|
---|
98 |
|
---|
99 | return S_OK;
|
---|
100 | }
|
---|
101 |
|
---|
102 | STDMETHODIMP HardDiskAttachment::COMGETTER(Bus) (StorageBus_T *aBus)
|
---|
103 | {
|
---|
104 | CheckComArgOutPointerValid(aBus);
|
---|
105 |
|
---|
106 | AutoCaller autoCaller (this);
|
---|
107 | CheckComRCReturnRC (autoCaller.rc());
|
---|
108 |
|
---|
109 | /* m.bus is constant during life time, no need to lock */
|
---|
110 | *aBus = m.bus;
|
---|
111 |
|
---|
112 | return S_OK;
|
---|
113 | }
|
---|
114 |
|
---|
115 | STDMETHODIMP HardDiskAttachment::COMGETTER(Channel) (LONG *aChannel)
|
---|
116 | {
|
---|
117 | CheckComArgOutPointerValid(aChannel);
|
---|
118 |
|
---|
119 | AutoCaller autoCaller (this);
|
---|
120 | CheckComRCReturnRC (autoCaller.rc());
|
---|
121 |
|
---|
122 | /* m.channel is constant during life time, no need to lock */
|
---|
123 | *aChannel = m.channel;
|
---|
124 |
|
---|
125 | return S_OK;
|
---|
126 | }
|
---|
127 |
|
---|
128 | STDMETHODIMP HardDiskAttachment::COMGETTER(Device) (LONG *aDevice)
|
---|
129 | {
|
---|
130 | CheckComArgOutPointerValid(aDevice);
|
---|
131 |
|
---|
132 | AutoCaller autoCaller (this);
|
---|
133 | CheckComRCReturnRC (autoCaller.rc());
|
---|
134 |
|
---|
135 | /* m.device is constant during life time, no need to lock */
|
---|
136 | *aDevice = m.device;
|
---|
137 |
|
---|
138 | return S_OK;
|
---|
139 | }
|
---|
140 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|