VirtualBox

source: vbox/trunk/src/VBox/Main/include/HardDiskImpl.h@ 17982

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

API/HardDisk, Storage/VBoxHDD, Frontend/VBoxManage: eliminated base image type, which led to much unnecessary code duplication. Was triggered by VBoxManage finally being able to create all image variants the backends can support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 11.1 KB
Line 
1/* $Id: HardDiskImpl.h 17970 2009-03-16 19:08:16Z vboxsync $ */
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_HARDDISKIMPL
25#define ____H_HARDDISKIMPL
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.h>
36
37#include <map>
38
39class Progress;
40
41////////////////////////////////////////////////////////////////////////////////
42
43/**
44 * The HardDisk component class implements the IHardDisk interface.
45 */
46class ATL_NO_VTABLE HardDisk
47 : public com::SupportErrorInfoDerived<MediumBase, HardDisk, IHardDisk>
48 , public VirtualBoxBaseWithTypedChildrenNEXT<HardDisk>
49 , public VirtualBoxSupportTranslation<HardDisk>
50 , public IHardDisk
51{
52public:
53
54 typedef VirtualBoxBaseWithTypedChildrenNEXT <HardDisk>::DependentChildren
55 List;
56
57 class MergeChain;
58
59 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE (HardDisk)
60
61 DECLARE_NOT_AGGREGATABLE (HardDisk)
62
63 DECLARE_PROTECT_FINAL_CONSTRUCT()
64
65 BEGIN_COM_MAP (HardDisk)
66 COM_INTERFACE_ENTRY (ISupportErrorInfo)
67 COM_INTERFACE_ENTRY2 (IMedium, MediumBase)
68 COM_INTERFACE_ENTRY (IHardDisk)
69 END_COM_MAP()
70
71 NS_DECL_ISUPPORTS
72
73 DECLARE_EMPTY_CTOR_DTOR (HardDisk)
74
75 HRESULT FinalConstruct();
76 void FinalRelease();
77
78 // public initializer/uninitializer for internal purposes only
79 HRESULT init (VirtualBox *aVirtualBox, CBSTR aFormat,
80 CBSTR aLocation);
81 HRESULT init (VirtualBox *aVirtualBox,
82 CBSTR aLocation);
83 HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
84 const settings::Key &aNode);
85 void uninit();
86
87 // IMedium properties & methods
88 COM_FORWARD_IMedium_TO_BASE (MediumBase)
89
90 // IHardDisk properties
91 STDMETHOD(COMGETTER(Format)) (BSTR *aFormat);
92 STDMETHOD(COMGETTER(Type)) (HardDiskType_T *aType);
93 STDMETHOD(COMSETTER(Type)) (HardDiskType_T aType);
94 STDMETHOD(COMGETTER(Parent)) (IHardDisk **aParent);
95 STDMETHOD(COMGETTER(Children)) (ComSafeArrayOut (IHardDisk *, aChildren));
96 STDMETHOD(COMGETTER(Root)) (IHardDisk **aRoot);
97 STDMETHOD(COMGETTER(ReadOnly)) (BOOL *aReadOnly);
98 STDMETHOD(COMGETTER(LogicalSize)) (ULONG64 *aLogicalSize);
99 STDMETHOD(COMGETTER(AutoReset)) (BOOL *aAutoReset);
100 STDMETHOD(COMSETTER(AutoReset)) (BOOL aAutoReset);
101
102 // IHardDisk methods
103 STDMETHOD(GetProperty) (IN_BSTR aName, BSTR *aValue);
104 STDMETHOD(SetProperty) (IN_BSTR aName, IN_BSTR aValue);
105 STDMETHOD(GetProperties) (IN_BSTR aNames,
106 ComSafeArrayOut (BSTR, aReturnNames),
107 ComSafeArrayOut (BSTR, aReturnValues));
108 STDMETHOD(SetProperties) (ComSafeArrayIn (IN_BSTR, aNames),
109 ComSafeArrayIn (IN_BSTR, aValues));
110 STDMETHOD(CreateBaseStorage) (ULONG64 aLogicalSize,
111 HardDiskVariant_T aVariant,
112 IProgress **aProgress);
113 STDMETHOD(DeleteStorage) (IProgress **aProgress);
114 STDMETHOD(CreateDiffStorage) (IHardDisk *aTarget,
115 HardDiskVariant_T aVariant,
116 IProgress **aProgress);
117 STDMETHOD(MergeTo) (IN_GUID aTargetId, IProgress **aProgress);
118 STDMETHOD(CloneTo) (IHardDisk *aTarget, HardDiskVariant_T aVariant,
119 IProgress **aProgress);
120 STDMETHOD(FlattenTo) (IHardDisk *aTarget, HardDiskVariant_T aVariant,
121 IProgress **aProgress);
122 STDMETHOD(Compact) (IProgress **aProgress);
123 STDMETHOD(Reset) (IProgress **aProgress);
124
125 // public methods for internal purposes only
126
127 /**
128 * Shortcut to VirtualBoxBaseWithTypedChildrenNEXT::dependentChildren().
129 */
130 const List &children() const { return dependentChildren(); }
131
132 void updatePaths (const char *aOldPath, const char *aNewPath);
133
134 ComObjPtr<HardDisk> root (uint32_t *aLevel = NULL);
135
136 bool isReadOnly();
137
138 HRESULT saveSettings (settings::Key &aParentNode);
139
140 HRESULT compareLocationTo (const char *aLocation, int &aResult);
141
142 /**
143 * Shortcut to #deleteStorage() that doesn't wait for operation completion
144 * and implies the progress object will be used for waiting.
145 */
146 HRESULT deleteStorageNoWait (ComObjPtr <Progress> &aProgress)
147 { return deleteStorage (&aProgress, false /* aWait */); }
148
149 /**
150 * Shortcut to #deleteStorage() that wait for operation completion by
151 * blocking the current thread.
152 */
153 HRESULT deleteStorageAndWait (ComObjPtr <Progress> *aProgress = NULL)
154 { return deleteStorage (aProgress, true /* aWait */); }
155
156 /**
157 * Shortcut to #createDiffStorage() that doesn't wait for operation
158 * completion and implies the progress object will be used for waiting.
159 */
160 HRESULT createDiffStorageNoWait (ComObjPtr<HardDisk> &aTarget,
161 HardDiskVariant_T aVariant,
162 ComObjPtr <Progress> &aProgress)
163 { return createDiffStorage (aTarget, aVariant, &aProgress, false /* aWait */); }
164
165 /**
166 * Shortcut to #createDiffStorage() that wait for operation completion by
167 * blocking the current thread.
168 */
169 HRESULT createDiffStorageAndWait (ComObjPtr<HardDisk> &aTarget,
170 HardDiskVariant_T aVariant,
171 ComObjPtr <Progress> *aProgress = NULL)
172 { return createDiffStorage (aTarget, aVariant, aProgress, true /* aWait */); }
173
174 HRESULT prepareMergeTo (HardDisk *aTarget, MergeChain * &aChain,
175 bool aIgnoreAttachments = false);
176
177 /**
178 * Shortcut to #mergeTo() that doesn't wait for operation completion and
179 * implies the progress object will be used for waiting.
180 */
181 HRESULT mergeToNoWait (MergeChain *aChain,
182 ComObjPtr <Progress> &aProgress)
183 { return mergeTo (aChain, &aProgress, false /* aWait */); }
184
185 /**
186 * Shortcut to #mergeTo() that wait for operation completion by
187 * blocking the current thread.
188 */
189 HRESULT mergeToAndWait (MergeChain *aChain,
190 ComObjPtr <Progress> *aProgress = NULL)
191 { return mergeTo (aChain, aProgress, true /* aWait */); }
192
193 void cancelMergeTo (MergeChain *aChain);
194
195 Utf8Str name();
196
197 HRESULT prepareDiscard (MergeChain * &aChain);
198 HRESULT discard (ComObjPtr <Progress> &aProgress, MergeChain *aChain);
199 void cancelDiscard (MergeChain *aChain);
200
201 /** Returns a preferred format for a differencing hard disk. */
202 Bstr preferredDiffFormat();
203
204 // unsafe inline public methods for internal purposes only (ensure there is
205 // a caller and a read lock before calling them!)
206
207 ComObjPtr <HardDisk> parent() const { return static_cast <HardDisk *> (mParent); }
208 HardDiskType_T type() const { return mm.type; }
209
210 /** For com::SupportErrorInfoImpl. */
211 static const char *ComponentName() { return "HardDisk"; }
212
213protected:
214
215 HRESULT deleteStorage (ComObjPtr <Progress> *aProgress, bool aWait);
216
217 HRESULT createDiffStorage (ComObjPtr <HardDisk> &aTarget,
218 HardDiskVariant_T aVariant,
219 ComObjPtr <Progress> *aProgress,
220 bool aWait);
221
222 HRESULT mergeTo (MergeChain *aChain,
223 ComObjPtr <Progress> *aProgress,
224 bool aWait);
225
226 /**
227 * Returns VirtualBox::hardDiskTreeHandle(), for convenience. Don't forget
228 * to follow these locking rules:
229 *
230 * 1. The write lock on this handle must be either held alone on the thread
231 * or requested *after* the VirtualBox object lock. Mixing with other
232 * locks is prohibited.
233 *
234 * 2. The read lock on this handle may be intermixed with any other lock
235 * with the exception that it must be requested *after* the VirtualBox
236 * object lock.
237 */
238 RWLockHandle *treeLock() { return mVirtualBox->hardDiskTreeLockHandle(); }
239
240 /** Reimplements VirtualBoxWithTypedChildren::childrenLock() to return
241 * treeLock(). */
242 RWLockHandle *childrenLock() { return treeLock(); }
243
244private:
245
246 HRESULT setLocation (CBSTR aLocation);
247 HRESULT setFormat (CBSTR aFormat);
248
249 HRESULT queryInfo();
250
251 HRESULT canClose();
252 HRESULT canAttach (const Guid &aMachineId,
253 const Guid &aSnapshotId);
254
255 HRESULT unregisterWithVirtualBox();
256
257 Utf8Str vdError (int aVRC);
258
259 static DECLCALLBACK(void) vdErrorCall (void *pvUser, int rc, RT_SRC_POS_DECL,
260 const char *pszFormat, va_list va);
261
262 static DECLCALLBACK(int) vdProgressCall (PVM /* pVM */, unsigned uPercent,
263 void *pvUser);
264
265 static DECLCALLBACK(bool) vdConfigAreKeysValid (void *pvUser,
266 const char *pszzValid);
267 static DECLCALLBACK(int) vdConfigQuerySize (void *pvUser, const char *pszName,
268 size_t *pcbValue);
269 static DECLCALLBACK(int) vdConfigQuery (void *pvUser, const char *pszName,
270 char *pszValue, size_t cchValue);
271
272 static DECLCALLBACK(int) taskThread (RTTHREAD thread, void *pvUser);
273
274 /** weak parent */
275 ComObjPtr <HardDisk, ComWeakRef> mParent;
276
277 struct Task;
278 friend struct Task;
279
280 struct Data
281 {
282 Data() : type (HardDiskType_Normal), logicalSize (0), autoReset (false)
283 , implicit (false), numCreateDiffTasks (0)
284 , vdProgress (NULL) , vdDiskIfaces (NULL) {}
285
286 const Bstr format;
287 ComObjPtr <HardDiskFormat> formatObj;
288
289 HardDiskType_T type;
290 uint64_t logicalSize; /*< In MBytes. */
291
292 BOOL autoReset : 1;
293
294 typedef std::map <Bstr, Bstr> PropertyMap;
295 PropertyMap properties;
296
297 bool implicit : 1;
298
299 uint32_t numCreateDiffTasks;
300
301 Utf8Str vdError; /*< Error remembered by the VD error callback. */
302 Progress *vdProgress; /*< Progress for the VD progress callback. */
303
304 VDINTERFACE vdIfError;
305 VDINTERFACEERROR vdIfCallsError;
306
307 VDINTERFACE vdIfProgress;
308 VDINTERFACEPROGRESS vdIfCallsProgress;
309
310 VDINTERFACE vdIfConfig;
311 VDINTERFACECONFIG vdIfCallsConfig;
312
313 VDINTERFACE vdIfTcpNet;
314 VDINTERFACETCPNET vdIfCallsTcpNet;
315
316 PVDINTERFACE vdDiskIfaces;
317 };
318
319 Data mm;
320};
321
322#endif /* ____H_HARDDISKIMPL */
323
324/* 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