VirtualBox

source: vbox/trunk/src/VBox/Main/include/VirtualBoxImpl.h@ 37596

Last change on this file since 37596 was 37525, checked in by vboxsync, 14 years ago

Main/VirtualBox+Medium: resurrect the feature of changing the medium UUID when opening the image, which allows to resolve duplicate UUIDs without using external tools. Also fixes Medium::setIDs, which wasn't correctly working.
Frontends/*: corresponding changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 KB
Line 
1/* $Id: VirtualBoxImpl.h 37525 2011-06-17 10:09:21Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_VIRTUALBOXIMPL
19#define ____H_VIRTUALBOXIMPL
20
21#include "VirtualBoxBase.h"
22
23#ifdef RT_OS_WINDOWS
24# include "win/resource.h"
25#endif
26
27namespace com
28{
29 class Event;
30 class EventQueue;
31}
32
33class SessionMachine;
34class GuestOSType;
35class SharedFolder;
36class Progress;
37class Host;
38class SystemProperties;
39class DHCPServer;
40class PerformanceCollector;
41class VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
42#ifdef VBOX_WITH_EXTPACK
43class ExtPackManager;
44#endif
45
46typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
47
48#ifdef RT_OS_WINDOWS
49class SVCHlpClient;
50#endif
51
52struct VMClientWatcherData;
53
54namespace settings
55{
56 class MainConfigFile;
57 struct MediaRegistry;
58}
59class ATL_NO_VTABLE VirtualBox :
60 public VirtualBoxBase,
61 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
62#ifdef RT_OS_WINDOWS
63 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
64#endif
65{
66
67public:
68
69 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
70
71 class CallbackEvent;
72 friend class CallbackEvent;
73
74 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
75
76 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
77
78 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
79 DECLARE_NOT_AGGREGATABLE(VirtualBox)
80
81 DECLARE_PROTECT_FINAL_CONSTRUCT()
82
83 BEGIN_COM_MAP(VirtualBox)
84 VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualBox)
85 END_COM_MAP()
86
87 // to postpone generation of the default ctor/dtor
88 VirtualBox();
89 ~VirtualBox();
90
91 HRESULT FinalConstruct();
92 void FinalRelease();
93
94 /* public initializer/uninitializer for internal purposes only */
95 HRESULT init();
96 HRESULT initMachines();
97 HRESULT initMedia(const Guid &uuidMachineRegistry,
98 const settings::MediaRegistry mediaRegistry,
99 const Utf8Str &strMachineFolder);
100 void uninit();
101
102 /* IVirtualBox properties */
103 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
104 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
105 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
106 STDMETHOD(COMGETTER(APIVersion)) (BSTR *aAPIVersion);
107 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
108 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
109 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
110 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
111 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut(IMachine *, aMachines));
112 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut(IMedium *, aHardDisks));
113 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut(IMedium *, aDVDImages));
114 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut(IMedium *, aFloppyImages));
115 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut(IProgress *, aOperations));
116 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
117 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut(ISharedFolder *, aSharedFolders));
118 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
119 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut(IDHCPServer *, aDHCPServers));
120 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
121 STDMETHOD(COMGETTER(ExtensionPackManager)) (IExtPackManager **aExtPackManager);
122
123 /* IVirtualBox methods */
124 STDMETHOD(ComposeMachineFilename) (IN_BSTR aName, IN_BSTR aBaseFolder, BSTR *aFilename);
125 STDMETHOD(CreateMachine) (IN_BSTR aSettingsFile,
126 IN_BSTR aName,
127 IN_BSTR aOsTypeId,
128 IN_BSTR aId,
129 BOOL forceOverwrite,
130 IMachine **aMachine);
131 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
132 STDMETHOD(RegisterMachine) (IMachine *aMachine);
133 STDMETHOD(FindMachine) (IN_BSTR aNameOrId, IMachine **aMachine);
134 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
135
136 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
137 IN_BSTR aLocation,
138 IMedium **aHardDisk);
139 STDMETHOD(OpenMedium)(IN_BSTR aLocation,
140 DeviceType_T deviceType,
141 AccessMode_T accessMode,
142 BOOL fForceNewUuid,
143 IMedium **aMedium);
144 STDMETHOD(FindMedium)(IN_BSTR aLocation,
145 DeviceType_T deviceType,
146 IMedium **aMedium);
147
148 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
149 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
150 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
151 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
152 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
153 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
154
155 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
156 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
157 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
158 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
159 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
160
161 /* public methods only for internal purposes */
162
163 /**
164 * Override of the default locking class to be used for validating lock
165 * order with the standard member lock handle.
166 */
167 virtual VBoxLockingClass getLockingClass() const
168 {
169 return LOCKCLASS_VIRTUALBOXOBJECT;
170 }
171
172#ifdef DEBUG
173 void dumpAllBackRefs();
174#endif
175
176 HRESULT postEvent(Event *event);
177
178 HRESULT addProgress(IProgress *aProgress);
179 HRESULT removeProgress(IN_GUID aId);
180
181#ifdef RT_OS_WINDOWS
182 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
183 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
184 HRESULT startSVCHelperClient(bool aPrivileged,
185 SVCHelperClientFunc aFunc,
186 void *aUser, Progress *aProgress);
187#endif
188
189 void addProcessToReap (RTPROCESS pid);
190 void updateClientWatcher();
191
192 void onMachineStateChange(const Guid &aId, MachineState_T aState);
193 void onMachineDataChange(const Guid &aId);
194 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
195 Bstr &aError);
196 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
197 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
198 void onSessionStateChange(const Guid &aId, SessionState_T aState);
199
200 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
201 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
202 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
203 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
204 IN_BSTR aFlags);
205 void onMachineUninit(Machine *aMachine);
206 void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
207 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
208 IN_BSTR aGuestIp, uint16_t aGuestPort);
209
210 ComObjPtr<GuestOSType> getUnknownOSType();
211
212 void getOpenedMachines(SessionMachinesList &aMachines,
213 InternalControlList *aControls = NULL);
214
215 HRESULT findMachine(const Guid &aId,
216 bool fPermitInaccessible,
217 bool aSetError,
218 ComObjPtr<Machine> *machine = NULL);
219
220 HRESULT findHardDiskById(const Guid &id,
221 bool aSetError,
222 ComObjPtr<Medium> *aHardDisk = NULL);
223 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
224 bool aSetError,
225 ComObjPtr<Medium> *aHardDisk = NULL);
226 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
227 const Guid *aId,
228 const Utf8Str &aLocation,
229 bool aSetError,
230 ComObjPtr<Medium> *aImage = NULL);
231 HRESULT findRemoveableMedium(DeviceType_T mediumType,
232 const Guid &uuid,
233 bool fRefresh,
234 bool aSetError,
235 ComObjPtr<Medium> &pMedium);
236
237 HRESULT findGuestOSType(const Bstr &bstrOSType,
238 GuestOSType*& pGuestOSType);
239
240 const Guid& getGlobalRegistryId() const;
241
242 const ComObjPtr<Host>& host() const;
243 SystemProperties* getSystemProperties() const;
244#ifdef VBOX_WITH_EXTPACK
245 ExtPackManager* getExtPackManager() const;
246#endif
247#ifdef VBOX_WITH_RESOURCE_USAGE_API
248 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
249#endif /* VBOX_WITH_RESOURCE_USAGE_API */
250
251 void getDefaultMachineFolder(Utf8Str &str) const;
252 void getDefaultHardDiskFormat(Utf8Str &str) const;
253
254 /** Returns the VirtualBox home directory */
255 const Utf8Str& homeDir() const;
256
257 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
258 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
259
260 HRESULT registerHardDisk(Medium *aHardDisk, GuidList *pllRegistriesThatNeedSaving);
261 HRESULT unregisterHardDisk(Medium *aHardDisk, GuidList *pllRegistriesThatNeedSaving);
262
263 HRESULT registerImage(Medium *aImage, DeviceType_T argType, GuidList *pllRegistriesThatNeedSaving);
264 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, GuidList *pllRegistriesThatNeedSaving);
265
266 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
267 HRESULT unregisterMachineMedia(const Guid &id);
268
269 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
270
271 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
272 const Utf8Str &strNewConfigDir);
273
274 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
275 const Guid &uuidRegistry,
276 const Utf8Str &strMachineFolder);
277 HRESULT saveSettings();
278
279 void addGuidToListUniquely(GuidList &llRegistriesThatNeedSaving, const Guid &uuid);
280 HRESULT saveRegistries(const GuidList &llRegistriesThatNeedSaving);
281
282 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
283
284 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
285
286 const Utf8Str& settingsFilePath();
287
288 RWLockHandle& getMediaTreeLockHandle();
289
290private:
291
292 static HRESULT setErrorStatic(HRESULT aResultCode,
293 const Utf8Str &aText)
294 {
295 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
296 }
297
298 HRESULT checkMediaForConflicts(const Guid &aId,
299 const Utf8Str &aLocation,
300 Utf8Str &aConflictType,
301 bool &fIdentical);
302
303 HRESULT registerMachine(Machine *aMachine);
304
305 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
306 bool aSaveRegistry = true);
307 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
308 bool aSaveRegistry = true);
309
310 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
311 Data *m;
312
313 /* static variables (defined in VirtualBoxImpl.cpp) */
314 static Bstr sVersion;
315 static ULONG sRevision;
316 static Bstr sPackageType;
317 static Bstr sAPIVersion;
318
319 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
320 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
321
322#ifdef RT_OS_WINDOWS
323 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
324#endif
325};
326
327////////////////////////////////////////////////////////////////////////////////
328
329#endif // !____H_VIRTUALBOXIMPL
330
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