1 | /* $Id: VirtualBoxImpl.h 33294 2010-10-21 10:45:26Z 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 | struct MediaRegistry;
|
---|
57 | }
|
---|
58 |
|
---|
59 | class ATL_NO_VTABLE VirtualBox :
|
---|
60 | public VirtualBoxBase,
|
---|
61 | VBOX_SCRIPTABLE_IMPL(IVirtualBox)
|
---|
62 | #ifdef RT_OS_WINDOWS
|
---|
63 | , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
|
---|
64 | #endif
|
---|
65 | {
|
---|
66 |
|
---|
67 | public:
|
---|
68 |
|
---|
69 | typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
|
---|
70 |
|
---|
71 | class CallbackEvent;
|
---|
72 | friend class CallbackEvent;
|
---|
73 |
|
---|
74 | VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
|
---|
75 |
|
---|
76 | DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
|
---|
77 |
|
---|
78 | DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
|
---|
79 | DECLARE_NOT_AGGREGATABLE(VirtualBox)
|
---|
80 |
|
---|
81 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
82 |
|
---|
83 | BEGIN_COM_MAP(VirtualBox)
|
---|
84 | COM_INTERFACE_ENTRY2(IDispatch, IVirtualBox)
|
---|
85 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
86 | COM_INTERFACE_ENTRY(IVirtualBox)
|
---|
87 | END_COM_MAP()
|
---|
88 |
|
---|
89 | // to postpone generation of the default ctor/dtor
|
---|
90 | VirtualBox();
|
---|
91 | ~VirtualBox();
|
---|
92 |
|
---|
93 | HRESULT FinalConstruct();
|
---|
94 | void FinalRelease();
|
---|
95 |
|
---|
96 | /* public initializer/uninitializer for internal purposes only */
|
---|
97 | HRESULT init();
|
---|
98 | HRESULT initMachines();
|
---|
99 | HRESULT initMedia(const Guid &uuidMachineRegistry,
|
---|
100 | const settings::MediaRegistry mediaRegistry,
|
---|
101 | const Utf8Str &strMachineFolder);
|
---|
102 | void uninit();
|
---|
103 |
|
---|
104 | /* IVirtualBox properties */
|
---|
105 | STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
|
---|
106 | STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
|
---|
107 | STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
|
---|
108 | STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
|
---|
109 | STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
|
---|
110 | STDMETHOD(COMGETTER(Host)) (IHost **aHost);
|
---|
111 | STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
|
---|
112 | STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut(IMachine *, aMachines));
|
---|
113 | STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut(IMedium *, aHardDisks));
|
---|
114 | STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut(IMedium *, aDVDImages));
|
---|
115 | STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut(IMedium *, aFloppyImages));
|
---|
116 | STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut(IProgress *, aOperations));
|
---|
117 | STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
|
---|
118 | STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut(ISharedFolder *, aSharedFolders));
|
---|
119 | STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
|
---|
120 | STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut(IDHCPServer *, aDHCPServers));
|
---|
121 | STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
|
---|
122 |
|
---|
123 | /* IVirtualBox methods */
|
---|
124 | STDMETHOD(ComposeMachineFilename) (IN_BSTR aName, IN_BSTR aBaseFolder, BSTR *aFilename);
|
---|
125 | STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
|
---|
126 | IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
|
---|
127 | STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
|
---|
128 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
129 | STDMETHOD(FindMachine) (IN_BSTR aNameOrId, IMachine **aMachine);
|
---|
130 | STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
|
---|
131 |
|
---|
132 | STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
|
---|
133 | IN_BSTR aLocation,
|
---|
134 | IMedium **aHardDisk);
|
---|
135 | STDMETHOD(OpenMedium)(IN_BSTR aLocation,
|
---|
136 | DeviceType_T deviceType,
|
---|
137 | AccessMode_T accessMode,
|
---|
138 | IMedium **aMedium);
|
---|
139 | STDMETHOD(FindMedium)(IN_BSTR aLocation,
|
---|
140 | DeviceType_T deviceType,
|
---|
141 | IMedium **aMedium);
|
---|
142 |
|
---|
143 | STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
|
---|
144 | STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
|
---|
145 | STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
|
---|
146 | STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
|
---|
147 | STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
|
---|
148 | STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
|
---|
149 |
|
---|
150 | STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
151 | STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
152 | STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
|
---|
153 | STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
|
---|
154 | BSTR * aUrl, BSTR * aFile, BOOL * aResult);
|
---|
155 |
|
---|
156 | /* public methods only for internal purposes */
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Override of the default locking class to be used for validating lock
|
---|
160 | * order with the standard member lock handle.
|
---|
161 | */
|
---|
162 | virtual VBoxLockingClass getLockingClass() const
|
---|
163 | {
|
---|
164 | return LOCKCLASS_VIRTUALBOXOBJECT;
|
---|
165 | }
|
---|
166 |
|
---|
167 | #ifdef DEBUG
|
---|
168 | void dumpAllBackRefs();
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | HRESULT postEvent(Event *event);
|
---|
172 |
|
---|
173 | HRESULT addProgress(IProgress *aProgress);
|
---|
174 | HRESULT removeProgress(IN_GUID aId);
|
---|
175 |
|
---|
176 | #ifdef RT_OS_WINDOWS
|
---|
177 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
178 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
179 | HRESULT startSVCHelperClient(bool aPrivileged,
|
---|
180 | SVCHelperClientFunc aFunc,
|
---|
181 | void *aUser, Progress *aProgress);
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | void addProcessToReap (RTPROCESS pid);
|
---|
185 | void updateClientWatcher();
|
---|
186 |
|
---|
187 | void onMachineStateChange(const Guid &aId, MachineState_T aState);
|
---|
188 | void onMachineDataChange(const Guid &aId);
|
---|
189 | BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
|
---|
190 | Bstr &aError);
|
---|
191 | void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
|
---|
192 | void onMachineRegistered(const Guid &aId, BOOL aRegistered);
|
---|
193 | void onSessionStateChange(const Guid &aId, SessionState_T aState);
|
---|
194 |
|
---|
195 | void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
196 | void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
197 | void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
198 | void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
|
---|
199 | IN_BSTR aFlags);
|
---|
200 | void onMachineUninit(Machine *aMachine);
|
---|
201 |
|
---|
202 | ComObjPtr<GuestOSType> getUnknownOSType();
|
---|
203 |
|
---|
204 | void getOpenedMachines(SessionMachinesList &aMachines,
|
---|
205 | InternalControlList *aControls = NULL);
|
---|
206 |
|
---|
207 | HRESULT findMachine(const Guid &aId,
|
---|
208 | bool fPermitInaccessible,
|
---|
209 | bool aSetError,
|
---|
210 | ComObjPtr<Machine> *machine = NULL);
|
---|
211 |
|
---|
212 | HRESULT findHardDiskById(const Guid &id,
|
---|
213 | bool aSetError,
|
---|
214 | ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
215 | HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
|
---|
216 | bool aSetError,
|
---|
217 | ComObjPtr<Medium> *aHardDisk = NULL);
|
---|
218 | HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
|
---|
219 | const Guid *aId,
|
---|
220 | const Utf8Str &aLocation,
|
---|
221 | bool aSetError,
|
---|
222 | ComObjPtr<Medium> *aImage = NULL);
|
---|
223 | HRESULT findRemoveableMedium(DeviceType_T mediumType,
|
---|
224 | const Guid &uuid,
|
---|
225 | bool fRefresh,
|
---|
226 | ComObjPtr<Medium> &pMedium);
|
---|
227 |
|
---|
228 | HRESULT findGuestOSType(const Bstr &bstrOSType,
|
---|
229 | GuestOSType*& pGuestOSType);
|
---|
230 |
|
---|
231 | const Guid& getGlobalRegistryId() const;
|
---|
232 |
|
---|
233 | const ComObjPtr<Host>& host() const;
|
---|
234 | SystemProperties* getSystemProperties() const;
|
---|
235 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
236 | const ComObjPtr<PerformanceCollector>& performanceCollector() const;
|
---|
237 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
238 |
|
---|
239 | void getDefaultMachineFolder(Utf8Str &str) const;
|
---|
240 | void getDefaultHardDiskFormat(Utf8Str &str) const;
|
---|
241 |
|
---|
242 | /** Returns the VirtualBox home directory */
|
---|
243 | const Utf8Str& homeDir() const;
|
---|
244 |
|
---|
245 | int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
|
---|
246 | void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
|
---|
247 |
|
---|
248 | HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
|
---|
249 | HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
|
---|
250 |
|
---|
251 | HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
|
---|
252 | HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
|
---|
253 |
|
---|
254 | void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
|
---|
255 | HRESULT unregisterMachineMedia(const Guid &id);
|
---|
256 |
|
---|
257 | HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
|
---|
258 |
|
---|
259 | void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
|
---|
260 | const Utf8Str &strNewConfigDir);
|
---|
261 |
|
---|
262 | void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
|
---|
263 | const Guid &uuidRegistry,
|
---|
264 | const Utf8Str &strMachineFolder);
|
---|
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 checkMediaForConflicts(const Guid &aId,
|
---|
284 | const Utf8Str &aLocation,
|
---|
285 | Utf8Str &aConflictType,
|
---|
286 | bool &fIdentical);
|
---|
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
|
---|