VirtualBox

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

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

Main: make MediumAttachment instance data private

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 11.5 KB
Line 
1/* $Id: MediumImpl.h 25200 2009-12-04 18:19:05Z vboxsync $ */
2/** @file
3 *
4 * VirtualBox COM class implementation
5 */
6
7/*
8 * Copyright (C) 2008-2009 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#ifndef ____H_MEDIUMIMPL
24#define ____H_MEDIUMIMPL
25
26#include "VirtualBoxBase.h"
27
28class VirtualBox;
29class Progress;
30struct VM;
31
32namespace settings
33{
34 struct Medium;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38
39class Medium;
40typedef std::list< ComObjPtr<Medium> > MediaList;
41
42/**
43 * Medium component class for all media types.
44 */
45class ATL_NO_VTABLE Medium :
46 public VirtualBoxBase,
47 public com::SupportErrorInfoImpl<Medium, IMedium>,
48 public VirtualBoxSupportTranslation<Medium>,
49 VBOX_SCRIPTABLE_IMPL(IMedium)
50{
51public:
52 class MergeChain;
53 class ImageChain;
54
55 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium)
56
57 DECLARE_NOT_AGGREGATABLE(Medium)
58
59 DECLARE_PROTECT_FINAL_CONSTRUCT()
60
61 BEGIN_COM_MAP(Medium)
62 COM_INTERFACE_ENTRY(ISupportErrorInfo)
63 COM_INTERFACE_ENTRY(IMedium)
64 END_COM_MAP()
65
66 DECLARE_EMPTY_CTOR_DTOR(Medium)
67
68 HRESULT FinalConstruct();
69 void FinalRelease();
70
71 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
72 // have to use a special enum for the overloaded init() below;
73 // can't use AccessMode_T from XIDL because that's mapped to an int
74 // and would be ambiguous
75
76 // public initializer/uninitializer for internal purposes only
77 HRESULT init(VirtualBox *aVirtualBox,
78 CBSTR aFormat,
79 CBSTR aLocation);
80 HRESULT init(VirtualBox *aVirtualBox,
81 CBSTR aLocation,
82 HDDOpenMode enOpenMode,
83 DeviceType_T aDeviceType,
84 BOOL aSetImageId,
85 const Guid &aImageId,
86 BOOL aSetParentId,
87 const Guid &aParentId);
88 // initializer used when loading settings
89 HRESULT init(VirtualBox *aVirtualBox,
90 Medium *aParent,
91 DeviceType_T aDeviceType,
92 const settings::Medium &data);
93 // initializer for host floppy/DVD
94 HRESULT init(VirtualBox *aVirtualBox,
95 DeviceType_T aDeviceType,
96 CBSTR aLocation,
97 CBSTR aDescription = NULL);
98 void uninit();
99
100 void deparent();
101
102 // IMedium properties
103 STDMETHOD(COMGETTER(Id))(BSTR *aId);
104 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
105 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
106 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
107 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
108 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
109 STDMETHOD(COMGETTER(Name))(BSTR *aName);
110 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
111 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
112 STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
113 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
114 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
115 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
116 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
117 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
118 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
119 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
120 STDMETHOD(COMGETTER(LogicalSize))(ULONG64 *aLogicalSize);
121 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
122 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
123 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
124 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
125
126 // IMedium methods
127 STDMETHOD(RefreshState)(MediumState_T *aState);
128 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
129 ComSafeArrayOut(BSTR, aSnapshotIds));
130 STDMETHOD(LockRead)(MediumState_T *aState);
131 STDMETHOD(UnlockRead)(MediumState_T *aState);
132 STDMETHOD(LockWrite)(MediumState_T *aState);
133 STDMETHOD(UnlockWrite)(MediumState_T *aState);
134 STDMETHOD(Close)();
135 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
136 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
137 STDMETHOD(GetProperties)(IN_BSTR aNames,
138 ComSafeArrayOut(BSTR, aReturnNames),
139 ComSafeArrayOut(BSTR, aReturnValues));
140 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
141 ComSafeArrayIn(IN_BSTR, aValues));
142 STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
143 MediumVariant_T aVariant,
144 IProgress **aProgress);
145 STDMETHOD(DeleteStorage)(IProgress **aProgress);
146 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
147 MediumVariant_T aVariant,
148 IProgress **aProgress);
149 STDMETHOD(MergeTo)(IN_BSTR aTargetId, IProgress **aProgress);
150 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
151 IMedium *aParent, IProgress **aProgress);
152 STDMETHOD(Compact)(IProgress **aProgress);
153 STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
154 STDMETHOD(Reset)(IProgress **aProgress);
155
156 // public methods for internal purposes only
157 const ComObjPtr<Medium>& getParent() const;
158 const MediaList& getChildren() const;
159
160 const Guid& getId() const;
161 MediumState_T getState() const;
162 const Utf8Str& getLocation() const;
163 const Utf8Str& getLocationFull() const;
164 uint64_t getSize() const;
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 /**
190 * Shortcut to #deleteStorage() that doesn't wait for operation completion
191 * and implies the progress object will be used for waiting.
192 */
193 HRESULT deleteStorageNoWait(ComObjPtr<Progress> &aProgress)
194 { return deleteStorage(&aProgress, false /* aWait */); }
195
196 /**
197 * Shortcut to #deleteStorage() that wait for operation completion by
198 * blocking the current thread.
199 */
200 HRESULT deleteStorageAndWait(ComObjPtr<Progress> *aProgress = NULL)
201 { return deleteStorage(aProgress, true /* aWait */); }
202
203 /**
204 * Shortcut to #createDiffStorage() that doesn't wait for operation
205 * completion and implies the progress object will be used for waiting.
206 */
207 HRESULT createDiffStorageNoWait(ComObjPtr<Medium> &aTarget,
208 MediumVariant_T aVariant,
209 ComObjPtr<Progress> &aProgress)
210 { return createDiffStorage(aTarget, aVariant, &aProgress, false /* aWait */); }
211
212 /**
213 * Shortcut to #createDiffStorage() that wait for operation completion by
214 * blocking the current thread.
215 */
216 HRESULT createDiffStorageAndWait(ComObjPtr<Medium> &aTarget,
217 MediumVariant_T aVariant,
218 ComObjPtr<Progress> *aProgress = NULL)
219 { return createDiffStorage(aTarget, aVariant, aProgress, true /* aWait */); }
220
221 HRESULT prepareMergeTo(Medium *aTarget, MergeChain * &aChain,
222 bool aIgnoreAttachments = false);
223
224 /**
225 * Shortcut to #mergeTo() that doesn't wait for operation completion and
226 * implies the progress object will be used for waiting.
227 */
228 HRESULT mergeToNoWait(MergeChain *aChain,
229 ComObjPtr<Progress> &aProgress)
230 { return mergeTo(aChain, &aProgress, false /* aWait */); }
231
232 /**
233 * Shortcut to #mergeTo() that wait for operation completion by
234 * blocking the current thread.
235 */
236 HRESULT mergeToAndWait(MergeChain *aChain,
237 ComObjPtr<Progress> *aProgress = NULL)
238 { return mergeTo(aChain, aProgress, true /* aWait */); }
239
240 void cancelMergeTo(MergeChain *aChain);
241
242 Utf8Str getName();
243
244 HRESULT prepareDiscard(MergeChain * &aChain);
245 HRESULT discard(ComObjPtr<Progress> &aProgress, ULONG ulWeight, MergeChain *aChain);
246 void cancelDiscard(MergeChain *aChain);
247
248 /** Returns a preferred format for a differencing hard disk. */
249 Bstr preferredDiffFormat();
250
251 // unsafe inline public methods for internal purposes only (ensure there is
252 // a caller and a read lock before calling them!)
253 MediumType_T getType() const;
254
255 /** For com::SupportErrorInfoImpl. */
256 static const char *ComponentName() { return "Medium"; }
257
258private:
259
260 HRESULT queryInfo();
261
262 /**
263 * Performs extra checks if the medium can be closed and returns S_OK in
264 * this case. Otherwise, returns a respective error message. Called by
265 * Close() from within this object's AutoMayUninitSpan and from under
266 * mVirtualBox write lock.
267 */
268 HRESULT canClose();
269
270 /**
271 * Unregisters this medium with mVirtualBox. Called by Close() from within
272 * this object's AutoMayUninitSpan and from under mVirtualBox write lock.
273 */
274 HRESULT unregisterWithVirtualBox();
275
276 HRESULT setStateError();
277
278 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait);
279
280 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
281 MediumVariant_T aVariant,
282 ComObjPtr<Progress> *aProgress,
283 bool aWait);
284
285 HRESULT mergeTo(MergeChain *aChain,
286 ComObjPtr<Progress> *aProgress,
287 bool aWait);
288
289 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
290 HRESULT setFormat(CBSTR aFormat);
291
292 Utf8Str vdError(int aVRC);
293
294 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
295 const char *pszFormat, va_list va);
296
297 static DECLCALLBACK(int) vdProgressCall(VM* /* pVM */, unsigned uPercent,
298 void *pvUser);
299
300 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
301 const char *pszzValid);
302 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
303 size_t *pcbValue);
304 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
305 char *pszValue, size_t cchValue);
306
307 static DECLCALLBACK(int) taskThread(RTTHREAD thread, void *pvUser);
308
309 struct Task;
310 friend struct Task;
311
312 struct Data; // opaque data struct, defined in MediumImpl.cpp
313 Data *m;
314};
315
316#endif /* ____H_MEDIUMIMPL */
317
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