VirtualBox

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

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

Main: remove VirtualBoxSupportTranslation template, add translation support to generic base class, clean up COM headers more, remove SupportErrorInfo.cpp|h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1/* $Id: VirtualBoxImpl.h 30739 2010-07-08 12:27:42Z 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}
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 , public IConnectionPointContainerImpl<VirtualBox>
64 , public IConnectionPointImpl<VirtualBox, &IID_IVirtualBoxCallback, CComDynamicUnkArray>
65#endif
66{
67
68public:
69
70 typedef std::list< VirtualBoxCallbackRegistration > CallbackList;
71 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
72
73 class CallbackEvent;
74 friend class CallbackEvent;
75
76 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
77
78 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
79
80 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
81 DECLARE_NOT_AGGREGATABLE(VirtualBox)
82
83 DECLARE_PROTECT_FINAL_CONSTRUCT()
84
85 BEGIN_COM_MAP(VirtualBox)
86 COM_INTERFACE_ENTRY2(IDispatch, IVirtualBox)
87 COM_INTERFACE_ENTRY(ISupportErrorInfo)
88 COM_INTERFACE_ENTRY(IVirtualBox)
89 COM_INTERFACE_ENTRY(IConnectionPointContainer)
90 END_COM_MAP()
91
92#ifdef RT_OS_WINDOWS
93 BEGIN_CONNECTION_POINT_MAP(VirtualBox)
94 CONNECTION_POINT_ENTRY(IID_IVirtualBoxCallback)
95 END_CONNECTION_POINT_MAP()
96
97 typedef CComDynamicUnkArray EventListenersList;
98#endif
99
100 // to postpone generation of the default ctor/dtor
101 VirtualBox();
102 ~VirtualBox();
103
104 HRESULT FinalConstruct();
105 void FinalRelease();
106
107 /* public initializer/uninitializer for internal purposes only */
108 HRESULT init();
109 HRESULT initMachines();
110 HRESULT initMedia();
111 void uninit();
112
113 /* IVirtualBox properties */
114 STDMETHOD(COMGETTER(Version)) (BSTR *aVersion);
115 STDMETHOD(COMGETTER(Revision)) (ULONG *aRevision);
116 STDMETHOD(COMGETTER(PackageType)) (BSTR *aPackageType);
117 STDMETHOD(COMGETTER(HomeFolder)) (BSTR *aHomeFolder);
118 STDMETHOD(COMGETTER(SettingsFilePath)) (BSTR *aSettingsFilePath);
119 STDMETHOD(COMGETTER(Host)) (IHost **aHost);
120 STDMETHOD(COMGETTER(SystemProperties)) (ISystemProperties **aSystemProperties);
121 STDMETHOD(COMGETTER(Machines)) (ComSafeArrayOut (IMachine *, aMachines));
122 STDMETHOD(COMGETTER(HardDisks)) (ComSafeArrayOut (IMedium *, aHardDisks));
123 STDMETHOD(COMGETTER(DVDImages)) (ComSafeArrayOut (IMedium *, aDVDImages));
124 STDMETHOD(COMGETTER(FloppyImages)) (ComSafeArrayOut (IMedium *, aFloppyImages));
125 STDMETHOD(COMGETTER(ProgressOperations)) (ComSafeArrayOut (IProgress *, aOperations));
126 STDMETHOD(COMGETTER(GuestOSTypes)) (ComSafeArrayOut (IGuestOSType *, aGuestOSTypes));
127 STDMETHOD(COMGETTER(SharedFolders)) (ComSafeArrayOut (ISharedFolder *, aSharedFolders));
128 STDMETHOD(COMGETTER(PerformanceCollector)) (IPerformanceCollector **aPerformanceCollector);
129 STDMETHOD(COMGETTER(DHCPServers)) (ComSafeArrayOut (IDHCPServer *, aDHCPServers));
130 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
131
132 /* IVirtualBox methods */
133
134 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
135 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
136 STDMETHOD(CreateLegacyMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aSettingsFile,
137 IN_BSTR aId, IMachine **aMachine);
138 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
139 STDMETHOD(RegisterMachine) (IMachine *aMachine);
140 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
141 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
142 STDMETHOD(UnregisterMachine) (IN_BSTR aId, IMachine **aMachine);
143 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
144
145 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
146 IMedium **aHardDisk);
147 STDMETHOD(OpenHardDisk) (IN_BSTR aLocation, AccessMode_T accessMode,
148 BOOL aSetImageId, IN_BSTR aImageId,
149 BOOL aSetParentId, IN_BSTR aParentId,
150 IMedium **aHardDisk);
151 STDMETHOD(GetHardDisk) (IN_BSTR aId, IMedium **aHardDisk);
152 STDMETHOD(FindHardDisk) (IN_BSTR aLocation, IMedium **aHardDisk);
153
154 STDMETHOD(OpenDVDImage) (IN_BSTR aLocation, IN_BSTR aId,
155 IMedium **aDVDImage);
156 STDMETHOD(GetDVDImage) (IN_BSTR aId, IMedium **aDVDImage);
157 STDMETHOD(FindDVDImage) (IN_BSTR aLocation, IMedium **aDVDImage);
158
159 STDMETHOD(OpenFloppyImage) (IN_BSTR aLocation, IN_BSTR aId,
160 IMedium **aFloppyImage);
161 STDMETHOD(GetFloppyImage) (IN_BSTR aId, IMedium **aFloppyImage);
162 STDMETHOD(FindFloppyImage) (IN_BSTR aLocation, IMedium **aFloppyImage);
163
164 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
165 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable);
166 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
167 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
168 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
169 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
170 STDMETHOD(OpenSession) (ISession *aSession, IN_BSTR aMachineId);
171 STDMETHOD(OpenRemoteSession) (ISession *aSession, IN_BSTR aMachineId,
172 IN_BSTR aType, IN_BSTR aEnvironment,
173 IProgress **aProgress);
174 STDMETHOD(OpenExistingSession) (ISession *aSession, IN_BSTR aMachineId);
175
176 STDMETHOD(RegisterCallback) (IVirtualBoxCallback *aCallback);
177 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
178
179 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
180 BSTR *aChanged, BSTR *aValues);
181
182 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
183 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
184 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
185 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
186 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
187
188 /* public methods only for internal purposes */
189
190 /**
191 * Override of the default locking class to be used for validating lock
192 * order with the standard member lock handle.
193 */
194 virtual VBoxLockingClass getLockingClass() const
195 {
196 return LOCKCLASS_VIRTUALBOXOBJECT;
197 }
198
199#ifdef DEBUG
200 void dumpAllBackRefs();
201#endif
202
203 HRESULT postEvent(Event *event);
204
205 HRESULT addProgress(IProgress *aProgress);
206 HRESULT removeProgress(IN_GUID aId);
207
208#ifdef RT_OS_WINDOWS
209 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
210 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
211 HRESULT startSVCHelperClient(bool aPrivileged,
212 SVCHelperClientFunc aFunc,
213 void *aUser, Progress *aProgress);
214#endif
215
216 void addProcessToReap (RTPROCESS pid);
217 void updateClientWatcher();
218
219 void removeDeadCallback(const ComPtr<IVirtualBoxCallback> &aCallback);
220
221 void onMachineStateChange(const Guid &aId, MachineState_T aState);
222 void onMachineDataChange(const Guid &aId);
223 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
224 Bstr &aError);
225 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
226 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
227 void onSessionStateChange(const Guid &aId, SessionState_T aState);
228
229 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
230 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
231 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
232 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
233 IN_BSTR aFlags);
234
235 ComObjPtr<GuestOSType> getUnknownOSType();
236
237 void getOpenedMachines(SessionMachinesList &aMachines,
238 InternalControlList *aControls = NULL);
239
240 bool isMachineIdValid(const Guid &aId)
241 {
242 return SUCCEEDED(findMachine(aId, false /* aSetError */, NULL));
243 }
244
245 HRESULT findMachine (const Guid &aId, bool aSetError,
246 ComObjPtr<Machine> *machine = NULL);
247
248 HRESULT findHardDisk(const Guid *aId, CBSTR aLocation,
249 bool aSetError, ComObjPtr<Medium> *aHardDisk = NULL);
250 HRESULT findDVDImage(const Guid *aId, CBSTR aLocation,
251 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
252 HRESULT findFloppyImage(const Guid *aId, CBSTR aLocation,
253 bool aSetError, ComObjPtr<Medium> *aImage = NULL);
254
255 HRESULT findGuestOSType(const Bstr &bstrOSType,
256 GuestOSType*& pGuestOSType);
257
258 const ComObjPtr<Host>& host() const;
259 const ComObjPtr<SystemProperties>& systemProperties() const;
260#ifdef VBOX_WITH_RESOURCE_USAGE_API
261 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
262#endif /* VBOX_WITH_RESOURCE_USAGE_API */
263
264 const Utf8Str& getDefaultMachineFolder() const;
265 const Utf8Str& getDefaultHardDiskFolder() const;
266 const Utf8Str& getDefaultHardDiskFormat() const;
267
268 /** Returns the VirtualBox home directory */
269 const Utf8Str& homeDir() const;
270
271 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
272 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
273
274 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
275 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
276
277 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
278 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
279
280 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
281 const Utf8Str &strNewConfigDir);
282
283 HRESULT saveSettings();
284
285 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
286
287 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
288
289 const Utf8Str& settingsFilePath();
290
291 RWLockHandle& getMediaTreeLockHandle();
292
293private:
294
295 static HRESULT setErrorStatic(HRESULT aResultCode,
296 const Utf8Str &aText)
297 {
298 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
299 }
300
301 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
302 Utf8Str &aConflictType);
303
304 HRESULT registerMachine (Machine *aMachine);
305
306 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
307 bool aSaveRegistry = true);
308 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
309 bool aSaveRegistry = true);
310
311 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
312 Data *m;
313
314 /* static variables (defined in VirtualBoxImpl.cpp) */
315 static Bstr sVersion;
316 static ULONG sRevision;
317 static Bstr sPackageType;
318
319 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
320 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
321
322#ifdef RT_OS_WINDOWS
323 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
324#endif
325};
326
327////////////////////////////////////////////////////////////////////////////////
328
329#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