VirtualBox

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

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

#3285: Improve error handling API to include unique error numbers

The mega commit that implements Main-wide usage of new CheckCom*
macros, mostly CheckComArgNotNull, CheckComArgStrNotEmptyOrNull,
CheckComArgOutSafeArrayPointerValid, CheckComArgExpr.
Note that some methods incorrectly returned E_INVALIDARG where they
should have returned E_POINTER and vice versa. If any higher level
function tests these, they will behave differently now...

Special thanks to: vi macros, making it easy to semi-automatically
find and replace several hundred instances of if (!aName) ...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
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
29HRESULT HardDisk2Attachment::FinalConstruct()
30{
31 return S_OK;
32}
33
34void HardDisk2Attachment::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 */
51HRESULT HardDisk2Attachment::init (HardDisk2 *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 */
77void HardDisk2Attachment::uninit()
78{
79 /* Enclose the state transition Ready->InUninit->NotReady */
80 AutoUninitSpan autoUninitSpan (this);
81 if (autoUninitSpan.uninitDone())
82 return;
83}
84
85// IHardDisk2Attachment properties
86/////////////////////////////////////////////////////////////////////////////
87
88STDMETHODIMP HardDisk2Attachment::COMGETTER(HardDisk) (IHardDisk2 **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
102STDMETHODIMP HardDisk2Attachment::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
115STDMETHODIMP HardDisk2Attachment::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
128STDMETHODIMP HardDisk2Attachment::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: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette