VirtualBox

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

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

Shared Clipboard/URI: Update.

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