VirtualBox

source: vbox/trunk/src/VBox/Main/include/HardDisk2Impl.h@ 14446

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

Main: HardDisk2: Fixed opening VMDK images for the first time. Made the implicit diff creatoin routine use the default backend extension. Improved setLocation() to distinguish between file and non-file locations according to the backend capability.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 9.3 KB
Line 
1/* $Id $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_HARDDISK2IMPL
25#define ____H_HARDDISK2IMPL
26
27#include "VirtualBoxBase.h"
28
29#include "VirtualBoxImpl.h"
30#include "HardDiskFormatImpl.h"
31#include "MediumImpl.h"
32
33#include <VBox/com/SupportErrorInfo.h>
34
35#include <VBox/VBoxHDD-new.h>
36
37class Progress;
38
39////////////////////////////////////////////////////////////////////////////////
40
41/**
42 * The HardDisk2 component class implements the IHardDisk2 interface.
43 */
44class ATL_NO_VTABLE HardDisk2
45 : public com::SupportErrorInfoDerived <MediumBase, HardDisk2, IHardDisk2>
46 , public VirtualBoxBaseWithTypedChildrenNEXT <HardDisk2>
47 , public VirtualBoxSupportTranslation <HardDisk2>
48 , public IHardDisk2
49{
50public:
51
52 typedef VirtualBoxBaseWithTypedChildrenNEXT <HardDisk2>::DependentChildren
53 List;
54
55 class MergeChain;
56
57 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (HardDisk2)
58
59 DECLARE_NOT_AGGREGATABLE (HardDisk2)
60
61 DECLARE_PROTECT_FINAL_CONSTRUCT()
62
63 BEGIN_COM_MAP (HardDisk2)
64 COM_INTERFACE_ENTRY (ISupportErrorInfo)
65 COM_INTERFACE_ENTRY2 (IMedium, MediumBase)
66 COM_INTERFACE_ENTRY (IHardDisk2)
67 END_COM_MAP()
68
69 NS_DECL_ISUPPORTS
70
71 DECLARE_EMPTY_CTOR_DTOR (HardDisk2)
72
73 HRESULT FinalConstruct();
74 void FinalRelease();
75
76 // public initializer/uninitializer for internal purposes only
77 HRESULT init (VirtualBox *aVirtualBox, const BSTR aFormat,
78 const BSTR aLocation);
79 HRESULT init (VirtualBox *aVirtualBox,
80 const BSTR aLocation);
81 HRESULT init (VirtualBox *aVirtualBox, HardDisk2 *aParent,
82 const settings::Key &aNode);
83 void uninit();
84
85 // IMedium properties & methods
86 COM_FORWARD_IMedium_TO_BASE (MediumBase)
87
88 // IHardDisk2 properties
89 STDMETHOD(COMGETTER(Format)) (BSTR *aFormat);
90 STDMETHOD(COMGETTER(Type)) (HardDiskType_T *aType);
91 STDMETHOD(COMSETTER(Type)) (HardDiskType_T aType);
92 STDMETHOD(COMGETTER(Parent)) (IHardDisk2 **aParent);
93 STDMETHOD(COMGETTER(Children)) (ComSafeArrayOut (IHardDisk2 *, aChildren));
94 STDMETHOD(COMGETTER(Root)) (IHardDisk2 **aRoot);
95 STDMETHOD(COMGETTER(ReadOnly)) (BOOL *aReadOnly);
96 STDMETHOD(COMGETTER(LogicalSize)) (ULONG64 *aLogicalSize);
97
98 // IHardDisk2 methods
99 STDMETHOD(CreateDynamicStorage) (ULONG64 aLogicalSize, IProgress **aProgress);
100 STDMETHOD(CreateFixedStorage) (ULONG64 aLogicalSize, IProgress **aProgress);
101 STDMETHOD(DeleteStorage) (IProgress **aProgress);
102 STDMETHOD(CreateDiffStorage) (IHardDisk2 *aTarget, IProgress **aProgress);
103 STDMETHOD(MergeTo) (INPTR GUIDPARAM aTargetId, IProgress **aProgress);
104 STDMETHOD(CloneTo) (IHardDisk2 *aTarget, IProgress **aProgress);
105 STDMETHOD(FlattenTo) (IHardDisk2 *aTarget, IProgress **aProgress);
106
107 // public methods for internal purposes only
108
109 /**
110 * Shortcut to VirtualBoxBaseWithTypedChildrenNEXT::dependentChildren().
111 */
112 const List &children() const { return dependentChildren(); }
113
114 void updatePaths (const char *aOldPath, const char *aNewPath);
115
116 ComObjPtr <HardDisk2> root (uint32_t *aLevel = NULL);
117
118 bool isReadOnly();
119
120 HRESULT saveSettings (settings::Key &aParentNode);
121
122 HRESULT compareLocationTo (const char *aLocation, int &aResult);
123
124 /**
125 * Shortcut to #deleteStorage() that doesn't wait for operation completion
126 * and implies the progress object will be used for waiting.
127 */
128 HRESULT deleteStorageNoWait (ComObjPtr <Progress> &aProgress)
129 { return deleteStorage (&aProgress, false /* aWait */); }
130
131 /**
132 * Shortcut to #deleteStorage() that wait for operation completion by
133 * blocking the current thread.
134 */
135 HRESULT deleteStorageAndWait (ComObjPtr <Progress> *aProgress = NULL)
136 { return deleteStorage (aProgress, true /* aWait */); }
137
138 /**
139 * Shortcut to #createDiffStorage() that doesn't wait for operation
140 * completion and implies the progress object will be used for waiting.
141 */
142 HRESULT createDiffStorageNoWait (ComObjPtr <HardDisk2> &aTarget,
143 ComObjPtr <Progress> &aProgress)
144 { return createDiffStorage (aTarget, &aProgress, false /* aWait */); }
145
146 /**
147 * Shortcut to #createDiffStorage() that wait for operation completion by
148 * blocking the current thread.
149 */
150 HRESULT createDiffStorageAndWait (ComObjPtr <HardDisk2> &aTarget,
151 ComObjPtr <Progress> *aProgress = NULL)
152 { return createDiffStorage (aTarget, aProgress, true /* aWait */); }
153
154 HRESULT prepareMergeTo (HardDisk2 *aTarget, MergeChain * &aChain,
155 bool aIgnoreAttachments = false);
156
157 /**
158 * Shortcut to #mergeTo() that doesn't wait for operation completion and
159 * implies the progress object will be used for waiting.
160 */
161 HRESULT mergeToNoWait (MergeChain *aChain,
162 ComObjPtr <Progress> &aProgress)
163 { return mergeTo (aChain, &aProgress, false /* aWait */); }
164
165 /**
166 * Shortcut to #mergeTo() that wait for operation completion by
167 * blocking the current thread.
168 */
169 HRESULT mergeToAndWait (MergeChain *aChain,
170 ComObjPtr <Progress> *aProgress = NULL)
171 { return mergeTo (aChain, aProgress, true /* aWait */); }
172
173 void cancelMergeTo (MergeChain *aChain);
174
175 Utf8Str name();
176
177 HRESULT prepareDiscard (MergeChain * &aChain);
178 HRESULT discard (ComObjPtr <Progress> &aProgress, MergeChain *aChain);
179 void cancelDiscard (MergeChain *aChain);
180
181 /** Returns a preferred format for a differencing hard disk. */
182 Bstr preferredDiffFormat();
183
184 // unsafe inline public methods for internal purposes only (ensure there is
185 // a caller and a read lock before calling them!)
186
187 ComObjPtr <HardDisk2> parent() const { return static_cast <HardDisk2 *> (mParent); }
188 HardDiskType_T type() const { return mm.type; }
189
190 /** For com::SupportErrorInfoImpl. */
191 static const char *ComponentName() { return "HardDisk2"; }
192
193protected:
194
195 HRESULT deleteStorage (ComObjPtr <Progress> *aProgress, bool aWait);
196
197 HRESULT createDiffStorage (ComObjPtr <HardDisk2> &aTarget,
198 ComObjPtr <Progress> *aProgress,
199 bool aWait);
200
201 HRESULT mergeTo (MergeChain *aChain,
202 ComObjPtr <Progress> *aProgress,
203 bool aWait);
204
205 /**
206 * Returns VirtualBox::hardDiskTreeHandle(), for convenience. Don't forget
207 * to follow these locking rules:
208 *
209 * 1. The write lock on this handle must be either held alone on the thread
210 * or requested *after* the VirtualBox object lock. Mixing with other
211 * locks is prohibited.
212 *
213 * 2. The read lock on this handle may be intermixed with any other lock
214 * with the exception that it must be requested *after* the VirtualBox
215 * object lock.
216 */
217 RWLockHandle *treeLock() { return mVirtualBox->hardDiskTreeHandle(); }
218
219 /** Reimplements VirtualBoxWithTypedChildren::childrenLock() to return
220 * treeLock(). */
221 RWLockHandle *childrenLock() { return treeLock(); }
222
223private:
224
225 HRESULT setLocation (const BSTR aLocation);
226 HRESULT setFormat (const BSTR aFormat);
227
228 HRESULT queryInfo();
229
230 HRESULT canClose();
231 HRESULT canAttach (const Guid &aMachineId,
232 const Guid &aSnapshotId);
233
234 HRESULT unregisterWithVirtualBox();
235
236 Utf8Str vdError (int aVRC);
237
238 static DECLCALLBACK(void) vdErrorCall (void *pvUser, int rc, RT_SRC_POS_DECL,
239 const char *pszFormat, va_list va);
240
241 static DECLCALLBACK(int) vdProgressCall (PVM /* pVM */, unsigned uPercent,
242 void *pvUser);
243
244 static DECLCALLBACK(int) taskThread (RTTHREAD thread, void *pvUser);
245
246 /** weak parent */
247 ComObjPtr <HardDisk2, ComWeakRef> mParent;
248
249 struct Task;
250 friend struct Task;
251
252 struct Data
253 {
254 Data() : type (HardDiskType_Normal), logicalSize (0)
255 , implicit (false), numCreateDiffTasks (0)
256 , vdProgress (NULL) , vdDiskIfaces (NULL) {}
257
258 const Bstr format;
259 ComObjPtr <HardDiskFormat> formatObj;
260
261 HardDiskType_T type;
262 uint64_t logicalSize; /*< In MBytes. */
263
264 bool implicit : 1;
265
266 uint32_t numCreateDiffTasks;
267
268 Utf8Str vdError; /*< Error remembered by the VD error callback. */
269 Progress *vdProgress; /*< Progress for the VD progress callback. */
270
271 VDINTERFACE vdIfError;
272 VDINTERFACEERROR vdIfCallsError;
273
274 VDINTERFACE vdIfProgress;
275 VDINTERFACEPROGRESS vdIfCallsProgress;
276
277 PVDINTERFACE vdDiskIfaces;
278 };
279
280 Data mm;
281};
282
283#endif /* ____H_HARDDISK2IMPL */
284
Note: See TracBrowser for help on using the repository browser.

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