VirtualBox

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

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

Main: make calculateRelativePath methods a bit smarter and rename them to VirtualBox::copyPathRelativeToConfig() and Machine::copyPathRelativeToMachine()

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