VirtualBox

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

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

Main/CloudProviderManager+CloudProvider+CloudProfile: Introduce CloudProfile as separate interface, and do a big cleanup. Adding synchronization and incomplete support for moving to an extension pack. Updated VBoxManage to list providers and touched up the GUI code slightly to deal with the changed interfaces.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use