VirtualBox

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

Last change on this file since 14573 was 14573, checked in by vboxsync, 17 years ago

Main: Prototyped IHardDisk2::getProperty()/setProperty().

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