VirtualBox

source: vbox/trunk/src/VBox/Main/include/MediumImpl.h@ 28774

Last change on this file since 28774 was 28587, checked in by vboxsync, 15 years ago

Main/Medium: fix parameter passing for mergeTo(), eliminating unnecessary indirection and copying.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1/* $Id: MediumImpl.h 28587 2010-04-22 11:38:59Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2010 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_MEDIUMIMPL
25#define ____H_MEDIUMIMPL
26
27#include "VirtualBoxBase.h"
28#include "MediumLock.h"
29
30class Progress;
31
32namespace settings
33{
34 struct Medium;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38
39/**
40 * Medium component class for all media types.
41 */
42class ATL_NO_VTABLE Medium :
43 public VirtualBoxBase,
44 public com::SupportErrorInfoImpl<Medium, IMedium>,
45 public VirtualBoxSupportTranslation<Medium>,
46 VBOX_SCRIPTABLE_IMPL(IMedium)
47{
48public:
49 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium)
50
51 DECLARE_NOT_AGGREGATABLE(Medium)
52
53 DECLARE_PROTECT_FINAL_CONSTRUCT()
54
55 BEGIN_COM_MAP(Medium)
56 COM_INTERFACE_ENTRY(ISupportErrorInfo)
57 COM_INTERFACE_ENTRY(IMedium)
58 COM_INTERFACE_ENTRY(IDispatch)
59 END_COM_MAP()
60
61 DECLARE_EMPTY_CTOR_DTOR(Medium)
62
63 HRESULT FinalConstruct();
64 void FinalRelease();
65
66 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
67 // have to use a special enum for the overloaded init() below;
68 // can't use AccessMode_T from XIDL because that's mapped to an int
69 // and would be ambiguous
70
71 // public initializer/uninitializer for internal purposes only
72 HRESULT init(VirtualBox *aVirtualBox,
73 CBSTR aFormat,
74 CBSTR aLocation,
75 bool *pfNeedsSaveSettings);
76 HRESULT init(VirtualBox *aVirtualBox,
77 CBSTR aLocation,
78 HDDOpenMode enOpenMode,
79 DeviceType_T aDeviceType,
80 BOOL aSetImageId,
81 const Guid &aImageId,
82 BOOL aSetParentId,
83 const Guid &aParentId);
84 // initializer used when loading settings
85 HRESULT init(VirtualBox *aVirtualBox,
86 Medium *aParent,
87 DeviceType_T aDeviceType,
88 const settings::Medium &data);
89 // initializer for host floppy/DVD
90 HRESULT init(VirtualBox *aVirtualBox,
91 DeviceType_T aDeviceType,
92 CBSTR aLocation,
93 CBSTR aDescription = NULL);
94 void uninit();
95
96 void deparent();
97
98 // IMedium properties
99 STDMETHOD(COMGETTER(Id))(BSTR *aId);
100 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
101 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
102 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
103 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
104 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
105 STDMETHOD(COMGETTER(Name))(BSTR *aName);
106 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
107 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
108 STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
109 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
110 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
111 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
112 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
113 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
114 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
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 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
120 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
121
122 // IMedium methods
123 STDMETHOD(RefreshState)(MediumState_T *aState);
124 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
125 ComSafeArrayOut(BSTR, aSnapshotIds));
126 STDMETHOD(LockRead)(MediumState_T *aState);
127 STDMETHOD(UnlockRead)(MediumState_T *aState);
128 STDMETHOD(LockWrite)(MediumState_T *aState);
129 STDMETHOD(UnlockWrite)(MediumState_T *aState);
130 STDMETHOD(Close)();
131 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
132 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
133 STDMETHOD(GetProperties)(IN_BSTR aNames,
134 ComSafeArrayOut(BSTR, aReturnNames),
135 ComSafeArrayOut(BSTR, aReturnValues));
136 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
137 ComSafeArrayIn(IN_BSTR, aValues));
138 STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
139 MediumVariant_T aVariant,
140 IProgress **aProgress);
141 STDMETHOD(DeleteStorage)(IProgress **aProgress);
142 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
143 MediumVariant_T aVariant,
144 IProgress **aProgress);
145 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
146 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
147 IMedium *aParent, IProgress **aProgress);
148 STDMETHOD(Compact)(IProgress **aProgress);
149 STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
150 STDMETHOD(Reset)(IProgress **aProgress);
151
152 // public methods for internal purposes only
153 const ComObjPtr<Medium>& getParent() const;
154 const MediaList& getChildren() const;
155
156 // unsafe methods for internal purposes only (ensure there is
157 // a caller and a read lock before calling them!)
158 const Guid& getId() const;
159 MediumState_T getState() const;
160 const Utf8Str& getLocation() const;
161 const Utf8Str& getLocationFull() const;
162 uint64_t getSize() const;
163 MediumType_T getType() const;
164 Utf8Str getName();
165
166 HRESULT attachTo(const Guid &aMachineId,
167 const Guid &aSnapshotId = Guid::Empty);
168 HRESULT detachFrom(const Guid &aMachineId,
169 const Guid &aSnapshotId = Guid::Empty);
170
171 const Guid* getFirstMachineBackrefId() const;
172 const Guid* getFirstMachineBackrefSnapshotId() const;
173
174#ifdef DEBUG
175 void dumpBackRefs();
176#endif
177
178 HRESULT updatePath(const char *aOldPath, const char *aNewPath);
179 void updatePaths(const char *aOldPath, const char *aNewPath);
180
181 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
182
183 bool isReadOnly();
184
185 HRESULT saveSettings(settings::Medium &data);
186
187 HRESULT compareLocationTo(const char *aLocation, int &aResult);
188
189 HRESULT createMediumLockList(bool fMediumWritable, Medium *pToBeParent, MediumLockList &mediumLockList);
190
191 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
192 MediumVariant_T aVariant,
193 MediumLockList *pMediumLockList,
194 ComObjPtr<Progress> *aProgress,
195 bool aWait,
196 bool *pfNeedsSaveSettings);
197
198 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
199 HRESULT markForDeletion();
200 HRESULT unmarkForDeletion();
201 HRESULT markLockedForDeletion();
202 HRESULT unmarkLockedForDeletion();
203
204 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
205 const Guid *aMachineId,
206 const Guid *aSnapshotId,
207 bool fLockMedia,
208 bool &fMergeForward,
209 ComObjPtr<Medium> &pParentForTarget,
210 MediaList &aChildrenToReparent,
211 MediumLockList * &aMediumLockList);
212 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
213 bool fMergeForward,
214 const ComObjPtr<Medium> &pParentForTarget,
215 const MediaList &aChildrenToReparent,
216 MediumLockList *aMediumLockList,
217 ComObjPtr<Progress> *aProgress,
218 bool aWait,
219 bool *pfNeedsSaveSettings);
220 void cancelMergeTo(const MediaList &aChildrenToReparent,
221 MediumLockList *aMediumLockList);
222
223 /** Returns a preferred format for a differencing hard disk. */
224 Bstr preferredDiffFormat();
225
226 /** For com::SupportErrorInfoImpl. */
227 static const char *ComponentName() { return "Medium"; }
228
229private:
230
231 HRESULT queryInfo();
232
233 /**
234 * Performs extra checks if the medium can be closed and returns S_OK in
235 * this case. Otherwise, returns a respective error message. Called by
236 * Close() under the medium tree lock and the medium lock.
237 */
238 HRESULT canClose();
239
240 /**
241 * Unregisters this medium with mVirtualBox. Called by Close() under
242 * the medium tree lock.
243 */
244 HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
245
246 HRESULT setStateError();
247
248 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
249 HRESULT setFormat(CBSTR aFormat);
250
251 Utf8Str vdError(int aVRC);
252
253 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
254 const char *pszFormat, va_list va);
255
256 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
257 const char *pszzValid);
258 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
259 size_t *pcbValue);
260 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
261 char *pszValue, size_t cchValue);
262
263 class Task;
264 class CreateBaseTask;
265 class CreateDiffTask;
266 class CloneTask;
267 class CompactTask;
268 class ResetTask;
269 class DeleteTask;
270 class MergeTask;
271 friend class Task;
272 friend class CreateBaseTask;
273 friend class CreateDiffTask;
274 friend class CloneTask;
275 friend class CompactTask;
276 friend class ResetTask;
277 friend class DeleteTask;
278 friend class MergeTask;
279
280 HRESULT startThread(Medium::Task *pTask);
281 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
282
283 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
284 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
285 HRESULT taskMergeHandler(Medium::MergeTask &task);
286 HRESULT taskCloneHandler(Medium::CloneTask &task);
287 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
288 HRESULT taskResetHandler(Medium::ResetTask &task);
289 HRESULT taskCompactHandler(Medium::CompactTask &task);
290
291 struct Data; // opaque data struct, defined in MediumImpl.cpp
292 Data *m;
293};
294
295#endif /* ____H_MEDIUMIMPL */
296
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