VirtualBox

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

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

Main: Add possibility to add medium properties for filters in a way wihtout changing any interfaces (for 4.3) for now

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