VirtualBox

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

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

Main: bugref:6913: Added OnStorageControllerChanged to IVirtualBox events and fixed generation the medium events

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