VirtualBox

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

Last change on this file since 48112 was 44528, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.1 KB
Line 
1/* $Id: MediumImpl.h 44528 2013-02-04 14:27:54Z 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
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
74 // initializer for opening existing media
75 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
76 HRESULT init(VirtualBox *aVirtualBox,
77 const Utf8Str &aLocation,
78 HDDOpenMode enOpenMode,
79 bool fForceNewUuid,
80 DeviceType_T aDeviceType);
81
82 // initializer used when loading settings
83 HRESULT init(VirtualBox *aVirtualBox,
84 Medium *aParent,
85 DeviceType_T aDeviceType,
86 const Guid &uuidMachineRegistry,
87 const settings::Medium &data,
88 const Utf8Str &strMachineFolder);
89
90 // initializer for host floppy/DVD
91 HRESULT init(VirtualBox *aVirtualBox,
92 DeviceType_T aDeviceType,
93 const Utf8Str &aLocation,
94 const Utf8Str &aDescription = Utf8Str::Empty);
95
96 void uninit();
97
98 void deparent();
99 void setParent(const ComObjPtr<Medium> &pParent);
100
101 // IMedium properties
102 STDMETHOD(COMGETTER(Id))(BSTR *aId);
103 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
104 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
105 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
106 STDMETHOD(COMGETTER(Variant))(ComSafeArrayOut(MediumVariant_T, aVariant));
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))(LONG64 *aSize);
113 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
114 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
115 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
116 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
117 STDMETHOD(COMGETTER(AllowedTypes))(ComSafeArrayOut(MediumType_T, aAllowedTypes));
118 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
119 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
120 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
121 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
122 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
123 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
124 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
125 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
126 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
127
128 // IMedium methods
129 STDMETHOD(SetIds)(BOOL aSetImageId, IN_BSTR aImageId,
130 BOOL aSetParentId, IN_BSTR aParentId);
131 STDMETHOD(RefreshState)(MediumState_T *aState);
132 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
133 ComSafeArrayOut(BSTR, aSnapshotIds));
134 STDMETHOD(LockRead)(MediumState_T *aState);
135 STDMETHOD(UnlockRead)(MediumState_T *aState);
136 STDMETHOD(LockWrite)(MediumState_T *aState);
137 STDMETHOD(UnlockWrite)(MediumState_T *aState);
138 STDMETHOD(Close)();
139 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
140 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
141 STDMETHOD(GetProperties)(IN_BSTR aNames,
142 ComSafeArrayOut(BSTR, aReturnNames),
143 ComSafeArrayOut(BSTR, aReturnValues));
144 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
145 ComSafeArrayIn(IN_BSTR, aValues));
146 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
147 ComSafeArrayIn(MediumVariant_T, aVariant),
148 IProgress **aProgress);
149 STDMETHOD(DeleteStorage)(IProgress **aProgress);
150 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
151 ComSafeArrayIn(MediumVariant_T, aVariant),
152 IProgress **aProgress);
153 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
154 STDMETHOD(CloneTo)(IMedium *aTarget, ComSafeArrayIn(MediumVariant_T, aVariant),
155 IMedium *aParent, IProgress **aProgress);
156 STDMETHOD(CloneToBase)(IMedium *aTarget, ComSafeArrayIn(MediumVariant_T, aVariant),
157 IProgress **aProgress);
158 STDMETHOD(Compact)(IProgress **aProgress);
159 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
160 STDMETHOD(Reset)(IProgress **aProgress);
161
162 // unsafe methods for internal purposes only (ensure there is
163 // a caller and a read lock before calling them!)
164 const ComObjPtr<Medium>& getParent() const;
165 const MediaList& getChildren() const;
166
167 const Guid& getId() const;
168 MediumState_T getState() const;
169 MediumVariant_T getVariant() const;
170 bool isHostDrive() const;
171 const Utf8Str& getLocationFull() const;
172 const Utf8Str& getFormat() const;
173 const ComObjPtr<MediumFormat> & getMediumFormat() const;
174 bool isMediumFormatFile() const;
175 uint64_t getSize() const;
176 DeviceType_T getDeviceType() const;
177 MediumType_T getType() const;
178 Utf8Str getName();
179
180 /* handles caller/locking itself */
181 bool addRegistry(const Guid& id, bool fRecurse);
182 /* handles caller/locking itself */
183 bool removeRegistry(const Guid& id, bool fRecurse);
184 bool isInRegistry(const Guid& id);
185 bool getFirstRegistryMachineId(Guid &uuid) const;
186 void markRegistriesModified();
187
188 HRESULT setPropertyDirect(const Utf8Str &aName, const Utf8Str &aValue);
189
190 HRESULT addBackReference(const Guid &aMachineId,
191 const Guid &aSnapshotId = Guid::Empty);
192 HRESULT removeBackReference(const Guid &aMachineId,
193 const Guid &aSnapshotId = Guid::Empty);
194
195
196 const Guid* getFirstMachineBackrefId() const;
197 const Guid* getAnyMachineBackref() const;
198 const Guid* getFirstMachineBackrefSnapshotId() const;
199 size_t getMachineBackRefCount() const;
200
201#ifdef DEBUG
202 void dumpBackRefs();
203#endif
204
205 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
206
207 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
208
209 bool isReadOnly();
210 void updateId(const Guid &id);
211
212 HRESULT saveSettings(settings::Medium &data,
213 const Utf8Str &strHardDiskFolder);
214
215 HRESULT createMediumLockList(bool fFailIfInaccessible,
216 bool fMediumLockWrite,
217 Medium *pToBeParent,
218 MediumLockList &mediumLockList);
219
220 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
221 MediumVariant_T aVariant,
222 MediumLockList *pMediumLockList,
223 ComObjPtr<Progress> *aProgress,
224 bool aWait);
225 Utf8Str getPreferredDiffFormat();
226
227 HRESULT close(AutoCaller &autoCaller);
228 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait);
229 HRESULT markForDeletion();
230 HRESULT unmarkForDeletion();
231 HRESULT markLockedForDeletion();
232 HRESULT unmarkLockedForDeletion();
233
234 HRESULT queryPreferredMergeDirection(const ComObjPtr<Medium> &pOther,
235 bool &fMergeForward);
236
237 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
238 const Guid *aMachineId,
239 const Guid *aSnapshotId,
240 bool fLockMedia,
241 bool &fMergeForward,
242 ComObjPtr<Medium> &pParentForTarget,
243 MediaList &aChildrenToReparent,
244 MediumLockList * &aMediumLockList);
245 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
246 bool fMergeForward,
247 const ComObjPtr<Medium> &pParentForTarget,
248 const MediaList &aChildrenToReparent,
249 MediumLockList *aMediumLockList,
250 ComObjPtr<Progress> *aProgress,
251 bool aWait);
252 void cancelMergeTo(const MediaList &aChildrenToReparent,
253 MediumLockList *aMediumLockList);
254
255 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
256
257 HRESULT exportFile(const char *aFilename,
258 const ComObjPtr<MediumFormat> &aFormat,
259 MediumVariant_T aVariant,
260 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
261 const ComObjPtr<Progress> &aProgress);
262 HRESULT importFile(const char *aFilename,
263 const ComObjPtr<MediumFormat> &aFormat,
264 MediumVariant_T aVariant,
265 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
266 const ComObjPtr<Medium> &aParent,
267 const ComObjPtr<Progress> &aProgress);
268
269 HRESULT cloneToEx(const ComObjPtr<Medium> &aTarget, ULONG aVariant,
270 const ComObjPtr<Medium> &aParent, IProgress **aProgress,
271 uint32_t idxSrcImageSame, uint32_t idxDstImageSame);
272
273private:
274
275 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
276
277 HRESULT canClose();
278 HRESULT unregisterWithVirtualBox();
279
280 HRESULT setStateError();
281
282 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
283 HRESULT setFormat(const Utf8Str &aFormat);
284
285 VDTYPE convertDeviceType();
286 DeviceType_T convertToDeviceType(VDTYPE enmType);
287
288 Utf8Str vdError(int aVRC);
289
290 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
291 const char *pszFormat, va_list va);
292
293 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
294 const char *pszzValid);
295 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
296 size_t *pcbValue);
297 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
298 char *pszValue, size_t cchValue);
299
300 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
301 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
302 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
303 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
304 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
305 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
306 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
307 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
308 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
309 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
310 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
311 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
312 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
313
314 class Task;
315 class CreateBaseTask;
316 class CreateDiffTask;
317 class CloneTask;
318 class CompactTask;
319 class ResizeTask;
320 class ResetTask;
321 class DeleteTask;
322 class MergeTask;
323 class ExportTask;
324 class ImportTask;
325 friend class Task;
326 friend class CreateBaseTask;
327 friend class CreateDiffTask;
328 friend class CloneTask;
329 friend class CompactTask;
330 friend class ResizeTask;
331 friend class ResetTask;
332 friend class DeleteTask;
333 friend class MergeTask;
334 friend class ExportTask;
335 friend class ImportTask;
336
337 HRESULT startThread(Medium::Task *pTask);
338 HRESULT runNow(Medium::Task *pTask);
339
340 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
341 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
342 HRESULT taskMergeHandler(Medium::MergeTask &task);
343 HRESULT taskCloneHandler(Medium::CloneTask &task);
344 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
345 HRESULT taskResetHandler(Medium::ResetTask &task);
346 HRESULT taskCompactHandler(Medium::CompactTask &task);
347 HRESULT taskResizeHandler(Medium::ResizeTask &task);
348 HRESULT taskExportHandler(Medium::ExportTask &task);
349 HRESULT taskImportHandler(Medium::ImportTask &task);
350
351 struct Data; // opaque data struct, defined in MediumImpl.cpp
352 Data *m;
353};
354
355#endif /* ____H_MEDIUMIMPL */
356
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