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