VirtualBox

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

Last change on this file since 37831 was 37831, checked in by vboxsync, 13 years ago

Main/Medium: added new attribute for getting the possible medium types, not implemented right now

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.7 KB
Line 
1/* $Id: MediumImpl.h 37831 2011-07-08 10:10:41Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2011 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 GuidList *pllRegistriesThatNeedSaving);
74
75 // initializer for opening existing media
76 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
77 HRESULT init(VirtualBox *aVirtualBox,
78 const Utf8Str &aLocation,
79 HDDOpenMode enOpenMode,
80 bool fForceNewUuid,
81 DeviceType_T aDeviceType);
82
83 // initializer used when loading settings
84 HRESULT init(VirtualBox *aVirtualBox,
85 Medium *aParent,
86 DeviceType_T aDeviceType,
87 const Guid &uuidMachineRegistry,
88 const settings::Medium &data,
89 const Utf8Str &strMachineFolder);
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))(ULONG *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(AllowedTypes))(ComSafeArrayOut(MediumType_T, aAllowedTypes));
119 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
120 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
121 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
122 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
123 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
124 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
125 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
126 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
127 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
128
129 // IMedium methods
130 STDMETHOD(SetIDs)(BOOL aSetImageId, IN_BSTR aImageId,
131 BOOL aSetParentId, IN_BSTR aParentId);
132 STDMETHOD(RefreshState)(MediumState_T *aState);
133 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
134 ComSafeArrayOut(BSTR, aSnapshotIds));
135 STDMETHOD(LockRead)(MediumState_T *aState);
136 STDMETHOD(UnlockRead)(MediumState_T *aState);
137 STDMETHOD(LockWrite)(MediumState_T *aState);
138 STDMETHOD(UnlockWrite)(MediumState_T *aState);
139 STDMETHOD(Close)();
140 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
141 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
142 STDMETHOD(GetProperties)(IN_BSTR aNames,
143 ComSafeArrayOut(BSTR, aReturnNames),
144 ComSafeArrayOut(BSTR, aReturnValues));
145 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
146 ComSafeArrayIn(IN_BSTR, aValues));
147 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
148 ULONG aVariant,
149 IProgress **aProgress);
150 STDMETHOD(DeleteStorage)(IProgress **aProgress);
151 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
152 ULONG aVariant,
153 IProgress **aProgress);
154 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
155 STDMETHOD(CloneTo)(IMedium *aTarget, ULONG aVariant,
156 IMedium *aParent, IProgress **aProgress);
157 STDMETHOD(Compact)(IProgress **aProgress);
158 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
159 STDMETHOD(Reset)(IProgress **aProgress);
160
161 // unsafe methods for internal purposes only (ensure there is
162 // a caller and a read lock before calling them!)
163 const ComObjPtr<Medium>& getParent() const;
164 const MediaList& getChildren() const;
165
166 const Guid& getId() const;
167 MediumState_T getState() const;
168 MediumVariant_T getVariant() const;
169 bool isHostDrive() const;
170 const Utf8Str& getLocationFull() const;
171 const Utf8Str& getFormat() const;
172 const ComObjPtr<MediumFormat> & getMediumFormat() const;
173 bool isMediumFormatFile() const;
174 uint64_t getSize() const;
175 DeviceType_T getDeviceType() const;
176 MediumType_T getType() const;
177 Utf8Str getName();
178
179 bool addRegistry(const Guid& id, bool fRecurse);
180private:
181 void addRegistryImpl(const Guid& id, bool fRecurse);
182public:
183 bool removeRegistry(const Guid& id, bool fRecurse);
184 bool isInRegistry(const Guid& id);
185 bool getFirstRegistryMachineId(Guid &uuid) const;
186 HRESULT addToRegistryIDList(GuidList &llRegistryIDs);
187
188 HRESULT addBackReference(const Guid &aMachineId,
189 const Guid &aSnapshotId = Guid::Empty);
190 HRESULT removeBackReference(const Guid &aMachineId,
191 const Guid &aSnapshotId = Guid::Empty);
192
193 const Guid* getFirstMachineBackrefId() const;
194 const Guid* getAnyMachineBackref() const;
195 const Guid* getFirstMachineBackrefSnapshotId() const;
196 size_t getMachineBackRefCount() const;
197
198#ifdef DEBUG
199 void dumpBackRefs();
200#endif
201
202 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
203
204 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
205
206 bool isReadOnly();
207
208 HRESULT saveSettings(settings::Medium &data,
209 const Utf8Str &strHardDiskFolder);
210
211 HRESULT createMediumLockList(bool fFailIfInaccessible,
212 bool fMediumLockWrite,
213 Medium *pToBeParent,
214 MediumLockList &mediumLockList);
215
216 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
217 MediumVariant_T aVariant,
218 MediumLockList *pMediumLockList,
219 ComObjPtr<Progress> *aProgress,
220 bool aWait,
221 GuidList *pllRegistriesThatNeedSaving);
222 Utf8Str getPreferredDiffFormat();
223
224 HRESULT close(GuidList *pllRegistriesThatNeedSaving, AutoCaller &autoCaller);
225 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, GuidList *pllRegistriesThatNeedSaving);
226 HRESULT markForDeletion();
227 HRESULT unmarkForDeletion();
228 HRESULT markLockedForDeletion();
229 HRESULT unmarkLockedForDeletion();
230
231 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
232 const Guid *aMachineId,
233 const Guid *aSnapshotId,
234 bool fLockMedia,
235 bool &fMergeForward,
236 ComObjPtr<Medium> &pParentForTarget,
237 MediaList &aChildrenToReparent,
238 MediumLockList * &aMediumLockList);
239 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
240 bool fMergeForward,
241 const ComObjPtr<Medium> &pParentForTarget,
242 const MediaList &aChildrenToReparent,
243 MediumLockList *aMediumLockList,
244 ComObjPtr<Progress> *aProgress,
245 bool aWait,
246 GuidList *pllRegistriesThatNeedSaving);
247 void cancelMergeTo(const MediaList &aChildrenToReparent,
248 MediumLockList *aMediumLockList);
249
250 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
251
252 HRESULT exportFile(const char *aFilename,
253 const ComObjPtr<MediumFormat> &aFormat,
254 MediumVariant_T aVariant,
255 void *aVDImageIOCallbacks, void *aVDImageIOUser,
256 const ComObjPtr<Progress> &aProgress);
257 HRESULT importFile(const char *aFilename,
258 const ComObjPtr<MediumFormat> &aFormat,
259 MediumVariant_T aVariant,
260 void *aVDImageIOCallbacks, void *aVDImageIOUser,
261 const ComObjPtr<Medium> &aParent,
262 const ComObjPtr<Progress> &aProgress);
263
264private:
265
266 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
267
268 HRESULT canClose();
269 HRESULT unregisterWithVirtualBox(GuidList *pllRegistriesThatNeedSaving);
270
271 HRESULT setStateError();
272
273 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
274 HRESULT setFormat(const Utf8Str &aFormat);
275
276 VDTYPE convertDeviceType();
277 DeviceType_T convertToDeviceType(VDTYPE enmType);
278
279 Utf8Str vdError(int aVRC);
280
281 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
282 const char *pszFormat, va_list va);
283
284 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
285 const char *pszzValid);
286 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
287 size_t *pcbValue);
288 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
289 char *pszValue, size_t cchValue);
290
291 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
292 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
293 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
294 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
295 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
296 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
297 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
298 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
299 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
300 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
301 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
302 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
303 static DECLCALLBACK(int) 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 startThread(Medium::Task *pTask);
329 HRESULT runNow(Medium::Task *pTask, GuidList *pllRegistriesThatNeedSaving);
330
331 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
332 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
333 HRESULT taskMergeHandler(Medium::MergeTask &task);
334 HRESULT taskCloneHandler(Medium::CloneTask &task);
335 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
336 HRESULT taskResetHandler(Medium::ResetTask &task);
337 HRESULT taskCompactHandler(Medium::CompactTask &task);
338 HRESULT taskResizeHandler(Medium::ResizeTask &task);
339 HRESULT taskExportHandler(Medium::ExportTask &task);
340 HRESULT 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