VirtualBox

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

Last change on this file since 22396 was 22183, checked in by vboxsync, 15 years ago

Main: fix more windows warnings + burns

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