VirtualBox

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

Last change on this file since 84627 was 83169, checked in by vboxsync, 5 years ago

OCI: (bugref:9469) cloud network integration multiple targets and configuration support (enabled in Config.kmk).

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