VirtualBox

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

Last change on this file since 49795 was 49795, checked in by vboxsync, 11 years ago

6813 - stage 3 rev 1

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