VirtualBox

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

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

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