VirtualBox

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

Last change on this file since 68222 was 68133, checked in by vboxsync, 7 years ago

Unattended: Moved the createUnattendedInstaller method from IMachine to IVirtualBox as we will be needing it without a virtual machine in a new-vm-from-installation-iso wizard.

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