VirtualBox

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

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

Main/Medium: new method exportFile which allows to export a medium using any VBoxHDD VFS implementation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.4 KB
Line 
1/* $Id: MediumImpl.h 32695 2010-09-22 11:16:48Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2010 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/VBoxHDD.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 COM_INTERFACE_ENTRY(ISupportErrorInfo)
54 COM_INTERFACE_ENTRY(IMedium)
55 COM_INTERFACE_ENTRY(IDispatch)
56 END_COM_MAP()
57
58 DECLARE_EMPTY_CTOR_DTOR(Medium)
59
60 HRESULT FinalConstruct();
61 void FinalRelease();
62
63 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
64 // have to use a special enum for the overloaded init() below;
65 // can't use AccessMode_T from XIDL because that's mapped to an int
66 // and would be ambiguous
67
68 // public initializer/uninitializer for internal purposes only
69
70 // initializer to create empty medium (VirtualBox::CreateHardDisk())
71 HRESULT init(VirtualBox *aVirtualBox,
72 const Utf8Str &aFormat,
73 const Utf8Str &aLocation,
74 const Guid &uuidMachineRegistry,
75 bool *pfNeedsGlobalSaveSettings);
76
77 // initializer for opening existing media
78 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
79 HRESULT init(VirtualBox *aVirtualBox,
80 const Utf8Str &aLocation,
81 HDDOpenMode enOpenMode,
82 DeviceType_T aDeviceType);
83
84 // initializer used when loading settings
85 HRESULT init(VirtualBox *aVirtualBox,
86 Medium *aParent,
87 DeviceType_T aDeviceType,
88 const Guid &uuidMachineRegistry,
89 const settings::Medium &data);
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))(MediumVariant_T *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(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 MediumVariant_T aVariant,
148 IProgress **aProgress);
149 STDMETHOD(DeleteStorage)(IProgress **aProgress);
150 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
151 MediumVariant_T aVariant,
152 IProgress **aProgress);
153 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
154 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
155 IMedium *aParent, IProgress **aProgress);
156 STDMETHOD(Compact)(IProgress **aProgress);
157 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
158 STDMETHOD(Reset)(IProgress **aProgress);
159
160 // unsafe methods for internal purposes only (ensure there is
161 // a caller and a read lock before calling them!)
162 const ComObjPtr<Medium>& getParent() const;
163 const MediaList& getChildren() const;
164
165 const Guid& getRegistryMachineId() const;
166
167 const Guid& getId() const;
168 MediumState_T getState() const;
169 MediumVariant_T getVariant() const;
170 bool isHostDrive() const;
171 const Utf8Str& getLocation() const;
172 const Utf8Str& getLocationFull() const;
173 const Utf8Str& getFormat() const;
174 const ComObjPtr<MediumFormat> & getMediumFormat() const;
175 uint64_t getSize() const;
176 DeviceType_T getDeviceType() const;
177 MediumType_T getType() const;
178 Utf8Str getName();
179
180 void setRegistryIdIfFirst(const Guid& id);
181 const Guid& getRegistryId() const;
182
183 HRESULT addBackReference(const Guid &aMachineId,
184 const Guid &aSnapshotId = Guid::Empty);
185 HRESULT removeBackReference(const Guid &aMachineId,
186 const Guid &aSnapshotId = Guid::Empty);
187
188 const Guid* getFirstMachineBackrefId() const;
189 const Guid* getFirstMachineBackrefSnapshotId() const;
190
191#ifdef DEBUG
192 void dumpBackRefs();
193#endif
194
195 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
196
197 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
198
199 bool isReadOnly();
200
201 HRESULT saveSettings(settings::Medium &data);
202
203 HRESULT compareLocationTo(const Utf8Str &strLocation, int &aResult);
204
205 HRESULT createMediumLockList(bool fFailIfInaccessible,
206 bool fMediumLockWrite,
207 Medium *pToBeParent,
208 MediumLockList &mediumLockList);
209
210 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
211 MediumVariant_T aVariant,
212 MediumLockList *pMediumLockList,
213 ComObjPtr<Progress> *aProgress,
214 bool aWait,
215 bool *pfNeedsGlobalSaveSettings);
216
217 HRESULT close(bool *pfNeedsGlobalSaveSettings, AutoCaller &autoCaller);
218 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsGlobalSaveSettings);
219 HRESULT markForDeletion();
220 HRESULT unmarkForDeletion();
221 HRESULT markLockedForDeletion();
222 HRESULT unmarkLockedForDeletion();
223
224 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
225 const Guid *aMachineId,
226 const Guid *aSnapshotId,
227 bool fLockMedia,
228 bool &fMergeForward,
229 ComObjPtr<Medium> &pParentForTarget,
230 MediaList &aChildrenToReparent,
231 MediumLockList * &aMediumLockList);
232 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
233 bool fMergeForward,
234 const ComObjPtr<Medium> &pParentForTarget,
235 const MediaList &aChildrenToReparent,
236 MediumLockList *aMediumLockList,
237 ComObjPtr<Progress> *aProgress,
238 bool aWait,
239 bool *pfNeedsGlobalSaveSettings);
240 void cancelMergeTo(const MediaList &aChildrenToReparent,
241 MediumLockList *aMediumLockList);
242
243 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
244
245 /**
246 * Used by IAppliance to export disk images.
247 *
248 * @param aFilename Filename to create (UTF8).
249 * @param aFormat Which medium format to use.
250 * @param aVariant Which exact image format variant to use.
251 * @param aVDImageIOCallbacks Pointer to the callback table for a
252 * VDINTERFACEIO interface. May be NULL.
253 * @param aVDImageIOUser Opaque data for the callbacks.
254 * @param aProgress Progress object to use.
255 * @return
256 */
257 HRESULT exportFile(const char *aFilename,
258 ComObjPtr<MediumFormat> aFormat,
259 MediumVariant_T aVariant,
260 void *aVDImageIOCallbacks, void *aVDImageIOUser,
261 ComObjPtr<Progress> aProgress);
262
263 /** Returns a preferred format for a differencing hard disk. */
264 Utf8Str getPreferredDiffFormat();
265
266private:
267
268 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
269
270 HRESULT canClose();
271 HRESULT unregisterWithVirtualBox(bool *pfNeedsGlobalSaveSettings);
272
273 HRESULT setStateError();
274
275 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
276 HRESULT setFormat(const Utf8Str &aFormat);
277
278 Utf8Str vdError(int aVRC);
279
280 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
281 const char *pszFormat, va_list va);
282
283 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
284 const char *pszzValid);
285 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
286 size_t *pcbValue);
287 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
288 char *pszValue, size_t cchValue);
289
290 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
291 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
292 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
293 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
294 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
295 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
296 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
297 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
298 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
299 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
300 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
301 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
302 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
303
304 class Task;
305 class CreateBaseTask;
306 class CreateDiffTask;
307 class CloneTask;
308 class CompactTask;
309 class ResizeTask;
310 class ResetTask;
311 class DeleteTask;
312 class MergeTask;
313 class ExportTask;
314 friend class Task;
315 friend class CreateBaseTask;
316 friend class CreateDiffTask;
317 friend class CloneTask;
318 friend class CompactTask;
319 friend class ResizeTask;
320 friend class ResetTask;
321 friend class DeleteTask;
322 friend class MergeTask;
323 friend class ExportTask;
324
325 HRESULT startThread(Medium::Task *pTask);
326 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsGlobalSaveSettings);
327
328 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
329 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
330 HRESULT taskMergeHandler(Medium::MergeTask &task);
331 HRESULT taskCloneHandler(Medium::CloneTask &task);
332 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
333 HRESULT taskResetHandler(Medium::ResetTask &task);
334 HRESULT taskCompactHandler(Medium::CompactTask &task);
335 HRESULT taskResizeHandler(Medium::ResizeTask &task);
336 HRESULT taskExportHandler(Medium::ExportTask &task);
337
338 struct Data; // opaque data struct, defined in MediumImpl.cpp
339 Data *m;
340};
341
342#endif /* ____H_MEDIUMIMPL */
343
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