VirtualBox

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

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

Main: attempt at USB locking fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.2 KB
Line 
1/* $Id: VirtualBoxImpl.h 27796 2010-03-29 16:04:55Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_VIRTUALBOXIMPL
25#define ____H_VIRTUALBOXIMPL
26
27#include "VirtualBoxBase.h"
28
29#ifdef RT_OS_WINDOWS
30# include "win/resource.h"
31#endif
32
33namespace com
34{
35 class Event;
36 class EventQueue;
37}
38
39class SessionMachine;
40class GuestOSType;
41class SharedFolder;
42class Progress;
43class Host;
44class SystemProperties;
45class DHCPServer;
46class PerformanceCollector;
47
48typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
49
50#ifdef RT_OS_WINDOWS
51class SVCHlpClient;
52#endif
53
54struct VMClientWatcherData;
55
56namespace settings
57{
58 class MainConfigFile;
59}
60
61class ATL_NO_VTABLE VirtualBox :
62 public VirtualBoxBase,
63 public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
64 public VirtualBoxSupportTranslation<VirtualBox>,
65 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
66#ifdef RT_OS_WINDOWS
67 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
68#endif
69{
70
71public:
72
73 typedef std::list< ComPtr<IVirtualBoxCallback> > CallbackList;
74 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
75
76 class CallbackEvent;
77 friend class CallbackEvent;
78
79 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox)
80
81 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
82
83 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
84 DECLARE_NOT_AGGREGATABLE(VirtualBox)
85
86 DECLARE_PROTECT_FINAL_CONSTRUCT()
87
88 BEGIN_COM_MAP(VirtualBox)
89 COM_INTERFACE_ENTRY(IDispatch)
90 COM_INTERFACE_ENTRY(ISupportErrorInfo)
91 COM_INTERFACE_ENTRY(IVirtualBox)
92 END_COM_MAP()
93
94 // to postpone generation of the default ctor/dtor
95 VirtualBox();
96 ~VirtualBox();
97
98 HRESULT FinalConstruct();
99 void FinalRelease();
100
101 /* public initializer/uninitializer for internal purposes only */
102 HRESULT init();
103 HRESULT initMachines();
104 HRESULT initMedia();
105 void uninit();
106
107 /* IVirtualBox properties */
108 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
109 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
110 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
111 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
112 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
113 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
114 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
115 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
116 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
117 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
118 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
119 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
120 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
121 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
122 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
123 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
124
125 /* IVirtualBox methods */
126
127 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
128 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
129 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
130 IN_BSTR aId, IMachine **aMachine);
131 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
132 STDMETHOD(RegisterMachine) (IMachine *aMachine);
133 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
134 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
135 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
136 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
137
138 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
139 IMedium **aHardDisk);
140 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
141 BOOL aSetImageId, IN_BSTR aImageId,
142 BOOL aSetParentId, IN_BSTR aParentId,
143 IMedium **aHardDisk);
144 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
145 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
146
147 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
148 IMedium **aDVDImage);
149 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
150 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
151
152 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
153 IMedium **aFloppyImage);
154 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
155 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
156
157 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
158 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
159 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
160 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
161 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
162 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
163 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
164 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
165 IN_BSTR aType, IN_BSTR aEnvironment,
166 IProgress **aProgress);
167 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
168
169 STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
170 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
171
172 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
173 BSTR *aChanged, BSTR *aValues);
174
175 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
176 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
177 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
178 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
179 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
180
181 /* public methods only for internal purposes */
182
183 /**
184 * Simple run-time type identification without having to enable C++ RTTI.
185 * The class IDs are defined in VirtualBoxBase.h.
186 * @return
187 */
188 virtual VBoxClsID getClassID() const
189 {
190 return clsidVirtualBox;
191 }
192
193 /**
194 * Override of the default locking class to be used for validating lock
195 * order with the standard member lock handle.
196 */
197 virtual VBoxLockingClass getLockingClass() const
198 {
199 return LOCKCLASS_VIRTUALBOXOBJECT;
200 }
201
202#ifdef DEBUG
203 void dumpAllBackRefs();
204#endif
205
206 HRESULT postEvent(Event *event);
207
208 HRESULT addProgress(IProgress *aProgress);
209 HRESULT removeProgress(IN_GUID aId);
210
211#ifdef RT_OS_WINDOWS
212 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
213 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
214 HRESULT startSVCHelperClient(bool aPrivileged,
215 SVCHelperClientFunc aFunc,
216 void *aUser, Progress *aProgress);
217#endif
218
219 void addProcessToReap (RTPROCESS pid);
220 void updateClientWatcher();
221
222 void onMachineStateChange(const Guid &aId, MachineState_T aState);
223 void onMachineDataChange(const Guid &aId);
224 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
225 Bstr &aError);
226 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
227 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
228 void onSessionStateChange(const Guid &aId, SessionState_T aState);
229
230 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
231 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
232 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
233 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
234 IN_BSTR aFlags);
235
236 ComObjPtr<GuestOSType> getUnknownOSType();
237
238 void getOpenedMachines(SessionMachinesList &aMachines,
239 InternalControlList *aControls = NULL);
240
241 bool isMachineIdValid(const Guid &aId)
242 {
243 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
244 }
245
246 HRESULT findMachine (const Guid &aId, bool aSetError,
247 ComObjPtr<Machine> *machine = NULL);
248
249 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
250 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
251 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
252 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
253 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
254 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
255
256 HRESULT findGuestOSType(const Bstr &bstrOSType,
257 GuestOSType*& pGuestOSType);
258
259 const ComObjPtr<Host>& host() const;
260 const ComObjPtr<SystemProperties>& systemProperties() const;
261#ifdef VBOX_WITH_RESOURCE_USAGE_API
262 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
263#endif /* VBOX_WITH_RESOURCE_USAGE_API */
264
265 const Utf8Str& getDefaultMachineFolder() const;
266 const Utf8Str& getDefaultHardDiskFolder() const;
267 const Utf8Str& getDefaultHardDiskFormat() const;
268
269 /** Returns the VirtualBox home directory */
270 const Utf8Str& homeDir() const;
271
272 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
273 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
274
275 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
276 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
277
278 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
279 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
280
281 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
282 const Utf8Str &strNewConfigDir);
283
284 HRESULT saveSettings();
285
286 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
287
288 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
289
290 const Utf8Str& settingsFilePath();
291
292 RWLockHandle& getMediaTreeLockHandle();
293
294 /* for VirtualBoxSupportErrorInfoImpl */
295 static const wchar_t *getComponentName() { return L"VirtualBox"; }
296
297private:
298
299 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
300 Utf8Str &aConflictType);
301
302 HRESULT registerMachine (Machine *aMachine);
303
304 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
305 bool aSaveRegistry = true);
306 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
307 bool aSaveRegistry = true);
308
309 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
310 Data *m;
311
312 /* static variables (defined in VirtualBoxImpl.cpp) */
313 static Bstr sVersion;
314 static ULONG sRevision;
315 static Bstr sPackageType;
316
317 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
318 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
319
320#ifdef RT_OS_WINDOWS
321 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
322#endif
323};
324
325////////////////////////////////////////////////////////////////////////////////
326
327#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