VirtualBox

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

Last change on this file since 76240 was 76240, checked in by vboxsync, 6 years ago

Main: bugref:6913: had to revert all changes for the defect because of crashing VBoxSVC on MacOS

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.8 KB
Line 
1/* $Id: VirtualBoxImpl.h 76240 2018-12-14 20:34:20Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2017 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#include "objectslist.h"
23#include "VirtualBoxWrap.h"
24
25#ifdef RT_OS_WINDOWS
26# include "win/resource.h"
27#endif
28
29//#ifdef DEBUG_bird
30//# define VBOXSVC_WITH_CLIENT_WATCHER
31//#endif
32
33namespace com
34{
35 class Event;
36 class EventQueue;
37}
38
39class SessionMachine;
40class GuestOSType;
41class Progress;
42class Host;
43class SystemProperties;
44class DHCPServer;
45class PerformanceCollector;
46class CloudProviderManager;
47#ifdef VBOX_WITH_EXTPACK
48class ExtPackManager;
49#endif
50class AutostartDb;
51class NATNetwork;
52
53
54typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;
55
56#ifdef RT_OS_WINDOWS
57class SVCHlpClient;
58#endif
59
60namespace settings
61{
62 class MainConfigFile;
63 struct MediaRegistry;
64}
65
66
67#if defined(VBOX_WITH_SDS) && !defined(VBOX_WITH_XPCOM)
68class VirtualBoxClassFactory; /* See ../src-server/win/svcmain.cpp */
69#endif
70
71
72class ATL_NO_VTABLE VirtualBox :
73 public VirtualBoxWrap
74#ifdef RT_OS_WINDOWS
75 , public ATL::CComCoClass<VirtualBox, &CLSID_VirtualBox>
76#endif
77{
78
79public:
80
81 typedef std::list<ComPtr<IInternalSessionControl> > InternalControlList;
82 typedef ObjectsList<Machine> MachinesOList;
83
84 class CallbackEvent;
85 friend class CallbackEvent;
86
87#ifndef VBOX_WITH_XPCOM
88# ifdef VBOX_WITH_SDS
89 DECLARE_CLASSFACTORY_EX(VirtualBoxClassFactory)
90# else
91 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
92# endif
93#endif
94
95 // Do not use any ATL registry support.
96 //DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
97
98 // Kind of redundant (VirtualBoxWrap declares itself not aggregatable and
99 // CComCoClass<VirtualBox, &CLSID_VirtualBox> as aggregatable, the former
100 // is the first inheritance), but the C++ multiple inheritance rules and
101 // the class factory in svcmain.cpp needs this to disambiguate.
102 DECLARE_NOT_AGGREGATABLE(VirtualBox)
103
104 // to postpone generation of the default ctor/dtor
105 DECLARE_EMPTY_CTOR_DTOR(VirtualBox)
106
107 HRESULT FinalConstruct();
108 void FinalRelease();
109
110 // public initializer/uninitializer for internal purposes only
111 HRESULT init();
112 HRESULT initMachines();
113 HRESULT initMedia(const Guid &uuidMachineRegistry,
114 const settings::MediaRegistry &mediaRegistry,
115 const Utf8Str &strMachineFolder);
116 void uninit();
117
118 // public methods only for internal purposes
119
120 /**
121 * Override of the default locking class to be used for validating lock
122 * order with the standard member lock handle.
123 */
124 virtual VBoxLockingClass getLockingClass() const
125 {
126 return LOCKCLASS_VIRTUALBOXOBJECT;
127 }
128
129#ifdef DEBUG
130 void i_dumpAllBackRefs();
131#endif
132
133 HRESULT i_postEvent(Event *event);
134
135 HRESULT i_addProgress(IProgress *aProgress);
136 HRESULT i_removeProgress(IN_GUID aId);
137
138#ifdef RT_OS_WINDOWS
139 typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
140 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
141 HRESULT i_startSVCHelperClient(bool aPrivileged,
142 SVCHelperClientFunc aFunc,
143 void *aUser, Progress *aProgress);
144#endif
145
146 void i_addProcessToReap(RTPROCESS pid);
147 void i_updateClientWatcher();
148
149 int i_loadVDPlugin(const char *pszPluginLibrary);
150 int i_unloadVDPlugin(const char *pszPluginLibrary);
151
152 void i_onMachineStateChange(const Guid &aId, MachineState_T aState);
153 void i_onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
154 BOOL i_onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
155 Bstr &aError);
156 void i_onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
157 void i_onMachineRegistered(const Guid &aId, BOOL aRegistered);
158 void i_onSessionStateChange(const Guid &aId, SessionState_T aState);
159
160 void i_onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
161 void i_onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
162 void i_onSnapshotRestored(const Guid &aMachineId, const Guid &aSnapshotId);
163 void i_onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
164 void i_onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
165 IN_BSTR aFlags);
166 void i_onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
167 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
168 IN_BSTR aGuestIp, uint16_t aGuestPort);
169 void i_onNATNetworkChange(IN_BSTR aNetworkName);
170 void i_onNATNetworkStartStop(IN_BSTR aNetworkName, BOOL aStart);
171 void i_onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled, IN_BSTR aNetwork,
172 IN_BSTR aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
173 BOOL fNeedDhcpServer);
174 void i_onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,
175 IN_BSTR aRuleName, NATProtocol_T proto,
176 IN_BSTR aHostIp, LONG aHostPort,
177 IN_BSTR aGuestIp, LONG aGuestPort);
178 void i_onHostNameResolutionConfigurationChange();
179
180 int i_natNetworkRefInc(const Utf8Str &aNetworkName);
181 int i_natNetworkRefDec(const Utf8Str &aNetworkName);
182
183 ComObjPtr<GuestOSType> i_getUnknownOSType();
184
185 void i_getOpenedMachines(SessionMachinesList &aMachines,
186 InternalControlList *aControls = NULL);
187 MachinesOList &i_getMachinesList();
188
189 HRESULT i_findMachine(const Guid &aId,
190 bool fPermitInaccessible,
191 bool aSetError,
192 ComObjPtr<Machine> *aMachine = NULL);
193
194 HRESULT i_findMachineByName(const Utf8Str &aName,
195 bool aSetError,
196 ComObjPtr<Machine> *aMachine = NULL);
197
198 HRESULT i_validateMachineGroup(const com::Utf8Str &aGroup, bool fPrimary);
199 HRESULT i_convertMachineGroups(const std::vector<com::Utf8Str> aMachineGroups, StringsList *pllMachineGroups);
200
201 HRESULT i_findHardDiskById(const Guid &id,
202 bool aSetError,
203 ComObjPtr<Medium> *aHardDisk = NULL);
204 HRESULT i_findHardDiskByLocation(const Utf8Str &strLocation,
205 bool aSetError,
206 ComObjPtr<Medium> *aHardDisk = NULL);
207 HRESULT i_findDVDOrFloppyImage(DeviceType_T mediumType,
208 const Guid *aId,
209 const Utf8Str &aLocation,
210 bool aSetError,
211 ComObjPtr<Medium> *aImage = NULL);
212 HRESULT i_findRemoveableMedium(DeviceType_T mediumType,
213 const Guid &uuid,
214 bool fRefresh,
215 bool aSetError,
216 ComObjPtr<Medium> &pMedium);
217
218 HRESULT i_findGuestOSType(const Utf8Str &strOSType,
219 ComObjPtr<GuestOSType> &guestOSType);
220
221 const Guid &i_getGlobalRegistryId() const;
222
223 const ComObjPtr<Host> &i_host() const;
224 SystemProperties *i_getSystemProperties() const;
225 CloudProviderManager *i_getCloudProviderManager() const;
226#ifdef VBOX_WITH_EXTPACK
227 ExtPackManager *i_getExtPackManager() const;
228#endif
229#ifdef VBOX_WITH_RESOURCE_USAGE_API
230 const ComObjPtr<PerformanceCollector> &i_performanceCollector() const;
231#endif /* VBOX_WITH_RESOURCE_USAGE_API */
232
233 void i_getDefaultMachineFolder(Utf8Str &str) const;
234 void i_getDefaultHardDiskFormat(Utf8Str &str) const;
235
236 /** Returns the VirtualBox home directory */
237 const Utf8Str &i_homeDir() const;
238 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
239 void i_copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
240 HRESULT i_registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium,
241 AutoWriteLock &mediaTreeLock);
242 HRESULT i_unregisterMedium(Medium *pMedium);
243 void i_pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
244 HRESULT i_unregisterMachineMedia(const Guid &id);
245 HRESULT i_unregisterMachine(Machine *pMachine, const Guid &id);
246 void i_rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
247 const Utf8Str &strNewConfigDir);
248 void i_saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
249 const Guid &uuidRegistry,
250 const Utf8Str &strMachineFolder);
251 HRESULT i_saveSettings();
252 void i_markRegistryModified(const Guid &uuid);
253 void i_unmarkRegistryModified(const Guid &uuid);
254 void i_saveModifiedRegistries();
255 static const com::Utf8Str &i_getVersionNormalized();
256 static HRESULT i_ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
257 const Utf8Str& i_settingsFilePath();
258 AutostartDb* i_getAutostartDb() const;
259 RWLockHandle& i_getMachinesListLockHandle();
260 RWLockHandle& i_getMediaTreeLockHandle();
261 int i_encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
262 int i_decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
263 void i_storeSettingsKey(const Utf8Str &aKey);
264 bool i_isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
265
266
267
268private:
269 class ClientWatcher;
270
271 // wrapped IVirtualBox properties
272 HRESULT getVersion(com::Utf8Str &aVersion);
273 HRESULT getVersionNormalized(com::Utf8Str &aVersionNormalized);
274 HRESULT getRevision(ULONG *aRevision);
275 HRESULT getPackageType(com::Utf8Str &aPackageType);
276 HRESULT getAPIVersion(com::Utf8Str &aAPIVersion);
277 HRESULT getAPIRevision(LONG64 *aAPIRevision);
278 HRESULT getHomeFolder(com::Utf8Str &aHomeFolder);
279 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
280 HRESULT getHost(ComPtr<IHost> &aHost);
281 HRESULT getSystemProperties(ComPtr<ISystemProperties> &aSystemProperties);
282 HRESULT getMachines(std::vector<ComPtr<IMachine> > &aMachines);
283 HRESULT getMachineGroups(std::vector<com::Utf8Str> &aMachineGroups);
284 HRESULT getHardDisks(std::vector<ComPtr<IMedium> > &aHardDisks);
285 HRESULT getDVDImages(std::vector<ComPtr<IMedium> > &aDVDImages);
286 HRESULT getFloppyImages(std::vector<ComPtr<IMedium> > &aFloppyImages);
287 HRESULT getProgressOperations(std::vector<ComPtr<IProgress> > &aProgressOperations);
288 HRESULT getGuestOSTypes(std::vector<ComPtr<IGuestOSType> > &aGuestOSTypes);
289 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
290 HRESULT getPerformanceCollector(ComPtr<IPerformanceCollector> &aPerformanceCollector);
291 HRESULT getDHCPServers(std::vector<ComPtr<IDHCPServer> > &aDHCPServers);
292 HRESULT getNATNetworks(std::vector<ComPtr<INATNetwork> > &aNATNetworks);
293 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
294 HRESULT getExtensionPackManager(ComPtr<IExtPackManager> &aExtensionPackManager);
295 HRESULT getInternalNetworks(std::vector<com::Utf8Str> &aInternalNetworks);
296 HRESULT getGenericNetworkDrivers(std::vector<com::Utf8Str> &aGenericNetworkDrivers);
297 HRESULT getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager);
298
299 // wrapped IVirtualBox methods
300 HRESULT composeMachineFilename(const com::Utf8Str &aName,
301 const com::Utf8Str &aGroup,
302 const com::Utf8Str &aCreateFlags,
303 const com::Utf8Str &aBaseFolder,
304 com::Utf8Str &aFile);
305 HRESULT createMachine(const com::Utf8Str &aSettingsFile,
306 const com::Utf8Str &aName,
307 const std::vector<com::Utf8Str> &aGroups,
308 const com::Utf8Str &aOsTypeId,
309 const com::Utf8Str &aFlags,
310 ComPtr<IMachine> &aMachine);
311 HRESULT openMachine(const com::Utf8Str &aSettingsFile,
312 ComPtr<IMachine> &aMachine);
313 HRESULT registerMachine(const ComPtr<IMachine> &aMachine);
314 HRESULT findMachine(const com::Utf8Str &aNameOrId,
315 ComPtr<IMachine> &aMachine);
316 HRESULT getMachinesByGroups(const std::vector<com::Utf8Str> &aGroups,
317 std::vector<ComPtr<IMachine> > &aMachines);
318 HRESULT getMachineStates(const std::vector<ComPtr<IMachine> > &aMachines,
319 std::vector<MachineState_T> &aStates);
320 HRESULT createAppliance(ComPtr<IAppliance> &aAppliance);
321 HRESULT createUnattendedInstaller(ComPtr<IUnattended> &aUnattended);
322 HRESULT createMedium(const com::Utf8Str &aFormat,
323 const com::Utf8Str &aLocation,
324 AccessMode_T aAccessMode,
325 DeviceType_T aDeviceType,
326 ComPtr<IMedium> &aMedium);
327 HRESULT openMedium(const com::Utf8Str &aLocation,
328 DeviceType_T aDeviceType,
329 AccessMode_T aAccessMode,
330 BOOL aForceNewUuid,
331 ComPtr<IMedium> &aMedium);
332 HRESULT getGuestOSType(const com::Utf8Str &aId,
333 ComPtr<IGuestOSType> &aType);
334 HRESULT createSharedFolder(const com::Utf8Str &aName,
335 const com::Utf8Str &aHostPath,
336 BOOL aWritable,
337 BOOL aAutomount,
338 const com::Utf8Str &aAutoMountPoint);
339 HRESULT removeSharedFolder(const com::Utf8Str &aName);
340 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
341 HRESULT getExtraData(const com::Utf8Str &aKey,
342 com::Utf8Str &aValue);
343 HRESULT setExtraData(const com::Utf8Str &aKey,
344 const com::Utf8Str &aValue);
345 HRESULT setSettingsSecret(const com::Utf8Str &aPassword);
346 HRESULT createDHCPServer(const com::Utf8Str &aName,
347 ComPtr<IDHCPServer> &aServer);
348 HRESULT findDHCPServerByNetworkName(const com::Utf8Str &aName,
349 ComPtr<IDHCPServer> &aServer);
350 HRESULT removeDHCPServer(const ComPtr<IDHCPServer> &aServer);
351 HRESULT createNATNetwork(const com::Utf8Str &aNetworkName,
352 ComPtr<INATNetwork> &aNetwork);
353 HRESULT findNATNetworkByName(const com::Utf8Str &aNetworkName,
354 ComPtr<INATNetwork> &aNetwork);
355 HRESULT removeNATNetwork(const ComPtr<INATNetwork> &aNetwork);
356 HRESULT checkFirmwarePresent(FirmwareType_T aFirmwareType,
357 const com::Utf8Str &aVersion,
358 com::Utf8Str &aUrl,
359 com::Utf8Str &aFile,
360 BOOL *aResult);
361
362 static HRESULT i_setErrorStaticBoth(HRESULT aResultCode, int vrc, const Utf8Str &aText)
363 {
364 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true, vrc);
365 }
366
367 HRESULT i_registerMachine(Machine *aMachine);
368 HRESULT i_registerDHCPServer(DHCPServer *aDHCPServer,
369 bool aSaveRegistry = true);
370 HRESULT i_unregisterDHCPServer(DHCPServer *aDHCPServer);
371 HRESULT i_registerNATNetwork(NATNetwork *aNATNetwork,
372 bool aSaveRegistry = true);
373 HRESULT i_unregisterNATNetwork(NATNetwork *aNATNetwork,
374 bool aSaveRegistry = true);
375 HRESULT i_checkMediaForConflicts(const Guid &aId,
376 const Utf8Str &aLocation,
377 Utf8Str &aConflictType,
378 ComObjPtr<Medium> *pDupMedium);
379 int i_decryptSettings();
380 int i_decryptMediumSettings(Medium *pMedium);
381 int i_decryptSettingBytes(uint8_t *aPlaintext,
382 const uint8_t *aCiphertext,
383 size_t aCiphertextSize) const;
384 int i_encryptSettingBytes(const uint8_t *aPlaintext,
385 uint8_t *aCiphertext,
386 size_t aPlaintextSize,
387 size_t aCiphertextSize) const;
388 void i_reportDriverVersions(void);
389
390 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
391
392 Data *m;
393
394 /* static variables (defined in VirtualBoxImpl.cpp) */
395 static com::Utf8Str sVersion;
396 static com::Utf8Str sVersionNormalized;
397 static ULONG sRevision;
398 static com::Utf8Str sPackageType;
399 static com::Utf8Str sAPIVersion;
400 static std::map<com::Utf8Str, int> sNatNetworkNameToRefCount;
401 static RWLockHandle* spMtxNatNetworkNameToRefCountLock;
402
403 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
404
405#ifdef RT_OS_WINDOWS
406 friend class StartSVCHelperClientData;
407 static void i_SVCHelperClientThreadTask(StartSVCHelperClientData *pTask);
408#endif
409
410#if defined(RT_OS_WINDOWS) && defined(VBOXSVC_WITH_CLIENT_WATCHER)
411protected:
412 void i_callHook(const char *a_pszFunction) RT_OVERRIDE;
413 bool i_watchClientProcess(RTPROCESS a_pidClient, const char *a_pszFunction);
414public:
415 static void i_logCaller(const char *a_pszFormat, ...);
416private:
417
418#endif
419};
420
421////////////////////////////////////////////////////////////////////////////////
422
423#endif // !____H_VIRTUALBOXIMPL
424
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