VirtualBox

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

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

Main: bugref:6913: Added generation of some medium events. Contains some fixes for VBoxSVC crash in the MacOS

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.1 KB
Line 
1/* $Id: VirtualBoxImpl.h 76298 2018-12-19 18:17:50Z 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_onMediumRegistered(const Guid &aMediumId, const DeviceType_T aDevType, const BOOL aRegistered);
153 void i_onMediumConfigChanged(IMedium *aMedium);
154 void i_onMediumChanged(IMediumAttachment* aMediumAttachment);
155 void i_onStorageDeviceChanged(IMediumAttachment* aStorageDevice, const BOOL fRemoved, const BOOL fSilent);
156 void i_onMachineStateChange(const Guid &aId, MachineState_T aState);
157 void i_onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
158 BOOL i_onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
159 Bstr &aError);
160 void i_onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
161 void i_onMachineRegistered(const Guid &aId, BOOL aRegistered);
162 void i_onSessionStateChange(const Guid &aId, SessionState_T aState);
163
164 void i_onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
165 void i_onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
166 void i_onSnapshotRestored(const Guid &aMachineId, const Guid &aSnapshotId);
167 void i_onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
168 void i_onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
169 IN_BSTR aFlags);
170 void i_onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
171 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
172 IN_BSTR aGuestIp, uint16_t aGuestPort);
173 void i_onNATNetworkChange(IN_BSTR aNetworkName);
174 void i_onNATNetworkStartStop(IN_BSTR aNetworkName, BOOL aStart);
175 void i_onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled, IN_BSTR aNetwork,
176 IN_BSTR aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
177 BOOL fNeedDhcpServer);
178 void i_onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,
179 IN_BSTR aRuleName, NATProtocol_T proto,
180 IN_BSTR aHostIp, LONG aHostPort,
181 IN_BSTR aGuestIp, LONG aGuestPort);
182 void i_onHostNameResolutionConfigurationChange();
183
184 int i_natNetworkRefInc(const Utf8Str &aNetworkName);
185 int i_natNetworkRefDec(const Utf8Str &aNetworkName);
186
187 ComObjPtr<GuestOSType> i_getUnknownOSType();
188
189 void i_getOpenedMachines(SessionMachinesList &aMachines,
190 InternalControlList *aControls = NULL);
191 MachinesOList &i_getMachinesList();
192
193 HRESULT i_findMachine(const Guid &aId,
194 bool fPermitInaccessible,
195 bool aSetError,
196 ComObjPtr<Machine> *aMachine = NULL);
197
198 HRESULT i_findMachineByName(const Utf8Str &aName,
199 bool aSetError,
200 ComObjPtr<Machine> *aMachine = NULL);
201
202 HRESULT i_validateMachineGroup(const com::Utf8Str &aGroup, bool fPrimary);
203 HRESULT i_convertMachineGroups(const std::vector<com::Utf8Str> aMachineGroups, StringsList *pllMachineGroups);
204
205 HRESULT i_findHardDiskById(const Guid &id,
206 bool aSetError,
207 ComObjPtr<Medium> *aHardDisk = NULL);
208 HRESULT i_findHardDiskByLocation(const Utf8Str &strLocation,
209 bool aSetError,
210 ComObjPtr<Medium> *aHardDisk = NULL);
211 HRESULT i_findDVDOrFloppyImage(DeviceType_T mediumType,
212 const Guid *aId,
213 const Utf8Str &aLocation,
214 bool aSetError,
215 ComObjPtr<Medium> *aImage = NULL);
216 HRESULT i_findRemoveableMedium(DeviceType_T mediumType,
217 const Guid &uuid,
218 bool fRefresh,
219 bool aSetError,
220 ComObjPtr<Medium> &pMedium);
221
222 HRESULT i_findGuestOSType(const Utf8Str &strOSType,
223 ComObjPtr<GuestOSType> &guestOSType);
224
225 const Guid &i_getGlobalRegistryId() const;
226
227 const ComObjPtr<Host> &i_host() const;
228 SystemProperties *i_getSystemProperties() const;
229 CloudProviderManager *i_getCloudProviderManager() const;
230#ifdef VBOX_WITH_EXTPACK
231 ExtPackManager *i_getExtPackManager() const;
232#endif
233#ifdef VBOX_WITH_RESOURCE_USAGE_API
234 const ComObjPtr<PerformanceCollector> &i_performanceCollector() const;
235#endif /* VBOX_WITH_RESOURCE_USAGE_API */
236
237 void i_getDefaultMachineFolder(Utf8Str &str) const;
238 void i_getDefaultHardDiskFormat(Utf8Str &str) const;
239
240 /** Returns the VirtualBox home directory */
241 const Utf8Str &i_homeDir() const;
242 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
243 void i_copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
244 HRESULT i_registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium,
245 AutoWriteLock &mediaTreeLock);
246 HRESULT i_unregisterMedium(Medium *pMedium);
247 void i_pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
248 HRESULT i_unregisterMachineMedia(const Guid &id);
249 HRESULT i_unregisterMachine(Machine *pMachine, const Guid &id);
250 void i_rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
251 const Utf8Str &strNewConfigDir);
252 void i_saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
253 const Guid &uuidRegistry,
254 const Utf8Str &strMachineFolder);
255 HRESULT i_saveSettings();
256 void i_markRegistryModified(const Guid &uuid);
257 void i_unmarkRegistryModified(const Guid &uuid);
258 void i_saveModifiedRegistries();
259 static const com::Utf8Str &i_getVersionNormalized();
260 static HRESULT i_ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
261 const Utf8Str& i_settingsFilePath();
262 AutostartDb* i_getAutostartDb() const;
263 RWLockHandle& i_getMachinesListLockHandle();
264 RWLockHandle& i_getMediaTreeLockHandle();
265 int i_encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
266 int i_decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
267 void i_storeSettingsKey(const Utf8Str &aKey);
268 bool i_isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
269
270
271
272private:
273 class ClientWatcher;
274
275 // wrapped IVirtualBox properties
276 HRESULT getVersion(com::Utf8Str &aVersion);
277 HRESULT getVersionNormalized(com::Utf8Str &aVersionNormalized);
278 HRESULT getRevision(ULONG *aRevision);
279 HRESULT getPackageType(com::Utf8Str &aPackageType);
280 HRESULT getAPIVersion(com::Utf8Str &aAPIVersion);
281 HRESULT getAPIRevision(LONG64 *aAPIRevision);
282 HRESULT getHomeFolder(com::Utf8Str &aHomeFolder);
283 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
284 HRESULT getHost(ComPtr<IHost> &aHost);
285 HRESULT getSystemProperties(ComPtr<ISystemProperties> &aSystemProperties);
286 HRESULT getMachines(std::vector<ComPtr<IMachine> > &aMachines);
287 HRESULT getMachineGroups(std::vector<com::Utf8Str> &aMachineGroups);
288 HRESULT getHardDisks(std::vector<ComPtr<IMedium> > &aHardDisks);
289 HRESULT getDVDImages(std::vector<ComPtr<IMedium> > &aDVDImages);
290 HRESULT getFloppyImages(std::vector<ComPtr<IMedium> > &aFloppyImages);
291 HRESULT getProgressOperations(std::vector<ComPtr<IProgress> > &aProgressOperations);
292 HRESULT getGuestOSTypes(std::vector<ComPtr<IGuestOSType> > &aGuestOSTypes);
293 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
294 HRESULT getPerformanceCollector(ComPtr<IPerformanceCollector> &aPerformanceCollector);
295 HRESULT getDHCPServers(std::vector<ComPtr<IDHCPServer> > &aDHCPServers);
296 HRESULT getNATNetworks(std::vector<ComPtr<INATNetwork> > &aNATNetworks);
297 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
298 HRESULT getExtensionPackManager(ComPtr<IExtPackManager> &aExtensionPackManager);
299 HRESULT getInternalNetworks(std::vector<com::Utf8Str> &aInternalNetworks);
300 HRESULT getGenericNetworkDrivers(std::vector<com::Utf8Str> &aGenericNetworkDrivers);
301 HRESULT getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager);
302
303 // wrapped IVirtualBox methods
304 HRESULT composeMachineFilename(const com::Utf8Str &aName,
305 const com::Utf8Str &aGroup,
306 const com::Utf8Str &aCreateFlags,
307 const com::Utf8Str &aBaseFolder,
308 com::Utf8Str &aFile);
309 HRESULT createMachine(const com::Utf8Str &aSettingsFile,
310 const com::Utf8Str &aName,
311 const std::vector<com::Utf8Str> &aGroups,
312 const com::Utf8Str &aOsTypeId,
313 const com::Utf8Str &aFlags,
314 ComPtr<IMachine> &aMachine);
315 HRESULT openMachine(const com::Utf8Str &aSettingsFile,
316 ComPtr<IMachine> &aMachine);
317 HRESULT registerMachine(const ComPtr<IMachine> &aMachine);
318 HRESULT findMachine(const com::Utf8Str &aNameOrId,
319 ComPtr<IMachine> &aMachine);
320 HRESULT getMachinesByGroups(const std::vector<com::Utf8Str> &aGroups,
321 std::vector<ComPtr<IMachine> > &aMachines);
322 HRESULT getMachineStates(const std::vector<ComPtr<IMachine> > &aMachines,
323 std::vector<MachineState_T> &aStates);
324 HRESULT createAppliance(ComPtr<IAppliance> &aAppliance);
325 HRESULT createUnattendedInstaller(ComPtr<IUnattended> &aUnattended);
326 HRESULT createMedium(const com::Utf8Str &aFormat,
327 const com::Utf8Str &aLocation,
328 AccessMode_T aAccessMode,
329 DeviceType_T aDeviceType,
330 ComPtr<IMedium> &aMedium);
331 HRESULT openMedium(const com::Utf8Str &aLocation,
332 DeviceType_T aDeviceType,
333 AccessMode_T aAccessMode,
334 BOOL aForceNewUuid,
335 ComPtr<IMedium> &aMedium);
336 HRESULT getGuestOSType(const com::Utf8Str &aId,
337 ComPtr<IGuestOSType> &aType);
338 HRESULT createSharedFolder(const com::Utf8Str &aName,
339 const com::Utf8Str &aHostPath,
340 BOOL aWritable,
341 BOOL aAutomount,
342 const com::Utf8Str &aAutoMountPoint);
343 HRESULT removeSharedFolder(const com::Utf8Str &aName);
344 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
345 HRESULT getExtraData(const com::Utf8Str &aKey,
346 com::Utf8Str &aValue);
347 HRESULT setExtraData(const com::Utf8Str &aKey,
348 const com::Utf8Str &aValue);
349 HRESULT setSettingsSecret(const com::Utf8Str &aPassword);
350 HRESULT createDHCPServer(const com::Utf8Str &aName,
351 ComPtr<IDHCPServer> &aServer);
352 HRESULT findDHCPServerByNetworkName(const com::Utf8Str &aName,
353 ComPtr<IDHCPServer> &aServer);
354 HRESULT removeDHCPServer(const ComPtr<IDHCPServer> &aServer);
355 HRESULT createNATNetwork(const com::Utf8Str &aNetworkName,
356 ComPtr<INATNetwork> &aNetwork);
357 HRESULT findNATNetworkByName(const com::Utf8Str &aNetworkName,
358 ComPtr<INATNetwork> &aNetwork);
359 HRESULT removeNATNetwork(const ComPtr<INATNetwork> &aNetwork);
360 HRESULT checkFirmwarePresent(FirmwareType_T aFirmwareType,
361 const com::Utf8Str &aVersion,
362 com::Utf8Str &aUrl,
363 com::Utf8Str &aFile,
364 BOOL *aResult);
365
366 static HRESULT i_setErrorStaticBoth(HRESULT aResultCode, int vrc, const Utf8Str &aText)
367 {
368 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true, vrc);
369 }
370
371 HRESULT i_registerMachine(Machine *aMachine);
372 HRESULT i_registerDHCPServer(DHCPServer *aDHCPServer,
373 bool aSaveRegistry = true);
374 HRESULT i_unregisterDHCPServer(DHCPServer *aDHCPServer);
375 HRESULT i_registerNATNetwork(NATNetwork *aNATNetwork,
376 bool aSaveRegistry = true);
377 HRESULT i_unregisterNATNetwork(NATNetwork *aNATNetwork,
378 bool aSaveRegistry = true);
379 HRESULT i_checkMediaForConflicts(const Guid &aId,
380 const Utf8Str &aLocation,
381 Utf8Str &aConflictType,
382 ComObjPtr<Medium> *pDupMedium);
383 int i_decryptSettings();
384 int i_decryptMediumSettings(Medium *pMedium);
385 int i_decryptSettingBytes(uint8_t *aPlaintext,
386 const uint8_t *aCiphertext,
387 size_t aCiphertextSize) const;
388 int i_encryptSettingBytes(const uint8_t *aPlaintext,
389 uint8_t *aCiphertext,
390 size_t aPlaintextSize,
391 size_t aCiphertextSize) const;
392 void i_reportDriverVersions(void);
393
394 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
395
396 Data *m;
397
398 /* static variables (defined in VirtualBoxImpl.cpp) */
399 static com::Utf8Str sVersion;
400 static com::Utf8Str sVersionNormalized;
401 static ULONG sRevision;
402 static com::Utf8Str sPackageType;
403 static com::Utf8Str sAPIVersion;
404 static std::map<com::Utf8Str, int> sNatNetworkNameToRefCount;
405 static RWLockHandle* spMtxNatNetworkNameToRefCountLock;
406
407 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
408
409#ifdef RT_OS_WINDOWS
410 friend class StartSVCHelperClientData;
411 static void i_SVCHelperClientThreadTask(StartSVCHelperClientData *pTask);
412#endif
413
414#if defined(RT_OS_WINDOWS) && defined(VBOXSVC_WITH_CLIENT_WATCHER)
415protected:
416 void i_callHook(const char *a_pszFunction) RT_OVERRIDE;
417 bool i_watchClientProcess(RTPROCESS a_pidClient, const char *a_pszFunction);
418public:
419 static void i_logCaller(const char *a_pszFormat, ...);
420private:
421
422#endif
423};
424
425////////////////////////////////////////////////////////////////////////////////
426
427#endif // !____H_VIRTUALBOXIMPL
428
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