VirtualBox

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

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

API/HardDIsk: introduce parameter for specifying the image variant to be created.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 11.3 KB
Line 
1/* $Id: HardDiskImpl.h 17825 2009-03-13 14:03:09Z 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(CreateDynamicStorage) (ULONG64 aLogicalSize,
111 HardDiskVariant_T aVariant,
112 IProgress **aProgress);
113 STDMETHOD(CreateFixedStorage) (ULONG64 aLogicalSize,
114 HardDiskVariant_T aVariant,
115 IProgress **aProgress);
116 STDMETHOD(DeleteStorage) (IProgress **aProgress);
117 STDMETHOD(CreateDiffStorage) (IHardDisk *aTarget,
118 HardDiskVariant_T aVariant,
119 IProgress **aProgress);
120 STDMETHOD(MergeTo) (IN_GUID aTargetId, IProgress **aProgress);
121 STDMETHOD(CloneTo) (IHardDisk *aTarget, HardDiskVariant_T aVariant,
122 IProgress **aProgress);
123 STDMETHOD(FlattenTo) (IHardDisk *aTarget, HardDiskVariant_T aVariant,
124 IProgress **aProgress);
125 STDMETHOD(Compact) (IProgress **aProgress);
126 STDMETHOD(Reset) (IProgress **aProgress);
127
128 // public methods for internal purposes only
129
130 /**
131 * Shortcut to VirtualBoxBaseWithTypedChildrenNEXT::dependentChildren().
132 */
133 const List &children() const { return dependentChildren(); }
134
135 void updatePaths (const char *aOldPath, const char *aNewPath);
136
137 ComObjPtr<HardDisk> root (uint32_t *aLevel = NULL);
138
139 bool isReadOnly();
140
141 HRESULT saveSettings (settings::Key &aParentNode);
142
143 HRESULT compareLocationTo (const char *aLocation, int &aResult);
144
145 /**
146 * Shortcut to #deleteStorage() that doesn't wait for operation completion
147 * and implies the progress object will be used for waiting.
148 */
149 HRESULT deleteStorageNoWait (ComObjPtr <Progress> &aProgress)
150 { return deleteStorage (&aProgress, false /* aWait */); }
151
152 /**
153 * Shortcut to #deleteStorage() that wait for operation completion by
154 * blocking the current thread.
155 */
156 HRESULT deleteStorageAndWait (ComObjPtr <Progress> *aProgress = NULL)
157 { return deleteStorage (aProgress, true /* aWait */); }
158
159 /**
160 * Shortcut to #createDiffStorage() that doesn't wait for operation
161 * completion and implies the progress object will be used for waiting.
162 */
163 HRESULT createDiffStorageNoWait (ComObjPtr<HardDisk> &aTarget,
164 HardDiskVariant_T aVariant,
165 ComObjPtr <Progress> &aProgress)
166 { return createDiffStorage (aTarget, aVariant, &aProgress, false /* aWait */); }
167
168 /**
169 * Shortcut to #createDiffStorage() that wait for operation completion by
170 * blocking the current thread.
171 */
172 HRESULT createDiffStorageAndWait (ComObjPtr<HardDisk> &aTarget,
173 HardDiskVariant_T aVariant,
174 ComObjPtr <Progress> *aProgress = NULL)
175 { return createDiffStorage (aTarget, aVariant, aProgress, true /* aWait */); }
176
177 HRESULT prepareMergeTo (HardDisk *aTarget, MergeChain * &aChain,
178 bool aIgnoreAttachments = false);
179
180 /**
181 * Shortcut to #mergeTo() that doesn't wait for operation completion and
182 * implies the progress object will be used for waiting.
183 */
184 HRESULT mergeToNoWait (MergeChain *aChain,
185 ComObjPtr <Progress> &aProgress)
186 { return mergeTo (aChain, &aProgress, false /* aWait */); }
187
188 /**
189 * Shortcut to #mergeTo() that wait for operation completion by
190 * blocking the current thread.
191 */
192 HRESULT mergeToAndWait (MergeChain *aChain,
193 ComObjPtr <Progress> *aProgress = NULL)
194 { return mergeTo (aChain, aProgress, true /* aWait */); }
195
196 void cancelMergeTo (MergeChain *aChain);
197
198 Utf8Str name();
199
200 HRESULT prepareDiscard (MergeChain * &aChain);
201 HRESULT discard (ComObjPtr <Progress> &aProgress, MergeChain *aChain);
202 void cancelDiscard (MergeChain *aChain);
203
204 /** Returns a preferred format for a differencing hard disk. */
205 Bstr preferredDiffFormat();
206
207 // unsafe inline public methods for internal purposes only (ensure there is
208 // a caller and a read lock before calling them!)
209
210 ComObjPtr <HardDisk> parent() const { return static_cast <HardDisk *> (mParent); }
211 HardDiskType_T type() const { return mm.type; }
212
213 /** For com::SupportErrorInfoImpl. */
214 static const char *ComponentName() { return "HardDisk"; }
215
216protected:
217
218 HRESULT deleteStorage (ComObjPtr <Progress> *aProgress, bool aWait);
219
220 HRESULT createDiffStorage (ComObjPtr <HardDisk> &aTarget,
221 HardDiskVariant_T aVariant,
222 ComObjPtr <Progress> *aProgress,
223 bool aWait);
224
225 HRESULT mergeTo (MergeChain *aChain,
226 ComObjPtr <Progress> *aProgress,
227 bool aWait);
228
229 /**
230 * Returns VirtualBox::hardDiskTreeHandle(), for convenience. Don't forget
231 * to follow these locking rules:
232 *
233 * 1. The write lock on this handle must be either held alone on the thread
234 * or requested *after* the VirtualBox object lock. Mixing with other
235 * locks is prohibited.
236 *
237 * 2. The read lock on this handle may be intermixed with any other lock
238 * with the exception that it must be requested *after* the VirtualBox
239 * object lock.
240 */
241 RWLockHandle *treeLock() { return mVirtualBox->hardDiskTreeLockHandle(); }
242
243 /** Reimplements VirtualBoxWithTypedChildren::childrenLock() to return
244 * treeLock(). */
245 RWLockHandle *childrenLock() { return treeLock(); }
246
247private:
248
249 HRESULT setLocation (CBSTR aLocation);
250 HRESULT setFormat (CBSTR aFormat);
251
252 HRESULT queryInfo();
253
254 HRESULT canClose();
255 HRESULT canAttach (const Guid &aMachineId,
256 const Guid &aSnapshotId);
257
258 HRESULT unregisterWithVirtualBox();
259
260 Utf8Str vdError (int aVRC);
261
262 static DECLCALLBACK(void) vdErrorCall (void *pvUser, int rc, RT_SRC_POS_DECL,
263 const char *pszFormat, va_list va);
264
265 static DECLCALLBACK(int) vdProgressCall (PVM /* pVM */, unsigned uPercent,
266 void *pvUser);
267
268 static DECLCALLBACK(bool) vdConfigAreKeysValid (void *pvUser,
269 const char *pszzValid);
270 static DECLCALLBACK(int) vdConfigQuerySize (void *pvUser, const char *pszName,
271 size_t *pcbValue);
272 static DECLCALLBACK(int) vdConfigQuery (void *pvUser, const char *pszName,
273 char *pszValue, size_t cchValue);
274
275 static DECLCALLBACK(int) taskThread (RTTHREAD thread, void *pvUser);
276
277 /** weak parent */
278 ComObjPtr <HardDisk, ComWeakRef> mParent;
279
280 struct Task;
281 friend struct Task;
282
283 struct Data
284 {
285 Data() : type (HardDiskType_Normal), logicalSize (0), autoReset (false)
286 , implicit (false), numCreateDiffTasks (0)
287 , vdProgress (NULL) , vdDiskIfaces (NULL) {}
288
289 const Bstr format;
290 ComObjPtr <HardDiskFormat> formatObj;
291
292 HardDiskType_T type;
293 uint64_t logicalSize; /*< In MBytes. */
294
295 BOOL autoReset : 1;
296
297 typedef std::map <Bstr, Bstr> PropertyMap;
298 PropertyMap properties;
299
300 bool implicit : 1;
301
302 uint32_t numCreateDiffTasks;
303
304 Utf8Str vdError; /*< Error remembered by the VD error callback. */
305 Progress *vdProgress; /*< Progress for the VD progress callback. */
306
307 VDINTERFACE vdIfError;
308 VDINTERFACEERROR vdIfCallsError;
309
310 VDINTERFACE vdIfProgress;
311 VDINTERFACEPROGRESS vdIfCallsProgress;
312
313 VDINTERFACE vdIfConfig;
314 VDINTERFACECONFIG vdIfCallsConfig;
315
316 VDINTERFACE vdIfTcpNet;
317 VDINTERFACETCPNET vdIfCallsTcpNet;
318
319 PVDINTERFACE vdDiskIfaces;
320 };
321
322 Data mm;
323};
324
325#endif /* ____H_HARDDISKIMPL */
326
327/* 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