1 | /* $Id: VirtualBoxImpl.h 45138 2013-03-22 11:52:24Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 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 | class AutostartDb;
|
---|
46 | class NATNetwork;
|
---|
47 |
|
---|
48 |
|
---|
49 | typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;
|
---|
50 |
|
---|
51 | #ifdef RT_OS_WINDOWS
|
---|
52 | class SVCHlpClient;
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | struct VMClientWatcherData;
|
---|
56 |
|
---|
57 | namespace settings
|
---|
58 | {
|
---|
59 | class MainConfigFile;
|
---|
60 | struct MediaRegistry;
|
---|
61 | }
|
---|
62 | class ATL_NO_VTABLE VirtualBox :
|
---|
63 | public VirtualBoxBase,
|
---|
64 | VBOX_SCRIPTABLE_IMPL(IVirtualBox)
|
---|
65 | #ifdef RT_OS_WINDOWS
|
---|
66 | , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
|
---|
67 | #endif
|
---|
68 | {
|
---|
69 |
|
---|
70 | public:
|
---|
71 |
|
---|
72 | typedef std::list<ComPtr<IInternalSessionControl> > InternalControlList;
|
---|
73 |
|
---|
74 | class CallbackEvent;
|
---|
75 | friend class CallbackEvent;
|
---|
76 |
|
---|
77 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
|
---|
78 |
|
---|
79 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
|
---|
80 |
|
---|
81 | DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
82 | DECLARE_NOT_AGGREGATABLE(VirtualBox)
|
---|
83 |
|
---|
84 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
85 |
|
---|
86 | BEGIN_COM_MAP(VirtualBox)
|
---|
87 | VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualBox)
|
---|
88 | END_COM_MAP()
|
---|
89 |
|
---|
90 | // to postpone generation of the default ctor/dtor
|
---|
91 | VirtualBox();
|
---|
92 | ~VirtualBox();
|
---|
93 |
|
---|
94 | HRESULT FinalConstruct();
|
---|
95 | void FinalRelease();
|
---|
96 |
|
---|
97 | /* public initializer/uninitializer for internal purposes only */
|
---|
98 | HRESULT init();
|
---|
99 | HRESULT initMachines();
|
---|
100 | HRESULT initMedia(const Guid &uuidMachineRegistry,
|
---|
101 | const settings::MediaRegistry mediaRegistry,
|
---|
102 | const Utf8Str &strMachineFolder);
|
---|
103 | void uninit();
|
---|
104 |
|
---|
105 | /* IVirtualBox properties */
|
---|
106 | STDMETHOD(COMGETTER(Version))(BSTR *aVersion);
|
---|
107 | STDMETHOD(COMGETTER(VersionNormalized))(BSTR *aVersionNormalized);
|
---|
108 | STDMETHOD(COMGETTER(Revision))(ULONG *aRevision);
|
---|
109 | STDMETHOD(COMGETTER(PackageType))(BSTR *aPackageType);
|
---|
110 | STDMETHOD(COMGETTER(APIVersion))(BSTR *aAPIVersion);
|
---|
111 | STDMETHOD(COMGETTER(HomeFolder))(BSTR *aHomeFolder);
|
---|
112 | STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aSettingsFilePath);
|
---|
113 | STDMETHOD(COMGETTER(Host))(IHost **aHost);
|
---|
114 | STDMETHOD(COMGETTER(SystemProperties))(ISystemProperties **aSystemProperties);
|
---|
115 | STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(IMachine *, aMachines));
|
---|
116 | STDMETHOD(COMGETTER(MachineGroups))(ComSafeArrayOut(BSTR, aMachineGroups));
|
---|
117 | STDMETHOD(COMGETTER(HardDisks))(ComSafeArrayOut(IMedium *, aHardDisks));
|
---|
118 | STDMETHOD(COMGETTER(DVDImages))(ComSafeArrayOut(IMedium *, aDVDImages));
|
---|
119 | STDMETHOD(COMGETTER(FloppyImages))(ComSafeArrayOut(IMedium *, aFloppyImages));
|
---|
120 | STDMETHOD(COMGETTER(ProgressOperations))(ComSafeArrayOut(IProgress *, aOperations));
|
---|
121 | STDMETHOD(COMGETTER(GuestOSTypes))(ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
|
---|
122 | STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
|
---|
123 | STDMETHOD(COMGETTER(PerformanceCollector))(IPerformanceCollector **aPerformanceCollector);
|
---|
124 | STDMETHOD(COMGETTER(DHCPServers))(ComSafeArrayOut(IDHCPServer *, aDHCPServers));
|
---|
125 | STDMETHOD(COMGETTER(NATNetworks))(ComSafeArrayOut(INATNetwork *, aNATNetworks));
|
---|
126 | STDMETHOD(COMGETTER(EventSource))(IEventSource ** aEventSource);
|
---|
127 | STDMETHOD(COMGETTER(ExtensionPackManager))(IExtPackManager **aExtPackManager);
|
---|
128 | STDMETHOD(COMGETTER(InternalNetworks))(ComSafeArrayOut(BSTR, aInternalNetworks));
|
---|
129 | STDMETHOD(COMGETTER(GenericNetworkDrivers))(ComSafeArrayOut(BSTR, aGenericNetworkDrivers));
|
---|
130 |
|
---|
131 | /* IVirtualBox methods */
|
---|
132 | STDMETHOD(ComposeMachineFilename)(IN_BSTR aName, IN_BSTR aGroup, IN_BSTR aCreateFlags, IN_BSTR aBaseFolder, BSTR *aFilename);
|
---|
133 | STDMETHOD(CreateMachine)(IN_BSTR aSettingsFile,
|
---|
134 | IN_BSTR aName,
|
---|
135 | ComSafeArrayIn(IN_BSTR, aGroups),
|
---|
136 | IN_BSTR aOsTypeId,
|
---|
137 | IN_BSTR aCreateFlags,
|
---|
138 | IMachine **aMachine);
|
---|
139 | STDMETHOD(OpenMachine)(IN_BSTR aSettingsFile, IMachine **aMachine);
|
---|
140 | STDMETHOD(RegisterMachine)(IMachine *aMachine);
|
---|
141 | STDMETHOD(FindMachine)(IN_BSTR aNameOrId, IMachine **aMachine);
|
---|
142 | STDMETHOD(GetMachinesByGroups)(ComSafeArrayIn(IN_BSTR, aGroups), ComSafeArrayOut(IMachine *, aMachines));
|
---|
143 | STDMETHOD(GetMachineStates)(ComSafeArrayIn(IMachine *, aMachines), ComSafeArrayOut(MachineState_T, aStates));
|
---|
144 | STDMETHOD(CreateAppliance)(IAppliance **anAppliance);
|
---|
145 |
|
---|
146 | STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
|
---|
147 | IN_BSTR aLocation,
|
---|
148 | IMedium **aHardDisk);
|
---|
149 | STDMETHOD(OpenMedium)(IN_BSTR aLocation,
|
---|
150 | DeviceType_T deviceType,
|
---|
151 | AccessMode_T accessMode,
|
---|
152 | BOOL fForceNewUuid,
|
---|
153 | IMedium **aMedium);
|
---|
154 |
|
---|
155 | STDMETHOD(GetGuestOSType)(IN_BSTR aId, IGuestOSType **aType);
|
---|
156 | STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
|
---|
157 | STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
|
---|
158 | STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
|
---|
159 | STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
|
---|
160 | STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
|
---|
161 | STDMETHOD(SetSettingsSecret)(IN_BSTR aKey);
|
---|
162 |
|
---|
163 | STDMETHOD(CreateDHCPServer)(IN_BSTR aName, IDHCPServer ** aServer);
|
---|
164 | STDMETHOD(FindDHCPServerByNetworkName)(IN_BSTR aName, IDHCPServer ** aServer);
|
---|
165 | STDMETHOD(RemoveDHCPServer)(IDHCPServer * aServer);
|
---|
166 |
|
---|
167 | STDMETHOD(CreateNATNetwork)(IN_BSTR aName, INATNetwork ** aNATNetworks);
|
---|
168 | STDMETHOD(FindNATNetworkByName)(IN_BSTR aName, INATNetwork ** aNATNetworks);
|
---|
169 | STDMETHOD(RemoveNATNetwork)(INATNetwork * aNATNetwork);
|
---|
170 |
|
---|
171 | STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
|
---|
172 | BSTR * aUrl, BSTR * aFile, BOOL * aResult);
|
---|
173 |
|
---|
174 | /* public methods only for internal purposes */
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Override of the default locking class to be used for validating lock
|
---|
178 | * order with the standard member lock handle.
|
---|
179 | */
|
---|
180 | virtual VBoxLockingClass getLockingClass() const
|
---|
181 | {
|
---|
182 | return LOCKCLASS_VIRTUALBOXOBJECT;
|
---|
183 | }
|
---|
184 |
|
---|
185 | #ifdef DEBUG
|
---|
186 | void dumpAllBackRefs();
|
---|
187 | #endif
|
---|
188 |
|
---|
189 | HRESULT postEvent(Event *event);
|
---|
190 |
|
---|
191 | HRESULT addProgress(IProgress *aProgress);
|
---|
192 | HRESULT removeProgress(IN_GUID aId);
|
---|
193 |
|
---|
194 | #ifdef RT_OS_WINDOWS
|
---|
195 | typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
|
---|
196 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
197 | HRESULT startSVCHelperClient(bool aPrivileged,
|
---|
198 | SVCHelperClientFunc aFunc,
|
---|
199 | void *aUser, Progress *aProgress);
|
---|
200 | #endif
|
---|
201 |
|
---|
202 | void addProcessToReap(RTPROCESS pid);
|
---|
203 | void updateClientWatcher();
|
---|
204 |
|
---|
205 | void onMachineStateChange(const Guid &aId, MachineState_T aState);
|
---|
206 | void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
|
---|
207 | BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
|
---|
208 | Bstr &aError);
|
---|
209 | void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
|
---|
210 | void onMachineRegistered(const Guid &aId, BOOL aRegistered);
|
---|
211 | void onSessionStateChange(const Guid &aId, SessionState_T aState);
|
---|
212 |
|
---|
213 | void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
214 | void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
215 | void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
216 | void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
|
---|
217 | IN_BSTR aFlags);
|
---|
218 | void onMachineUninit(Machine *aMachine);
|
---|
219 | void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
|
---|
220 | NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
|
---|
221 | IN_BSTR aGuestIp, uint16_t aGuestPort);
|
---|
222 | void onNATNetworkChange(IN_BSTR aNetworkName);
|
---|
223 | void onNATNetworkStartStop(IN_BSTR aNetworkName, BOOL aStart);
|
---|
224 | void onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled, IN_BSTR aNetwork,
|
---|
225 | IN_BSTR aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
|
---|
226 | BOOL fNeedDhcpServer);
|
---|
227 | void onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,
|
---|
228 | IN_BSTR aRuleName, NATProtocol_T proto,
|
---|
229 | IN_BSTR aHostIp, LONG aHostPort,
|
---|
230 | IN_BSTR aGuestIp, LONG aGuestPort);
|
---|
231 |
|
---|
232 | ComObjPtr<GuestOSType> getUnknownOSType();
|
---|
233 |
|
---|
234 | void getOpenedMachines(SessionMachinesList &aMachines,
|
---|
235 | InternalControlList *aControls = NULL);
|
---|
236 |
|
---|
237 | HRESULT findMachine(const Guid &aId,
|
---|
238 | bool fPermitInaccessible,
|
---|
239 | bool aSetError,
|
---|
240 | ComObjPtr<Machine> *aMachine = NULL);
|
---|
241 | HRESULT findMachineByName(const Utf8Str &aName,
|
---|
242 | bool aSetError,
|
---|
243 | ComObjPtr<Machine> *aMachine = NULL);
|
---|
244 |
|
---|
245 | HRESULT validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
|
---|
246 | HRESULT convertMachineGroups(ComSafeArrayIn(IN_BSTR, aMachineGroups), StringsList *pllMachineGroups);
|
---|
247 |
|
---|
248 | HRESULT findHardDiskById(const Guid &id,
|
---|
249 | bool aSetError,
|
---|
250 | ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
251 | HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
|
---|
252 | bool aSetError,
|
---|
253 | ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
254 | HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
|
---|
255 | const Guid *aId,
|
---|
256 | const Utf8Str &aLocation,
|
---|
257 | bool aSetError,
|
---|
258 | ComObjPtr<Medium> *aImage = NULL);
|
---|
259 | HRESULT findRemoveableMedium(DeviceType_T mediumType,
|
---|
260 | const Guid &uuid,
|
---|
261 | bool fRefresh,
|
---|
262 | bool aSetError,
|
---|
263 | ComObjPtr<Medium> &pMedium);
|
---|
264 |
|
---|
265 | HRESULT findGuestOSType(const Bstr &bstrOSType,
|
---|
266 | GuestOSType*& pGuestOSType);
|
---|
267 |
|
---|
268 | const Guid &getGlobalRegistryId() const;
|
---|
269 |
|
---|
270 | const ComObjPtr<Host>& host() const;
|
---|
271 | SystemProperties* getSystemProperties() const;
|
---|
272 | #ifdef VBOX_WITH_EXTPACK
|
---|
273 | ExtPackManager* getExtPackManager() const;
|
---|
274 | #endif
|
---|
275 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
276 | const ComObjPtr<PerformanceCollector>& performanceCollector() const;
|
---|
277 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
278 |
|
---|
279 | void getDefaultMachineFolder(Utf8Str &str) const;
|
---|
280 | void getDefaultHardDiskFormat(Utf8Str &str) const;
|
---|
281 |
|
---|
282 | /** Returns the VirtualBox home directory */
|
---|
283 | const Utf8Str& homeDir() const;
|
---|
284 |
|
---|
285 | int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
|
---|
286 | void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
|
---|
287 |
|
---|
288 | HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
|
---|
289 | HRESULT unregisterMedium(Medium *pMedium);
|
---|
290 |
|
---|
291 | void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
|
---|
292 | HRESULT unregisterMachineMedia(const Guid &id);
|
---|
293 |
|
---|
294 | HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
|
---|
295 |
|
---|
296 | void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
|
---|
297 | const Utf8Str &strNewConfigDir);
|
---|
298 |
|
---|
299 | void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
|
---|
300 | const Guid &uuidRegistry,
|
---|
301 | const Utf8Str &strMachineFolder);
|
---|
302 | HRESULT saveSettings();
|
---|
303 |
|
---|
304 | void markRegistryModified(const Guid &uuid);
|
---|
305 | void saveModifiedRegistries();
|
---|
306 |
|
---|
307 | static const Bstr &getVersionNormalized();
|
---|
308 |
|
---|
309 | static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
|
---|
310 |
|
---|
311 | const Utf8Str& settingsFilePath();
|
---|
312 |
|
---|
313 | AutostartDb* getAutostartDb() const;
|
---|
314 |
|
---|
315 | RWLockHandle& getMediaTreeLockHandle();
|
---|
316 |
|
---|
317 | int encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
|
---|
318 | int decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
|
---|
319 | void storeSettingsKey(const Utf8Str &aKey);
|
---|
320 |
|
---|
321 | bool isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
|
---|
322 |
|
---|
323 | private:
|
---|
324 |
|
---|
325 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
326 | const Utf8Str &aText)
|
---|
327 | {
|
---|
328 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
329 | }
|
---|
330 |
|
---|
331 | HRESULT registerMachine(Machine *aMachine);
|
---|
332 |
|
---|
333 | HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
|
---|
334 | bool aSaveRegistry = true);
|
---|
335 | HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
|
---|
336 | bool aSaveRegistry = true);
|
---|
337 | HRESULT registerNATNetwork(NATNetwork *aNATNetwork,
|
---|
338 | bool aSaveRegistry = true);
|
---|
339 | HRESULT unregisterNATNetwork(NATNetwork *aNATNetwork,
|
---|
340 | bool aSaveRegistry = true);
|
---|
341 | HRESULT checkMediaForConflicts(const Guid &aId,
|
---|
342 | const Utf8Str &aLocation,
|
---|
343 | Utf8Str &aConflictType,
|
---|
344 | ComObjPtr<Medium> *pDupMedium);
|
---|
345 |
|
---|
346 | int decryptSettings();
|
---|
347 | int decryptMediumSettings(Medium *pMedium);
|
---|
348 | int decryptSettingBytes(uint8_t *aPlaintext, const uint8_t *aCiphertext,
|
---|
349 | size_t aCiphertextSize) const;
|
---|
350 | int encryptSettingBytes(const uint8_t *aPlaintext, uint8_t *aCiphertext,
|
---|
351 | size_t aPlaintextSize, size_t aCiphertextSize) const;
|
---|
352 |
|
---|
353 | struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
|
---|
354 | Data *m;
|
---|
355 |
|
---|
356 | /* static variables (defined in VirtualBoxImpl.cpp) */
|
---|
357 | static Bstr sVersion;
|
---|
358 | static Bstr sVersionNormalized;
|
---|
359 | static ULONG sRevision;
|
---|
360 | static Bstr sPackageType;
|
---|
361 | static Bstr sAPIVersion;
|
---|
362 |
|
---|
363 | static DECLCALLBACK(int) ClientWatcher(RTTHREAD thread, void *pvUser);
|
---|
364 | static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
|
---|
365 |
|
---|
366 | #ifdef RT_OS_WINDOWS
|
---|
367 | static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
|
---|
368 | #endif
|
---|
369 | };
|
---|
370 |
|
---|
371 | ////////////////////////////////////////////////////////////////////////////////
|
---|
372 |
|
---|
373 | #endif // !____H_VIRTUALBOXIMPL
|
---|
374 |
|
---|