VirtualBox

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

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

VRDE: More API changes for the VRDP server separation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
Line 
1/* $Id: VirtualBoxImpl.h 33556 2010-10-28 13:16: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.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 STDMETHOD(VRDEIsLibraryRegistered)(IN_BSTR aName, BOOL *aRegistered);
164 /* public methods only for internal purposes */
165
166 /**
167 * Override of the default locking class to be used for validating lock
168 * order with the standard member lock handle.
169 */
170 virtual VBoxLockingClass getLockingClass() const
171 {
172 return LOCKCLASS_VIRTUALBOXOBJECT;
173 }
174
175#ifdef DEBUG
176 void dumpAllBackRefs();
177#endif
178
179 HRESULT postEvent(Event *event);
180
181 HRESULT addProgress(IProgress *aProgress);
182 HRESULT removeProgress(IN_GUID aId);
183
184#ifdef RT_OS_WINDOWS
185 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
186 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
187 HRESULT startSVCHelperClient(bool aPrivileged,
188 SVCHelperClientFunc aFunc,
189 void *aUser, Progress *aProgress);
190#endif
191
192 void addProcessToReap (RTPROCESS pid);
193 void updateClientWatcher();
194
195 void onMachineStateChange(const Guid &aId, MachineState_T aState);
196 void onMachineDataChange(const Guid &aId);
197 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
198 Bstr &aError);
199 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
200 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
201 void onSessionStateChange(const Guid &aId, SessionState_T aState);
202
203 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
204 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
205 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
206 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
207 IN_BSTR aFlags);
208 void onMachineUninit(Machine *aMachine);
209
210 ComObjPtr<GuestOSType> getUnknownOSType();
211
212 void getOpenedMachines(SessionMachinesList &aMachines,
213 InternalControlList *aControls = NULL);
214
215 HRESULT findMachine(const Guid &aId,
216 bool fPermitInaccessible,
217 bool aSetError,
218 ComObjPtr<Machine> *machine = NULL);
219
220 HRESULT findHardDiskById(const Guid &id,
221 bool aSetError,
222 ComObjPtr<Medium> *aHardDisk = NULL);
223 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
224 bool aSetError,
225 ComObjPtr<Medium> *aHardDisk = NULL);
226 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
227 const Guid *aId,
228 const Utf8Str &aLocation,
229 bool aSetError,
230 ComObjPtr<Medium> *aImage = NULL);
231 HRESULT findRemoveableMedium(DeviceType_T mediumType,
232 const Guid &uuid,
233 bool fRefresh,
234 ComObjPtr<Medium> &pMedium);
235
236 HRESULT findGuestOSType(const Bstr &bstrOSType,
237 GuestOSType*& pGuestOSType);
238
239 const Guid& getGlobalRegistryId() const;
240
241 const ComObjPtr<Host>& host() const;
242 SystemProperties* getSystemProperties() const;
243#ifdef VBOX_WITH_RESOURCE_USAGE_API
244 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
245#endif /* VBOX_WITH_RESOURCE_USAGE_API */
246
247 void getDefaultMachineFolder(Utf8Str &str) const;
248 void getDefaultHardDiskFormat(Utf8Str &str) const;
249
250 /** Returns the VirtualBox home directory */
251 const Utf8Str& homeDir() const;
252
253 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
254 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
255
256 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
257 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsGlobalSaveSettings);
258
259 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
260 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsGlobalSaveSettings);
261
262 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
263 HRESULT unregisterMachineMedia(const Guid &id);
264
265 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
266
267 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
268 const Utf8Str &strNewConfigDir);
269
270 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
271 const Guid &uuidRegistry,
272 const Utf8Str &strMachineFolder);
273 HRESULT saveSettings();
274
275 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
276
277 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
278
279 const Utf8Str& settingsFilePath();
280
281 RWLockHandle& getMediaTreeLockHandle();
282
283private:
284
285 static HRESULT setErrorStatic(HRESULT aResultCode,
286 const Utf8Str &aText)
287 {
288 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
289 }
290
291 HRESULT checkMediaForConflicts(const Guid &aId,
292 const Utf8Str &aLocation,
293 Utf8Str &aConflictType,
294 bool &fIdentical);
295
296 HRESULT registerMachine(Machine *aMachine);
297
298 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
299 bool aSaveRegistry = true);
300 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
301 bool aSaveRegistry = true);
302
303 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
304 Data *m;
305
306 /* static variables (defined in VirtualBoxImpl.cpp) */
307 static Bstr sVersion;
308 static ULONG sRevision;
309 static Bstr sPackageType;
310
311 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
312 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
313
314#ifdef RT_OS_WINDOWS
315 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
316#endif
317};
318
319////////////////////////////////////////////////////////////////////////////////
320
321#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