1 | /* $Id: VirtualBoxImpl.h 40262 2012-02-27 14:14:16Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 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 |
|
---|
27 | namespace com
|
---|
28 | {
|
---|
29 | class Event;
|
---|
30 | class EventQueue;
|
---|
31 | }
|
---|
32 |
|
---|
33 | class SessionMachine;
|
---|
34 | class GuestOSType;
|
---|
35 | class SharedFolder;
|
---|
36 | class Progress;
|
---|
37 | class Host;
|
---|
38 | class SystemProperties;
|
---|
39 | class DHCPServer;
|
---|
40 | class PerformanceCollector;
|
---|
41 | class VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
|
---|
42 | #ifdef VBOX_WITH_EXTPACK
|
---|
43 | class ExtPackManager;
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
|
---|
47 |
|
---|
48 | #ifdef RT_OS_WINDOWS
|
---|
49 | class SVCHlpClient;
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | struct VMClientWatcherData;
|
---|
53 |
|
---|
54 | namespace settings
|
---|
55 | {
|
---|
56 | class MainConfigFile;
|
---|
57 | struct MediaRegistry;
|
---|
58 | }
|
---|
59 | class 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 |
|
---|
67 | public:
|
---|
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 | STDMETHOD(COMGETTER(InternalNetworks)) (ComSafeArrayOut(BSTR, aInternalNetworks));
|
---|
123 | STDMETHOD(COMGETTER(GenericNetworkDrivers)) (ComSafeArrayOut(BSTR, aGenericNetworkDrivers));
|
---|
124 |
|
---|
125 | /* IVirtualBox methods */
|
---|
126 | STDMETHOD(ComposeMachineFilename) (IN_BSTR aName, IN_BSTR aBaseFolder, BSTR *aFilename);
|
---|
127 | STDMETHOD(CreateMachine) (IN_BSTR aSettingsFile,
|
---|
128 | IN_BSTR aName,
|
---|
129 | IN_BSTR aOsTypeId,
|
---|
130 | IN_BSTR aId,
|
---|
131 | BOOL forceOverwrite,
|
---|
132 | IMachine **aMachine);
|
---|
133 | STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
|
---|
134 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
135 | STDMETHOD(FindMachine) (IN_BSTR aNameOrId, IMachine **aMachine);
|
---|
136 | STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
|
---|
137 |
|
---|
138 | STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
|
---|
139 | IN_BSTR aLocation,
|
---|
140 | IMedium **aHardDisk);
|
---|
141 | STDMETHOD(OpenMedium)(IN_BSTR aLocation,
|
---|
142 | DeviceType_T deviceType,
|
---|
143 | AccessMode_T accessMode,
|
---|
144 | BOOL fForceNewUuid,
|
---|
145 | IMedium **aMedium);
|
---|
146 | STDMETHOD(FindMedium)(IN_BSTR aLocation,
|
---|
147 | DeviceType_T deviceType,
|
---|
148 | IMedium **aMedium);
|
---|
149 |
|
---|
150 | STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
|
---|
151 | STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
|
---|
152 | STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
|
---|
153 | STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
|
---|
154 | STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
|
---|
155 | STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
|
---|
156 |
|
---|
157 | STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
158 | STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
159 | STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
|
---|
160 | STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
|
---|
161 | BSTR * aUrl, BSTR * aFile, BOOL * aResult);
|
---|
162 |
|
---|
163 | /* public methods only for internal purposes */
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Override of the default locking class to be used for validating lock
|
---|
167 | * order with the standard member lock handle.
|
---|
168 | */
|
---|
169 | virtual VBoxLockingClass getLockingClass() const
|
---|
170 | {
|
---|
171 | return LOCKCLASS_VIRTUALBOXOBJECT;
|
---|
172 | }
|
---|
173 |
|
---|
174 | #ifdef DEBUG
|
---|
175 | void dumpAllBackRefs();
|
---|
176 | #endif
|
---|
177 |
|
---|
178 | HRESULT postEvent(Event *event);
|
---|
179 |
|
---|
180 | HRESULT addProgress(IProgress *aProgress);
|
---|
181 | HRESULT removeProgress(IN_GUID aId);
|
---|
182 |
|
---|
183 | #ifdef RT_OS_WINDOWS
|
---|
184 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
185 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
186 | HRESULT startSVCHelperClient(bool aPrivileged,
|
---|
187 | SVCHelperClientFunc aFunc,
|
---|
188 | void *aUser, Progress *aProgress);
|
---|
189 | #endif
|
---|
190 |
|
---|
191 | void addProcessToReap (RTPROCESS pid);
|
---|
192 | void updateClientWatcher();
|
---|
193 |
|
---|
194 | void onMachineStateChange(const Guid &aId, MachineState_T aState);
|
---|
195 | void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
|
---|
196 | BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
|
---|
197 | Bstr &aError);
|
---|
198 | void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
|
---|
199 | void onMachineRegistered(const Guid &aId, BOOL aRegistered);
|
---|
200 | void onSessionStateChange(const Guid &aId, SessionState_T aState);
|
---|
201 |
|
---|
202 | void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
203 | void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
204 | void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
205 | void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
|
---|
206 | IN_BSTR aFlags);
|
---|
207 | void onMachineUninit(Machine *aMachine);
|
---|
208 | void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
|
---|
209 | NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
|
---|
210 | IN_BSTR aGuestIp, uint16_t aGuestPort);
|
---|
211 |
|
---|
212 | ComObjPtr<GuestOSType> getUnknownOSType();
|
---|
213 |
|
---|
214 | void getOpenedMachines(SessionMachinesList &aMachines,
|
---|
215 | InternalControlList *aControls = NULL);
|
---|
216 |
|
---|
217 | HRESULT findMachine(const Guid &aId,
|
---|
218 | bool fPermitInaccessible,
|
---|
219 | bool aSetError,
|
---|
220 | ComObjPtr<Machine> *machine = NULL);
|
---|
221 |
|
---|
222 | HRESULT findHardDiskById(const Guid &id,
|
---|
223 | bool aSetError,
|
---|
224 | ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
225 | HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
|
---|
226 | bool aSetError,
|
---|
227 | ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
228 | HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
|
---|
229 | const Guid *aId,
|
---|
230 | const Utf8Str &aLocation,
|
---|
231 | bool aSetError,
|
---|
232 | ComObjPtr<Medium> *aImage = NULL);
|
---|
233 | HRESULT findRemoveableMedium(DeviceType_T mediumType,
|
---|
234 | const Guid &uuid,
|
---|
235 | bool fRefresh,
|
---|
236 | bool aSetError,
|
---|
237 | ComObjPtr<Medium> &pMedium);
|
---|
238 |
|
---|
239 | HRESULT findGuestOSType(const Bstr &bstrOSType,
|
---|
240 | GuestOSType*& pGuestOSType);
|
---|
241 |
|
---|
242 | const Guid& getGlobalRegistryId() const;
|
---|
243 |
|
---|
244 | const ComObjPtr<Host>& host() const;
|
---|
245 | SystemProperties* getSystemProperties() const;
|
---|
246 | #ifdef VBOX_WITH_EXTPACK
|
---|
247 | ExtPackManager* getExtPackManager() const;
|
---|
248 | #endif
|
---|
249 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
250 | const ComObjPtr<PerformanceCollector>& performanceCollector() const;
|
---|
251 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
252 |
|
---|
253 | void getDefaultMachineFolder(Utf8Str &str) const;
|
---|
254 | void getDefaultHardDiskFormat(Utf8Str &str) const;
|
---|
255 |
|
---|
256 | /** Returns the VirtualBox home directory */
|
---|
257 | const Utf8Str& homeDir() const;
|
---|
258 |
|
---|
259 | int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
|
---|
260 | void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
|
---|
261 |
|
---|
262 | HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType, GuidList *pllRegistriesThatNeedSaving);
|
---|
263 | HRESULT unregisterMedium(Medium *pMedium, GuidList *pllRegistriesThatNeedSaving);
|
---|
264 |
|
---|
265 | void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
|
---|
266 | HRESULT unregisterMachineMedia(const Guid &id);
|
---|
267 |
|
---|
268 | HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
|
---|
269 |
|
---|
270 | void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
|
---|
271 | const Utf8Str &strNewConfigDir);
|
---|
272 |
|
---|
273 | void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
|
---|
274 | const Guid &uuidRegistry,
|
---|
275 | const Utf8Str &strMachineFolder);
|
---|
276 | HRESULT saveSettings();
|
---|
277 |
|
---|
278 | static void addGuidToListUniquely(GuidList &llRegistriesThatNeedSaving, const Guid &uuid);
|
---|
279 | HRESULT saveRegistries(const GuidList &llRegistriesThatNeedSaving);
|
---|
280 |
|
---|
281 | static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
|
---|
282 |
|
---|
283 | static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
|
---|
284 |
|
---|
285 | const Utf8Str& settingsFilePath();
|
---|
286 |
|
---|
287 | RWLockHandle& getMediaTreeLockHandle();
|
---|
288 |
|
---|
289 | private:
|
---|
290 |
|
---|
291 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
292 | const Utf8Str &aText)
|
---|
293 | {
|
---|
294 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
295 | }
|
---|
296 |
|
---|
297 | HRESULT checkMediaForConflicts(const Guid &aId,
|
---|
298 | const Utf8Str &aLocation,
|
---|
299 | Utf8Str &aConflictType,
|
---|
300 | ComObjPtr<Medium> *pDupMedium);
|
---|
301 |
|
---|
302 | HRESULT registerMachine(Machine *aMachine);
|
---|
303 |
|
---|
304 | HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
|
---|
305 | bool aSaveRegistry = true);
|
---|
306 | HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
|
---|
307 | bool aSaveRegistry = true);
|
---|
308 |
|
---|
309 | struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
|
---|
310 | Data *m;
|
---|
311 |
|
---|
312 | /* static variables (defined in VirtualBoxImpl.cpp) */
|
---|
313 | static Bstr sVersion;
|
---|
314 | static ULONG sRevision;
|
---|
315 | static Bstr sPackageType;
|
---|
316 | static Bstr sAPIVersion;
|
---|
317 |
|
---|
318 | static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
|
---|
319 | static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
|
---|
320 |
|
---|
321 | #ifdef RT_OS_WINDOWS
|
---|
322 | static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
|
---|
323 | #endif
|
---|
324 | };
|
---|
325 |
|
---|
326 | ////////////////////////////////////////////////////////////////////////////////
|
---|
327 |
|
---|
328 | #endif // !____H_VIRTUALBOXIMPL
|
---|
329 |
|
---|