VirtualBox

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

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

Main: bring back r55600 with fix for broken machine creation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/* $Id: VirtualBoxImpl.h 25184 2009-12-04 11:37:03Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#ifndef ____H_VIRTUALBOXIMPL
25#define ____H_VIRTUALBOXIMPL
26
27#include "VirtualBoxBase.h"
28
29#ifdef RT_OS_WINDOWS
30# include "win/resource.h"
31#endif
32
33namespace com
34{
35 class Event;
36 class EventQueue;
37}
38
39class Machine;
40class SessionMachine;
41class Medium;
42class GuestOSType;
43class SharedFolder;
44class Progress;
45class Host;
46class SystemProperties;
47class DHCPServer;
48class PerformanceCollector;
49
50#ifdef RT_OS_WINDOWS
51class SVCHlpClient;
52#endif
53
54struct VMClientWatcherData;
55
56namespace settings
57{
58 class MainConfigFile;
59}
60
61class ATL_NO_VTABLE VirtualBox :
62 public VirtualBoxBase,
63 public VirtualBoxSupportErrorInfoImpl<VirtualBox, IVirtualBox>,
64 public VirtualBoxSupportTranslation<VirtualBox>,
65 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
66#ifdef RT_OS_WINDOWS
67 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
68#endif
69{
70
71public:
72
73 typedef std::list< ComPtr<IVirtualBoxCallback> > CallbackList;
74 typedef std::list< ComObjPtr<SessionMachine> > SessionMachineList;
75 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
76
77 class CallbackEvent;
78 friend class CallbackEvent;
79
80 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox)
81
82 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
83
84 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
85 DECLARE_NOT_AGGREGATABLE(VirtualBox)
86
87 DECLARE_PROTECT_FINAL_CONSTRUCT()
88
89 BEGIN_COM_MAP(VirtualBox)
90 COM_INTERFACE_ENTRY(IDispatch)
91 COM_INTERFACE_ENTRY(ISupportErrorInfo)
92 COM_INTERFACE_ENTRY(IVirtualBox)
93 END_COM_MAP()
94
95 // to postpone generation of the default ctor/dtor
96 VirtualBox();
97 ~VirtualBox();
98
99 HRESULT FinalConstruct();
100 void FinalRelease();
101
102 /* public initializer/uninitializer for internal purposes only */
103 HRESULT init();
104 HRESULT initMachines();
105 HRESULT initMedia();
106 void uninit();
107
108 /* IVirtualBox properties */
109 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
110 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
111 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
112 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
113 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
114 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
115 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
116 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
117 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
118 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
119 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
120 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
121 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
122 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
123 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
124 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
125
126 /* IVirtualBox methods */
127
128 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
129 IN_BSTR aId, IMachine **aMachine);
130 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
131 IN_BSTR aId, IMachine **aMachine);
132 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
133 STDMETHOD(RegisterMachine) (IMachine *aMachine);
134 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
135 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
136 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
137 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
138
139 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
140 IMedium **aHardDisk);
141 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
142 BOOL aSetImageId, IN_BSTR aImageId,
143 BOOL aSetParentId, IN_BSTR aParentId,
144 IMedium **aHardDisk);
145 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
146 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
147
148 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
149 IMedium **aDVDImage);
150 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
151 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
152
153 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
154 IMedium **aFloppyImage);
155 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
156 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
157
158 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
159 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
160 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
161 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
162 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
163 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
164 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
165 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
166 IN_BSTR aType, IN_BSTR aEnvironment,
167 IProgress **aProgress);
168 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
169
170 STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
171 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
172
173 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
174 BSTR *aChanged, BSTR *aValues);
175
176 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
177 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
178 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
179 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
180 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
181
182 /* public methods only for internal purposes */
183#ifdef DEBUG
184 void dumpAllBackRefs();
185#endif
186
187 HRESULT postEvent(Event *event);
188
189 HRESULT addProgress(IProgress *aProgress);
190 HRESULT removeProgress(IN_GUID aId);
191
192#ifdef RT_OS_WINDOWS
193 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
194 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
195 HRESULT startSVCHelperClient(bool aPrivileged,
196 SVCHelperClientFunc aFunc,
197 void *aUser, Progress *aProgress);
198#endif
199
200 void addProcessToReap (RTPROCESS pid);
201 void updateClientWatcher();
202
203 void onMachineStateChange(const Guid &aId, MachineState_T aState);
204 void onMachineDataChange(const Guid &aId);
205 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
206 Bstr &aError);
207 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
208 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
209 void onSessionStateChange(const Guid &aId, SessionState_T aState);
210
211 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
212 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
213 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
214 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
215 IN_BSTR aFlags);
216
217 ComObjPtr<GuestOSType> getUnknownOSType();
218
219 void getOpenedMachines(SessionMachineList &aMachines,
220 InternalControlList *aControls = NULL);
221
222 bool isMachineIdValid(const Guid &aId)
223 {
224 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
225 }
226
227 HRESULT findMachine (const Guid &aId, bool aSetError,
228 ComObjPtr<Machine> *machine = NULL);
229
230 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
231 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
232 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
233 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
234 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
235 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
236
237 HRESULT findGuestOSType(CBSTR bstrOSType,
238 GuestOSType*& pGuestOSType);
239
240 const ComObjPtr<Host>& host() const;
241 const ComObjPtr<SystemProperties>& systemProperties() const;
242#ifdef VBOX_WITH_RESOURCE_USAGE_API
243 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
244#endif /* VBOX_WITH_RESOURCE_USAGE_API */
245
246 const Utf8Str& getDefaultMachineFolder() const;
247 const Utf8Str& getDefaultHardDiskFolder() const;
248 const Utf8Str& getDefaultHardDiskFormat() const;
249
250 /** Returns the VirtualBox home directory */
251 const Utf8Str& homeDir() const;
252
253 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
254 void calculateRelativePath(const Utf8Str &strPath, Utf8Str &aResult);
255
256 HRESULT registerHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
257 HRESULT unregisterHardDisk(Medium *aHardDisk, bool aSaveRegistry = true);
258
259 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true);
260 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool aSaveRegistry = true);
261
262 HRESULT saveSettings();
263 HRESULT updateSettings(const char *aOldPath, const char *aNewPath);
264
265 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
266
267 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
268
269 const Utf8Str& settingsFilePath();
270
271 RWLockHandle& hardDiskTreeLockHandle();
272
273 /* for VirtualBoxSupportErrorInfoImpl */
274 static const wchar_t *getComponentName() { return L"VirtualBox"; }
275
276private:
277
278 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
279 Utf8Str &aConflictType);
280
281 HRESULT registerMachine (Machine *aMachine);
282
283 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
284 bool aSaveRegistry = true);
285 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
286 bool aSaveRegistry = true);
287
288 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
289 Data *m;
290
291 /* static variables (defined in VirtualBoxImpl.cpp) */
292 static Bstr sVersion;
293 static ULONG sRevision;
294 static Bstr sPackageType;
295
296 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
297 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
298
299#ifdef RT_OS_WINDOWS
300 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
301#endif
302};
303
304////////////////////////////////////////////////////////////////////////////////
305
306#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