VirtualBox

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

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

Main/ExtPackManager+CloudProviderManager+VirtualBox: Handle runtime install and uninstall of extension packs containing cloud providers. This is a safeguard against uninstalling active cloud providers (which would cause crashes), and makes the install more convcenient. At the same time it eliminated the need to have a special "detect all cloud providers" logic when VBoxSVC is started. It achieves perfect singleton property of the per-extpack CloudProviderManager and the related CloudProvider objects. Nothing is ever created twice (which would cause trouble with coordinating e.g. the profile file updates).

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette