VirtualBox

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

Last change on this file since 53517 was 53354, checked in by vboxsync, 10 years ago

R7524 - needs testing in VBoxManage.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.7 KB
Line 
1/* $Id: MediumImpl.h 53354 2014-11-19 18:32:03Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2014 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
21#ifndef ____H_MEDIUMIMPL
22#define ____H_MEDIUMIMPL
23
24#include <VBox/vd.h>
25#include "MediumWrap.h"
26#include "VirtualBoxBase.h"
27#include "AutoCaller.h"
28class Progress;
29class MediumFormat;
30class MediumLockList;
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 MediumWrap
44{
45public:
46 DECLARE_EMPTY_CTOR_DTOR(Medium)
47
48 HRESULT FinalConstruct();
49 void FinalRelease();
50
51 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
52 // have to use a special enum for the overloaded init() below;
53 // can't use AccessMode_T from XIDL because that's mapped to an int
54 // and would be ambiguous
55
56 // public initializer/uninitializer for internal purposes only
57
58 // initializer to create empty medium (VirtualBox::CreateMedium())
59 HRESULT init(VirtualBox *aVirtualBox,
60 const Utf8Str &aFormat,
61 const Utf8Str &aLocation,
62 const Guid &uuidMachineRegistry,
63 const DeviceType_T aDeviceType);
64
65 // initializer for opening existing media
66 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
67 HRESULT init(VirtualBox *aVirtualBox,
68 const Utf8Str &aLocation,
69 HDDOpenMode enOpenMode,
70 bool fForceNewUuid,
71 DeviceType_T aDeviceType);
72
73 // initializer used when loading settings
74 HRESULT init(VirtualBox *aVirtualBox,
75 Medium *aParent,
76 DeviceType_T aDeviceType,
77 const Guid &uuidMachineRegistry,
78 const settings::Medium &data,
79 const Utf8Str &strMachineFolder);
80
81 // initializer for host floppy/DVD
82 HRESULT init(VirtualBox *aVirtualBox,
83 DeviceType_T aDeviceType,
84 const Utf8Str &aLocation,
85 const Utf8Str &aDescription = Utf8Str::Empty);
86
87 void uninit();
88
89 void i_deparent();
90 void i_setParent(const ComObjPtr<Medium> &pParent);
91
92 // unsafe methods for internal purposes only (ensure there is
93 // a caller and a read lock before calling them!)
94 const ComObjPtr<Medium>& i_getParent() const;
95 const MediaList& i_getChildren() const;
96
97 const Guid& i_getId() const;
98 MediumState_T i_getState() const;
99 MediumVariant_T i_getVariant() const;
100 bool i_isHostDrive() const;
101 const Utf8Str& i_getLocationFull() const;
102 const Utf8Str& i_getFormat() const;
103 const ComObjPtr<MediumFormat> & i_getMediumFormat() const;
104 bool i_isMediumFormatFile() const;
105 uint64_t i_getSize() const;
106 DeviceType_T i_getDeviceType() const;
107 MediumType_T i_getType() const;
108 Utf8Str i_getName();
109
110 /* handles caller/locking itself */
111 bool i_addRegistry(const Guid& id, bool fRecurse);
112 /* handles caller/locking itself */
113 bool i_removeRegistry(const Guid& id, bool fRecurse);
114 bool i_isInRegistry(const Guid& id);
115 bool i_getFirstRegistryMachineId(Guid &uuid) const;
116 void i_markRegistriesModified();
117
118 HRESULT i_setPropertyDirect(const Utf8Str &aName, const Utf8Str &aValue);
119
120 HRESULT i_addBackReference(const Guid &aMachineId,
121 const Guid &aSnapshotId = Guid::Empty);
122 HRESULT i_removeBackReference(const Guid &aMachineId,
123 const Guid &aSnapshotId = Guid::Empty);
124
125
126 const Guid* i_getFirstMachineBackrefId() const;
127 const Guid* i_getAnyMachineBackref() const;
128 const Guid* i_getFirstMachineBackrefSnapshotId() const;
129 size_t i_getMachineBackRefCount() const;
130
131#ifdef DEBUG
132 void i_dumpBackRefs();
133#endif
134
135 HRESULT i_updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
136
137 ComObjPtr<Medium> i_getBase(uint32_t *aLevel = NULL);
138
139 bool i_isReadOnly();
140 void i_updateId(const Guid &id);
141
142 HRESULT i_saveSettings(settings::Medium &data,
143 const Utf8Str &strHardDiskFolder);
144
145 HRESULT i_createMediumLockList(bool fFailIfInaccessible,
146 bool fMediumLockWrite,
147 Medium *pToBeParent,
148 MediumLockList &mediumLockList);
149
150 HRESULT i_createDiffStorage(ComObjPtr<Medium> &aTarget,
151 MediumVariant_T aVariant,
152 MediumLockList *pMediumLockList,
153 ComObjPtr<Progress> *aProgress,
154 bool aWait);
155 Utf8Str i_getPreferredDiffFormat();
156
157 HRESULT i_close(AutoCaller &autoCaller);
158 HRESULT i_unlockRead(MediumState_T *aState);
159 HRESULT i_unlockWrite(MediumState_T *aState);
160 HRESULT i_deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait);
161 HRESULT i_markForDeletion();
162 HRESULT i_unmarkForDeletion();
163 HRESULT i_markLockedForDeletion();
164 HRESULT i_unmarkLockedForDeletion();
165
166 HRESULT i_queryPreferredMergeDirection(const ComObjPtr<Medium> &pOther,
167 bool &fMergeForward);
168
169 HRESULT i_prepareMergeTo(const ComObjPtr<Medium> &pTarget,
170 const Guid *aMachineId,
171 const Guid *aSnapshotId,
172 bool fLockMedia,
173 bool &fMergeForward,
174 ComObjPtr<Medium> &pParentForTarget,
175 MediumLockList * &aChildrenToReparent,
176 MediumLockList * &aMediumLockList);
177 HRESULT i_mergeTo(const ComObjPtr<Medium> &pTarget,
178 bool fMergeForward,
179 const ComObjPtr<Medium> &pParentForTarget,
180 MediumLockList *aChildrenToReparent,
181 MediumLockList *aMediumLockList,
182 ComObjPtr<Progress> *aProgress,
183 bool aWait);
184 void i_cancelMergeTo(MediumLockList *aChildrenToReparent,
185 MediumLockList *aMediumLockList);
186
187 HRESULT i_fixParentUuidOfChildren(MediumLockList *pChildrenToReparent);
188
189 HRESULT i_exportFile(const char *aFilename,
190 const ComObjPtr<MediumFormat> &aFormat,
191 MediumVariant_T aVariant,
192 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
193 const ComObjPtr<Progress> &aProgress);
194 HRESULT i_importFile(const char *aFilename,
195 const ComObjPtr<MediumFormat> &aFormat,
196 MediumVariant_T aVariant,
197 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
198 const ComObjPtr<Medium> &aParent,
199 const ComObjPtr<Progress> &aProgress);
200
201 HRESULT i_cloneToEx(const ComObjPtr<Medium> &aTarget, ULONG aVariant,
202 const ComObjPtr<Medium> &aParent, IProgress **aProgress,
203 uint32_t idxSrcImageSame, uint32_t idxDstImageSame);
204
205private:
206
207 // wrapped IMedium properties
208 HRESULT getId(com::Guid &aId);
209 HRESULT getDescription(com::Utf8Str &aDescription);
210 HRESULT setDescription(const com::Utf8Str &aDescription);
211 HRESULT getState(MediumState_T *aState);
212 HRESULT getVariant(std::vector<MediumVariant_T> &aVariant);
213 HRESULT getLocation(com::Utf8Str &aLocation);
214 HRESULT getName(com::Utf8Str &aName);
215 HRESULT getDeviceType(DeviceType_T *aDeviceType);
216 HRESULT getHostDrive(BOOL *aHostDrive);
217 HRESULT getSize(LONG64 *aSize);
218 HRESULT getFormat(com::Utf8Str &aFormat);
219 HRESULT getMediumFormat(ComPtr<IMediumFormat> &aMediumFormat);
220 HRESULT getType(MediumType_T *aType);
221 HRESULT setType(MediumType_T aType);
222 HRESULT getAllowedTypes(std::vector<MediumType_T> &aAllowedTypes);
223 HRESULT getParent(AutoCaller &autoCaller, ComPtr<IMedium> &aParent);
224 HRESULT getChildren(AutoCaller &autoCaller, std::vector<ComPtr<IMedium> > &aChildren);
225 HRESULT getBase(AutoCaller &autoCaller, ComPtr<IMedium> &aBase);
226 HRESULT getReadOnly(BOOL *aReadOnly);
227 HRESULT getLogicalSize(LONG64 *aLogicalSize);
228 HRESULT getAutoReset(BOOL *aAutoReset);
229 HRESULT setAutoReset(BOOL aAutoReset);
230 HRESULT getLastAccessError(com::Utf8Str &aLastAccessError);
231 HRESULT getMachineIds(std::vector<com::Guid> &aMachineIds);
232
233 // wrapped IMedium methods
234 HRESULT setIds(AutoCaller &aAutoCaller,
235 BOOL aSetImageId,
236 const com::Guid &aImageId,
237 BOOL aSetParentId,
238 const com::Guid &aParentId);
239 HRESULT refreshState(AutoCaller &aAutoCaller,
240 MediumState_T *aState);
241 HRESULT getSnapshotIds(const com::Guid &aMachineId,
242 std::vector<com::Guid> &aSnapshotIds);
243 HRESULT lockRead(ComPtr<IToken> &aToken);
244 HRESULT lockWrite(ComPtr<IToken> &aToken);
245 HRESULT close(AutoCaller &aAutoCaller);
246 HRESULT getProperty(const com::Utf8Str &aName,
247 com::Utf8Str &aValue);
248 HRESULT setProperty(const com::Utf8Str &aName,
249 const com::Utf8Str &aValue);
250 HRESULT getProperties(const com::Utf8Str &aNames,
251 std::vector<com::Utf8Str> &aReturnNames,
252 std::vector<com::Utf8Str> &aReturnValues);
253 HRESULT setProperties(const std::vector<com::Utf8Str> &aNames,
254 const std::vector<com::Utf8Str> &aValues);
255 HRESULT createBaseStorage(LONG64 aLogicalSize,
256 const std::vector<MediumVariant_T> &aVariant,
257 ComPtr<IProgress> &aProgress);
258 HRESULT deleteStorage(ComPtr<IProgress> &aProgress);
259 HRESULT createDiffStorage(const ComPtr<IMedium> &aTarget,
260 const std::vector<MediumVariant_T> &aVariant,
261 ComPtr<IProgress> &aProgress);
262 HRESULT mergeTo(const ComPtr<IMedium> &aTarget,
263 ComPtr<IProgress> &aProgress);
264 HRESULT cloneTo(const ComPtr<IMedium> &aTarget,
265 const std::vector<MediumVariant_T> &aVariant,
266 const ComPtr<IMedium> &aParent,
267 ComPtr<IProgress> &aProgress);
268 HRESULT cloneToBase(const ComPtr<IMedium> &aTarget,
269 const std::vector<MediumVariant_T> &aVariant,
270 ComPtr<IProgress> &aProgress);
271 HRESULT setLocation(const com::Utf8Str &aLocation,
272 ComPtr<IProgress> &aProgress);
273 HRESULT compact(ComPtr<IProgress> &aProgress);
274 HRESULT resize(LONG64 aLogicalSize,
275 ComPtr<IProgress> &aProgress);
276 HRESULT reset(ComPtr<IProgress> &aProgress);
277
278 // Private internal nmethods
279 HRESULT i_queryInfo(bool fSetImageId, bool fSetParentId, AutoCaller &autoCaller);
280 HRESULT i_canClose();
281 HRESULT i_unregisterWithVirtualBox();
282 HRESULT i_setStateError();
283 HRESULT i_setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
284 HRESULT i_setFormat(const Utf8Str &aFormat);
285 VDTYPE i_convertDeviceType();
286 DeviceType_T i_convertToDeviceType(VDTYPE enmType);
287 Utf8Str i_vdError(int aVRC);
288
289 bool i_isPropertyForFilter(const com::Utf8Str &aName);
290
291 static DECLCALLBACK(void) i_vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
292 const char *pszFormat, va_list va);
293 static DECLCALLBACK(bool) i_vdConfigAreKeysValid(void *pvUser,
294 const char *pszzValid);
295 static DECLCALLBACK(int) i_vdConfigQuerySize(void *pvUser, const char *pszName,
296 size_t *pcbValue);
297 static DECLCALLBACK(int) i_vdConfigQuery(void *pvUser, const char *pszName,
298 char *pszValue, size_t cchValue);
299 static DECLCALLBACK(int) i_vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
300 static DECLCALLBACK(int) i_vdTcpSocketDestroy(VDSOCKET Sock);
301 static DECLCALLBACK(int) i_vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
302 static DECLCALLBACK(int) i_vdTcpClientClose(VDSOCKET Sock);
303 static DECLCALLBACK(bool) i_vdTcpIsClientConnected(VDSOCKET Sock);
304 static DECLCALLBACK(int) i_vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
305 static DECLCALLBACK(int) i_vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
306 static DECLCALLBACK(int) i_vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
307 static DECLCALLBACK(int) i_vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
308 static DECLCALLBACK(int) i_vdTcpFlush(VDSOCKET Sock);
309 static DECLCALLBACK(int) i_vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
310 static DECLCALLBACK(int) i_vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
311 static DECLCALLBACK(int) i_vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
312
313 class Task;
314 class CreateBaseTask;
315 class CreateDiffTask;
316 class CloneTask;
317 class CompactTask;
318 class ResizeTask;
319 class ResetTask;
320 class DeleteTask;
321 class MergeTask;
322 class ExportTask;
323 class ImportTask;
324 friend class Task;
325 friend class CreateBaseTask;
326 friend class CreateDiffTask;
327 friend class CloneTask;
328 friend class CompactTask;
329 friend class ResizeTask;
330 friend class ResetTask;
331 friend class DeleteTask;
332 friend class MergeTask;
333 friend class ExportTask;
334 friend class ImportTask;
335
336 HRESULT i_startThread(Medium::Task *pTask);
337 HRESULT i_runNow(Medium::Task *pTask);
338
339 HRESULT i_taskCreateBaseHandler(Medium::CreateBaseTask &task);
340 HRESULT i_taskCreateDiffHandler(Medium::CreateDiffTask &task);
341 HRESULT i_taskMergeHandler(Medium::MergeTask &task);
342 HRESULT i_taskCloneHandler(Medium::CloneTask &task);
343 HRESULT i_taskDeleteHandler(Medium::DeleteTask &task);
344 HRESULT i_taskResetHandler(Medium::ResetTask &task);
345 HRESULT i_taskCompactHandler(Medium::CompactTask &task);
346 HRESULT i_taskResizeHandler(Medium::ResizeTask &task);
347 HRESULT i_taskExportHandler(Medium::ExportTask &task);
348 HRESULT i_taskImportHandler(Medium::ImportTask &task);
349
350 struct Data; // opaque data struct, defined in MediumImpl.cpp
351 Data *m;
352};
353
354#endif /* ____H_MEDIUMIMPL */
355
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