1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
/* $Id: VirtualBoxImpl.h $ */
/** @file
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ____H_VIRTUALBOXIMPL
#define ____H_VIRTUALBOXIMPL
#include "VirtualBoxBase.h"
#include "objectslist.h"
#ifdef RT_OS_WINDOWS
# include "win/resource.h"
#endif
namespace com
{
class Event;
class EventQueue;
}
class SessionMachine;
class GuestOSType;
class Progress;
class Host;
class SystemProperties;
class DHCPServer;
class PerformanceCollector;
#ifdef VBOX_WITH_EXTPACK
class ExtPackManager;
#endif
class AutostartDb;
class NATNetwork;
typedef std::list<ComObjPtr<SessionMachine> > SessionMachinesList;
#ifdef RT_OS_WINDOWS
class SVCHlpClient;
#endif
namespace settings
{
class MainConfigFile;
struct MediaRegistry;
}
class ATL_NO_VTABLE VirtualBox :
public VirtualBoxBase,
VBOX_SCRIPTABLE_IMPL(IVirtualBox)
#ifdef RT_OS_WINDOWS
, public CComCoClass<VirtualBox, &CLSID_VirtualBox>
#endif
{
public:
typedef std::list<ComPtr<IInternalSessionControl> > InternalControlList;
typedef ObjectsList<Machine> MachinesOList;
class CallbackEvent;
friend class CallbackEvent;
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(VirtualBox, IVirtualBox)
DECLARE_CLASSFACTORY_SINGLETON(VirtualBox)
DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
DECLARE_NOT_AGGREGATABLE(VirtualBox)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(VirtualBox)
VBOX_DEFAULT_INTERFACE_ENTRIES(IVirtualBox)
END_COM_MAP()
// to postpone generation of the default ctor/dtor
VirtualBox();
~VirtualBox();
HRESULT FinalConstruct();
void FinalRelease();
/* public initializer/uninitializer for internal purposes only */
HRESULT init();
HRESULT initMachines();
HRESULT initMedia(const Guid &uuidMachineRegistry,
const settings::MediaRegistry mediaRegistry,
const Utf8Str &strMachineFolder);
void uninit();
/* IVirtualBox properties */
STDMETHOD(COMGETTER(Version))(BSTR *aVersion);
STDMETHOD(COMGETTER(VersionNormalized))(BSTR *aVersionNormalized);
STDMETHOD(COMGETTER(Revision))(ULONG *aRevision);
STDMETHOD(COMGETTER(PackageType))(BSTR *aPackageType);
STDMETHOD(COMGETTER(APIVersion))(BSTR *aAPIVersion);
STDMETHOD(COMGETTER(HomeFolder))(BSTR *aHomeFolder);
STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aSettingsFilePath);
STDMETHOD(COMGETTER(Host))(IHost **aHost);
STDMETHOD(COMGETTER(SystemProperties))(ISystemProperties **aSystemProperties);
STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(IMachine *, aMachines));
STDMETHOD(COMGETTER(MachineGroups))(ComSafeArrayOut(BSTR, aMachineGroups));
STDMETHOD(COMGETTER(HardDisks))(ComSafeArrayOut(IMedium *, aHardDisks));
STDMETHOD(COMGETTER(DVDImages))(ComSafeArrayOut(IMedium *, aDVDImages));
STDMETHOD(COMGETTER(FloppyImages))(ComSafeArrayOut(IMedium *, aFloppyImages));
STDMETHOD(COMGETTER(ProgressOperations))(ComSafeArrayOut(IProgress *, aOperations));
STDMETHOD(COMGETTER(GuestOSTypes))(ComSafeArrayOut(IGuestOSType *, aGuestOSTypes));
STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
STDMETHOD(COMGETTER(PerformanceCollector))(IPerformanceCollector **aPerformanceCollector);
STDMETHOD(COMGETTER(DHCPServers))(ComSafeArrayOut(IDHCPServer *, aDHCPServers));
STDMETHOD(COMGETTER(NATNetworks))(ComSafeArrayOut(INATNetwork *, aNATNetworks));
STDMETHOD(COMGETTER(EventSource))(IEventSource ** aEventSource);
STDMETHOD(COMGETTER(ExtensionPackManager))(IExtPackManager **aExtPackManager);
STDMETHOD(COMGETTER(InternalNetworks))(ComSafeArrayOut(BSTR, aInternalNetworks));
STDMETHOD(COMGETTER(GenericNetworkDrivers))(ComSafeArrayOut(BSTR, aGenericNetworkDrivers));
/* IVirtualBox methods */
STDMETHOD(ComposeMachineFilename)(IN_BSTR aName, IN_BSTR aGroup, IN_BSTR aCreateFlags, IN_BSTR aBaseFolder, BSTR *aFilename);
STDMETHOD(CreateMachine)(IN_BSTR aSettingsFile,
IN_BSTR aName,
ComSafeArrayIn(IN_BSTR, aGroups),
IN_BSTR aOsTypeId,
IN_BSTR aCreateFlags,
IMachine **aMachine);
STDMETHOD(OpenMachine)(IN_BSTR aSettingsFile, IMachine **aMachine);
STDMETHOD(RegisterMachine)(IMachine *aMachine);
STDMETHOD(FindMachine)(IN_BSTR aNameOrId, IMachine **aMachine);
STDMETHOD(GetMachinesByGroups)(ComSafeArrayIn(IN_BSTR, aGroups), ComSafeArrayOut(IMachine *, aMachines));
STDMETHOD(GetMachineStates)(ComSafeArrayIn(IMachine *, aMachines), ComSafeArrayOut(MachineState_T, aStates));
STDMETHOD(CreateAppliance)(IAppliance **anAppliance);
STDMETHOD(CreateHardDisk)(IN_BSTR aFormat,
IN_BSTR aLocation,
IMedium **aHardDisk);
STDMETHOD(OpenMedium)(IN_BSTR aLocation,
DeviceType_T deviceType,
AccessMode_T accessMode,
BOOL fForceNewUuid,
IMedium **aMedium);
STDMETHOD(GetGuestOSType)(IN_BSTR aId, IGuestOSType **aType);
STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
STDMETHOD(SetSettingsSecret)(IN_BSTR aKey);
STDMETHOD(CreateDHCPServer)(IN_BSTR aName, IDHCPServer ** aServer);
STDMETHOD(FindDHCPServerByNetworkName)(IN_BSTR aName, IDHCPServer ** aServer);
STDMETHOD(RemoveDHCPServer)(IDHCPServer * aServer);
STDMETHOD(CreateNATNetwork)(IN_BSTR aName, INATNetwork ** aNATNetworks);
STDMETHOD(FindNATNetworkByName)(IN_BSTR aName, INATNetwork ** aNATNetworks);
STDMETHOD(RemoveNATNetwork)(INATNetwork * aNATNetwork);
STDMETHOD(CheckFirmwarePresent)(FirmwareType_T aFirmwareType, IN_BSTR aVersion,
BSTR * aUrl, BSTR * aFile, BOOL * aResult);
/* public methods only for internal purposes */
/**
* Override of the default locking class to be used for validating lock
* order with the standard member lock handle.
*/
virtual VBoxLockingClass getLockingClass() const
{
return LOCKCLASS_VIRTUALBOXOBJECT;
}
#ifdef DEBUG
void dumpAllBackRefs();
#endif
HRESULT postEvent(Event *event);
HRESULT addProgress(IProgress *aProgress);
HRESULT removeProgress(IN_GUID aId);
#ifdef RT_OS_WINDOWS
typedef DECLCALLBACKPTR(HRESULT, SVCHelperClientFunc)
(SVCHlpClient *aClient, Progress *aProgress, void *aUser, int *aVrc);
HRESULT startSVCHelperClient(bool aPrivileged,
SVCHelperClientFunc aFunc,
void *aUser, Progress *aProgress);
#endif
void addProcessToReap(RTPROCESS pid);
void updateClientWatcher();
void onMachineStateChange(const Guid &aId, MachineState_T aState);
void onMachineDataChange(const Guid &aId, BOOL aTemporary = FALSE);
BOOL onExtraDataCanChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue,
Bstr &aError);
void onExtraDataChange(const Guid &aId, IN_BSTR aKey, IN_BSTR aValue);
void onMachineRegistered(const Guid &aId, BOOL aRegistered);
void onSessionStateChange(const Guid &aId, SessionState_T aState);
void onSnapshotTaken(const Guid &aMachineId, const Guid &aSnapshotId);
void onSnapshotDeleted(const Guid &aMachineId, const Guid &aSnapshotId);
void onSnapshotChange(const Guid &aMachineId, const Guid &aSnapshotId);
void onGuestPropertyChange(const Guid &aMachineId, IN_BSTR aName, IN_BSTR aValue,
IN_BSTR aFlags);
void onNatRedirectChange(const Guid &aMachineId, ULONG ulSlot, bool fRemove, IN_BSTR aName,
NATProtocol_T aProto, IN_BSTR aHostIp, uint16_t aHostPort,
IN_BSTR aGuestIp, uint16_t aGuestPort);
void onNATNetworkChange(IN_BSTR aNetworkName);
void onNATNetworkStartStop(IN_BSTR aNetworkName, BOOL aStart);
void onNATNetworkSetting(IN_BSTR aNetworkName, BOOL aEnabled, IN_BSTR aNetwork,
IN_BSTR aGateway, BOOL aAdvertiseDefaultIpv6RouteEnabled,
BOOL fNeedDhcpServer);
void onNATNetworkPortForward(IN_BSTR aNetworkName, BOOL create, BOOL fIpv6,
IN_BSTR aRuleName, NATProtocol_T proto,
IN_BSTR aHostIp, LONG aHostPort,
IN_BSTR aGuestIp, LONG aGuestPort);
void onHostNameResolutionConfigurationChange();
int natNetworkRefInc(IN_BSTR aNetworkName);
int natNetworkRefDec(IN_BSTR aNetworkName);
ComObjPtr<GuestOSType> getUnknownOSType();
void getOpenedMachines(SessionMachinesList &aMachines,
InternalControlList *aControls = NULL);
MachinesOList &getMachinesList();
HRESULT findMachine(const Guid &aId,
bool fPermitInaccessible,
bool aSetError,
ComObjPtr<Machine> *aMachine = NULL);
HRESULT findMachineByName(const Utf8Str &aName,
bool aSetError,
ComObjPtr<Machine> *aMachine = NULL);
HRESULT validateMachineGroup(const Utf8Str &aGroup, bool fPrimary);
HRESULT convertMachineGroups(ComSafeArrayIn(IN_BSTR, aMachineGroups), StringsList *pllMachineGroups);
HRESULT findHardDiskById(const Guid &id,
bool aSetError,
ComObjPtr<Medium> *aHardDisk = NULL);
HRESULT findHardDiskByLocation(const Utf8Str &strLocation,
bool aSetError,
ComObjPtr<Medium> *aHardDisk = NULL);
HRESULT findDVDOrFloppyImage(DeviceType_T mediumType,
const Guid *aId,
const Utf8Str &aLocation,
bool aSetError,
ComObjPtr<Medium> *aImage = NULL);
HRESULT findRemoveableMedium(DeviceType_T mediumType,
const Guid &uuid,
bool fRefresh,
bool aSetError,
ComObjPtr<Medium> &pMedium);
HRESULT findGuestOSType(const Bstr &bstrOSType,
GuestOSType*& pGuestOSType);
const Guid &getGlobalRegistryId() const;
const ComObjPtr<Host>& host() const;
SystemProperties* getSystemProperties() const;
#ifdef VBOX_WITH_EXTPACK
ExtPackManager* getExtPackManager() const;
#endif
#ifdef VBOX_WITH_RESOURCE_USAGE_API
const ComObjPtr<PerformanceCollector>& performanceCollector() const;
#endif /* VBOX_WITH_RESOURCE_USAGE_API */
void getDefaultMachineFolder(Utf8Str &str) const;
void getDefaultHardDiskFormat(Utf8Str &str) const;
/** Returns the VirtualBox home directory */
const Utf8Str& homeDir() const;
int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
void copyPathRelativeToConfig(const Utf8Str &strSource, Utf8Str &strTarget);
HRESULT registerMedium(const ComObjPtr<Medium> &pMedium, ComObjPtr<Medium> *ppMedium, DeviceType_T argType);
HRESULT unregisterMedium(Medium *pMedium);
void pushMediumToListWithChildren(MediaList &llMedia, Medium *pMedium);
HRESULT unregisterMachineMedia(const Guid &id);
HRESULT unregisterMachine(Machine *pMachine, const Guid &id);
void rememberMachineNameChangeForMedia(const Utf8Str &strOldConfigDir,
const Utf8Str &strNewConfigDir);
void saveMediaRegistry(settings::MediaRegistry &mediaRegistry,
const Guid &uuidRegistry,
const Utf8Str &strMachineFolder);
HRESULT saveSettings();
void markRegistryModified(const Guid &uuid);
void saveModifiedRegistries();
static const Bstr &getVersionNormalized();
static HRESULT ensureFilePathExists(const Utf8Str &strFileName, bool fCreate);
const Utf8Str& settingsFilePath();
AutostartDb* getAutostartDb() const;
RWLockHandle& getMachinesListLockHandle();
RWLockHandle& getMediaTreeLockHandle();
int encryptSetting(const Utf8Str &aPlaintext, Utf8Str *aCiphertext);
int decryptSetting(Utf8Str *aPlaintext, const Utf8Str &aCiphertext);
void storeSettingsKey(const Utf8Str &aKey);
bool isMediaUuidInUse(const Guid &aId, DeviceType_T deviceType);
private:
class ClientWatcher;
static HRESULT setErrorStatic(HRESULT aResultCode,
const Utf8Str &aText)
{
return setErrorInternal(aResultCode, getStaticClassIID(), getStaticComponentName(), aText, false, true);
}
HRESULT registerMachine(Machine *aMachine);
HRESULT registerDHCPServer(DHCPServer *aDHCPServer,
bool aSaveRegistry = true);
HRESULT unregisterDHCPServer(DHCPServer *aDHCPServer,
bool aSaveRegistry = true);
HRESULT registerNATNetwork(NATNetwork *aNATNetwork,
bool aSaveRegistry = true);
HRESULT unregisterNATNetwork(NATNetwork *aNATNetwork,
bool aSaveRegistry = true);
HRESULT checkMediaForConflicts(const Guid &aId,
const Utf8Str &aLocation,
Utf8Str &aConflictType,
ComObjPtr<Medium> *pDupMedium);
int decryptSettings();
int decryptMediumSettings(Medium *pMedium);
int decryptSettingBytes(uint8_t *aPlaintext, const uint8_t *aCiphertext,
size_t aCiphertextSize) const;
int encryptSettingBytes(const uint8_t *aPlaintext, uint8_t *aCiphertext,
size_t aPlaintextSize, size_t aCiphertextSize) const;
struct Data; // opaque data structure, defined in VirtualBoxImpl.cpp
Data *m;
/* static variables (defined in VirtualBoxImpl.cpp) */
static Bstr sVersion;
static Bstr sVersionNormalized;
static ULONG sRevision;
static Bstr sPackageType;
static Bstr sAPIVersion;
static std::map<Bstr, int> sNatNetworkNameToRefCount;
static RWLockHandle* spMtxNatNetworkNameToRefCountLock;
static DECLCALLBACK(int) AsyncEventHandler(RTTHREAD thread, void *pvUser);
#ifdef RT_OS_WINDOWS
static DECLCALLBACK(int) SVCHelperClientThread(RTTHREAD aThread, void *aUser);
#endif
};
////////////////////////////////////////////////////////////////////////////////
#endif // !____H_VIRTUALBOXIMPL
|