VirtualBox

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

Last change on this file since 31579 was 31568, checked in by vboxsync, 14 years ago

Main: combine IVirtualBox::openHardDisk(), openDVDImage(), openFloppyImage() into new IVirtualBox::openMedium(); add new IMedium::setImageUUIDs() method for a rare use case of the old openHardDisk(); optimize client code now that code is mostly the same

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1/* $Id: MediumImpl.h 31568 2010-08-11 13:35:59Z 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 bool *pfNeedsSaveSettings);
75
76 // initializer for opening existing media
77 // (VirtualBox::OpenHardDisk/DVD(); Machine::AttachDevice())
78 HRESULT init(VirtualBox *aVirtualBox,
79 const Utf8Str &aLocation,
80 HDDOpenMode enOpenMode,
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 settings::Medium &data);
88
89 // initializer for host floppy/DVD
90 HRESULT init(VirtualBox *aVirtualBox,
91 DeviceType_T aDeviceType,
92 const Utf8Str &aLocation,
93 const Utf8Str &aDescription = Utf8Str::Empty);
94
95 void uninit();
96
97 void deparent();
98 void setParent(const ComObjPtr<Medium> &pParent);
99
100 // IMedium properties
101 STDMETHOD(COMGETTER(Id))(BSTR *aId);
102 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
103 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
104 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
105 STDMETHOD(COMGETTER(Variant))(MediumVariant_T *aVariant);
106 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
107 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
108 STDMETHOD(COMGETTER(Name))(BSTR *aName);
109 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
110 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
111 STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
112 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
113 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
114 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
115 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
116 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
117 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
118 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
119 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
120 STDMETHOD(COMGETTER(LogicalSize))(ULONG64 *aLogicalSize);
121 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
122 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
123 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
124 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
125
126 // IMedium methods
127 STDMETHOD(SetIDs)(BOOL aSetImageId, IN_BSTR aImageId,
128 BOOL aSetParentId, IN_BSTR aParentId);
129 STDMETHOD(RefreshState)(MediumState_T *aState);
130 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
131 ComSafeArrayOut(BSTR, aSnapshotIds));
132 STDMETHOD(LockRead)(MediumState_T *aState);
133 STDMETHOD(UnlockRead)(MediumState_T *aState);
134 STDMETHOD(LockWrite)(MediumState_T *aState);
135 STDMETHOD(UnlockWrite)(MediumState_T *aState);
136 STDMETHOD(Close)();
137 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
138 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
139 STDMETHOD(GetProperties)(IN_BSTR aNames,
140 ComSafeArrayOut(BSTR, aReturnNames),
141 ComSafeArrayOut(BSTR, aReturnValues));
142 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
143 ComSafeArrayIn(IN_BSTR, aValues));
144 STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
145 MediumVariant_T aVariant,
146 IProgress **aProgress);
147 STDMETHOD(DeleteStorage)(IProgress **aProgress);
148 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
149 MediumVariant_T aVariant,
150 IProgress **aProgress);
151 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
152 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
153 IMedium *aParent, IProgress **aProgress);
154 STDMETHOD(Compact)(IProgress **aProgress);
155 STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
156 STDMETHOD(Reset)(IProgress **aProgress);
157
158 // unsafe methods for internal purposes only (ensure there is
159 // a caller and a read lock before calling them!)
160 const ComObjPtr<Medium>& getParent() const;
161 const MediaList& getChildren() const;
162
163 const Guid& getRegistryMachineId() const;
164
165 const Guid& getId() const;
166 MediumState_T getState() const;
167 MediumVariant_T getVariant() const;
168 bool isHostDrive() const;
169 const Utf8Str& getLocation() const;
170 const Utf8Str& getLocationFull() const;
171 const Utf8Str& getFormat() const;
172 const ComObjPtr<MediumFormat> & getMediumFormat() const;
173 uint64_t getSize() const;
174 DeviceType_T getDeviceType() const;
175 MediumType_T getType() const;
176 Utf8Str getName();
177
178 HRESULT addBackReference(const Guid &aMachineId,
179 const Guid &aSnapshotId = Guid::Empty);
180 HRESULT removeBackReference(const Guid &aMachineId,
181 const Guid &aSnapshotId = Guid::Empty);
182
183 const Guid* getFirstMachineBackrefId() const;
184 const Guid* getFirstMachineBackrefSnapshotId() const;
185
186#ifdef DEBUG
187 void dumpBackRefs();
188#endif
189
190 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
191
192 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
193
194 bool isReadOnly();
195
196 HRESULT saveSettings(settings::Medium &data);
197
198 HRESULT compareLocationTo(const Utf8Str &strLocation, int &aResult);
199
200 HRESULT createMediumLockList(bool fFailIfInaccessible,
201 bool fMediumLockWrite,
202 Medium *pToBeParent,
203 MediumLockList &mediumLockList);
204
205 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
206 MediumVariant_T aVariant,
207 MediumLockList *pMediumLockList,
208 ComObjPtr<Progress> *aProgress,
209 bool aWait,
210 bool *pfNeedsSaveSettings);
211
212 HRESULT close(bool *pfNeedsSaveSettings, AutoCaller &autoCaller);
213 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
214 HRESULT markForDeletion();
215 HRESULT unmarkForDeletion();
216 HRESULT markLockedForDeletion();
217 HRESULT unmarkLockedForDeletion();
218
219 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
220 const Guid *aMachineId,
221 const Guid *aSnapshotId,
222 bool fLockMedia,
223 bool &fMergeForward,
224 ComObjPtr<Medium> &pParentForTarget,
225 MediaList &aChildrenToReparent,
226 MediumLockList * &aMediumLockList);
227 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
228 bool fMergeForward,
229 const ComObjPtr<Medium> &pParentForTarget,
230 const MediaList &aChildrenToReparent,
231 MediumLockList *aMediumLockList,
232 ComObjPtr<Progress> *aProgress,
233 bool aWait,
234 bool *pfNeedsSaveSettings);
235 void cancelMergeTo(const MediaList &aChildrenToReparent,
236 MediumLockList *aMediumLockList);
237
238 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
239
240 /** Returns a preferred format for a differencing hard disk. */
241 Utf8Str getPreferredDiffFormat();
242
243private:
244
245 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
246
247 HRESULT canClose();
248 HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
249
250 HRESULT setStateError();
251
252 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
253 HRESULT setFormat(const Utf8Str &aFormat);
254
255 Utf8Str vdError(int aVRC);
256
257 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
258 const char *pszFormat, va_list va);
259
260 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
261 const char *pszzValid);
262 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
263 size_t *pcbValue);
264 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
265 char *pszValue, size_t cchValue);
266
267 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
268 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
269 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
270 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
271 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
272 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
273 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
274 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
275 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
276 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
277 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
278 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
279 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
280
281 class Task;
282 class CreateBaseTask;
283 class CreateDiffTask;
284 class CloneTask;
285 class CompactTask;
286 class ResetTask;
287 class DeleteTask;
288 class MergeTask;
289 friend class Task;
290 friend class CreateBaseTask;
291 friend class CreateDiffTask;
292 friend class CloneTask;
293 friend class CompactTask;
294 friend class ResetTask;
295 friend class DeleteTask;
296 friend class MergeTask;
297
298 HRESULT startThread(Medium::Task *pTask);
299 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
300
301 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
302 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
303 HRESULT taskMergeHandler(Medium::MergeTask &task);
304 HRESULT taskCloneHandler(Medium::CloneTask &task);
305 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
306 HRESULT taskResetHandler(Medium::ResetTask &task);
307 HRESULT taskCompactHandler(Medium::CompactTask &task);
308
309 struct Data; // opaque data struct, defined in MediumImpl.cpp
310 Data *m;
311};
312
313#endif /* ____H_MEDIUMIMPL */
314
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