VirtualBox

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

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

Main: move VirtualBox::UnregisterMachine() to Machine::Unregister(); rename Machine::DeleteSettings() to Machine::Delete()

  • 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 30956 2010-07-21 12:59:12Z 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}
57
58class ATL_NO_VTABLE VirtualBox :
59 public VirtualBoxBase,
60 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
61#ifdef RT_OS_WINDOWS
62 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
63#endif
64{
65
66public:
67
68 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
69
70 class CallbackEvent;
71 friend class CallbackEvent;
72
73 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
74
75 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
76
77 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
78 DECLARE_NOT_AGGREGATABLE(VirtualBox)
79
80 DECLARE_PROTECT_FINAL_CONSTRUCT()
81
82 BEGIN_COM_MAP(VirtualBox)
83 COM_INTERFACE_ENTRY2(IDispatch, IVirtualBox)
84 COM_INTERFACE_ENTRY(ISupportErrorInfo)
85 COM_INTERFACE_ENTRY(IVirtualBox)
86 END_COM_MAP()
87
88 // to postpone generation of the default ctor/dtor
89 VirtualBox();
90 ~VirtualBox();
91
92 HRESULT FinalConstruct();
93 void FinalRelease();
94
95 /* public initializer/uninitializer for internal purposes only */
96 HRESULT init();
97 HRESULT initMachines();
98 HRESULT initMedia();
99 void uninit();
100
101 /* IVirtualBox properties */
102 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
103 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
104 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
105 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
106 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
107 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
108 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
109 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut(IMachine *, aMachines));
110 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut(IMedium *, aHardDisks));
111 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut(IMedium *, aDVDImages));
112 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut(IMedium *, aFloppyImages));
113 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut(IProgress *, aOperations));
114 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
115 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut(ISharedFolder *, aSharedFolders));
116 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
117 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut(IDHCPServer *, aDHCPServers));
118 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
119
120 /* IVirtualBox methods */
121
122 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
123 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
124 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
125 IN_BSTR aId, IMachine **aMachine);
126 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
127 STDMETHOD(RegisterMachine) (IMachine *aMachine);
128 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
129 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
130 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
131
132 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
133 IMedium **aHardDisk);
134 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
135 BOOL aSetImageId, IN_BSTR aImageId,
136 BOOL aSetParentId, IN_BSTR aParentId,
137 IMedium **aHardDisk);
138 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
139 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
140
141 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
142 IMedium **aDVDImage);
143 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
144 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
145
146 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
147 IMedium **aFloppyImage);
148 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
149 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
150
151 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
152 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
153 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
154 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
155 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
156 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
157 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
158 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
159 IN_BSTR aType, IN_BSTR aEnvironment,
160 IProgress **aProgress);
161 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
162
163 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
164 BSTR *aChanged, BSTR *aValues);
165
166 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
167 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
168 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
169 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
170 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
171
172 /* public methods only for internal purposes */
173
174 /**
175 * Override of the default locking class to be used for validating lock
176 * order with the standard member lock handle.
177 */
178 virtual VBoxLockingClass getLockingClass() const
179 {
180 return LOCKCLASS_VIRTUALBOXOBJECT;
181 }
182
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 void onMachineUninit(Machine *aMachine);
217
218 ComObjPtr<GuestOSType> getUnknownOSType();
219
220 void getOpenedMachines(SessionMachinesList &aMachines,
221 InternalControlList *aControls = NULL);
222
223 bool isMachineIdValid(const Guid &aId)
224 {
225 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
226 }
227
228 HRESULT findMachine (const Guid &aId,
229 bool fPermitInaccessible,
230 bool aSetError,
231 ComObjPtr<Machine> *machine = NULL);
232
233 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
234 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
235 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
236 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
237 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
238 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
239
240 HRESULT findGuestOSType(const Bstr &bstrOSType,
241 GuestOSType*& pGuestOSType);
242
243 const ComObjPtr<Host>& host() const;
244 const ComObjPtr<SystemProperties>& systemProperties() const;
245#ifdef VBOX_WITH_RESOURCE_USAGE_API
246 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
247#endif /* VBOX_WITH_RESOURCE_USAGE_API */
248
249 const Utf8Str& getDefaultMachineFolder() const;
250 const Utf8Str& getDefaultHardDiskFolder() const;
251 const Utf8Str& getDefaultHardDiskFormat() const;
252
253 /** Returns the VirtualBox home directory */
254 const Utf8Str& homeDir() const;
255
256 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
257 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
258
259 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
260 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
261
262 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
263 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
264
265 HRESULT unregisterMachine(Machine *pMachine);
266
267 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
268 const Utf8Str &strNewConfigDir);
269
270 HRESULT saveSettings();
271
272 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
273
274 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
275
276 const Utf8Str& settingsFilePath();
277
278 RWLockHandle& getMediaTreeLockHandle();
279
280private:
281
282 static HRESULT setErrorStatic(HRESULT aResultCode,
283 const Utf8Str &aText)
284 {
285 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
286 }
287
288 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
289 Utf8Str &aConflictType);
290
291 HRESULT registerMachine(Machine *aMachine);
292
293 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
294 bool aSaveRegistry = true);
295 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
296 bool aSaveRegistry = true);
297
298 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
299 Data *m;
300
301 /* static variables (defined in VirtualBoxImpl.cpp) */
302 static Bstr sVersion;
303 static ULONG sRevision;
304 static Bstr sPackageType;
305
306 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
307 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
308
309#ifdef RT_OS_WINDOWS
310 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
311#endif
312};
313
314////////////////////////////////////////////////////////////////////////////////
315
316#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