VirtualBox

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

Last change on this file since 34079 was 33952, checked in by vboxsync, 14 years ago

Main: replaces callback mechanism of NAT redirect change event notification with event-driven model.

  • 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 33952 2010-11-11 03:49:28Z 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 struct MediaRegistry;
57}
58
59class 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
67public:
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 STDMETHOD(COMGETTER(ExtensionPackManager)) (IExtPackManager **aExtPackManager);
123
124 /* IVirtualBox methods */
125 STDMETHOD(ComposeMachineFilename) (IN_BSTR aName, IN_BSTR aBaseFolder, BSTR *aFilename);
126 STDMETHOD(CreateMachine) (IN_BSTR aSettingsFile,
127 IN_BSTR aName,
128 IN_BSTR aOsTypeId,
129 IN_BSTR aId,
130 BOOL forceOverwrite,
131 IMachine **aMachine);
132 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
133 STDMETHOD(RegisterMachine) (IMachine *aMachine);
134 STDMETHOD(FindMachine) (IN_BSTR aNameOrId, IMachine **aMachine);
135 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
136
137 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
138 IN_BSTR aLocation,
139 IMedium **aHardDisk);
140 STDMETHOD(OpenMedium)(IN_BSTR aLocation,
141 DeviceType_T deviceType,
142 AccessMode_T accessMode,
143 IMedium **aMedium);
144 STDMETHOD(FindMedium)(IN_BSTR aLocation,
145 DeviceType_T deviceType,
146 IMedium **aMedium);
147
148 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
149 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
150 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
151 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
152 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
153 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
154
155 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
156 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
157 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
158 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
159 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
160
161 STDMETHOD(VRDERegisterLibrary)(IN_BSTR aName);
162 STDMETHOD(VRDEUnregisterLibrary)(IN_BSTR aName);
163 STDMETHOD(VRDEListLibraries)(ComSafeArrayOut(BSTR, aNames));
164 STDMETHOD(VRDEIsLibraryRegistered)(IN_BSTR aName, BOOL *aRegistered);
165 /* public methods only for internal purposes */
166
167 /**
168 * Override of the default locking class to be used for validating lock
169 * order with the standard member lock handle.
170 */
171 virtual VBoxLockingClass getLockingClass() const
172 {
173 return LOCKCLASS_VIRTUALBOXOBJECT;
174 }
175
176#ifdef DEBUG
177 void dumpAllBackRefs();
178#endif
179
180 HRESULT postEvent(Event *event);
181
182 HRESULT addProgress(IProgress *aProgress);
183 HRESULT removeProgress(IN_GUID aId);
184
185#ifdef RT_OS_WINDOWS
186 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
187 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
188 HRESULT startSVCHelperClient(bool aPrivileged,
189 SVCHelperClientFunc aFunc,
190 void *aUser, Progress *aProgress);
191#endif
192
193 void addProcessToReap (RTPROCESS pid);
194 void updateClientWatcher();
195
196 void onMachineStateChange(const Guid &aId, MachineState_T aState);
197 void onMachineDataChange(const Guid &aId);
198 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
199 Bstr &aError);
200 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
201 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
202 void onSessionStateChange(const Guid &aId, SessionState_T aState);
203
204 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
205 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
206 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
207 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
208 IN_BSTR aFlags);
209 void onMachineUninit(Machine *aMachine);
210 void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
211 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
212 IN_BSTR aGuestIp, uint16_t aGuestPort);
213
214 ComObjPtr<GuestOSType> getUnknownOSType();
215
216 void getOpenedMachines(SessionMachinesList &aMachines,
217 InternalControlList *aControls = NULL);
218
219 HRESULT findMachine(const Guid &aId,
220 bool fPermitInaccessible,
221 bool aSetError,
222 ComObjPtr<Machine> *machine = NULL);
223
224 HRESULT findHardDiskById(const Guid &id,
225 bool aSetError,
226 ComObjPtr<Medium> *aHardDisk = NULL);
227 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
228 bool aSetError,
229 ComObjPtr<Medium> *aHardDisk = NULL);
230 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
231 const Guid *aId,
232 const Utf8Str &aLocation,
233 bool aSetError,
234 ComObjPtr<Medium> *aImage = NULL);
235 HRESULT findRemoveableMedium(DeviceType_T mediumType,
236 const Guid &uuid,
237 bool fRefresh,
238 ComObjPtr<Medium> &pMedium);
239
240 HRESULT findGuestOSType(const Bstr &bstrOSType,
241 GuestOSType*& pGuestOSType);
242
243 const Guid& getGlobalRegistryId() const;
244
245 const ComObjPtr<Host>& host() const;
246 SystemProperties* getSystemProperties() const;
247#ifdef VBOX_WITH_RESOURCE_USAGE_API
248 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
249#endif /* VBOX_WITH_RESOURCE_USAGE_API */
250
251 void getDefaultMachineFolder(Utf8Str &str) const;
252 void getDefaultHardDiskFormat(Utf8Str &str) const;
253
254 /** Returns the VirtualBox home directory */
255 const Utf8Str& homeDir() const;
256
257 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
258 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
259
260 HRESULT registerHardDisk(Medium *aHardDisk, GuidList *pllRegistriesThatNeedSaving);
261 HRESULT unregisterHardDisk(Medium *aHardDisk, GuidList *pllRegistriesThatNeedSaving);
262
263 HRESULT registerImage(Medium *aImage, DeviceType_T argType, GuidList *pllRegistriesThatNeedSaving);
264 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, GuidList *pllRegistriesThatNeedSaving);
265
266 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
267 HRESULT unregisterMachineMedia(const Guid &id);
268
269 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
270
271 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
272 const Utf8Str &strNewConfigDir);
273
274 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
275 const Guid &uuidRegistry,
276 const Utf8Str &strMachineFolder);
277 HRESULT saveSettings();
278
279 void addGuidToListUniquely(GuidList &llRegistriesThatNeedSaving, Guid uuid);
280 HRESULT saveRegistries(const GuidList &llRegistriesThatNeedSaving);
281
282 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
283
284 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
285
286 const Utf8Str& settingsFilePath();
287
288 RWLockHandle& getMediaTreeLockHandle();
289
290private:
291
292 static HRESULT setErrorStatic(HRESULT aResultCode,
293 const Utf8Str &aText)
294 {
295 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
296 }
297
298 HRESULT checkMediaForConflicts(const Guid &aId,
299 const Utf8Str &aLocation,
300 Utf8Str &aConflictType,
301 bool &fIdentical);
302
303 HRESULT registerMachine(Machine *aMachine);
304
305 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
306 bool aSaveRegistry = true);
307 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
308 bool aSaveRegistry = true);
309
310 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
311 Data *m;
312
313 /* static variables (defined in VirtualBoxImpl.cpp) */
314 static Bstr sVersion;
315 static ULONG sRevision;
316 static Bstr sPackageType;
317
318 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
319 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
320
321#ifdef RT_OS_WINDOWS
322 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
323#endif
324};
325
326////////////////////////////////////////////////////////////////////////////////
327
328#endif // !____H_VIRTUALBOXIMPL
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette