1 | /* $Id: VirtualBoxImpl.h 31814 2010-08-20 12:38:56Z 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 | void uninit();
|
---|
102 |
|
---|
103 | /* IVirtualBox properties */
|
---|
104 | STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
|
---|
105 | STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
|
---|
106 | STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
|
---|
107 | STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
|
---|
108 | STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
|
---|
109 | STDMETHOD(COMGETTER(Host)) (IHost **aHost);
|
---|
110 | STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
|
---|
111 | STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut(IMachine *, aMachines));
|
---|
112 | STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut(IMedium *, aHardDisks));
|
---|
113 | STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut(IMedium *, aDVDImages));
|
---|
114 | STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut(IMedium *, aFloppyImages));
|
---|
115 | STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut(IProgress *, aOperations));
|
---|
116 | STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
|
---|
117 | STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut(ISharedFolder *, aSharedFolders));
|
---|
118 | STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
|
---|
119 | STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut(IDHCPServer *, aDHCPServers));
|
---|
120 | STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
|
---|
121 |
|
---|
122 | /* IVirtualBox methods */
|
---|
123 | STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
|
---|
124 | IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
|
---|
125 | STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
|
---|
126 | STDMETHOD(RegisterMachine) (IMachine *aMachine);
|
---|
127 | STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
|
---|
128 | STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
|
---|
129 | STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
|
---|
130 |
|
---|
131 | STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
|
---|
132 | IN_BSTR aLocation,
|
---|
133 | IMedium **aHardDisk);
|
---|
134 | STDMETHOD(OpenMedium)(IN_BSTR aLocation,
|
---|
135 | DeviceType_T deviceType,
|
---|
136 | AccessMode_T accessMode,
|
---|
137 | IMedium **aMedium);
|
---|
138 | STDMETHOD(FindMedium)(IN_BSTR aLocation,
|
---|
139 | DeviceType_T deviceType,
|
---|
140 | IMedium **aMedium);
|
---|
141 |
|
---|
142 | STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
|
---|
143 | STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
|
---|
144 | STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
|
---|
145 | STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
|
---|
146 | STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
|
---|
147 | STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
|
---|
148 |
|
---|
149 | STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
|
---|
150 | BSTR *aChanged, BSTR *aValues);
|
---|
151 |
|
---|
152 | STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
153 | STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
|
---|
154 | STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
|
---|
155 | STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
|
---|
156 | BSTR * aUrl, BSTR * aFile, BOOL * aResult);
|
---|
157 |
|
---|
158 | /* public methods only for internal purposes */
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Override of the default locking class to be used for validating lock
|
---|
162 | * order with the standard member lock handle.
|
---|
163 | */
|
---|
164 | virtual VBoxLockingClass getLockingClass() const
|
---|
165 | {
|
---|
166 | return LOCKCLASS_VIRTUALBOXOBJECT;
|
---|
167 | }
|
---|
168 |
|
---|
169 | #ifdef DEBUG
|
---|
170 | void dumpAllBackRefs();
|
---|
171 | #endif
|
---|
172 |
|
---|
173 | HRESULT postEvent(Event *event);
|
---|
174 |
|
---|
175 | HRESULT addProgress(IProgress *aProgress);
|
---|
176 | HRESULT removeProgress(IN_GUID aId);
|
---|
177 |
|
---|
178 | #ifdef RT_OS_WINDOWS
|
---|
179 | typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
|
---|
180 | (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
|
---|
181 | HRESULT startSVCHelperClient(bool aPrivileged,
|
---|
182 | SVCHelperClientFunc aFunc,
|
---|
183 | void *aUser, Progress *aProgress);
|
---|
184 | #endif
|
---|
185 |
|
---|
186 | void addProcessToReap (RTPROCESS pid);
|
---|
187 | void updateClientWatcher();
|
---|
188 |
|
---|
189 | void onMachineStateChange(const Guid &aId, MachineState_T aState);
|
---|
190 | void onMachineDataChange(const Guid &aId);
|
---|
191 | BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
|
---|
192 | Bstr &aError);
|
---|
193 | void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
|
---|
194 | void onMachineRegistered(const Guid &aId, BOOL aRegistered);
|
---|
195 | void onSessionStateChange(const Guid &aId, SessionState_T aState);
|
---|
196 |
|
---|
197 | void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
198 | void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
199 | void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
|
---|
200 | void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
|
---|
201 | IN_BSTR aFlags);
|
---|
202 | void onMachineUninit(Machine *aMachine);
|
---|
203 |
|
---|
204 | ComObjPtr<GuestOSType> getUnknownOSType();
|
---|
205 |
|
---|
206 | void getOpenedMachines(SessionMachinesList &aMachines,
|
---|
207 | InternalControlList *aControls = NULL);
|
---|
208 |
|
---|
209 | HRESULT findMachine(const Guid &aId,
|
---|
210 | bool fPermitInaccessible,
|
---|
211 | bool aSetError,
|
---|
212 | ComObjPtr<Machine> *machine = NULL);
|
---|
213 |
|
---|
214 | HRESULT findHardDisk(const Guid *aId,
|
---|
215 | 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 getDefaultHardDiskFolder(Utf8Str &str) const;
|
---|
241 | void getDefaultHardDiskFormat(Utf8Str &str) const;
|
---|
242 |
|
---|
243 | /** Returns the VirtualBox home directory */
|
---|
244 | const Utf8Str& homeDir() const;
|
---|
245 |
|
---|
246 | int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
|
---|
247 | void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
|
---|
248 |
|
---|
249 | HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
|
---|
250 | HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
|
---|
251 |
|
---|
252 | HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
|
---|
253 | HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
|
---|
254 |
|
---|
255 | void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
|
---|
256 | HRESULT unregisterMachineMedia(const Guid &id);
|
---|
257 |
|
---|
258 | HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
|
---|
259 |
|
---|
260 | void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
|
---|
261 | const Utf8Str &strNewConfigDir);
|
---|
262 |
|
---|
263 | void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
|
---|
264 | const Guid &uuidRegistry);
|
---|
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 | Utf8Str getRegistryPath(Medium *pMedium);
|
---|
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
|
---|