1 | /* $Id: VirtualBoxImpl.h 31296 2010-08-02 13:13: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 |
|
---|
29 | namespace com
|
---|
30 | {
|
---|
31 | class Event;
|
---|
32 | class EventQueue;
|
---|
33 | }
|
---|
34 |
|
---|
35 | class SessionMachine;
|
---|
36 | class GuestOSType;
|
---|
37 | class SharedFolder;
|
---|
38 | class Progress;
|
---|
39 | class Host;
|
---|
40 | class SystemProperties;
|
---|
41 | class DHCPServer;
|
---|
42 | class PerformanceCollector;
|
---|
43 | class VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
|
---|
44 |
|
---|
45 | typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
|
---|
46 |
|
---|
47 | #ifdef RT_OS_WINDOWS
|
---|
48 | class SVCHlpClient;
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | struct VMClientWatcherData;
|
---|
52 |
|
---|
53 | namespace settings
|
---|
54 | {
|
---|
55 | class MainConfigFile;
|
---|
56 | }
|
---|
57 |
|
---|
58 | class ATL_NO_VTABLE VirtualBox :
|
---|
59 | public VirtualBoxBase,
|
---|
60 | VBOX_SCRIPTABLE_IMPL(IVirtualBox)
|
---|
61 | #ifdef RT_OS_WINDOWS
|
---|
62 | , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
|
---|
63 | #endif
|
---|
64 | {
|
---|
65 |
|
---|
66 | public:
|
---|
67 |
|
---|
68 | typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
|
---|
69 |
|
---|
70 | class CallbackEvent;
|
---|
71 | friend class CallbackEvent;
|
---|
72 |
|
---|
73 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
|
---|
74 |
|
---|
75 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
|
---|
76 |
|
---|
77 | DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
78 | DECLARE_NOT_AGGREGATABLE(VirtualBox)
|
---|
79 |
|
---|
80 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
81 |
|
---|
82 | BEGIN_COM_MAP(VirtualBox)
|
---|
83 | COM_INTERFACE_ENTRY2(IDispatch, IVirtualBox)
|
---|
84 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
85 | COM_INTERFACE_ENTRY(IVirtualBox)
|
---|
86 | END_COM_MAP()
|
---|
87 |
|
---|
88 | // to postpone generation of the default ctor/dtor
|
---|
89 | VirtualBox();
|
---|
90 | ~VirtualBox();
|
---|
91 |
|
---|
92 | HRESULT FinalConstruct();
|
---|
93 | void FinalRelease();
|
---|
94 |
|
---|
95 | /* public initializer/uninitializer for internal purposes only */
|
---|
96 | HRESULT init();
|
---|
97 | HRESULT initMachines();
|
---|
98 | HRESULT initMedia();
|
---|
99 | void uninit();
|
---|
100 |
|
---|
101 | /* IVirtualBox properties */
|
---|
102 | STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
|
---|
103 | STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
|
---|
104 | STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
|
---|
105 | STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
|
---|
106 | STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
|
---|
107 | STDMETHOD(COMGETTER(Host)) (IHost **aHost);
|
---|
108 | STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
|
---|
109 | STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut(IMachine *, aMachines));
|
---|
110 | STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut(IMedium *, aHardDisks));
|
---|
111 | STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut(IMedium *, aDVDImages));
|
---|
112 | STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut(IMedium *, aFloppyImages));
|
---|
113 | STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut(IProgress *, aOperations));
|
---|
114 | STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
|
---|
115 | STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut(ISharedFolder *, aSharedFolders));
|
---|
116 | STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
|
---|
117 | STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut(IDHCPServer *, aDHCPServers));
|
---|
118 | STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
|
---|
119 |
|
---|
120 | /* IVirtualBox methods */
|
---|
121 |
|
---|
122 | STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
|
---|
123 | IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
|
---|
124 | STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
|
---|
125 | IN_BSTR aId, IMachine **aMachine);
|
---|
126 | STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
|
---|
127 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
128 | STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
|
---|
129 | STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
|
---|
130 | STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
|
---|
131 |
|
---|
132 | STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
|
---|
133 | IMedium **aHardDisk);
|
---|
134 | STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
|
---|
135 | BOOL aSetImageId, IN_BSTR aImageId,
|
---|
136 | BOOL aSetParentId, IN_BSTR aParentId,
|
---|
137 | IMedium **aHardDisk);
|
---|
138 | STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
|
---|
139 | STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
|
---|
140 |
|
---|
141 | STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
|
---|
142 | IMedium **aDVDImage);
|
---|
143 | STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
|
---|
144 | STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
|
---|
145 |
|
---|
146 | STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
|
---|
147 | IMedium **aFloppyImage);
|
---|
148 | STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
|
---|
149 | STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
|
---|
150 |
|
---|
151 | STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
|
---|
152 | STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
|
---|
153 | STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
|
---|
154 | STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
|
---|
155 | STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
|
---|
156 | STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
|
---|
157 |
|
---|
158 | STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
|
---|
159 | BSTR *aChanged, BSTR *aValues);
|
---|
160 |
|
---|
161 | STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
162 | STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
163 | STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
|
---|
164 | STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
|
---|
165 | BSTR * aUrl, BSTR * aFile, BOOL * aResult);
|
---|
166 |
|
---|
167 | /* public methods only for internal purposes */
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Override of the default locking class to be used for validating lock
|
---|
171 | * order with the standard member lock handle.
|
---|
172 | */
|
---|
173 | virtual VBoxLockingClass getLockingClass() const
|
---|
174 | {
|
---|
175 | return LOCKCLASS_VIRTUALBOXOBJECT;
|
---|
176 | }
|
---|
177 |
|
---|
178 | #ifdef DEBUG
|
---|
179 | void dumpAllBackRefs();
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | HRESULT postEvent(Event *event);
|
---|
183 |
|
---|
184 | HRESULT addProgress(IProgress *aProgress);
|
---|
185 | HRESULT removeProgress(IN_GUID aId);
|
---|
186 |
|
---|
187 | #ifdef RT_OS_WINDOWS
|
---|
188 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
189 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
190 | HRESULT startSVCHelperClient(bool aPrivileged,
|
---|
191 | SVCHelperClientFunc aFunc,
|
---|
192 | void *aUser, Progress *aProgress);
|
---|
193 | #endif
|
---|
194 |
|
---|
195 | void addProcessToReap (RTPROCESS pid);
|
---|
196 | void updateClientWatcher();
|
---|
197 |
|
---|
198 | void onMachineStateChange(const Guid &aId, MachineState_T aState);
|
---|
199 | void onMachineDataChange(const Guid &aId);
|
---|
200 | BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
|
---|
201 | Bstr &aError);
|
---|
202 | void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
|
---|
203 | void onMachineRegistered(const Guid &aId, BOOL aRegistered);
|
---|
204 | void onSessionStateChange(const Guid &aId, SessionState_T aState);
|
---|
205 |
|
---|
206 | void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
207 | void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
208 | void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
209 | void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
|
---|
210 | IN_BSTR aFlags);
|
---|
211 | void onMachineUninit(Machine *aMachine);
|
---|
212 |
|
---|
213 | ComObjPtr<GuestOSType> getUnknownOSType();
|
---|
214 |
|
---|
215 | void getOpenedMachines(SessionMachinesList &aMachines,
|
---|
216 | InternalControlList *aControls = NULL);
|
---|
217 |
|
---|
218 | HRESULT findMachine (const Guid &aId,
|
---|
219 | bool fPermitInaccessible,
|
---|
220 | bool aSetError,
|
---|
221 | ComObjPtr<Machine> *machine = NULL);
|
---|
222 |
|
---|
223 | HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
|
---|
224 | bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
225 | HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
|
---|
226 | const Guid *aId,
|
---|
227 | const Utf8Str &aLocation,
|
---|
228 | bool aSetError,
|
---|
229 | ComObjPtr<Medium> *aImage = NULL);
|
---|
230 | HRESULT findRemoveableMedium(DeviceType_T mediumType,
|
---|
231 | const Guid &uuid,
|
---|
232 | bool fRefresh,
|
---|
233 | ComObjPtr<Medium> &pMedium);
|
---|
234 |
|
---|
235 | HRESULT findGuestOSType(const Bstr &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 copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
|
---|
253 |
|
---|
254 | HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
|
---|
255 | HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
|
---|
256 |
|
---|
257 | HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
|
---|
258 | HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
|
---|
259 |
|
---|
260 | HRESULT unregisterMachine(Machine *pMachine);
|
---|
261 |
|
---|
262 | void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
|
---|
263 | const Utf8Str &strNewConfigDir);
|
---|
264 |
|
---|
265 | HRESULT saveSettings();
|
---|
266 |
|
---|
267 | static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
|
---|
268 |
|
---|
269 | static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
|
---|
270 |
|
---|
271 | const Utf8Str& settingsFilePath();
|
---|
272 |
|
---|
273 | RWLockHandle& getMediaTreeLockHandle();
|
---|
274 |
|
---|
275 | private:
|
---|
276 |
|
---|
277 | static HRESULT setErrorStatic(HRESULT aResultCode,
|
---|
278 | const Utf8Str &aText)
|
---|
279 | {
|
---|
280 | return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
|
---|
281 | }
|
---|
282 |
|
---|
283 | HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
|
---|
284 | Utf8Str &aConflictType);
|
---|
285 |
|
---|
286 | HRESULT registerMachine(Machine *aMachine);
|
---|
287 |
|
---|
288 | HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
|
---|
289 | bool aSaveRegistry = true);
|
---|
290 | HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
|
---|
291 | bool aSaveRegistry = true);
|
---|
292 |
|
---|
293 | struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
|
---|
294 | Data *m;
|
---|
295 |
|
---|
296 | /* static variables (defined in VirtualBoxImpl.cpp) */
|
---|
297 | static Bstr sVersion;
|
---|
298 | static ULONG sRevision;
|
---|
299 | static Bstr sPackageType;
|
---|
300 |
|
---|
301 | static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
|
---|
302 | static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
|
---|
303 |
|
---|
304 | #ifdef RT_OS_WINDOWS
|
---|
305 | static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
|
---|
306 | #endif
|
---|
307 | };
|
---|
308 |
|
---|
309 | ////////////////////////////////////////////////////////////////////////////////
|
---|
310 |
|
---|
311 | #endif // !____H_VIRTUALBOXIMPL
|
---|