VirtualBox

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

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

Main: new VirtualBox::ComposeMachineFilename() API; remove the 'default hard disk folder' concept and related APIs; GUI wizards need fixing

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

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