VirtualBox

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

Last change on this file since 42888 was 42888, checked in by vboxsync, 13 years ago

Main/VirtualBox: validate group names for collision with VM names. Other direction still missing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.7 KB
Line 
1/* $Id: VirtualBoxImpl.h 42888 2012-08-20 17:36:31Z 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.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 ____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 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 aId,
135 BOOL forceOverwrite,
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 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
165 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
166
167 /* public methods only for internal purposes */
168
169 /**
170 * Override of the default locking class to be used for validating lock
171 * order with the standard member lock handle.
172 */
173 virtual VBoxLockingClass getLockingClass() const
174 {
175 return LOCKCLASS_VIRTUALBOXOBJECT;
176 }
177
178#ifdef DEBUG
179 void dumpAllBackRefs();
180#endif
181
182 HRESULT postEvent(Event *event);
183
184 HRESULT addProgress(IProgress *aProgress);
185 HRESULT removeProgress(IN_GUID aId);
186
187#ifdef RT_OS_WINDOWS
188 typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
189 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
190 HRESULT startSVCHelperClient(bool aPrivileged,
191 SVCHelperClientFunc aFunc,
192 void *aUser, Progress *aProgress);
193#endif
194
195 void addProcessToReap(RTPROCESS pid);
196 void updateClientWatcher();
197
198 void onMachineStateChange(const Guid &aId, MachineState_T aState);
199 void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
200 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
201 Bstr &aError);
202 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
203 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
204 void onSessionStateChange(const Guid &aId, SessionState_T aState);
205
206 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
207 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
208 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
209 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
210 IN_BSTR aFlags);
211 void onMachineUninit(Machine *aMachine);
212 void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
213 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
214 IN_BSTR aGuestIp, uint16_t aGuestPort);
215
216 ComObjPtr<GuestOSType> getUnknownOSType();
217
218 void getOpenedMachines(SessionMachinesList &aMachines,
219 InternalControlList *aControls = NULL);
220
221 HRESULT findMachine(const Guid &aId,
222 bool fPermitInaccessible,
223 bool aSetError,
224 ComObjPtr<Machine> *aMachine = NULL);
225 HRESULT findMachineByName(const Utf8Str &aName,
226 bool aSetError,
227 ComObjPtr<Machine> *aMachine = NULL);
228
229 HRESULT validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
230 HRESULT convertMachineGroups(ComSafeArrayIn(IN_BSTR, aMachineGroups), StringsList *pllMachineGroups);
231
232 HRESULT findHardDiskById(const Guid &id,
233 bool aSetError,
234 ComObjPtr<Medium> *aHardDisk = NULL);
235 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
236 bool aSetError,
237 ComObjPtr<Medium> *aHardDisk = NULL);
238 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
239 const Guid *aId,
240 const Utf8Str &aLocation,
241 bool aSetError,
242 ComObjPtr<Medium> *aImage = NULL);
243 HRESULT findRemoveableMedium(DeviceType_T mediumType,
244 const Guid &uuid,
245 bool fRefresh,
246 bool aSetError,
247 ComObjPtr<Medium> &pMedium);
248
249 HRESULT findGuestOSType(const Bstr &bstrOSType,
250 GuestOSType*& pGuestOSType);
251
252 const Guid &getGlobalRegistryId() const;
253
254 const ComObjPtr<Host>& host() const;
255 SystemProperties* getSystemProperties() const;
256#ifdef VBOX_WITH_EXTPACK
257 ExtPackManager* getExtPackManager() const;
258#endif
259#ifdef VBOX_WITH_RESOURCE_USAGE_API
260 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
261#endif /* VBOX_WITH_RESOURCE_USAGE_API */
262
263 void getDefaultMachineFolder(Utf8Str &str) const;
264 void getDefaultHardDiskFormat(Utf8Str &str) const;
265
266 /** Returns the VirtualBox home directory */
267 const Utf8Str& homeDir() const;
268
269 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
270 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
271
272 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
273 HRESULT unregisterMedium(Medium *pMedium);
274
275 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
276 HRESULT unregisterMachineMedia(const Guid &id);
277
278 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
279
280 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
281 const Utf8Str &strNewConfigDir);
282
283 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
284 const Guid &uuidRegistry,
285 const Utf8Str &strMachineFolder);
286 HRESULT saveSettings();
287
288 void markRegistryModified(const Guid &uuid);
289 void saveModifiedRegistries();
290
291 static const Bstr &getVersionNormalized();
292
293 static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
294
295 const Utf8Str& settingsFilePath();
296
297 AutostartDb* getAutostartDb() const;
298
299 RWLockHandle& getMediaTreeLockHandle();
300
301 int encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
302 int decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
303 void storeSettingsKey(const Utf8Str &aKey);
304
305private:
306
307 static HRESULT setErrorStatic(HRESULT aResultCode,
308 const Utf8Str &aText)
309 {
310 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
311 }
312
313 HRESULT checkMediaForConflicts(const Guid &aId,
314 const Utf8Str &aLocation,
315 Utf8Str &aConflictType,
316 ComObjPtr<Medium> *pDupMedium);
317
318 HRESULT registerMachine(Machine *aMachine);
319
320 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
321 bool aSaveRegistry = true);
322 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
323 bool aSaveRegistry = true);
324
325 int decryptSettings();
326 int decryptMediumSettings(Medium *pMedium);
327 int decryptSettingBytes(uint8_t *aPlaintext, const uint8_t *aCiphertext,
328 size_t aCiphertextSize) const;
329 int encryptSettingBytes(const uint8_t *aPlaintext, uint8_t *aCiphertext,
330 size_t aPlaintextSize, size_t aCiphertextSize) const;
331
332 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
333 Data *m;
334
335 /* static variables (defined in VirtualBoxImpl.cpp) */
336 static Bstr sVersion;
337 static Bstr sVersionNormalized;
338 static ULONG sRevision;
339 static Bstr sPackageType;
340 static Bstr sAPIVersion;
341
342 static DECLCALLBACK(int) ClientWatcher(RTTHREAD thread, void *pvUser);
343 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
344
345#ifdef RT_OS_WINDOWS
346 static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
347#endif
348};
349
350////////////////////////////////////////////////////////////////////////////////
351
352#endif // !____H_VIRTUALBOXIMPL
353
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