VirtualBox

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

Last change on this file since 43831 was 43041, checked in by vboxsync, 12 years ago

Main/VirtualBox: final API change, cleans up optional parameters to IVirtualBox::createMachine, preparing for adding more flags.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.6 KB
Line 
1/* $Id: VirtualBoxImpl.h 43041 2012-08-28 13:58:40Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2012 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
23#ifdef RT_OS_WINDOWS
24# include "win/resource.h"
25#endif
26
27namespace com
28{
29 class Event;
30 class EventQueue;
31}
32
33class SessionMachine;
34class GuestOSType;
35class SharedFolder;
36class Progress;
37class Host;
38class SystemProperties;
39class DHCPServer;
40class PerformanceCollector;
41class VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
42#ifdef VBOX_WITH_EXTPACK
43class ExtPackManager;
44#endif
45class AutostartDb;
46
47typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;
48
49#ifdef RT_OS_WINDOWS
50class SVCHlpClient;
51#endif
52
53struct VMClientWatcherData;
54
55namespace settings
56{
57 class MainConfigFile;
58 struct MediaRegistry;
59}
60class ATL_NO_VTABLE VirtualBox :
61 public VirtualBoxBase,
62 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
63#ifdef RT_OS_WINDOWS
64 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
65#endif
66{
67
68public:
69
70 typedef std::list<ComPtr<IInternalSessionControl> > InternalControlList;
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(EventSource))(IEventSource ** aEventSource);
124 STDMETHOD(COMGETTER(ExtensionPackManager))(IExtPackManager **aExtPackManager);
125 STDMETHOD(COMGETTER(InternalNetworks))(ComSafeArrayOut(BSTR, aInternalNetworks));
126 STDMETHOD(COMGETTER(GenericNetworkDrivers))(ComSafeArrayOut(BSTR, aGenericNetworkDrivers));
127
128 /* IVirtualBox methods */
129 STDMETHOD(ComposeMachineFilename)(IN_BSTR aName, IN_BSTR aGroup, IN_BSTR aCreateFlags, IN_BSTR aBaseFolder, BSTR *aFilename);
130 STDMETHOD(CreateMachine)(IN_BSTR aSettingsFile,
131 IN_BSTR aName,
132 ComSafeArrayIn(IN_BSTR, aGroups),
133 IN_BSTR aOsTypeId,
134 IN_BSTR aCreateFlags,
135 IMachine **aMachine);
136 STDMETHOD(OpenMachine)(IN_BSTR aSettingsFile, IMachine **aMachine);
137 STDMETHOD(RegisterMachine)(IMachine *aMachine);
138 STDMETHOD(FindMachine)(IN_BSTR aNameOrId, IMachine **aMachine);
139 STDMETHOD(GetMachinesByGroups)(ComSafeArrayIn(IN_BSTR, aGroups), ComSafeArrayOut(IMachine *, aMachines));
140 STDMETHOD(GetMachineStates)(ComSafeArrayIn(IMachine *, aMachines), ComSafeArrayOut(MachineState_T, aStates));
141 STDMETHOD(CreateAppliance)(IAppliance **anAppliance);
142
143 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
144 IN_BSTR aLocation,
145 IMedium **aHardDisk);
146 STDMETHOD(OpenMedium)(IN_BSTR aLocation,
147 DeviceType_T deviceType,
148 AccessMode_T accessMode,
149 BOOL fForceNewUuid,
150 IMedium **aMedium);
151
152 STDMETHOD(GetGuestOSType)(IN_BSTR aId, IGuestOSType **aType);
153 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
154 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
155 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
156 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
157 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
158 STDMETHOD(SetSettingsSecret)(IN_BSTR aKey);
159
160 STDMETHOD(CreateDHCPServer)(IN_BSTR aName, IDHCPServer ** aServer);
161 STDMETHOD(FindDHCPServerByNetworkName)(IN_BSTR aName, IDHCPServer ** aServer);
162 STDMETHOD(RemoveDHCPServer)(IDHCPServer * aServer);
163 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
164 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
165
166 /* public methods only for internal purposes */
167
168 /**
169 * Override of the default locking class to be used for validating lock
170 * order with the standard member lock handle.
171 */
172 virtual VBoxLockingClass getLockingClass() const
173 {
174 return LOCKCLASS_VIRTUALBOXOBJECT;
175 }
176
177#ifdef DEBUG
178 void dumpAllBackRefs();
179#endif
180
181 HRESULT postEvent(Event *event);
182
183 HRESULT addProgress(IProgress *aProgress);
184 HRESULT removeProgress(IN_GUID aId);
185
186#ifdef RT_OS_WINDOWS
187 typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
188 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
189 HRESULT startSVCHelperClient(bool aPrivileged,
190 SVCHelperClientFunc aFunc,
191 void *aUser, Progress *aProgress);
192#endif
193
194 void addProcessToReap(RTPROCESS pid);
195 void updateClientWatcher();
196
197 void onMachineStateChange(const Guid &aId, MachineState_T aState);
198 void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
199 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
200 Bstr &aError);
201 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
202 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
203 void onSessionStateChange(const Guid &aId, SessionState_T aState);
204
205 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
206 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
207 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
208 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
209 IN_BSTR aFlags);
210 void onMachineUninit(Machine *aMachine);
211 void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
212 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
213 IN_BSTR aGuestIp, uint16_t aGuestPort);
214
215 ComObjPtr<GuestOSType> getUnknownOSType();
216
217 void getOpenedMachines(SessionMachinesList &aMachines,
218 InternalControlList *aControls = NULL);
219
220 HRESULT findMachine(const Guid &aId,
221 bool fPermitInaccessible,
222 bool aSetError,
223 ComObjPtr<Machine> *aMachine = NULL);
224 HRESULT findMachineByName(const Utf8Str &aName,
225 bool aSetError,
226 ComObjPtr<Machine> *aMachine = NULL);
227
228 HRESULT validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
229 HRESULT convertMachineGroups(ComSafeArrayIn(IN_BSTR, aMachineGroups), StringsList *pllMachineGroups);
230
231 HRESULT findHardDiskById(const Guid &id,
232 bool aSetError,
233 ComObjPtr<Medium> *aHardDisk = NULL);
234 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
235 bool aSetError,
236 ComObjPtr<Medium> *aHardDisk = NULL);
237 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
238 const Guid *aId,
239 const Utf8Str &aLocation,
240 bool aSetError,
241 ComObjPtr<Medium> *aImage = NULL);
242 HRESULT findRemoveableMedium(DeviceType_T mediumType,
243 const Guid &uuid,
244 bool fRefresh,
245 bool aSetError,
246 ComObjPtr<Medium> &pMedium);
247
248 HRESULT findGuestOSType(const Bstr &bstrOSType,
249 GuestOSType*& pGuestOSType);
250
251 const Guid &getGlobalRegistryId() const;
252
253 const ComObjPtr<Host>& host() const;
254 SystemProperties* getSystemProperties() const;
255#ifdef VBOX_WITH_EXTPACK
256 ExtPackManager* getExtPackManager() const;
257#endif
258#ifdef VBOX_WITH_RESOURCE_USAGE_API
259 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
260#endif /* VBOX_WITH_RESOURCE_USAGE_API */
261
262 void getDefaultMachineFolder(Utf8Str &str) const;
263 void getDefaultHardDiskFormat(Utf8Str &str) const;
264
265 /** Returns the VirtualBox home directory */
266 const Utf8Str& homeDir() const;
267
268 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
269 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
270
271 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
272 HRESULT unregisterMedium(Medium *pMedium);
273
274 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
275 HRESULT unregisterMachineMedia(const Guid &id);
276
277 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
278
279 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
280 const Utf8Str &strNewConfigDir);
281
282 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
283 const Guid &uuidRegistry,
284 const Utf8Str &strMachineFolder);
285 HRESULT saveSettings();
286
287 void markRegistryModified(const Guid &uuid);
288 void saveModifiedRegistries();
289
290 static const Bstr &getVersionNormalized();
291
292 static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
293
294 const Utf8Str& settingsFilePath();
295
296 AutostartDb* getAutostartDb() const;
297
298 RWLockHandle& getMediaTreeLockHandle();
299
300 int encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
301 int decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
302 void storeSettingsKey(const Utf8Str &aKey);
303
304private:
305
306 static HRESULT setErrorStatic(HRESULT aResultCode,
307 const Utf8Str &aText)
308 {
309 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
310 }
311
312 HRESULT checkMediaForConflicts(const Guid &aId,
313 const Utf8Str &aLocation,
314 Utf8Str &aConflictType,
315 ComObjPtr<Medium> *pDupMedium);
316
317 HRESULT registerMachine(Machine *aMachine);
318
319 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
320 bool aSaveRegistry = true);
321 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
322 bool aSaveRegistry = true);
323
324 int decryptSettings();
325 int decryptMediumSettings(Medium *pMedium);
326 int decryptSettingBytes(uint8_t *aPlaintext, const uint8_t *aCiphertext,
327 size_t aCiphertextSize) const;
328 int encryptSettingBytes(const uint8_t *aPlaintext, uint8_t *aCiphertext,
329 size_t aPlaintextSize, size_t aCiphertextSize) const;
330
331 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
332 Data *m;
333
334 /* static variables (defined in VirtualBoxImpl.cpp) */
335 static Bstr sVersion;
336 static Bstr sVersionNormalized;
337 static ULONG sRevision;
338 static Bstr sPackageType;
339 static Bstr sAPIVersion;
340
341 static DECLCALLBACK(int) ClientWatcher(RTTHREAD thread, void *pvUser);
342 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
343
344#ifdef RT_OS_WINDOWS
345 static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
346#endif
347};
348
349////////////////////////////////////////////////////////////////////////////////
350
351#endif // !____H_VIRTUALBOXIMPL
352
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