VirtualBox

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

Last change on this file since 48112 was 47561, checked in by vboxsync, 11 years ago

Main/VirtualBox+Machine+Session: separate out the client death detection functionality into separate objects

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.8 KB
Line 
1/* $Id: VirtualBoxImpl.h 47561 2013-08-06 15:18:17Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2013 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
24#ifdef RT_OS_WINDOWS
25# include "win/resource.h"
26#endif
27
28namespace com
29{
30 class Event;
31 class EventQueue;
32}
33
34class SessionMachine;
35class GuestOSType;
36class Progress;
37class Host;
38class SystemProperties;
39class DHCPServer;
40class PerformanceCollector;
41#ifdef VBOX_WITH_EXTPACK
42class ExtPackManager;
43#endif
44class AutostartDb;
45class NATNetwork;
46
47
48typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;
49
50#ifdef RT_OS_WINDOWS
51class SVCHlpClient;
52#endif
53
54namespace settings
55{
56 class MainConfigFile;
57 struct MediaRegistry;
58}
59class ATL_NO_VTABLE VirtualBox :
60 public VirtualBoxBase,
61 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
62#ifdef RT_OS_WINDOWS
63 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
64#endif
65{
66
67public:
68
69 typedef std::list<ComPtr<IInternalSessionControl> > InternalControlList;
70 typedef ObjectsList<Machine> MachinesOList;
71
72 class CallbackEvent;
73 friend class CallbackEvent;
74
75 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
76
77 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
78
79 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
80 DECLARE_NOT_AGGREGATABLE(VirtualBox)
81
82 DECLARE_PROTECT_FINAL_CONSTRUCT()
83
84 BEGIN_COM_MAP(VirtualBox)
85 VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualBox)
86 END_COM_MAP()
87
88 // to postpone generation of the default ctor/dtor
89 VirtualBox();
90 ~VirtualBox();
91
92 HRESULT FinalConstruct();
93 void FinalRelease();
94
95 /* public initializer/uninitializer for internal purposes only */
96 HRESULT init();
97 HRESULT initMachines();
98 HRESULT initMedia(const Guid &uuidMachineRegistry,
99 const settings::MediaRegistry mediaRegistry,
100 const Utf8Str &strMachineFolder);
101 void uninit();
102
103 /* IVirtualBox properties */
104 STDMETHOD(COMGETTER(Version))(BSTR *aVersion);
105 STDMETHOD(COMGETTER(VersionNormalized))(BSTR *aVersionNormalized);
106 STDMETHOD(COMGETTER(Revision))(ULONG *aRevision);
107 STDMETHOD(COMGETTER(PackageType))(BSTR *aPackageType);
108 STDMETHOD(COMGETTER(APIVersion))(BSTR *aAPIVersion);
109 STDMETHOD(COMGETTER(HomeFolder))(BSTR *aHomeFolder);
110 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aSettingsFilePath);
111 STDMETHOD(COMGETTER(Host))(IHost **aHost);
112 STDMETHOD(COMGETTER(SystemProperties))(ISystemProperties **aSystemProperties);
113 STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(IMachine *, aMachines));
114 STDMETHOD(COMGETTER(MachineGroups))(ComSafeArrayOut(BSTR, aMachineGroups));
115 STDMETHOD(COMGETTER(HardDisks))(ComSafeArrayOut(IMedium *, aHardDisks));
116 STDMETHOD(COMGETTER(DVDImages))(ComSafeArrayOut(IMedium *, aDVDImages));
117 STDMETHOD(COMGETTER(FloppyImages))(ComSafeArrayOut(IMedium *, aFloppyImages));
118 STDMETHOD(COMGETTER(ProgressOperations))(ComSafeArrayOut(IProgress *, aOperations));
119 STDMETHOD(COMGETTER(GuestOSTypes))(ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
120 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
121 STDMETHOD(COMGETTER(PerformanceCollector))(IPerformanceCollector **aPerformanceCollector);
122 STDMETHOD(COMGETTER(DHCPServers))(ComSafeArrayOut(IDHCPServer *, aDHCPServers));
123 STDMETHOD(COMGETTER(NATNetworks))(ComSafeArrayOut(INATNetwork *, aNATNetworks));
124 STDMETHOD(COMGETTER(EventSource))(IEventSource ** aEventSource);
125 STDMETHOD(COMGETTER(ExtensionPackManager))(IExtPackManager **aExtPackManager);
126 STDMETHOD(COMGETTER(InternalNetworks))(ComSafeArrayOut(BSTR, aInternalNetworks));
127 STDMETHOD(COMGETTER(GenericNetworkDrivers))(ComSafeArrayOut(BSTR, aGenericNetworkDrivers));
128
129 /* IVirtualBox methods */
130 STDMETHOD(ComposeMachineFilename)(IN_BSTR aName, IN_BSTR aGroup, IN_BSTR aCreateFlags, IN_BSTR aBaseFolder, BSTR *aFilename);
131 STDMETHOD(CreateMachine)(IN_BSTR aSettingsFile,
132 IN_BSTR aName,
133 ComSafeArrayIn(IN_BSTR, aGroups),
134 IN_BSTR aOsTypeId,
135 IN_BSTR aCreateFlags,
136 IMachine **aMachine);
137 STDMETHOD(OpenMachine)(IN_BSTR aSettingsFile, IMachine **aMachine);
138 STDMETHOD(RegisterMachine)(IMachine *aMachine);
139 STDMETHOD(FindMachine)(IN_BSTR aNameOrId, IMachine **aMachine);
140 STDMETHOD(GetMachinesByGroups)(ComSafeArrayIn(IN_BSTR, aGroups), ComSafeArrayOut(IMachine *, aMachines));
141 STDMETHOD(GetMachineStates)(ComSafeArrayIn(IMachine *, aMachines), ComSafeArrayOut(MachineState_T, aStates));
142 STDMETHOD(CreateAppliance)(IAppliance **anAppliance);
143
144 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
145 IN_BSTR aLocation,
146 IMedium **aHardDisk);
147 STDMETHOD(OpenMedium)(IN_BSTR aLocation,
148 DeviceType_T deviceType,
149 AccessMode_T accessMode,
150 BOOL fForceNewUuid,
151 IMedium **aMedium);
152
153 STDMETHOD(GetGuestOSType)(IN_BSTR aId, IGuestOSType **aType);
154 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
155 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
156 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
157 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
158 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
159 STDMETHOD(SetSettingsSecret)(IN_BSTR aKey);
160
161 STDMETHOD(CreateDHCPServer)(IN_BSTR aName, IDHCPServer ** aServer);
162 STDMETHOD(FindDHCPServerByNetworkName)(IN_BSTR aName, IDHCPServer ** aServer);
163 STDMETHOD(RemoveDHCPServer)(IDHCPServer * aServer);
164
165 STDMETHOD(CreateNATNetwork)(IN_BSTR aName, INATNetwork ** aNATNetworks);
166 STDMETHOD(FindNATNetworkByName)(IN_BSTR aName, INATNetwork ** aNATNetworks);
167 STDMETHOD(RemoveNATNetwork)(INATNetwork * aNATNetwork);
168
169 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
170 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
171
172 /* public methods only for internal purposes */
173
174 /**
175 * Override of the default locking class to be used for validating lock
176 * order with the standard member lock handle.
177 */
178 virtual VBoxLockingClass getLockingClass() const
179 {
180 return LOCKCLASS_VIRTUALBOXOBJECT;
181 }
182
183#ifdef DEBUG
184 void dumpAllBackRefs();
185#endif
186
187 HRESULT postEvent(Event *event);
188
189 HRESULT addProgress(IProgress *aProgress);
190 HRESULT removeProgress(IN_GUID aId);
191
192#ifdef RT_OS_WINDOWS
193 typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
194 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
195 HRESULT startSVCHelperClient(bool aPrivileged,
196 SVCHelperClientFunc aFunc,
197 void *aUser, Progress *aProgress);
198#endif
199
200 void addProcessToReap(RTPROCESS pid);
201 void updateClientWatcher();
202
203 void onMachineStateChange(const Guid &aId, MachineState_T aState);
204 void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
205 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
206 Bstr &aError);
207 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
208 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
209 void onSessionStateChange(const Guid &aId, SessionState_T aState);
210
211 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
212 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
213 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
214 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
215 IN_BSTR aFlags);
216 void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
217 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
218 IN_BSTR aGuestIp, uint16_t aGuestPort);
219 void onNATNetworkChange(IN_BSTR aNetworkName);
220 void onNATNetworkStartStop(IN_BSTR aNetworkName, BOOL aStart);
221 void onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled, IN_BSTR aNetwork,
222 IN_BSTR aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
223 BOOL fNeedDhcpServer);
224 void onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,
225 IN_BSTR aRuleName, NATProtocol_T proto,
226 IN_BSTR aHostIp, LONG aHostPort,
227 IN_BSTR aGuestIp, LONG aGuestPort);
228
229 ComObjPtr<GuestOSType> getUnknownOSType();
230
231 void getOpenedMachines(SessionMachinesList &aMachines,
232 InternalControlList *aControls = NULL);
233 MachinesOList &getMachinesList();
234
235 HRESULT findMachine(const Guid &aId,
236 bool fPermitInaccessible,
237 bool aSetError,
238 ComObjPtr<Machine> *aMachine = NULL);
239 HRESULT findMachineByName(const Utf8Str &aName,
240 bool aSetError,
241 ComObjPtr<Machine> *aMachine = NULL);
242
243 HRESULT validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
244 HRESULT convertMachineGroups(ComSafeArrayIn(IN_BSTR, aMachineGroups), StringsList *pllMachineGroups);
245
246 HRESULT findHardDiskById(const Guid &id,
247 bool aSetError,
248 ComObjPtr<Medium> *aHardDisk = NULL);
249 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
250 bool aSetError,
251 ComObjPtr<Medium> *aHardDisk = NULL);
252 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
253 const Guid *aId,
254 const Utf8Str &aLocation,
255 bool aSetError,
256 ComObjPtr<Medium> *aImage = NULL);
257 HRESULT findRemoveableMedium(DeviceType_T mediumType,
258 const Guid &uuid,
259 bool fRefresh,
260 bool aSetError,
261 ComObjPtr<Medium> &pMedium);
262
263 HRESULT findGuestOSType(const Bstr &bstrOSType,
264 GuestOSType*& pGuestOSType);
265
266 const Guid &getGlobalRegistryId() const;
267
268 const ComObjPtr<Host>& host() const;
269 SystemProperties* getSystemProperties() const;
270#ifdef VBOX_WITH_EXTPACK
271 ExtPackManager* getExtPackManager() const;
272#endif
273#ifdef VBOX_WITH_RESOURCE_USAGE_API
274 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
275#endif /* VBOX_WITH_RESOURCE_USAGE_API */
276
277 void getDefaultMachineFolder(Utf8Str &str) const;
278 void getDefaultHardDiskFormat(Utf8Str &str) const;
279
280 /** Returns the VirtualBox home directory */
281 const Utf8Str& homeDir() const;
282
283 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
284 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
285
286 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
287 HRESULT unregisterMedium(Medium *pMedium);
288
289 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
290 HRESULT unregisterMachineMedia(const Guid &id);
291
292 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
293
294 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
295 const Utf8Str &strNewConfigDir);
296
297 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
298 const Guid &uuidRegistry,
299 const Utf8Str &strMachineFolder);
300 HRESULT saveSettings();
301
302 void markRegistryModified(const Guid &uuid);
303 void saveModifiedRegistries();
304
305 static const Bstr &getVersionNormalized();
306
307 static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
308
309 const Utf8Str& settingsFilePath();
310
311 AutostartDb* getAutostartDb() const;
312
313 RWLockHandle& getMediaTreeLockHandle();
314
315 int encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
316 int decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
317 void storeSettingsKey(const Utf8Str &aKey);
318
319 bool isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
320
321private:
322 class ClientWatcher;
323
324 static HRESULT setErrorStatic(HRESULT aResultCode,
325 const Utf8Str &aText)
326 {
327 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
328 }
329
330 HRESULT registerMachine(Machine *aMachine);
331
332 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
333 bool aSaveRegistry = true);
334 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
335 bool aSaveRegistry = true);
336 HRESULT registerNATNetwork(NATNetwork *aNATNetwork,
337 bool aSaveRegistry = true);
338 HRESULT unregisterNATNetwork(NATNetwork *aNATNetwork,
339 bool aSaveRegistry = true);
340 HRESULT checkMediaForConflicts(const Guid &aId,
341 const Utf8Str &aLocation,
342 Utf8Str &aConflictType,
343 ComObjPtr<Medium> *pDupMedium);
344
345 int decryptSettings();
346 int decryptMediumSettings(Medium *pMedium);
347 int decryptSettingBytes(uint8_t *aPlaintext, const uint8_t *aCiphertext,
348 size_t aCiphertextSize) const;
349 int encryptSettingBytes(const uint8_t *aPlaintext, uint8_t *aCiphertext,
350 size_t aPlaintextSize, size_t aCiphertextSize) const;
351
352 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
353 Data *m;
354
355 /* static variables (defined in VirtualBoxImpl.cpp) */
356 static Bstr sVersion;
357 static Bstr sVersionNormalized;
358 static ULONG sRevision;
359 static Bstr sPackageType;
360 static Bstr sAPIVersion;
361
362 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
363
364#ifdef RT_OS_WINDOWS
365 static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
366#endif
367};
368
369////////////////////////////////////////////////////////////////////////////////
370
371#endif // !____H_VIRTUALBOXIMPL
372
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