VirtualBox

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

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

Main: make backrefs code a bit more readable + add backrefs logging, fix deleteSnapshot() progress bars, but deleteSnapshot() is still broken

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: VirtualBoxImpl.h 24345 2009-11-04 16:50:07Z 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 VirtualBoxBaseWithChildrenNEXT,
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
180 /* public methods only for internal purposes */
181#ifdef DEBUG
182 void dumpAllBackRefs();
183#endif
184
185 HRESULT postEvent(Event *event);
186
187 HRESULT addProgress(IProgress *aProgress);
188 HRESULT removeProgress(IN_GUID aId);
189
190#ifdef RT_OS_WINDOWS
191 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
192 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
193 HRESULT startSVCHelperClient(bool aPrivileged,
194 SVCHelperClientFunc aFunc,
195 void *aUser, Progress *aProgress);
196#endif
197
198 void addProcessToReap (RTPROCESS pid);
199 void updateClientWatcher();
200
201 void onMachineStateChange(const Guid &aId, MachineState_T aState);
202 void onMachineDataChange(const Guid &aId);
203 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
204 Bstr &aError);
205 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
206 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
207 void onSessionStateChange(const Guid &aId, SessionState_T aState);
208
209 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
210 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
211 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
212 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
213 IN_BSTR aFlags);
214
215 ComObjPtr<GuestOSType> getUnknownOSType();
216
217 void getOpenedMachines(SessionMachineList &aMachines,
218 InternalControlList *aControls = NULL);
219
220 bool isMachineIdValid(const Guid &aId)
221 {
222 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
223 }
224
225 HRESULT findMachine (const Guid &aId, bool aSetError,
226 ComObjPtr<Machine> *machine = NULL);
227
228 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
229 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
230 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
231 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
232 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
233 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
234
235 HRESULT findGuestOSType(CBSTR bstrOSType,
236 GuestOSType*& pGuestOSType);
237
238 const ComObjPtr<Host>& host() const;
239 const ComObjPtr<SystemProperties>& systemProperties() const;
240#ifdef VBOX_WITH_RESOURCE_USAGE_API
241 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
242#endif /* VBOX_WITH_RESOURCE_USAGE_API */
243
244 const Utf8Str& getDefaultMachineFolder() const;
245 const Utf8Str& getDefaultHardDiskFolder() const;
246 const Utf8Str& getDefaultHardDiskFormat() const;
247
248 /** Returns the VirtualBox home directory */
249 const Utf8Str& homeDir() const;
250
251 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
252 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
253
254 HRESULT registerHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
255 HRESULT unregisterHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
256
257 HRESULT registerDVDImage(Medium *aImage, bool aSaveRegistry = true);
258 HRESULT unregisterDVDImage(Medium *aImage, bool aSaveRegistry = true);
259
260 HRESULT registerFloppyImage (Medium *aImage, bool aSaveRegistry = true);
261 HRESULT unregisterFloppyImage (Medium *aImage, bool aSaveRegistry = true);
262
263 HRESULT cast (IMedium *aFrom, ComObjPtr<Medium> &aTo);
264
265 HRESULT saveSettings();
266 HRESULT updateSettings(const char *aOldPath, const char *aNewPath);
267
268 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
269
270 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
271
272 const Utf8Str& settingsFilePath();
273
274 RWLockHandle& hardDiskTreeLockHandle();
275 RWLockHandle* childrenLock();
276
277 /* for VirtualBoxSupportErrorInfoImpl */
278 static const wchar_t *getComponentName() { return L"VirtualBox"; }
279
280private:
281
282 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
283 Utf8Str &aConflictType);
284
285 HRESULT registerMachine (Machine *aMachine);
286
287 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
288 bool aSaveRegistry = true);
289 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
290 bool aSaveRegistry = true);
291
292 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
293 Data *m;
294
295 /* static variables (defined in VirtualBoxImpl.cpp) */
296 static Bstr sVersion;
297 static ULONG sRevision;
298 static Bstr sPackageType;
299
300 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
301 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
302
303#ifdef RT_OS_WINDOWS
304 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
305#endif
306};
307
308////////////////////////////////////////////////////////////////////////////////
309
310#endif // ____H_VIRTUALBOXIMPL
311
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