VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1/* $Id: VirtualBoxImpl.h 28800 2010-04-27 08:22:32Z 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;
43
44typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
45
46#ifdef RT_OS_WINDOWS
47class SVCHlpClient;
48#endif
49
50struct VMClientWatcherData;
51
52namespace settings
53{
54 class MainConfigFile;
55}
56
57class ATL_NO_VTABLE VirtualBox :
58 public VirtualBoxBase,
59 public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
60 public VirtualBoxSupportTranslation<VirtualBox>,
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<IVirtualBoxCallback> > CallbackList;
70 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
71
72 class CallbackEvent;
73 friend class CallbackEvent;
74
75 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox)
76
77 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
78
79 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
80 DECLARE_NOT_AGGREGATABLE(VirtualBox)
81
82 DECLARE_PROTECT_FINAL_CONSTRUCT()
83
84 BEGIN_COM_MAP(VirtualBox)
85 COM_INTERFACE_ENTRY(IDispatch)
86 COM_INTERFACE_ENTRY(ISupportErrorInfo)
87 COM_INTERFACE_ENTRY(IVirtualBox)
88 END_COM_MAP()
89
90 // to postpone generation of the default ctor/dtor
91 VirtualBox();
92 ~VirtualBox();
93
94 HRESULT FinalConstruct();
95 void FinalRelease();
96
97 /* public initializer/uninitializer for internal purposes only */
98 HRESULT init();
99 HRESULT initMachines();
100 HRESULT initMedia();
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
121 /* IVirtualBox methods */
122
123 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
124 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
125 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
126 IN_BSTR aId, IMachine **aMachine);
127 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
128 STDMETHOD(RegisterMachine) (IMachine *aMachine);
129 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
130 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
131 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
132 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
133
134 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
135 IMedium **aHardDisk);
136 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
137 BOOL aSetImageId, IN_BSTR aImageId,
138 BOOL aSetParentId, IN_BSTR aParentId,
139 IMedium **aHardDisk);
140 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
141 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
142
143 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
144 IMedium **aDVDImage);
145 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
146 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
147
148 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
149 IMedium **aFloppyImage);
150 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
151 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
152
153 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
154 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
155 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
156 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
157 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
158 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
159 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
160 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
161 IN_BSTR aType, IN_BSTR aEnvironment,
162 IProgress **aProgress);
163 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
164
165 STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
166 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
167
168 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
169 BSTR *aChanged, BSTR *aValues);
170
171 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
172 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
173 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
174 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
175 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
176
177 /* public methods only for internal purposes */
178
179 /**
180 * Simple run-time type identification without having to enable C++ RTTI.
181 * The class IDs are defined in VirtualBoxBase.h.
182 * @return
183 */
184 virtual VBoxClsID getClassID() const
185 {
186 return clsidVirtualBox;
187 }
188
189 /**
190 * Override of the default locking class to be used for validating lock
191 * order with the standard member lock handle.
192 */
193 virtual VBoxLockingClass getLockingClass() const
194 {
195 return LOCKCLASS_VIRTUALBOXOBJECT;
196 }
197
198#ifdef DEBUG
199 void dumpAllBackRefs();
200#endif
201
202 HRESULT postEvent(Event *event);
203
204 HRESULT addProgress(IProgress *aProgress);
205 HRESULT removeProgress(IN_GUID aId);
206
207#ifdef RT_OS_WINDOWS
208 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
209 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
210 HRESULT startSVCHelperClient(bool aPrivileged,
211 SVCHelperClientFunc aFunc,
212 void *aUser, Progress *aProgress);
213#endif
214
215 void addProcessToReap (RTPROCESS pid);
216 void updateClientWatcher();
217
218 void onMachineStateChange(const Guid &aId, MachineState_T aState);
219 void onMachineDataChange(const Guid &aId);
220 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
221 Bstr &aError);
222 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
223 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
224 void onSessionStateChange(const Guid &aId, SessionState_T aState);
225
226 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
227 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
228 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
229 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
230 IN_BSTR aFlags);
231
232 ComObjPtr<GuestOSType> getUnknownOSType();
233
234 void getOpenedMachines(SessionMachinesList &aMachines,
235 InternalControlList *aControls = NULL);
236
237 bool isMachineIdValid(const Guid &aId)
238 {
239 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
240 }
241
242 HRESULT findMachine (const Guid &aId, bool aSetError,
243 ComObjPtr<Machine> *machine = NULL);
244
245 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
246 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
247 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
248 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
249 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
250 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
251
252 HRESULT findGuestOSType(const Bstr &bstrOSType,
253 GuestOSType*& pGuestOSType);
254
255 const ComObjPtr<Host>& host() const;
256 const ComObjPtr<SystemProperties>& systemProperties() const;
257#ifdef VBOX_WITH_RESOURCE_USAGE_API
258 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
259#endif /* VBOX_WITH_RESOURCE_USAGE_API */
260
261 const Utf8Str& getDefaultMachineFolder() const;
262 const Utf8Str& getDefaultHardDiskFolder() const;
263 const Utf8Str& getDefaultHardDiskFormat() const;
264
265 /** Returns the VirtualBox home directory */
266 const Utf8Str& homeDir() const;
267
268 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
269 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
270
271 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
272 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
273
274 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
275 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
276
277 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
278 const Utf8Str &strNewConfigDir);
279
280 HRESULT saveSettings();
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
290 /* for VirtualBoxSupportErrorInfoImpl */
291 static const wchar_t *getComponentName() { return L"VirtualBox"; }
292
293private:
294
295 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
296 Utf8Str &aConflictType);
297
298 HRESULT registerMachine (Machine *aMachine);
299
300 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
301 bool aSaveRegistry = true);
302 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
303 bool aSaveRegistry = true);
304
305 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
306 Data *m;
307
308 /* static variables (defined in VirtualBoxImpl.cpp) */
309 static Bstr sVersion;
310 static ULONG sRevision;
311 static Bstr sPackageType;
312
313 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
314 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
315
316#ifdef RT_OS_WINDOWS
317 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
318#endif
319};
320
321////////////////////////////////////////////////////////////////////////////////
322
323#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