VirtualBox

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

Last change on this file since 50174 was 48955, checked in by vboxsync, 11 years ago

Main: Whitespace (including tabs!) and svn:keywords cleanups by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 KB
Line 
1/* $Id: VirtualBoxImpl.h 48955 2013-10-07 21:59:25Z 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 void onHostNameResolutionConfigurationChange();
229
230 int natNetworkRefInc(IN_BSTR aNetworkName);
231 int natNetworkRefDec(IN_BSTR aNetworkName);
232
233 ComObjPtr<GuestOSType> getUnknownOSType();
234
235 void getOpenedMachines(SessionMachinesList &aMachines,
236 InternalControlList *aControls = NULL);
237 MachinesOList &getMachinesList();
238
239 HRESULT findMachine(const Guid &aId,
240 bool fPermitInaccessible,
241 bool aSetError,
242 ComObjPtr<Machine> *aMachine = NULL);
243 HRESULT findMachineByName(const Utf8Str &aName,
244 bool aSetError,
245 ComObjPtr<Machine> *aMachine = NULL);
246
247 HRESULT validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
248 HRESULT convertMachineGroups(ComSafeArrayIn(IN_BSTR, aMachineGroups), StringsList *pllMachineGroups);
249
250 HRESULT findHardDiskById(const Guid &id,
251 bool aSetError,
252 ComObjPtr<Medium> *aHardDisk = NULL);
253 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
254 bool aSetError,
255 ComObjPtr<Medium> *aHardDisk = NULL);
256 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
257 const Guid *aId,
258 const Utf8Str &aLocation,
259 bool aSetError,
260 ComObjPtr<Medium> *aImage = NULL);
261 HRESULT findRemoveableMedium(DeviceType_T mediumType,
262 const Guid &uuid,
263 bool fRefresh,
264 bool aSetError,
265 ComObjPtr<Medium> &pMedium);
266
267 HRESULT findGuestOSType(const Bstr &bstrOSType,
268 GuestOSType*& pGuestOSType);
269
270 const Guid &getGlobalRegistryId() const;
271
272 const ComObjPtr<Host>& host() const;
273 SystemProperties* getSystemProperties() const;
274#ifdef VBOX_WITH_EXTPACK
275 ExtPackManager* getExtPackManager() const;
276#endif
277#ifdef VBOX_WITH_RESOURCE_USAGE_API
278 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
279#endif /* VBOX_WITH_RESOURCE_USAGE_API */
280
281 void getDefaultMachineFolder(Utf8Str &str) const;
282 void getDefaultHardDiskFormat(Utf8Str &str) const;
283
284 /** Returns the VirtualBox home directory */
285 const Utf8Str& homeDir() const;
286
287 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
288 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
289
290 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
291 HRESULT unregisterMedium(Medium *pMedium);
292
293 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
294 HRESULT unregisterMachineMedia(const Guid &id);
295
296 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
297
298 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
299 const Utf8Str &strNewConfigDir);
300
301 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
302 const Guid &uuidRegistry,
303 const Utf8Str &strMachineFolder);
304 HRESULT saveSettings();
305
306 void markRegistryModified(const Guid &uuid);
307 void saveModifiedRegistries();
308
309 static const Bstr &getVersionNormalized();
310
311 static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
312
313 const Utf8Str& settingsFilePath();
314
315 AutostartDb* getAutostartDb() const;
316
317 RWLockHandle& getMachinesListLockHandle();
318 RWLockHandle& getMediaTreeLockHandle();
319
320 int encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
321 int decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
322 void storeSettingsKey(const Utf8Str &aKey);
323
324 bool isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
325
326private:
327 class ClientWatcher;
328
329 static HRESULT setErrorStatic(HRESULT aResultCode,
330 const Utf8Str &aText)
331 {
332 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
333 }
334
335 HRESULT registerMachine(Machine *aMachine);
336
337 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
338 bool aSaveRegistry = true);
339 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
340 bool aSaveRegistry = true);
341 HRESULT registerNATNetwork(NATNetwork *aNATNetwork,
342 bool aSaveRegistry = true);
343 HRESULT unregisterNATNetwork(NATNetwork *aNATNetwork,
344 bool aSaveRegistry = true);
345 HRESULT checkMediaForConflicts(const Guid &aId,
346 const Utf8Str &aLocation,
347 Utf8Str &aConflictType,
348 ComObjPtr<Medium> *pDupMedium);
349
350 int decryptSettings();
351 int decryptMediumSettings(Medium *pMedium);
352 int decryptSettingBytes(uint8_t *aPlaintext, const uint8_t *aCiphertext,
353 size_t aCiphertextSize) const;
354 int encryptSettingBytes(const uint8_t *aPlaintext, uint8_t *aCiphertext,
355 size_t aPlaintextSize, size_t aCiphertextSize) const;
356
357 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
358 Data *m;
359
360 /* static variables (defined in VirtualBoxImpl.cpp) */
361 static Bstr sVersion;
362 static Bstr sVersionNormalized;
363 static ULONG sRevision;
364 static Bstr sPackageType;
365 static Bstr sAPIVersion;
366 static std::map<Bstr, int> sNatNetworkNameToRefCount;
367 static RWLockHandle* spMtxNatNetworkNameToRefCountLock;
368
369 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
370
371#ifdef RT_OS_WINDOWS
372 static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
373#endif
374};
375
376////////////////////////////////////////////////////////////////////////////////
377
378#endif // !____H_VIRTUALBOXIMPL
379
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