VirtualBox

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

Last change on this file since 30847 was 30847, checked in by vboxsync, 15 years ago

Main/Machine+Performance+VirtualBox: move deleting the performance metrics registration of a VM out of SessionMachine::uninit, where it was a risk of hangs due to callbacks. Doing it a little later won't hurt anyone. Additionally also make sure the total VMM memory stats are zeroed when the last VM has disabled its collector.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: VirtualBoxImpl.h 30847 2010-07-14 15:40:49Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#ifndef ____H_VIRTUALBOXIMPL
21#define ____H_VIRTUALBOXIMPL
22
23#include "VirtualBoxBase.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 SharedFolder;
38class Progress;
39class Host;
40class SystemProperties;
41class DHCPServer;
42class PerformanceCollector;
43class VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
44
45typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
46
47#ifdef RT_OS_WINDOWS
48class SVCHlpClient;
49#endif
50
51struct VMClientWatcherData;
52
53namespace settings
54{
55 class MainConfigFile;
56}
57
58class ATL_NO_VTABLE VirtualBox :
59 public VirtualBoxBase,
60 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
61#ifdef RT_OS_WINDOWS
62 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
63#endif
64{
65
66public:
67
68 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
69
70 class CallbackEvent;
71 friend class CallbackEvent;
72
73 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
74
75 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
76
77 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
78 DECLARE_NOT_AGGREGATABLE(VirtualBox)
79
80 DECLARE_PROTECT_FINAL_CONSTRUCT()
81
82 BEGIN_COM_MAP(VirtualBox)
83 COM_INTERFACE_ENTRY2(IDispatch, IVirtualBox)
84 COM_INTERFACE_ENTRY(ISupportErrorInfo)
85 COM_INTERFACE_ENTRY(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();
99 void uninit();
100
101 /* IVirtualBox properties */
102 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
103 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
104 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
105 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
106 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
107 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
108 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
109 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
110 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
111 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
112 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
113 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
114 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
115 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
116 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
117 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
118 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
119
120 /* IVirtualBox methods */
121
122 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
123 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
124 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
125 IN_BSTR aId, IMachine **aMachine);
126 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
127 STDMETHOD(RegisterMachine) (IMachine *aMachine);
128 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
129 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
130 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
131 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
132
133 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
134 IMedium **aHardDisk);
135 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
136 BOOL aSetImageId, IN_BSTR aImageId,
137 BOOL aSetParentId, IN_BSTR aParentId,
138 IMedium **aHardDisk);
139 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
140 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
141
142 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
143 IMedium **aDVDImage);
144 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
145 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
146
147 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
148 IMedium **aFloppyImage);
149 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
150 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
151
152 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
153 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
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(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
159 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
160 IN_BSTR aType, IN_BSTR aEnvironment,
161 IProgress **aProgress);
162 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
163
164 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
165 BSTR *aChanged, BSTR *aValues);
166
167 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
168 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
169 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
170 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
171 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
172
173 /* public methods only for internal purposes */
174
175 /**
176 * Override of the default locking class to be used for validating lock
177 * order with the standard member lock handle.
178 */
179 virtual VBoxLockingClass getLockingClass() const
180 {
181 return LOCKCLASS_VIRTUALBOXOBJECT;
182 }
183
184#ifdef DEBUG
185 void dumpAllBackRefs();
186#endif
187
188 HRESULT postEvent(Event *event);
189
190 HRESULT addProgress(IProgress *aProgress);
191 HRESULT removeProgress(IN_GUID aId);
192
193#ifdef RT_OS_WINDOWS
194 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
195 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
196 HRESULT startSVCHelperClient(bool aPrivileged,
197 SVCHelperClientFunc aFunc,
198 void *aUser, Progress *aProgress);
199#endif
200
201 void addProcessToReap (RTPROCESS pid);
202 void updateClientWatcher();
203
204 void onMachineStateChange(const Guid &aId, MachineState_T aState);
205 void onMachineDataChange(const Guid &aId);
206 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
207 Bstr &aError);
208 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
209 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
210 void onSessionStateChange(const Guid &aId, SessionState_T aState);
211
212 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
213 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
214 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
215 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
216 IN_BSTR aFlags);
217 void onMachineUninit(Machine *aMachine);
218
219 ComObjPtr<GuestOSType> getUnknownOSType();
220
221 void getOpenedMachines(SessionMachinesList &aMachines,
222 InternalControlList *aControls = NULL);
223
224 bool isMachineIdValid(const Guid &aId)
225 {
226 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
227 }
228
229 HRESULT findMachine (const Guid &aId, bool aSetError,
230 ComObjPtr<Machine> *machine = NULL);
231
232 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
233 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
234 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
235 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
236 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
237 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
238
239 HRESULT findGuestOSType(const Bstr &bstrOSType,
240 GuestOSType*& pGuestOSType);
241
242 const ComObjPtr<Host>& host() const;
243 const ComObjPtr<SystemProperties>& systemProperties() const;
244#ifdef VBOX_WITH_RESOURCE_USAGE_API
245 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
246#endif /* VBOX_WITH_RESOURCE_USAGE_API */
247
248 const Utf8Str& getDefaultMachineFolder() const;
249 const Utf8Str& getDefaultHardDiskFolder() const;
250 const Utf8Str& getDefaultHardDiskFormat() const;
251
252 /** Returns the VirtualBox home directory */
253 const Utf8Str& homeDir() const;
254
255 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
256 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
257
258 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
259 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
260
261 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
262 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
263
264 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
265 const Utf8Str &strNewConfigDir);
266
267 HRESULT saveSettings();
268
269 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
270
271 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
272
273 const Utf8Str& settingsFilePath();
274
275 RWLockHandle& getMediaTreeLockHandle();
276
277private:
278
279 static HRESULT setErrorStatic(HRESULT aResultCode,
280 const Utf8Str &aText)
281 {
282 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
283 }
284
285 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
286 Utf8Str &aConflictType);
287
288 HRESULT registerMachine (Machine *aMachine);
289
290 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
291 bool aSaveRegistry = true);
292 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
293 bool aSaveRegistry = true);
294
295 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
296 Data *m;
297
298 /* static variables (defined in VirtualBoxImpl.cpp) */
299 static Bstr sVersion;
300 static ULONG sRevision;
301 static Bstr sPackageType;
302
303 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
304 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
305
306#ifdef RT_OS_WINDOWS
307 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
308#endif
309};
310
311////////////////////////////////////////////////////////////////////////////////
312
313#endif // !____H_VIRTUALBOXIMPL
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