VirtualBox

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

Last change on this file since 14664 was 14628, checked in by vboxsync, 16 years ago

Main: add the Id keyword

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