VirtualBox

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

Last change on this file since 51856 was 50380, checked in by vboxsync, 11 years ago

Main: fixed attribute type of IVirtualBox::getGuestOSType(). It's a string, not a Guid.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.4 KB
Line 
1/* $Id: VirtualBoxImpl.h 50380 2014-02-10 10:31:35Z 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#include "VirtualBoxWrap.h"
24
25#ifdef RT_OS_WINDOWS
26# include "win/resource.h"
27#endif
28
29namespace com
30{
31 class Event;
32 class EventQueue;
33}
34
35class SessionMachine;
36class GuestOSType;
37class Progress;
38class Host;
39class SystemProperties;
40class DHCPServer;
41class PerformanceCollector;
42#ifdef VBOX_WITH_EXTPACK
43class ExtPackManager;
44#endif
45class AutostartDb;
46class NATNetwork;
47
48
49typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;
50
51#ifdef RT_OS_WINDOWS
52class SVCHlpClient;
53#endif
54
55namespace settings
56{
57 class MainConfigFile;
58 struct MediaRegistry;
59}
60class ATL_NO_VTABLE VirtualBox :
61 public VirtualBoxWrap
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 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
76
77 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
78
79 // Kind of redundant (VirtualBoxWrap declares itself not aggregatable and
80 // CComCoClass<VirtualBox, &CLSID_VirtualBox> as aggregatable, the former
81 // is the first inheritance), but the C++ multiple inheritance rules and
82 // the class factory in svcmain.cpp needs this to disambiguate.
83 DECLARE_NOT_AGGREGATABLE(VirtualBox)
84
85 // to postpone generation of the default ctor/dtor
86 DECLARE_EMPTY_CTOR_DTOR(VirtualBox)
87
88 HRESULT FinalConstruct();
89 void FinalRelease();
90
91 /* public initializer/uninitializer for internal purposes only */
92 HRESULT init();
93 HRESULT initMachines();
94 HRESULT initMedia(const Guid &uuidMachineRegistry,
95 const settings::MediaRegistry mediaRegistry,
96 const Utf8Str &strMachineFolder);
97 void uninit();
98
99 /* public methods only for internal purposes */
100
101 /**
102 * Override of the default locking class to be used for validating lock
103 * order with the standard member lock handle.
104 */
105 virtual VBoxLockingClass getLockingClass() const
106 {
107 return LOCKCLASS_VIRTUALBOXOBJECT;
108 }
109
110#ifdef DEBUG
111 void i_dumpAllBackRefs();
112#endif
113
114 HRESULT i_postEvent(Event *event);
115
116 HRESULT i_addProgress(IProgress *aProgress);
117 HRESULT i_removeProgress(IN_GUID aId);
118
119#ifdef RT_OS_WINDOWS
120 typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
121 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
122 HRESULT i_startSVCHelperClient(bool aPrivileged,
123 SVCHelperClientFunc aFunc,
124 void *aUser, Progress *aProgress);
125#endif
126
127 void i_addProcessToReap(RTPROCESS pid);
128 void i_updateClientWatcher();
129
130 void i_onMachineStateChange(const Guid &aId, MachineState_T aState);
131 void i_onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
132 BOOL i_onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
133 Bstr &aError);
134 void i_onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
135 void i_onMachineRegistered(const Guid &aId, BOOL aRegistered);
136 void i_onSessionStateChange(const Guid &aId, SessionState_T aState);
137
138 void i_onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
139 void i_onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
140 void i_onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
141 void i_onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
142 IN_BSTR aFlags);
143 void i_onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
144 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
145 IN_BSTR aGuestIp, uint16_t aGuestPort);
146 void i_onNATNetworkChange(IN_BSTR aNetworkName);
147 void i_onNATNetworkStartStop(IN_BSTR aNetworkName, BOOL aStart);
148 void i_onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled, IN_BSTR aNetwork,
149 IN_BSTR aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
150 BOOL fNeedDhcpServer);
151 void i_onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,
152 IN_BSTR aRuleName, NATProtocol_T proto,
153 IN_BSTR aHostIp, LONG aHostPort,
154 IN_BSTR aGuestIp, LONG aGuestPort);
155 void i_onHostNameResolutionConfigurationChange();
156
157 int i_natNetworkRefInc(IN_BSTR aNetworkName);
158 int i_natNetworkRefDec(IN_BSTR aNetworkName);
159
160 ComObjPtr<GuestOSType> i_getUnknownOSType();
161
162 void i_getOpenedMachines(SessionMachinesList &aMachines,
163 InternalControlList *aControls = NULL);
164 MachinesOList &i_getMachinesList();
165
166 HRESULT i_findMachine(const Guid &aId,
167 bool fPermitInaccessible,
168 bool aSetError,
169 ComObjPtr<Machine> *aMachine = NULL);
170
171 HRESULT i_findMachineByName(const Utf8Str &aName,
172 bool aSetError,
173 ComObjPtr<Machine> *aMachine = NULL);
174
175 HRESULT i_validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
176 HRESULT i_convertMachineGroups(const std::vector<com::Utf8Str> aMachineGroups, StringsList *pllMachineGroups);
177
178 HRESULT i_findHardDiskById(const Guid &id,
179 bool aSetError,
180 ComObjPtr<Medium> *aHardDisk = NULL);
181 HRESULT i_findHardDiskByLocation(const Utf8Str &strLocation,
182 bool aSetError,
183 ComObjPtr<Medium> *aHardDisk = NULL);
184 HRESULT i_findDVDOrFloppyImage(DeviceType_T mediumType,
185 const Guid *aId,
186 const Utf8Str &aLocation,
187 bool aSetError,
188 ComObjPtr<Medium> *aImage = NULL);
189 HRESULT i_findRemoveableMedium(DeviceType_T mediumType,
190 const Guid &uuid,
191 bool fRefresh,
192 bool aSetError,
193 ComObjPtr<Medium> &pMedium);
194
195 HRESULT i_findGuestOSType(const Bstr &bstrOSType,
196 GuestOSType*& pGuestOSType);
197
198 const Guid &i_getGlobalRegistryId() const;
199
200 const ComObjPtr<Host>& i_host() const;
201 SystemProperties* i_getSystemProperties() const;
202#ifdef VBOX_WITH_EXTPACK
203 ExtPackManager* i_getExtPackManager() const;
204#endif
205#ifdef VBOX_WITH_RESOURCE_USAGE_API
206 const ComObjPtr<PerformanceCollector>& i_performanceCollector() const;
207#endif /* VBOX_WITH_RESOURCE_USAGE_API */
208
209 void i_getDefaultMachineFolder(Utf8Str &str) const;
210 void i_getDefaultHardDiskFormat(Utf8Str &str) const;
211
212 /** Returns the VirtualBox home directory */
213 const Utf8Str& i_homeDir() const;
214 int i_calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
215 void i_copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
216 HRESULT i_registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
217 HRESULT i_unregisterMedium(Medium *pMedium);
218 void i_pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
219 HRESULT i_unregisterMachineMedia(const Guid &id);
220 HRESULT i_unregisterMachine(Machine *pMachine, const Guid &id);
221 void i_rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
222 const Utf8Str &strNewConfigDir);
223 void i_saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
224 const Guid &uuidRegistry,
225 const Utf8Str &strMachineFolder);
226 HRESULT i_saveSettings();
227 void i_markRegistryModified(const Guid &uuid);
228 void i_saveModifiedRegistries();
229 static const com::Utf8Str &i_getVersionNormalized();
230 static HRESULT i_ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
231 const Utf8Str& i_settingsFilePath();
232 AutostartDb* i_getAutostartDb() const;
233 RWLockHandle& i_getMachinesListLockHandle();
234 RWLockHandle& i_getMediaTreeLockHandle();
235 int i_encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
236 int i_decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
237 void i_storeSettingsKey(const Utf8Str &aKey);
238 bool i_isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
239
240private:
241 class ClientWatcher;
242
243 // wrapped IVirtualBox properties
244 HRESULT getVersion(com::Utf8Str &aVersion);
245 HRESULT getVersionNormalized(com::Utf8Str &aVersionNormalized);
246 HRESULT getRevision(ULONG *aRevision);
247 HRESULT getPackageType(com::Utf8Str &aPackageType);
248 HRESULT getAPIVersion(com::Utf8Str &aAPIVersion);
249 HRESULT getHomeFolder(com::Utf8Str &aHomeFolder);
250 HRESULT getSettingsFilePath(com::Utf8Str &aSettingsFilePath);
251 HRESULT getHost(ComPtr<IHost> &aHost);
252 HRESULT getSystemProperties(ComPtr<ISystemProperties> &aSystemProperties);
253 HRESULT getMachines(std::vector<ComPtr<IMachine> > &aMachines);
254 HRESULT getMachineGroups(std::vector<com::Utf8Str> &aMachineGroups);
255 HRESULT getHardDisks(std::vector<ComPtr<IMedium> > &aHardDisks);
256 HRESULT getDVDImages(std::vector<ComPtr<IMedium> > &aDVDImages);
257 HRESULT getFloppyImages(std::vector<ComPtr<IMedium> > &aFloppyImages);
258 HRESULT getProgressOperations(std::vector<ComPtr<IProgress> > &aProgressOperations);
259 HRESULT getGuestOSTypes(std::vector<ComPtr<IGuestOSType> > &aGuestOSTypes);
260 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
261 HRESULT getPerformanceCollector(ComPtr<IPerformanceCollector> &aPerformanceCollector);
262 HRESULT getDHCPServers(std::vector<ComPtr<IDHCPServer> > &aDHCPServers);
263 HRESULT getNATNetworks(std::vector<ComPtr<INATNetwork> > &aNATNetworks);
264 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
265 HRESULT getExtensionPackManager(ComPtr<IExtPackManager> &aExtensionPackManager);
266 HRESULT getInternalNetworks(std::vector<com::Utf8Str> &aInternalNetworks);
267 HRESULT getGenericNetworkDrivers(std::vector<com::Utf8Str> &aGenericNetworkDrivers);
268
269 // wrapped IVirtualBox methods
270 HRESULT composeMachineFilename(const com::Utf8Str &aName,
271 const com::Utf8Str &aGroup,
272 const com::Utf8Str &aCreateFlags,
273 const com::Utf8Str &aBaseFolder,
274 com::Utf8Str &aFile);
275 HRESULT createMachine(const com::Utf8Str &aSettingsFile,
276 const com::Utf8Str &aName,
277 const std::vector<com::Utf8Str> &aGroups,
278 const com::Utf8Str &aOsTypeId,
279 const com::Utf8Str &aFlags,
280 ComPtr<IMachine> &aMachine);
281 HRESULT openMachine(const com::Utf8Str &aSettingsFile,
282 ComPtr<IMachine> &aMachine);
283 HRESULT registerMachine(const ComPtr<IMachine> &aMachine);
284 HRESULT findMachine(const com::Utf8Str &aNameOrId,
285 ComPtr<IMachine> &aMachine);
286 HRESULT getMachinesByGroups(const std::vector<com::Utf8Str> &aGroups,
287 std::vector<ComPtr<IMachine> > &aMachines);
288 HRESULT getMachineStates(const std::vector<ComPtr<IMachine> > &aMachines,
289 std::vector<MachineState_T> &aStates);
290 HRESULT createAppliance(ComPtr<IAppliance> &aAppliance);
291 HRESULT createHardDisk(const com::Utf8Str &aFormat,
292 const com::Utf8Str &aLocation,
293 ComPtr<IMedium> &aMedium);
294 HRESULT openMedium(const com::Utf8Str &aLocation,
295 DeviceType_T aDeviceType,
296 AccessMode_T aAccessMode,
297 BOOL aForceNewUuid,
298 ComPtr<IMedium> &aMedium);
299 HRESULT getGuestOSType(const com::Utf8Str &aId,
300 ComPtr<IGuestOSType> &aType);
301 HRESULT createSharedFolder(const com::Utf8Str &aName,
302 const com::Utf8Str &aHostPath,
303 BOOL aWritable,
304 BOOL aAutomount);
305 HRESULT removeSharedFolder(const com::Utf8Str &aName);
306 HRESULT getExtraDataKeys(std::vector<com::Utf8Str> &aKeys);
307 HRESULT getExtraData(const com::Utf8Str &aKey,
308 com::Utf8Str &aValue);
309 HRESULT setExtraData(const com::Utf8Str &aKey,
310 const com::Utf8Str &aValue);
311 HRESULT setSettingsSecret(const com::Utf8Str &aPassword);
312 HRESULT createDHCPServer(const com::Utf8Str &aName,
313 ComPtr<IDHCPServer> &aServer);
314 HRESULT findDHCPServerByNetworkName(const com::Utf8Str &aName,
315 ComPtr<IDHCPServer> &aServer);
316 HRESULT removeDHCPServer(const ComPtr<IDHCPServer> &aServer);
317 HRESULT createNATNetwork(const com::Utf8Str &aNetworkName,
318 ComPtr<INATNetwork> &aNetwork);
319 HRESULT findNATNetworkByName(const com::Utf8Str &aNetworkName,
320 ComPtr<INATNetwork> &aNetwork);
321 HRESULT removeNATNetwork(const ComPtr<INATNetwork> &aNetwork);
322 HRESULT checkFirmwarePresent(FirmwareType_T aFirmwareType,
323 const com::Utf8Str &aVersion,
324 com::Utf8Str &aUrl,
325 com::Utf8Str &aFile,
326 BOOL *aResult);
327
328 static HRESULT i_setErrorStatic(HRESULT aResultCode,
329 const Utf8Str &aText)
330 {
331 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
332 }
333
334 HRESULT i_registerMachine(Machine *aMachine);
335 HRESULT i_registerDHCPServer(DHCPServer *aDHCPServer,
336 bool aSaveRegistry = true);
337 HRESULT i_unregisterDHCPServer(DHCPServer *aDHCPServer,
338 bool aSaveRegistry = true);
339 HRESULT i_registerNATNetwork(NATNetwork *aNATNetwork,
340 bool aSaveRegistry = true);
341 HRESULT i_unregisterNATNetwork(NATNetwork *aNATNetwork,
342 bool aSaveRegistry = true);
343 HRESULT i_checkMediaForConflicts(const Guid &aId,
344 const Utf8Str &aLocation,
345 Utf8Str &aConflictType,
346 ComObjPtr<Medium> *pDupMedium);
347 int i_decryptSettings();
348 int i_decryptMediumSettings(Medium *pMedium);
349 int i_decryptSettingBytes(uint8_t *aPlaintext,
350 const uint8_t *aCiphertext,
351 size_t aCiphertextSize) const;
352 int i_encryptSettingBytes(const uint8_t *aPlaintext,
353 uint8_t *aCiphertext,
354 size_t aPlaintextSize,
355 size_t aCiphertextSize) const;
356
357 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
358
359 Data *m;
360
361 /* static variables (defined in VirtualBoxImpl.cpp) */
362 static com::Utf8Str sVersion;
363 static com::Utf8Str sVersionNormalized;
364 static ULONG sRevision;
365 static com::Utf8Str sPackageType;
366 static com::Utf8Str sAPIVersion;
367 static std::map<com::Utf8Str, int> sNatNetworkNameToRefCount;
368 static RWLockHandle* spMtxNatNetworkNameToRefCountLock;
369
370 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
371
372#ifdef RT_OS_WINDOWS
373 static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
374#endif
375};
376
377////////////////////////////////////////////////////////////////////////////////
378
379#endif // !____H_VIRTUALBOXIMPL
380
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