VirtualBox

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

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

Main: remove deprecated VirtualBox::createLegacyMachine() and corresponding VBoxManage --settingsfile option; new API docs for IMachine::attachDevice() (not yet implemented)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 KB
Line 
1/* $Id: VirtualBoxImpl.h 31595 2010-08-12 11:44:47Z 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 STDMETHOD(CreateMachine) (IN_BSTR aName, IN_BSTR aOsTypeId, IN_BSTR aBaseFolder,
122 IN_BSTR aId, BOOL aOverride, IMachine **aMachine);
123 STDMETHOD(OpenMachine) (IN_BSTR aSettingsFile, IMachine **aMachine);
124 STDMETHOD(RegisterMachine) (IMachine *aMachine);
125 STDMETHOD(GetMachine) (IN_BSTR aId, IMachine **aMachine);
126 STDMETHOD(FindMachine) (IN_BSTR aName, IMachine **aMachine);
127 STDMETHOD(CreateAppliance) (IAppliance **anAppliance);
128
129 STDMETHOD(CreateHardDisk)(IN_BSTR aFormat, IN_BSTR aLocation,
130 IMedium **aHardDisk);
131 STDMETHOD(OpenMedium)(IN_BSTR aLocation,
132 DeviceType_T deviceType,
133 AccessMode_T accessMode,
134 IMedium **aMedium);
135 STDMETHOD(FindMedium)(IN_BSTR aLocation,
136 DeviceType_T deviceType,
137 IMedium **aMedium);
138
139 STDMETHOD(GetGuestOSType) (IN_BSTR aId, IGuestOSType **aType);
140 STDMETHOD(CreateSharedFolder) (IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
141 STDMETHOD(RemoveSharedFolder) (IN_BSTR aName);
142 STDMETHOD(GetExtraDataKeys) (ComSafeArrayOut(BSTR, aKeys));
143 STDMETHOD(GetExtraData) (IN_BSTR aKey, BSTR *aValue);
144 STDMETHOD(SetExtraData) (IN_BSTR aKey, IN_BSTR aValue);
145
146 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
147 BSTR *aChanged, BSTR *aValues);
148
149 STDMETHOD(CreateDHCPServer) (IN_BSTR aName, IDHCPServer ** aServer);
150 STDMETHOD(FindDHCPServerByNetworkName) (IN_BSTR aName, IDHCPServer ** aServer);
151 STDMETHOD(RemoveDHCPServer) (IDHCPServer * aServer);
152 STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
153 BSTR * aUrl, BSTR * aFile, BOOL * aResult);
154
155 /* public methods only for internal purposes */
156
157 /**
158 * Override of the default locking class to be used for validating lock
159 * order with the standard member lock handle.
160 */
161 virtual VBoxLockingClass getLockingClass() const
162 {
163 return LOCKCLASS_VIRTUALBOXOBJECT;
164 }
165
166#ifdef DEBUG
167 void dumpAllBackRefs();
168#endif
169
170 HRESULT postEvent(Event *event);
171
172 HRESULT addProgress(IProgress *aProgress);
173 HRESULT removeProgress(IN_GUID aId);
174
175#ifdef RT_OS_WINDOWS
176 typedef DECLCALLBACKPTR (HRESULT, SVCHelperClientFunc)
177 (SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
178 HRESULT startSVCHelperClient(bool aPrivileged,
179 SVCHelperClientFunc aFunc,
180 void *aUser, Progress *aProgress);
181#endif
182
183 void addProcessToReap (RTPROCESS pid);
184 void updateClientWatcher();
185
186 void onMachineStateChange(const Guid &aId, MachineState_T aState);
187 void onMachineDataChange(const Guid &aId);
188 BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
189 Bstr &aError);
190 void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
191 void onMachineRegistered(const Guid &aId, BOOL aRegistered);
192 void onSessionStateChange(const Guid &aId, SessionState_T aState);
193
194 void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
195 void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
196 void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
197 void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
198 IN_BSTR aFlags);
199 void onMachineUninit(Machine *aMachine);
200
201 ComObjPtr<GuestOSType> getUnknownOSType();
202
203 void getOpenedMachines(SessionMachinesList &aMachines,
204 InternalControlList *aControls = NULL);
205
206 HRESULT findMachine (const Guid &aId,
207 bool fPermitInaccessible,
208 bool aSetError,
209 ComObjPtr<Machine> *machine = NULL);
210
211 HRESULT findHardDisk(const Guid *aId,
212 const Utf8Str &strLocation,
213 bool aSetError,
214 ComObjPtr<Medium> *aHardDisk = NULL);
215 HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
216 const Guid *aId,
217 const Utf8Str &aLocation,
218 bool aSetError,
219 ComObjPtr<Medium> *aImage = NULL);
220 HRESULT findRemoveableMedium(DeviceType_T mediumType,
221 const Guid &uuid,
222 bool fRefresh,
223 ComObjPtr<Medium> &pMedium);
224
225 HRESULT findGuestOSType(const Bstr &bstrOSType,
226 GuestOSType*& pGuestOSType);
227
228 const ComObjPtr<Host>& host() const;
229 SystemProperties* getSystemProperties() const;
230#ifdef VBOX_WITH_RESOURCE_USAGE_API
231 const ComObjPtr<PerformanceCollector>& performanceCollector() const;
232#endif /* VBOX_WITH_RESOURCE_USAGE_API */
233
234 void getDefaultMachineFolder(Utf8Str &str) const;
235 void getDefaultHardDiskFolder(Utf8Str &str) const;
236 void getDefaultHardDiskFormat(Utf8Str &str) const;
237
238 /** Returns the VirtualBox home directory */
239 const Utf8Str& homeDir() const;
240
241 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
242 void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
243
244 HRESULT registerHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
245 HRESULT unregisterHardDisk(Medium *aHardDisk, bool *pfNeedsSaveSettings);
246
247 HRESULT registerImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
248 HRESULT unregisterImage(Medium *aImage, DeviceType_T argType, bool *pfNeedsSaveSettings);
249
250 HRESULT unregisterMachine(Machine *pMachine);
251
252 void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
253 const Utf8Str &strNewConfigDir);
254
255 HRESULT saveSettings();
256
257 static HRESULT ensureFilePathExists(const Utf8Str &strFileName);
258
259 static HRESULT handleUnexpectedExceptions (RT_SRC_POS_DECL);
260
261 const Utf8Str& settingsFilePath();
262
263 RWLockHandle& getMediaTreeLockHandle();
264
265private:
266
267 static HRESULT setErrorStatic(HRESULT aResultCode,
268 const Utf8Str &aText)
269 {
270 return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
271 }
272
273 HRESULT checkMediaForConflicts2(const Guid &aId, const Utf8Str &aLocation,
274 Utf8Str &aConflictType);
275
276 HRESULT registerMachine(Machine *aMachine);
277
278 HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
279 bool aSaveRegistry = true);
280 HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
281 bool aSaveRegistry = true);
282
283 struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
284 Data *m;
285
286 /* static variables (defined in VirtualBoxImpl.cpp) */
287 static Bstr sVersion;
288 static ULONG sRevision;
289 static Bstr sPackageType;
290
291 static DECLCALLBACK(int) ClientWatcher (RTTHREAD thread, void *pvUser);
292 static DECLCALLBACK(int) AsyncEventHandler (RTTHREAD thread, void *pvUser);
293
294#ifdef RT_OS_WINDOWS
295 static DECLCALLBACK(int) SVCHelperClientThread (RTTHREAD aThread, void *aUser);
296#endif
297};
298
299////////////////////////////////////////////////////////////////////////////////
300
301#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