VirtualBox

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

Last change on this file since 49240 was 48538, checked in by vboxsync, 11 years ago

Main/NetworkAdapter+Machine+Appliance+SystemProperties+Medium+Console+Settings+IDL: make NAT networking a separate network attachment type which improves the user experience, store the necessary settings, plus changing the design of the methods which will move images and entire VMs, they lacked a progress object
Frontends/VirtualBox: adapted fully, can configure NAT networks with proper drop down list support
Frontends/VBoxManage: also supports NAT networks completely, and adds the long missing code to list intnets

  • 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 48538 2013-09-19 15:17:43Z 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(COMGETTER(Name))(BSTR *aName);
109 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
110 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
111 STDMETHOD(COMGETTER(Size))(LONG64 *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(AllowedTypes))(ComSafeArrayOut(MediumType_T, aAllowedTypes));
117 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
118 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
119 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
120 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
121 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
122 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
123 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
124 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
125 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
126
127 // IMedium methods
128 STDMETHOD(SetIds)(BOOL aSetImageId, IN_BSTR aImageId,
129 BOOL aSetParentId, IN_BSTR aParentId);
130 STDMETHOD(RefreshState)(MediumState_T *aState);
131 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
132 ComSafeArrayOut(BSTR, aSnapshotIds));
133 STDMETHOD(LockRead)(IToken **aToken);
134 STDMETHOD(LockWrite)(IToken **aToken);
135 STDMETHOD(Close)();
136 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
137 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
138 STDMETHOD(GetProperties)(IN_BSTR aNames,
139 ComSafeArrayOut(BSTR, aReturnNames),
140 ComSafeArrayOut(BSTR, aReturnValues));
141 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
142 ComSafeArrayIn(IN_BSTR, aValues));
143 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
144 ComSafeArrayIn(MediumVariant_T, aVariant),
145 IProgress **aProgress);
146 STDMETHOD(DeleteStorage)(IProgress **aProgress);
147 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
148 ComSafeArrayIn(MediumVariant_T, aVariant),
149 IProgress **aProgress);
150 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
151 STDMETHOD(CloneTo)(IMedium *aTarget, ComSafeArrayIn(MediumVariant_T, aVariant),
152 IMedium *aParent, IProgress **aProgress);
153 STDMETHOD(CloneToBase)(IMedium *aTarget, ComSafeArrayIn(MediumVariant_T, aVariant),
154 IProgress **aProgress);
155 STDMETHOD(SetLocation)(IN_BSTR aLocation, 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& getId() const;
166 MediumState_T getState() const;
167 MediumVariant_T getVariant() const;
168 bool isHostDrive() const;
169 const Utf8Str& getLocationFull() const;
170 const Utf8Str& getFormat() const;
171 const ComObjPtr<MediumFormat> & getMediumFormat() const;
172 bool isMediumFormatFile() const;
173 uint64_t getSize() const;
174 DeviceType_T getDeviceType() const;
175 MediumType_T getType() const;
176 Utf8Str getName();
177
178 /* handles caller/locking itself */
179 bool addRegistry(const Guid& id, bool fRecurse);
180 /* handles caller/locking itself */
181 bool removeRegistry(const Guid& id, bool fRecurse);
182 bool isInRegistry(const Guid& id);
183 bool getFirstRegistryMachineId(Guid &uuid) const;
184 void markRegistriesModified();
185
186 HRESULT setPropertyDirect(const Utf8Str &aName, const Utf8Str &aValue);
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
194 const Guid* getFirstMachineBackrefId() const;
195 const Guid* getAnyMachineBackref() const;
196 const Guid* getFirstMachineBackrefSnapshotId() const;
197 size_t getMachineBackRefCount() const;
198
199#ifdef DEBUG
200 void dumpBackRefs();
201#endif
202
203 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
204
205 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
206
207 bool isReadOnly();
208 void updateId(const Guid &id);
209
210 HRESULT saveSettings(settings::Medium &data,
211 const Utf8Str &strHardDiskFolder);
212
213 HRESULT createMediumLockList(bool fFailIfInaccessible,
214 bool fMediumLockWrite,
215 Medium *pToBeParent,
216 MediumLockList &mediumLockList);
217
218 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
219 MediumVariant_T aVariant,
220 MediumLockList *pMediumLockList,
221 ComObjPtr<Progress> *aProgress,
222 bool aWait);
223 Utf8Str getPreferredDiffFormat();
224
225 HRESULT close(AutoCaller &autoCaller);
226 HRESULT unlockRead(MediumState_T *aState);
227 HRESULT unlockWrite(MediumState_T *aState);
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 MediumLockList * &aChildrenToReparent,
244 MediumLockList * &aMediumLockList);
245 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
246 bool fMergeForward,
247 const ComObjPtr<Medium> &pParentForTarget,
248 MediumLockList *aChildrenToReparent,
249 MediumLockList *aMediumLockList,
250 ComObjPtr<Progress> *aProgress,
251 bool aWait);
252 void cancelMergeTo(MediumLockList *aChildrenToReparent,
253 MediumLockList *aMediumLockList);
254
255 HRESULT fixParentUuidOfChildren(MediumLockList *pChildrenToReparent);
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