VirtualBox

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

Last change on this file since 41999 was 41999, checked in by vboxsync, 13 years ago

More autostart service updates, work in progress

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1/* $Id: VirtualBoxImpl.h 41999 2012-07-03 12:50:18Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ____H_VIRTUALBOXIMPL
19#define ____H_VIRTUALBOXIMPL
20
21#include "VirtualBoxBase.h"
22
23#ifdef RT_OS_WINDOWS
24# include "win/resource.h"
25#endif
26
27namespace com
28{
29 class Event;
30 class EventQueue;
31}
32
33class SessionMachine;
34class GuestOSType;
35class SharedFolder;
36class Progress;
37class Host;
38class SystemProperties;
39class DHCPServer;
40class PerformanceCollector;
41class VirtualBoxCallbackRegistration; /* see VirtualBoxImpl.cpp */
42#ifdef VBOX_WITH_EXTPACK
43class ExtPackManager;
44#endif
45class AutostartDb;
46
47typedef std::list< ComObjPtr<SessionMachine> > SessionMachinesList;
48
49#ifdef RT_OS_WINDOWS
50class SVCHlpClient;
51#endif
52
53struct VMClientWatcherData;
54
55namespace settings
56{
57 class MainConfigFile;
58 struct MediaRegistry;
59}
60class ATL_NO_VTABLE VirtualBox :
61 public VirtualBoxBase,
62 VBOX_SCRIPTABLE_IMPL(IVirtualBox)
63#ifdef RT_OS_WINDOWS
64 , public CComCoClass<VirtualBox, &CLSID_VirtualBox>
65#endif
66{
67
68public:
69
70 typedef std::list< ComPtr<IInternalSessionControl> > InternalControlList;
71
72 class CallbackEvent;
73 friend class CallbackEvent;
74
75 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
76
77 DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
78
79 DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
80 DECLARE_NOT_AGGREGATABLE(VirtualBox)
81
82 DECLARE_PROTECT_FINAL_CONSTRUCT()
83
84 BEGIN_COM_MAP(VirtualBox)
85 VBOX_DEFAULT_INTERFACE_ENTRIES(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(const Guid &uuidMachineRegistry,
99 const settings::MediaRegistry mediaRegistry,
100 const Utf8Str &strMachineFolder);
101 void uninit();
102
103 /* IVirtualBox properties */
104 STDMETHOD(COMGETTER(Version))(BSTR *aVersion);
105 STDMETHOD(COMGETTER(Revision))(ULONG *aRevision);
106 STDMETHOD(COMGETTER(PackageType))(BSTR *aPackageType);
107 STDMETHOD(COMGETTER(APIVersion))(BSTR *aAPIVersion);
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 STDMETHOD(COMGETTER(ExtensionPackManager))(IExtPackManager **aExtPackManager);
123 STDMETHOD(COMGETTER(InternalNetworks))(ComSafeArrayOut(BSTR, aInternalNetworks));
124 STDMETHOD(COMGETTER(GenericNetworkDrivers))(ComSafeArrayOut(BSTR, aGenericNetworkDrivers));
125
126 /* IVirtualBox methods */
127 STDMETHOD(ComposeMachineFilename)(IN_BSTR aName, IN_BSTR aBaseFolder, BSTR *aFilename);
128 STDMETHOD(CreateMachine)(IN_BSTR aSettingsFile,
129 IN_BSTR aName,
130 IN_BSTR aOsTypeId,
131 IN_BSTR aId,
132 BOOL forceOverwrite,
133 IMachine **aMachine);
134 STDMETHOD(OpenMachine)(IN_BSTR aSettingsFile, IMachine **aMachine);
135 STDMETHOD(RegisterMachine)(IMachine *aMachine);
136 STDMETHOD(FindMachine)(IN_BSTR aNameOrId, IMachine **aMachine);
137 STDMETHOD(GetMachineStates)(ComSafeArrayIn(IMachine *, aMachines), ComSafeArrayOut(MachineState_T, aStates));
138 STDMETHOD(CreateAppliance)(IAppliance **anAppliance);
139
140 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
141 IN_BSTR aLocation,
142 IMedium **aHardDisk);
143 STDMETHOD(OpenMedium)(IN_BSTR aLocation,
144 DeviceType_T deviceType,
145 AccessMode_T accessMode,
146 BOOL fForceNewUuid,
147 IMedium **aMedium);
148
149 STDMETHOD(GetGuestOSType)(IN_BSTR aId, IGuestOSType **aType);
150 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
151 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
152 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
153 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
154 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
155
156 STDMETHOD(CreateDHCPServer)(IN_BSTR aName, IDHCPServer ** aServer);
157 STDMETHOD(FindDHCPServerByNetworkName)(IN_BSTR aName, IDHCPServer ** aServer);
158 STDMETHOD(RemoveDHCPServer)(IDHCPServer * aServer);
159 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
160 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
161
162 /* public methods only for internal purposes */
163
164 /**
165 * Override of the default locking class to be used for validating lock
166 * order with the standard member lock handle.
167 */
168 virtual VBoxLockingClass getLockingClass() const
169 {
170 return LOCKCLASS_VIRTUALBOXOBJECT;
171 }
172
173#ifdef DEBUG
174 void dumpAllBackRefs();
175#endif
176
177 HRESULT postEvent(Event *event);
178
179 HRESULT addProgress(IProgress *aProgress);
180 HRESULT removeProgress(IN_GUID aId);
181
182#ifdef RT_OS_WINDOWS
183 typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
184 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
185 HRESULT startSVCHelperClient(bool aPrivileged,
186 SVCHelperClientFunc aFunc,
187 void *aUser, Progress *aProgress);
188#endif
189
190 void addProcessToReap(RTPROCESS pid);
191 void updateClientWatcher();
192
193 void onMachineStateChange(const Guid &aId, MachineState_T aState);
194 void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
195 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
196 Bstr &aError);
197 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
198 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
199 void onSessionStateChange(const Guid &aId, SessionState_T aState);
200
201 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
202 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
203 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
204 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
205 IN_BSTR aFlags);
206 void onMachineUninit(Machine *aMachine);
207 void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
208 NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
209 IN_BSTR aGuestIp, uint16_t aGuestPort);
210
211 ComObjPtr<GuestOSType> getUnknownOSType();
212
213 void getOpenedMachines(SessionMachinesList &aMachines,
214 InternalControlList *aControls = NULL);
215
216 HRESULT findMachine(const Guid &aId,
217 bool fPermitInaccessible,
218 bool aSetError,
219 ComObjPtr<Machine> *machine = NULL);
220
221 HRESULT findHardDiskById(const Guid &id,
222 bool aSetError,
223 ComObjPtr<Medium> *aHardDisk = NULL);
224 HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
225 bool aSetError,
226 ComObjPtr<Medium> *aHardDisk = NULL);
227 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
228 const Guid *aId,
229 const Utf8Str &aLocation,
230 bool aSetError,
231 ComObjPtr<Medium> *aImage = NULL);
232 HRESULT findRemoveableMedium(DeviceType_T mediumType,
233 const Guid &uuid,
234 bool fRefresh,
235 bool aSetError,
236 ComObjPtr<Medium> &pMedium);
237
238 HRESULT findGuestOSType(const Bstr &bstrOSType,
239 GuestOSType*& pGuestOSType);
240
241 const Guid& getGlobalRegistryId() const;
242
243 const ComObjPtr<Host>& host() const;
244 SystemProperties* getSystemProperties() const;
245#ifdef VBOX_WITH_EXTPACK
246 ExtPackManager* getExtPackManager() const;
247#endif
248#ifdef VBOX_WITH_RESOURCE_USAGE_API
249 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
250#endif /* VBOX_WITH_RESOURCE_USAGE_API */
251
252 void getDefaultMachineFolder(Utf8Str &str) const;
253 void getDefaultHardDiskFormat(Utf8Str &str) const;
254
255 /** Returns the VirtualBox home directory */
256 const Utf8Str& homeDir() const;
257
258 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
259 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
260
261 HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
262 HRESULT unregisterMedium(Medium *pMedium);
263
264 void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
265 HRESULT unregisterMachineMedia(const Guid &id);
266
267 HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
268
269 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
270 const Utf8Str &strNewConfigDir);
271
272 void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
273 const Guid &uuidRegistry,
274 const Utf8Str &strMachineFolder);
275 HRESULT saveSettings();
276
277 void markRegistryModified(const Guid &uuid);
278 void saveModifiedRegistries();
279
280 static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
281
282 const Utf8Str& settingsFilePath();
283
284 AutostartDb* getAutostartDb() const;
285
286 RWLockHandle& getMediaTreeLockHandle();
287
288private:
289
290 static HRESULT setErrorStatic(HRESULT aResultCode,
291 const Utf8Str &aText)
292 {
293 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
294 }
295
296 HRESULT checkMediaForConflicts(const Guid &aId,
297 const Utf8Str &aLocation,
298 Utf8Str &aConflictType,
299 ComObjPtr<Medium> *pDupMedium);
300
301 HRESULT registerMachine(Machine *aMachine);
302
303 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
304 bool aSaveRegistry = true);
305 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
306 bool aSaveRegistry = true);
307
308 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
309 Data *m;
310
311 /* static variables (defined in VirtualBoxImpl.cpp) */
312 static Bstr sVersion;
313 static ULONG sRevision;
314 static Bstr sPackageType;
315 static Bstr sAPIVersion;
316
317 static DECLCALLBACK(int) ClientWatcher(RTTHREAD thread, void *pvUser);
318 static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
319
320#ifdef RT_OS_WINDOWS
321 static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
322#endif
323};
324
325////////////////////////////////////////////////////////////////////////////////
326
327#endif // !____H_VIRTUALBOXIMPL
328
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