VirtualBox

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

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

Main: change VirtualBox::createMachine() to accept arbitrary paths for the XML settings file; remove the override parameter

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