VirtualBox

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

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

Main: finish integration of Main lock validation with IPRT; only enabled with VBOX_WITH_STRICT_LOCKS=1 (do NOT enable unless you want Main to stop working now)

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