VirtualBox

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

Last change on this file since 14959 was 14949, checked in by vboxsync, 16 years ago

Appended vim modeline to set tabstop and expand tabs (in the way
suggested by our coding guidelines).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 10.4 KB
Line 
1/* $Id: HardDisk2Impl.h 14949 2008-12-03 15:17:16Z 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_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(bool) vdConfigAreKeysValid (void *pvUser,
252 const char *pszzValid);
253 static DECLCALLBACK(int) vdConfigQuerySize (void *pvUser, const char *pszName,
254 size_t *pcbValue);
255 static DECLCALLBACK(int) vdConfigQuery (void *pvUser, const char *pszName,
256 char *pszValue, size_t cchValue);
257
258 static DECLCALLBACK(int) taskThread (RTTHREAD thread, void *pvUser);
259
260 /** weak parent */
261 ComObjPtr <HardDisk2, ComWeakRef> mParent;
262
263 struct Task;
264 friend struct Task;
265
266 struct Data
267 {
268 Data() : type (HardDiskType_Normal), logicalSize (0)
269 , implicit (false), numCreateDiffTasks (0)
270 , vdProgress (NULL) , vdDiskIfaces (NULL) {}
271
272 const Bstr format;
273 ComObjPtr <HardDiskFormat> formatObj;
274
275 HardDiskType_T type;
276 uint64_t logicalSize; /*< In MBytes. */
277
278 typedef std::map <Bstr, Bstr> PropertyMap;
279 PropertyMap properties;
280
281 bool implicit : 1;
282
283 uint32_t numCreateDiffTasks;
284
285 Utf8Str vdError; /*< Error remembered by the VD error callback. */
286 Progress *vdProgress; /*< Progress for the VD progress callback. */
287
288 VDINTERFACE vdIfError;
289 VDINTERFACEERROR vdIfCallsError;
290
291 VDINTERFACE vdIfProgress;
292 VDINTERFACEPROGRESS vdIfCallsProgress;
293
294 VDINTERFACE vdIfConfig;
295 VDINTERFACECONFIG vdIfCallsConfig;
296
297 VDINTERFACE vdIfTcpNet;
298 VDINTERFACETCPNET vdIfCallsTcpNet;
299
300 PVDINTERFACE vdDiskIfaces;
301 };
302
303 Data mm;
304};
305
306#endif /* ____H_HARDDISK2IMPL */
307
308/* 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