VirtualBox

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

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

Main: separate internal machine data structs into MachineImplPrivate.h to significantly speed up compilation and for better interface separation; remove obsolete ConsoleEvents.h file

  • 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 30760 2010-07-09 13:12:04Z 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
35typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
36
37#ifdef RT_OS_WINDOWS
38class SVCHlpClient;
39#endif
40
41struct VMClientWatcherData;
42
43class ATL_NO_VTABLE VirtualBox :
44 public VirtualBoxBase,
45 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
46#ifdef RT_OS_WINDOWS
47 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
48 , public IConnectionPointContainerImpl<VirtualBox>
49 , public IConnectionPointImpl<VirtualBox, &IID_IVirtualBoxCallback, CComDynamicUnkArray>
50#endif
51{
52
53public:
54
55 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
56
57 class CallbackEvent;
58 friend class CallbackEvent;
59
60 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
61
62 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
63
64 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
65 DECLARE_NOT_AGGREGATABLE(VirtualBox)
66
67 DECLARE_PROTECT_FINAL_CONSTRUCT()
68
69 BEGIN_COM_MAP(VirtualBox)
70 COM_INTERFACE_ENTRY2(IDispatch, IVirtualBox)
71 COM_INTERFACE_ENTRY(ISupportErrorInfo)
72 COM_INTERFACE_ENTRY(IVirtualBox)
73 COM_INTERFACE_ENTRY(IConnectionPointContainer)
74 END_COM_MAP()
75
76#ifdef RT_OS_WINDOWS
77 BEGIN_CONNECTION_POINT_MAP(VirtualBox)
78 CONNECTION_POINT_ENTRY(IID_IVirtualBoxCallback)
79 END_CONNECTION_POINT_MAP()
80
81 typedef CComDynamicUnkArray EventListenersList;
82#endif
83
84 // to postpone generation of the default ctor/dtor
85 VirtualBox();
86 ~VirtualBox();
87
88 HRESULT FinalConstruct();
89 void FinalRelease();
90
91 /* public initializer/uninitializer for internal purposes only */
92 HRESULT init();
93 HRESULT initMachines();
94 HRESULT initMedia();
95 void uninit();
96
97 /* IVirtualBox properties */
98 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
99 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
100 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
101 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
102 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
103 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
104 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
105 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
106 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
107 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
108 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
109 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
110 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
111 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
112 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
113 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
114 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
115
116 /* IVirtualBox methods */
117
118 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
119 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
120 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
121 IN_BSTR aId, IMachine **aMachine);
122 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
123 STDMETHOD(RegisterMachine) (IMachine *aMachine);
124 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
125 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
126 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
127 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
128
129 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
130 IMedium **aHardDisk);
131 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
132 BOOL aSetImageId, IN_BSTR aImageId,
133 BOOL aSetParentId, IN_BSTR aParentId,
134 IMedium **aHardDisk);
135 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
136 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
137
138 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
139 IMedium **aDVDImage);
140 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
141 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
142
143 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
144 IMedium **aFloppyImage);
145 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
146 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
147
148 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
149 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
150 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
151 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
152 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
153 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
154 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
155 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
156 IN_BSTR aType, IN_BSTR aEnvironment,
157 IProgress **aProgress);
158 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
159
160 STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
161 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
162
163 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
164 BSTR *aChanged, BSTR *aValues);
165
166 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
167 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
168 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
169 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
170 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
171
172 /* public methods only for internal purposes */
173
174 /**
175 * Override of the default locking class to be used for validating lock
176 * order with the standard member lock handle.
177 */
178 virtual VBoxLockingClass getLockingClass() const
179 {
180 return LOCKCLASS_VIRTUALBOXOBJECT;
181 }
182
183#ifdef DEBUG
184 void dumpAllBackRefs();
185#endif
186
187 HRESULT postEvent(Event *event);
188
189 HRESULT addProgress(IProgress *aProgress);
190 HRESULT removeProgress(IN_GUID aId);
191
192#ifdef RT_OS_WINDOWS
193 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
194 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
195 HRESULT startSVCHelperClient(bool aPrivileged,
196 SVCHelperClientFunc aFunc,
197 void *aUser, Progress *aProgress);
198#endif
199
200 void addProcessToReap (RTPROCESS pid);
201 void updateClientWatcher();
202
203 void removeDeadCallback(const ComPtr<IVirtualBoxCallback> &aCallback);
204
205 void onMachineStateChange(const Guid &aId, MachineState_T aState);
206 void onMachineDataChange(const Guid &aId);
207 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
208 Bstr &aError);
209 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
210 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
211 void onSessionStateChange(const Guid &aId, SessionState_T aState);
212
213 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
214 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
215 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
216 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
217 IN_BSTR aFlags);
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