VirtualBox

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

Last change on this file since 38469 was 38469, checked in by vboxsync, 14 years ago

VD: Interface cleanup. Merge the two involved structures (generic interface descriptor and callback table) into one, remove the duplicated interface wrappers in the backends and move the interface definitions into separate headers separating public and private interfaces.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.0 KB
Line 
1/* $Id: MediumImpl.h 38469 2011-08-16 10:34:32Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2011 Oracle Corporation
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
20#ifndef ____H_MEDIUMIMPL
21#define ____H_MEDIUMIMPL
22
23#include <VBox/vd.h>
24
25#include "VirtualBoxBase.h"
26#include "MediumLock.h"
27
28class Progress;
29class MediumFormat;
30
31namespace settings
32{
33 struct Medium;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37
38/**
39 * Medium component class for all media types.
40 */
41class ATL_NO_VTABLE Medium :
42 public VirtualBoxBase,
43 VBOX_SCRIPTABLE_IMPL(IMedium)
44{
45public:
46 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium, IMedium)
47
48 DECLARE_NOT_AGGREGATABLE(Medium)
49
50 DECLARE_PROTECT_FINAL_CONSTRUCT()
51
52 BEGIN_COM_MAP(Medium)
53 VBOX_DEFAULT_INTERFACE_ENTRIES(IMedium)
54 END_COM_MAP()
55
56 DECLARE_EMPTY_CTOR_DTOR(Medium)
57
58 HRESULT FinalConstruct();
59 void FinalRelease();
60
61 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
62 // have to use a special enum for the overloaded init() below;
63 // can't use AccessMode_T from XIDL because that's mapped to an int
64 // and would be ambiguous
65
66 // public initializer/uninitializer for internal purposes only
67
68 // initializer to create empty medium (VirtualBox::CreateHardDisk())
69 HRESULT init(VirtualBox *aVirtualBox,
70 const Utf8Str &aFormat,
71 const Utf8Str &aLocation,
72 const Guid &uuidMachineRegistry,
73 GuidList *pllRegistriesThatNeedSaving);
74
75 // initializer for opening existing media
76 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
77 HRESULT init(VirtualBox *aVirtualBox,
78 const Utf8Str &aLocation,
79 HDDOpenMode enOpenMode,
80 bool fForceNewUuid,
81 DeviceType_T aDeviceType);
82
83 // initializer used when loading settings
84 HRESULT init(VirtualBox *aVirtualBox,
85 Medium *aParent,
86 DeviceType_T aDeviceType,
87 const Guid &uuidMachineRegistry,
88 const settings::Medium &data,
89 const Utf8Str &strMachineFolder);
90
91 // initializer for host floppy/DVD
92 HRESULT init(VirtualBox *aVirtualBox,
93 DeviceType_T aDeviceType,
94 const Utf8Str &aLocation,
95 const Utf8Str &aDescription = Utf8Str::Empty);
96
97 void uninit();
98
99 void deparent();
100 void setParent(const ComObjPtr<Medium> &pParent);
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(Variant))(ULONG *aVariant);
108 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
109 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
110 STDMETHOD(COMGETTER(Name))(BSTR *aName);
111 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
112 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
113 STDMETHOD(COMGETTER(Size))(LONG64 *aSize);
114 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
115 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
116 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
117 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
118 STDMETHOD(COMGETTER(AllowedTypes))(ComSafeArrayOut(MediumType_T, aAllowedTypes));
119 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
120 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
121 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
122 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
123 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
124 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
125 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
126 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
127 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
128
129 // IMedium methods
130 STDMETHOD(SetIDs)(BOOL aSetImageId, IN_BSTR aImageId,
131 BOOL aSetParentId, IN_BSTR aParentId);
132 STDMETHOD(RefreshState)(MediumState_T *aState);
133 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
134 ComSafeArrayOut(BSTR, aSnapshotIds));
135 STDMETHOD(LockRead)(MediumState_T *aState);
136 STDMETHOD(UnlockRead)(MediumState_T *aState);
137 STDMETHOD(LockWrite)(MediumState_T *aState);
138 STDMETHOD(UnlockWrite)(MediumState_T *aState);
139 STDMETHOD(Close)();
140 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
141 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
142 STDMETHOD(GetProperties)(IN_BSTR aNames,
143 ComSafeArrayOut(BSTR, aReturnNames),
144 ComSafeArrayOut(BSTR, aReturnValues));
145 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
146 ComSafeArrayIn(IN_BSTR, aValues));
147 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
148 ULONG aVariant,
149 IProgress **aProgress);
150 STDMETHOD(DeleteStorage)(IProgress **aProgress);
151 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
152 ULONG aVariant,
153 IProgress **aProgress);
154 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
155 STDMETHOD(CloneTo)(IMedium *aTarget, ULONG aVariant,
156 IMedium *aParent, IProgress **aProgress);
157 STDMETHOD(Compact)(IProgress **aProgress);
158 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
159 STDMETHOD(Reset)(IProgress **aProgress);
160
161 // unsafe methods for internal purposes only (ensure there is
162 // a caller and a read lock before calling them!)
163 const ComObjPtr<Medium>& getParent() const;
164 const MediaList& getChildren() const;
165
166 const Guid& getId() const;
167 MediumState_T getState() const;
168 MediumVariant_T getVariant() const;
169 bool isHostDrive() const;
170 const Utf8Str& getLocationFull() const;
171 const Utf8Str& getFormat() const;
172 const ComObjPtr<MediumFormat> & getMediumFormat() const;
173 bool isMediumFormatFile() const;
174 uint64_t getSize() const;
175 DeviceType_T getDeviceType() const;
176 MediumType_T getType() const;
177 Utf8Str getName();
178
179 bool addRegistry(const Guid& id, bool fRecurse);
180private:
181 void addRegistryImpl(const Guid& id, bool fRecurse);
182public:
183 bool removeRegistry(const Guid& id, bool fRecurse);
184 bool isInRegistry(const Guid& id);
185 bool getFirstRegistryMachineId(Guid &uuid) const;
186 HRESULT addToRegistryIDList(GuidList &llRegistryIDs);
187
188 HRESULT addBackReference(const Guid &aMachineId,
189 const Guid &aSnapshotId = Guid::Empty);
190 HRESULT removeBackReference(const Guid &aMachineId,
191 const Guid &aSnapshotId = Guid::Empty);
192
193 const Guid* getFirstMachineBackrefId() const;
194 const Guid* getAnyMachineBackref() const;
195 const Guid* getFirstMachineBackrefSnapshotId() const;
196 size_t getMachineBackRefCount() const;
197
198#ifdef DEBUG
199 void dumpBackRefs();
200#endif
201
202 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
203
204 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
205
206 bool isReadOnly();
207 void updateId(const Guid &id);
208
209 HRESULT saveSettings(settings::Medium &data,
210 const Utf8Str &strHardDiskFolder);
211
212 HRESULT createMediumLockList(bool fFailIfInaccessible,
213 bool fMediumLockWrite,
214 Medium *pToBeParent,
215 MediumLockList &mediumLockList);
216
217 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
218 MediumVariant_T aVariant,
219 MediumLockList *pMediumLockList,
220 ComObjPtr<Progress> *aProgress,
221 bool aWait,
222 GuidList *pllRegistriesThatNeedSaving);
223 Utf8Str getPreferredDiffFormat();
224
225 HRESULT close(GuidList *pllRegistriesThatNeedSaving, AutoCaller &autoCaller);
226 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, GuidList *pllRegistriesThatNeedSaving);
227 HRESULT markForDeletion();
228 HRESULT unmarkForDeletion();
229 HRESULT markLockedForDeletion();
230 HRESULT unmarkLockedForDeletion();
231
232 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
233 const Guid *aMachineId,
234 const Guid *aSnapshotId,
235 bool fLockMedia,
236 bool &fMergeForward,
237 ComObjPtr<Medium> &pParentForTarget,
238 MediaList &aChildrenToReparent,
239 MediumLockList * &aMediumLockList);
240 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
241 bool fMergeForward,
242 const ComObjPtr<Medium> &pParentForTarget,
243 const MediaList &aChildrenToReparent,
244 MediumLockList *aMediumLockList,
245 ComObjPtr<Progress> *aProgress,
246 bool aWait,
247 GuidList *pllRegistriesThatNeedSaving);
248 void cancelMergeTo(const MediaList &aChildrenToReparent,
249 MediumLockList *aMediumLockList);
250
251 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
252
253 HRESULT exportFile(const char *aFilename,
254 const ComObjPtr<MediumFormat> &aFormat,
255 MediumVariant_T aVariant,
256 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
257 const ComObjPtr<Progress> &aProgress);
258 HRESULT importFile(const char *aFilename,
259 const ComObjPtr<MediumFormat> &aFormat,
260 MediumVariant_T aVariant,
261 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
262 const ComObjPtr<Medium> &aParent,
263 const ComObjPtr<Progress> &aProgress);
264
265 HRESULT cloneToEx(const ComObjPtr<Medium> &aTarget, ULONG aVariant,
266 const ComObjPtr<Medium> &aParent, IProgress **aProgress,
267 uint32_t idxSrcImageSame, uint32_t idxDstImageSame);
268
269private:
270
271 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
272
273 HRESULT canClose();
274 HRESULT unregisterWithVirtualBox(GuidList *pllRegistriesThatNeedSaving);
275
276 HRESULT setStateError();
277
278 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
279 HRESULT setFormat(const Utf8Str &aFormat);
280
281 VDTYPE convertDeviceType();
282 DeviceType_T convertToDeviceType(VDTYPE enmType);
283
284 Utf8Str vdError(int aVRC);
285
286 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
287 const char *pszFormat, va_list va);
288
289 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
290 const char *pszzValid);
291 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
292 size_t *pcbValue);
293 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
294 char *pszValue, size_t cchValue);
295
296 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
297 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
298 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
299 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
300 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
301 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
302 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
303 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
304 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
305 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
306 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
307 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
308 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
309
310 class Task;
311 class CreateBaseTask;
312 class CreateDiffTask;
313 class CloneTask;
314 class CompactTask;
315 class ResizeTask;
316 class ResetTask;
317 class DeleteTask;
318 class MergeTask;
319 class ExportTask;
320 class ImportTask;
321 friend class Task;
322 friend class CreateBaseTask;
323 friend class CreateDiffTask;
324 friend class CloneTask;
325 friend class CompactTask;
326 friend class ResizeTask;
327 friend class ResetTask;
328 friend class DeleteTask;
329 friend class MergeTask;
330 friend class ExportTask;
331 friend class ImportTask;
332
333 HRESULT startThread(Medium::Task *pTask);
334 HRESULT runNow(Medium::Task *pTask, GuidList *pllRegistriesThatNeedSaving);
335
336 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
337 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
338 HRESULT taskMergeHandler(Medium::MergeTask &task);
339 HRESULT taskCloneHandler(Medium::CloneTask &task);
340 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
341 HRESULT taskResetHandler(Medium::ResetTask &task);
342 HRESULT taskCompactHandler(Medium::CompactTask &task);
343 HRESULT taskResizeHandler(Medium::ResizeTask &task);
344 HRESULT taskExportHandler(Medium::ExportTask &task);
345 HRESULT taskImportHandler(Medium::ImportTask &task);
346
347 struct Data; // opaque data struct, defined in MediumImpl.cpp
348 Data *m;
349};
350
351#endif /* ____H_MEDIUMIMPL */
352
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