VirtualBox

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

Last change on this file since 16954 was 16873, checked in by vboxsync, 16 years ago

Storage/VBoxHDD: eliminate the obsolete "-new" part of the name.

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