VirtualBox

source: vbox/trunk/src/VBox/Main/include/MachineImpl.h@ 39459

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

Runtime: new guest OS type for Solaris 11
Frontends/VirtualBox: add new patterns for Solaris 11 guest OS type, reuse the icon
Frontends/VBoxManage: more details for "list ostypes"
Main/xml: make guest OS type in config file an arbitrary string (still validated/mapped in the old way in the settings code), remove hardcoded limit of 8 network adapters
Main/Global: move list of valid guest OS types into a single place, add function to get the network adapter limit for each chipset type
Main/Console+Machine+Snapshot+NetworkAdapter+Appliance+VirtualBox+Guest+SystemProperties: consistently use the appropriate network adapter limit so that ICH9 chipset can use 36 network adapters, adapt to cleaned up guest OS type handling, remove leftover rendundant guest OS mapping, whitespace
Network/NAT: release log message cosmetics, allow unlimited number of instances, fix maxconn clamping
Network/PCNet+VirtioNet+E1000: allow unlimited number of instances

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.7 KB
Line 
1/* $Id: MachineImpl.h 39248 2011-11-09 12:29:53Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2011 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_MACHINEIMPL
19#define ____H_MACHINEIMPL
20
21#include "VirtualBoxBase.h"
22#include "SnapshotImpl.h"
23#include "ProgressImpl.h"
24#include "VRDEServerImpl.h"
25#include "MediumAttachmentImpl.h"
26#include "PciDeviceAttachmentImpl.h"
27#include "MediumLock.h"
28#include "NetworkAdapterImpl.h"
29#include "AudioAdapterImpl.h"
30#include "SerialPortImpl.h"
31#include "ParallelPortImpl.h"
32#include "BIOSSettingsImpl.h"
33#include "StorageControllerImpl.h" // required for MachineImpl.h to compile on Windows
34#include "BandwidthControlImpl.h"
35#include "BandwidthGroupImpl.h"
36#include "VBox/settings.h"
37#ifdef VBOX_WITH_RESOURCE_USAGE_API
38#include "Performance.h"
39#include "PerformanceImpl.h"
40#endif /* VBOX_WITH_RESOURCE_USAGE_API */
41
42// generated header
43#include "SchemaDefs.h"
44
45#include "VBox/com/ErrorInfo.h"
46
47#include <iprt/file.h>
48#include <iprt/thread.h>
49#include <iprt/time.h>
50
51#include <list>
52#include <vector>
53
54// defines
55////////////////////////////////////////////////////////////////////////////////
56
57// helper declarations
58////////////////////////////////////////////////////////////////////////////////
59
60class Progress;
61class ProgressProxy;
62class Keyboard;
63class Mouse;
64class Display;
65class MachineDebugger;
66class USBController;
67class Snapshot;
68class SharedFolder;
69class HostUSBDevice;
70class StorageController;
71
72class SessionMachine;
73
74namespace settings
75{
76 class MachineConfigFile;
77 struct Snapshot;
78 struct Hardware;
79 struct Storage;
80 struct StorageController;
81 struct MachineRegistryEntry;
82}
83
84// Machine class
85////////////////////////////////////////////////////////////////////////////////
86
87class ATL_NO_VTABLE Machine :
88 public VirtualBoxBase,
89 VBOX_SCRIPTABLE_IMPL(IMachine)
90{
91 Q_OBJECT
92
93public:
94
95 enum StateDependency
96 {
97 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
98 };
99
100 /**
101 * Internal machine data.
102 *
103 * Only one instance of this data exists per every machine -- it is shared
104 * by the Machine, SessionMachine and all SnapshotMachine instances
105 * associated with the given machine using the util::Shareable template
106 * through the mData variable.
107 *
108 * @note |const| members are persistent during lifetime so can be
109 * accessed without locking.
110 *
111 * @note There is no need to lock anything inside init() or uninit()
112 * methods, because they are always serialized (see AutoCaller).
113 */
114 struct Data
115 {
116 /**
117 * Data structure to hold information about sessions opened for the
118 * given machine.
119 */
120 struct Session
121 {
122 /** Control of the direct session opened by lockMachine() */
123 ComPtr<IInternalSessionControl> mDirectControl;
124
125 typedef std::list<ComPtr<IInternalSessionControl> > RemoteControlList;
126
127 /** list of controls of all opened remote sessions */
128 RemoteControlList mRemoteControls;
129
130 /** launchVMProcess() and OnSessionEnd() progress indicator */
131 ComObjPtr<ProgressProxy> mProgress;
132
133 /**
134 * PID of the session object that must be passed to openSession()
135 * to finalize the launchVMProcess() request (i.e., PID of the
136 * process created by launchVMProcess())
137 */
138 RTPROCESS mPid;
139
140 /** Current session state */
141 SessionState_T mState;
142
143 /** Session type string (for indirect sessions) */
144 Bstr mType;
145
146 /** Session machine object */
147 ComObjPtr<SessionMachine> mMachine;
148
149 /** Medium object lock collection. */
150 MediumLockListMap mLockedMedia;
151 };
152
153 Data();
154 ~Data();
155
156 const Guid mUuid;
157 BOOL mRegistered;
158
159 Utf8Str m_strConfigFile;
160 Utf8Str m_strConfigFileFull;
161
162 // machine settings XML file
163 settings::MachineConfigFile *pMachineConfigFile;
164 uint32_t flModifications;
165 bool m_fAllowStateModification;
166
167 BOOL mAccessible;
168 com::ErrorInfo mAccessError;
169
170 MachineState_T mMachineState;
171 RTTIMESPEC mLastStateChange;
172
173 /* Note: These are guarded by VirtualBoxBase::stateLockHandle() */
174 uint32_t mMachineStateDeps;
175 RTSEMEVENTMULTI mMachineStateDepsSem;
176 uint32_t mMachineStateChangePending;
177
178 BOOL mCurrentStateModified;
179 /** Guest properties have been modified and need saving since the
180 * machine was started, or there are transient properties which need
181 * deleting and the machine is being shut down. */
182 BOOL mGuestPropertiesModified;
183
184 Session mSession;
185
186 ComObjPtr<Snapshot> mFirstSnapshot;
187 ComObjPtr<Snapshot> mCurrentSnapshot;
188
189 // list of files to delete in Delete(); this list is filled by Unregister()
190 std::list<Utf8Str> llFilesToDelete;
191 };
192
193 /**
194 * Saved state data.
195 *
196 * It's actually only the state file path string, but it needs to be
197 * separate from Data, because Machine and SessionMachine instances
198 * share it, while SnapshotMachine does not.
199 *
200 * The data variable is |mSSData|.
201 */
202 struct SSData
203 {
204 Utf8Str strStateFilePath;
205 };
206
207 /**
208 * User changeable machine data.
209 *
210 * This data is common for all machine snapshots, i.e. it is shared
211 * by all SnapshotMachine instances associated with the given machine
212 * using the util::Backupable template through the |mUserData| variable.
213 *
214 * SessionMachine instances can alter this data and discard changes.
215 *
216 * @note There is no need to lock anything inside init() or uninit()
217 * methods, because they are always serialized (see AutoCaller).
218 */
219 struct UserData
220 {
221 settings::MachineUserData s;
222 };
223
224 /**
225 * Hardware data.
226 *
227 * This data is unique for a machine and for every machine snapshot.
228 * Stored using the util::Backupable template in the |mHWData| variable.
229 *
230 * SessionMachine instances can alter this data and discard changes.
231 */
232 struct HWData
233 {
234 /**
235 * Data structure to hold information about a guest property.
236 */
237 struct GuestProperty {
238 /** Property name */
239 Utf8Str strName;
240 /** Property value */
241 Utf8Str strValue;
242 /** Property timestamp */
243 LONG64 mTimestamp;
244 /** Property flags */
245 ULONG mFlags;
246 };
247
248 HWData();
249 ~HWData();
250
251 Bstr mHWVersion;
252 Guid mHardwareUUID; /**< If Null, use mData.mUuid. */
253 ULONG mMemorySize;
254 ULONG mMemoryBalloonSize;
255 BOOL mPageFusionEnabled;
256 ULONG mVRAMSize;
257 ULONG mMonitorCount;
258 BOOL mHWVirtExEnabled;
259 BOOL mHWVirtExExclusive;
260 BOOL mHWVirtExNestedPagingEnabled;
261 BOOL mHWVirtExLargePagesEnabled;
262 BOOL mHWVirtExVPIDEnabled;
263 BOOL mHWVirtExForceEnabled;
264 BOOL mAccelerate2DVideoEnabled;
265 BOOL mPAEEnabled;
266 BOOL mSyntheticCpu;
267 ULONG mCPUCount;
268 BOOL mCPUHotPlugEnabled;
269 ULONG mCpuExecutionCap;
270 BOOL mAccelerate3DEnabled;
271 BOOL mHpetEnabled;
272
273 BOOL mCPUAttached[SchemaDefs::MaxCPUCount];
274
275 settings::CpuIdLeaf mCpuIdStdLeafs[11];
276 settings::CpuIdLeaf mCpuIdExtLeafs[11];
277
278 DeviceType_T mBootOrder[SchemaDefs::MaxBootPosition];
279
280 typedef std::list<ComObjPtr<SharedFolder> > SharedFolderList;
281 SharedFolderList mSharedFolders;
282
283 ClipboardMode_T mClipboardMode;
284
285 typedef std::list<GuestProperty> GuestPropertyList;
286 GuestPropertyList mGuestProperties;
287 Utf8Str mGuestPropertyNotificationPatterns;
288
289 FirmwareType_T mFirmwareType;
290 KeyboardHidType_T mKeyboardHidType;
291 PointingHidType_T mPointingHidType;
292 ChipsetType_T mChipsetType;
293
294 BOOL mIoCacheEnabled;
295 ULONG mIoCacheSize;
296
297 typedef std::list<ComObjPtr<PciDeviceAttachment> > PciDeviceAssignmentList;
298 PciDeviceAssignmentList mPciDeviceAssignments;
299 };
300
301 /**
302 * Hard disk and other media data.
303 *
304 * The usage policy is the same as for HWData, but a separate structure
305 * is necessary because hard disk data requires different procedures when
306 * taking or deleting snapshots, etc.
307 *
308 * The data variable is |mMediaData|.
309 */
310 struct MediaData
311 {
312 MediaData();
313 ~MediaData();
314
315 typedef std::list<ComObjPtr<MediumAttachment> > AttachmentList;
316 AttachmentList mAttachments;
317 };
318
319 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
320
321 DECLARE_NOT_AGGREGATABLE(Machine)
322
323 DECLARE_PROTECT_FINAL_CONSTRUCT()
324
325 BEGIN_COM_MAP(Machine)
326 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
327 END_COM_MAP()
328
329 DECLARE_EMPTY_CTOR_DTOR(Machine)
330
331 HRESULT FinalConstruct();
332 void FinalRelease();
333
334 // public initializer/uninitializer for internal purposes only:
335
336 // initializer for creating a new, empty machine
337 HRESULT init(VirtualBox *aParent,
338 const Utf8Str &strConfigFile,
339 const Utf8Str &strName,
340 GuestOSType *aOsType,
341 const Guid &aId,
342 bool fForceOverwrite);
343
344 // initializer for loading existing machine XML (either registered or not)
345 HRESULT init(VirtualBox *aParent,
346 const Utf8Str &strConfigFile,
347 const Guid *aId);
348
349 // initializer for machine config in memory (OVF import)
350 HRESULT init(VirtualBox *aParent,
351 const Utf8Str &strName,
352 const settings::MachineConfigFile &config);
353
354 void uninit();
355
356#ifdef VBOX_WITH_RESOURCE_USAGE_API
357 // Needed from VirtualBox, for the delayed metrics cleanup.
358 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
359#endif /* VBOX_WITH_RESOURCE_USAGE_API */
360
361protected:
362 HRESULT initImpl(VirtualBox *aParent,
363 const Utf8Str &strConfigFile);
364 HRESULT initDataAndChildObjects();
365 HRESULT registeredInit();
366 HRESULT tryCreateMachineConfigFile(bool fForceOverwrite);
367 void uninitDataAndChildObjects();
368
369public:
370 // IMachine properties
371 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
372 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
373 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
374 STDMETHOD(COMGETTER(Name))(BSTR *aName);
375 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
376 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
377 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
378 STDMETHOD(COMGETTER(Id))(BSTR *aId);
379 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
380 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
381 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
382 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
383 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
384 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
385 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
386 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
387 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
388 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
389 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
390 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
391 STDMETHOD(COMGETTER(CPUExecutionCap))(ULONG *aExecutionCap);
392 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
393 STDMETHOD(COMGETTER(EmulatedUSBCardReaderEnabled))(BOOL *enabled);
394 STDMETHOD(COMSETTER(EmulatedUSBCardReaderEnabled))(BOOL enabled);
395 STDMETHOD(COMGETTER(EmulatedUSBWebcameraEnabled))(BOOL *enabled);
396 STDMETHOD(COMSETTER(EmulatedUSBWebcameraEnabled))(BOOL enabled);
397 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
398 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
399 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
400 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
401 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
402 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
403 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
404 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
405 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
406 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
407 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
408 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
409 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
410 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
411 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
412 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
413 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
414 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
415 STDMETHOD(COMGETTER(VRDEServer))(IVRDEServer **vrdeServer);
416 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
417 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
418 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
419 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
420 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
421 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
422 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
423 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
424 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
425 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
426 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
427 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
428 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
429 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
430 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
431 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
432 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
433 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
434 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
435 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
436 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
437 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
438 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
439 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
440 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
441 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
442 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
443 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
444 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
445 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
446 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
447 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
448 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
449 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
450 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
451 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
452 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
453 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
454 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
455 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
456 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
457 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
458 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
459 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
460 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
461 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
462 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
463 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
464 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
465 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
466 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
467 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
468 STDMETHOD(COMGETTER(PciDeviceAssignments))(ComSafeArrayOut(IPciDeviceAttachment *, aAssignments));
469 STDMETHOD(COMGETTER(BandwidthControl))(IBandwidthControl **aBandwidthControl);
470
471 // IMachine methods
472 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
473 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
474
475 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
476 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
477 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
478 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
479 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
480 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
481 STDMETHOD(TemporaryEjectDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aTempEject);
482 STDMETHOD(NonRotationalDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aNonRotational);
483 STDMETHOD(SetAutoDiscardForDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aDiscard);
484 STDMETHOD(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
485 LONG aDevice, IBandwidthGroup *aBandwidthGroup);
486 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
487 LONG aDevice, IMedium *aMedium, BOOL aForce);
488 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
489 IMedium **aMedium);
490 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
491 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
492 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
493 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
494 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
495 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
496 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
497 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
498 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
499 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
500 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
501 STDMETHOD(RemoveAllCPUIDLeaves)();
502 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
503 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
504 STDMETHOD(SaveSettings)();
505 STDMETHOD(DiscardSettings)();
506 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
507 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
508 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
509 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
510 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
511 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
512 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
513 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
514 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
515 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
516 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
517 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
518 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
519 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
520 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
521 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
522 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
523 STDMETHOD(RemoveStorageController(IN_BSTR aName));
524 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
525 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
526 STDMETHOD(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
527 STDMETHOD(QuerySavedGuestSize)(ULONG aScreenId, ULONG *puWidth, ULONG *puHeight);
528 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
529 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
530 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
531 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
532 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
533 STDMETHOD(HotPlugCPU(ULONG aCpu));
534 STDMETHOD(HotUnplugCPU(ULONG aCpu));
535 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
536 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
537 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
538 STDMETHOD(AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, BOOL tryToUnbind));
539 STDMETHOD(DetachHostPciDevice(LONG hostAddress));
540 STDMETHOD(CloneTo(IMachine *pTarget, CloneMode_T mode, ComSafeArrayIn(CloneOptions_T, options), IProgress **pProgress));
541 // public methods only for internal purposes
542
543 virtual bool isSnapshotMachine() const
544 {
545 return false;
546 }
547
548 virtual bool isSessionMachine() const
549 {
550 return false;
551 }
552
553 /**
554 * Override of the default locking class to be used for validating lock
555 * order with the standard member lock handle.
556 */
557 virtual VBoxLockingClass getLockingClass() const
558 {
559 return LOCKCLASS_MACHINEOBJECT;
560 }
561
562 /// @todo (dmik) add lock and make non-inlined after revising classes
563 // that use it. Note: they should enter Machine lock to keep the returned
564 // information valid!
565 bool isRegistered() { return !!mData->mRegistered; }
566
567 // unsafe inline public methods for internal purposes only (ensure there is
568 // a caller and a read lock before calling them!)
569
570 /**
571 * Returns the VirtualBox object this machine belongs to.
572 *
573 * @note This method doesn't check this object's readiness. Intended to be
574 * used by ready Machine children (whose readiness is bound to the parent's
575 * one) or after doing addCaller() manually.
576 */
577 VirtualBox* getVirtualBox() const { return mParent; }
578
579 /**
580 * Checks if this machine is accessible, without attempting to load the
581 * config file.
582 *
583 * @note This method doesn't check this object's readiness. Intended to be
584 * used by ready Machine children (whose readiness is bound to the parent's
585 * one) or after doing addCaller() manually.
586 */
587 bool isAccessible() const { return mData->mAccessible; }
588
589 /**
590 * Returns this machine ID.
591 *
592 * @note This method doesn't check this object's readiness. Intended to be
593 * used by ready Machine children (whose readiness is bound to the parent's
594 * one) or after adding a caller manually.
595 */
596 const Guid& getId() const { return mData->mUuid; }
597
598 /**
599 * Returns the snapshot ID this machine represents or an empty UUID if this
600 * instance is not SnapshotMachine.
601 *
602 * @note This method doesn't check this object's readiness. Intended to be
603 * used by ready Machine children (whose readiness is bound to the parent's
604 * one) or after adding a caller manually.
605 */
606 inline const Guid& getSnapshotId() const;
607
608 /**
609 * Returns this machine's full settings file path.
610 *
611 * @note This method doesn't lock this object or check its readiness.
612 * Intended to be used only after doing addCaller() manually and locking it
613 * for reading.
614 */
615 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
616
617 /**
618 * Returns this machine name.
619 *
620 * @note This method doesn't lock this object or check its readiness.
621 * Intended to be used only after doing addCaller() manually and locking it
622 * for reading.
623 */
624 const Utf8Str& getName() const { return mUserData->s.strName; }
625
626 enum
627 {
628 IsModified_MachineData = 0x0001,
629 IsModified_Storage = 0x0002,
630 IsModified_NetworkAdapters = 0x0008,
631 IsModified_SerialPorts = 0x0010,
632 IsModified_ParallelPorts = 0x0020,
633 IsModified_VRDEServer = 0x0040,
634 IsModified_AudioAdapter = 0x0080,
635 IsModified_USB = 0x0100,
636 IsModified_BIOS = 0x0200,
637 IsModified_SharedFolders = 0x0400,
638 IsModified_Snapshots = 0x0800,
639 IsModified_BandwidthControl = 0x1000
640 };
641
642 /**
643 * Checks if this machine is accessible, without attempting to load the
644 * config file.
645 *
646 * @note This method doesn't check this object's readiness. Intended to be
647 * used by ready Machine children (whose readiness is bound to the parent's
648 * one) or after doing addCaller() manually.
649 */
650 ChipsetType_T getChipsetType() const { return mHWData->mChipsetType; }
651
652 void setModified(uint32_t fl, bool fAllowStateModification = true);
653 void setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
654
655 bool isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
656 void allowStateModification() { mData->m_fAllowStateModification = true; }
657 void disallowStateModification() { mData->m_fAllowStateModification = false; }
658
659 // callback handlers
660 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
661 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
662 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
663 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
664 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
665 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
666 virtual HRESULT onUSBControllerChange() { return S_OK; }
667 virtual HRESULT onStorageControllerChange() { return S_OK; }
668 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
669 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
670 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
671 virtual HRESULT onSharedFolderChange() { return S_OK; }
672 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
673 virtual HRESULT onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */) { return S_OK; }
674
675 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
676
677 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
678 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
679
680 void getLogFolder(Utf8Str &aLogFolder);
681 Utf8Str queryLogFilename(ULONG idx);
682
683 void composeSavedStateFilename(Utf8Str &strStateFilePath);
684
685 HRESULT launchVMProcess(IInternalSessionControl *aControl,
686 const Utf8Str &strType,
687 const Utf8Str &strEnvironment,
688 ProgressProxy *aProgress);
689
690 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
691 {
692 HRESULT rc;
693 *directControl = mData->mSession.mDirectControl;
694
695 if (!*directControl)
696 rc = E_ACCESSDENIED;
697 else
698 rc = S_OK;
699
700 return rc;
701 }
702
703#if defined(RT_OS_WINDOWS)
704
705 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
706 ComPtr<IInternalSessionControl> *aControl = NULL,
707 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
708 bool isSessionSpawning(RTPROCESS *aPID = NULL);
709
710 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
711 ComPtr<IInternalSessionControl> *aControl = NULL,
712 HANDLE *aIPCSem = NULL)
713 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
714
715#elif defined(RT_OS_OS2)
716
717 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
718 ComPtr<IInternalSessionControl> *aControl = NULL,
719 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
720
721 bool isSessionSpawning(RTPROCESS *aPID = NULL);
722
723 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
724 ComPtr<IInternalSessionControl> *aControl = NULL,
725 HMTX *aIPCSem = NULL)
726 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
727
728#else
729
730 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
731 ComPtr<IInternalSessionControl> *aControl = NULL,
732 bool aAllowClosing = false);
733 bool isSessionSpawning();
734
735 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
736 ComPtr<IInternalSessionControl> *aControl = NULL)
737 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
738
739#endif
740
741 bool checkForSpawnFailure();
742
743 HRESULT prepareRegister();
744
745 HRESULT getSharedFolder(CBSTR aName,
746 ComObjPtr<SharedFolder> &aSharedFolder,
747 bool aSetError = false)
748 {
749 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
750 return findSharedFolder(aName, aSharedFolder, aSetError);
751 }
752
753 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
754 MachineState_T *aState = NULL,
755 BOOL *aRegistered = NULL);
756 void releaseStateDependency();
757
758 HRESULT getBandwidthGroup(const Utf8Str &strBandwidthGroup,
759 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
760 bool fSetError = false)
761 {
762 return mBandwidthControl->getBandwidthGroupByName(strBandwidthGroup,
763 pBandwidthGroup,
764 fSetError);
765 }
766
767protected:
768
769 HRESULT checkStateDependency(StateDependency aDepType);
770
771 Machine *getMachine();
772
773 void ensureNoStateDependencies();
774
775 virtual HRESULT setMachineState(MachineState_T aMachineState);
776
777 HRESULT findSharedFolder(const Utf8Str &aName,
778 ComObjPtr<SharedFolder> &aSharedFolder,
779 bool aSetError = false);
780
781 HRESULT loadSettings(bool aRegistered);
782 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
783 const Guid *puuidRegistry);
784 HRESULT loadSnapshot(const settings::Snapshot &data,
785 const Guid &aCurSnapshotId,
786 Snapshot *aParentSnapshot);
787 HRESULT loadHardware(const settings::Hardware &data);
788 HRESULT loadStorageControllers(const settings::Storage &data,
789 const Guid *puuidRegistry,
790 const Guid *puuidSnapshot);
791 HRESULT loadStorageDevices(StorageController *aStorageController,
792 const settings::StorageController &data,
793 const Guid *puuidRegistry,
794 const Guid *puuidSnapshot);
795
796 HRESULT findSnapshotById(const Guid &aId,
797 ComObjPtr<Snapshot> &aSnapshot,
798 bool aSetError = false);
799 HRESULT findSnapshotByName(const Utf8Str &strName,
800 ComObjPtr<Snapshot> &aSnapshot,
801 bool aSetError = false);
802
803 HRESULT getStorageControllerByName(const Utf8Str &aName,
804 ComObjPtr<StorageController> &aStorageController,
805 bool aSetError = false);
806
807 HRESULT getMediumAttachmentsOfController(CBSTR aName,
808 MediaData::AttachmentList &aAttachments);
809
810 enum
811 {
812 /* flags for #saveSettings() */
813 SaveS_ResetCurStateModified = 0x01,
814 SaveS_InformCallbacksAnyway = 0x02,
815 SaveS_Force = 0x04,
816 /* flags for #saveStateSettings() */
817 SaveSTS_CurStateModified = 0x20,
818 SaveSTS_StateFilePath = 0x40,
819 SaveSTS_StateTimeStamp = 0x80
820 };
821
822 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
823 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
824
825 void copyMachineDataToSettings(settings::MachineConfigFile &config);
826 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
827 HRESULT saveHardware(settings::Hardware &data);
828 HRESULT saveStorageControllers(settings::Storage &data);
829 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
830 settings::StorageController &data);
831 HRESULT saveStateSettings(int aFlags);
832
833 void addMediumToRegistry(ComObjPtr<Medium> &pMedium,
834 GuidList &llRegistriesThatNeedSaving,
835 Guid *puuid);
836
837 HRESULT createImplicitDiffs(IProgress *aProgress,
838 ULONG aWeight,
839 bool aOnline,
840 GuidList *pllRegistriesThatNeedSaving);
841 HRESULT deleteImplicitDiffs(GuidList *pllRegistriesThatNeedSaving);
842
843 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
844 IN_BSTR aControllerName,
845 LONG aControllerPort,
846 LONG aDevice);
847 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
848 ComObjPtr<Medium> pMedium);
849 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
850 Guid &id);
851
852 HRESULT detachDevice(MediumAttachment *pAttach,
853 AutoWriteLock &writeLock,
854 Snapshot *pSnapshot,
855 GuidList *pllRegistriesThatNeedSaving);
856
857 HRESULT detachAllMedia(AutoWriteLock &writeLock,
858 Snapshot *pSnapshot,
859 CleanupMode_T cleanupMode,
860 MediaList &llMedia);
861
862 void commitMedia(bool aOnline = false);
863 void rollbackMedia();
864
865 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
866
867 void rollback(bool aNotify);
868 void commit();
869 void copyFrom(Machine *aThat);
870 bool isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
871
872 struct DeleteTask;
873 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
874 HRESULT deleteTaskWorker(DeleteTask &task);
875
876#ifdef VBOX_WITH_GUEST_PROPS
877 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
878 LONG64 *aTimestamp, BSTR *aFlags) const;
879 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
880 LONG64 *aTimestamp, BSTR *aFlags) const;
881 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
882 IN_BSTR aFlags);
883 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
884 IN_BSTR aFlags);
885 HRESULT enumerateGuestPropertiesInService
886 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
887 ComSafeArrayOut(BSTR, aValues),
888 ComSafeArrayOut(LONG64, aTimestamps),
889 ComSafeArrayOut(BSTR, aFlags));
890 HRESULT enumerateGuestPropertiesOnVM
891 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
892 ComSafeArrayOut(BSTR, aValues),
893 ComSafeArrayOut(LONG64, aTimestamps),
894 ComSafeArrayOut(BSTR, aFlags));
895#endif /* VBOX_WITH_GUEST_PROPS */
896
897#ifdef VBOX_WITH_RESOURCE_USAGE_API
898 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
899
900 pm::CollectorGuest *mCollectorGuest;
901#endif /* VBOX_WITH_RESOURCE_USAGE_API */
902
903 Machine* const mPeer;
904
905 VirtualBox * const mParent;
906
907 Shareable<Data> mData;
908 Shareable<SSData> mSSData;
909
910 Backupable<UserData> mUserData;
911 Backupable<HWData> mHWData;
912 Backupable<MediaData> mMediaData;
913
914 // the following fields need special backup/rollback/commit handling,
915 // so they cannot be a part of HWData
916
917 const ComObjPtr<VRDEServer> mVRDEServer;
918 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
919 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
920 const ComObjPtr<AudioAdapter> mAudioAdapter;
921 const ComObjPtr<USBController> mUSBController;
922 const ComObjPtr<BIOSSettings> mBIOSSettings;
923 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
924 NetworkAdapterVector mNetworkAdapters;
925 const ComObjPtr<BandwidthControl> mBandwidthControl;
926
927 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
928 Backupable<StorageControllerList> mStorageControllers;
929
930 friend class SessionMachine;
931 friend class SnapshotMachine;
932 friend class Appliance;
933 friend class VirtualBox;
934
935 friend class MachineCloneVM;
936};
937
938// SessionMachine class
939////////////////////////////////////////////////////////////////////////////////
940
941/**
942 * @note Notes on locking objects of this class:
943 * SessionMachine shares some data with the primary Machine instance (pointed
944 * to by the |mPeer| member). In order to provide data consistency it also
945 * shares its lock handle. This means that whenever you lock a SessionMachine
946 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
947 * instance is also locked in the same lock mode. Keep it in mind.
948 */
949class ATL_NO_VTABLE SessionMachine :
950 public Machine,
951 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
952{
953public:
954 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
955
956 DECLARE_NOT_AGGREGATABLE(SessionMachine)
957
958 DECLARE_PROTECT_FINAL_CONSTRUCT()
959
960 BEGIN_COM_MAP(SessionMachine)
961 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
962 COM_INTERFACE_ENTRY(IInternalMachineControl)
963 END_COM_MAP()
964
965 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
966
967 HRESULT FinalConstruct();
968 void FinalRelease();
969
970 // public initializer/uninitializer for internal purposes only
971 HRESULT init(Machine *aMachine);
972 void uninit() { uninit(Uninit::Unexpected); }
973
974 // util::Lockable interface
975 RWLockHandle *lockHandle() const;
976
977 // IInternalMachineControl methods
978 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
979 STDMETHOD(UpdateState)(MachineState_T machineState);
980 STDMETHOD(GetIPCId)(BSTR *id);
981 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
982 STDMETHOD(EndPowerUp)(LONG iResult);
983 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
984 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
985 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
986 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
987 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
988 STDMETHOD(AutoCaptureUSBDevices)();
989 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
990 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
991 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
992 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
993 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
994 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
995 IN_BSTR aName,
996 IN_BSTR aDescription,
997 IProgress *aConsoleProgress,
998 BOOL fTakingSnapshotOnline,
999 BSTR *aStateFilePath);
1000 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
1001 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aStartId,
1002 IN_BSTR aEndID, BOOL fDeleteAllChildren,
1003 MachineState_T *aMachineState, IProgress **aProgress);
1004 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
1005 IMedium *aSource, IMedium *aTarget,
1006 BOOL fMergeForward,
1007 IMedium *pParentForTarget,
1008 ComSafeArrayIn(IMedium *, aChildrenToReparent));
1009 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1010 ISnapshot *aSnapshot,
1011 MachineState_T *aMachineState,
1012 IProgress **aProgress);
1013 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1014 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1015 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1016 LONG64 aTimestamp, IN_BSTR aFlags);
1017 STDMETHOD(LockMedia)() { return lockMedia(); }
1018 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
1019 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1020 IMediumAttachment **aNewAttachment);
1021
1022 // public methods only for internal purposes
1023
1024 virtual bool isSessionMachine() const
1025 {
1026 return true;
1027 }
1028
1029 bool checkForDeath();
1030
1031 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1032 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1033 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
1034 HRESULT onStorageControllerChange();
1035 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1036 HRESULT onSerialPortChange(ISerialPort *serialPort);
1037 HRESULT onParallelPortChange(IParallelPort *parallelPort);
1038 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
1039 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1040 HRESULT onVRDEServerChange(BOOL aRestart);
1041 HRESULT onUSBControllerChange();
1042 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
1043 IVirtualBoxErrorInfo *aError,
1044 ULONG aMaskedIfs);
1045 HRESULT onUSBDeviceDetach(IN_BSTR aId,
1046 IVirtualBoxErrorInfo *aError);
1047 HRESULT onSharedFolderChange();
1048 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1049 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove);
1050
1051 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1052
1053private:
1054
1055 struct ConsoleTaskData
1056 {
1057 ConsoleTaskData()
1058 : mLastState(MachineState_Null)
1059 { }
1060
1061 MachineState_T mLastState;
1062 ComObjPtr<Progress> mProgress;
1063
1064 // used when taking snapshot
1065 ComObjPtr<Snapshot> mSnapshot;
1066
1067 // used when saving state (either as part of a snapshot or separate)
1068 Utf8Str strStateFilePath;
1069 };
1070
1071 struct Uninit
1072 {
1073 enum Reason { Unexpected, Abnormal, Normal };
1074 };
1075
1076 struct SnapshotTask;
1077 struct DeleteSnapshotTask;
1078 struct RestoreSnapshotTask;
1079
1080 friend struct DeleteSnapshotTask;
1081 friend struct RestoreSnapshotTask;
1082
1083 void uninit(Uninit::Reason aReason);
1084
1085 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1086 void releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1087
1088 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1089 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1090
1091 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1092 const Guid &machineId,
1093 const Guid &snapshotId,
1094 bool fOnlineMergePossible,
1095 MediumLockList *aVMMALockList,
1096 ComObjPtr<Medium> &aSource,
1097 ComObjPtr<Medium> &aTarget,
1098 bool &fMergeForward,
1099 ComObjPtr<Medium> &pParentForTarget,
1100 MediaList &aChildrenToReparent,
1101 bool &fNeedOnlineMerge,
1102 MediumLockList * &aMediumLockList);
1103 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1104 const ComObjPtr<Medium> &aSource,
1105 const MediaList &aChildrenToReparent,
1106 bool fNeedsOnlineMerge,
1107 MediumLockList *aMediumLockList,
1108 const Guid &aMediumId,
1109 const Guid &aSnapshotId);
1110 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1111 const ComObjPtr<Medium> &aSource,
1112 const ComObjPtr<Medium> &aTarget,
1113 bool fMergeForward,
1114 const ComObjPtr<Medium> &pParentForTarget,
1115 const MediaList &aChildrenToReparent,
1116 MediumLockList *aMediumLockList,
1117 ComObjPtr<Progress> &aProgress,
1118 bool *pfNeedsMachineSaveSettings);
1119
1120 HRESULT lockMedia();
1121 void unlockMedia();
1122
1123 HRESULT setMachineState(MachineState_T aMachineState);
1124 HRESULT updateMachineStateOnClient();
1125
1126 HRESULT mRemoveSavedState;
1127
1128 ConsoleTaskData mConsoleTaskData;
1129
1130 /** interprocess semaphore handle for this machine */
1131#if defined(RT_OS_WINDOWS)
1132 HANDLE mIPCSem;
1133 Bstr mIPCSemName;
1134 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1135 ComPtr<IInternalSessionControl> *aControl,
1136 HANDLE *aIPCSem, bool aAllowClosing);
1137#elif defined(RT_OS_OS2)
1138 HMTX mIPCSem;
1139 Bstr mIPCSemName;
1140 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1141 ComPtr<IInternalSessionControl> *aControl,
1142 HMTX *aIPCSem, bool aAllowClosing);
1143#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1144 int mIPCSem;
1145# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1146 Bstr mIPCKey;
1147# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1148#else
1149# error "Port me!"
1150#endif
1151
1152 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1153};
1154
1155// SnapshotMachine class
1156////////////////////////////////////////////////////////////////////////////////
1157
1158/**
1159 * @note Notes on locking objects of this class:
1160 * SnapshotMachine shares some data with the primary Machine instance (pointed
1161 * to by the |mPeer| member). In order to provide data consistency it also
1162 * shares its lock handle. This means that whenever you lock a SessionMachine
1163 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1164 * instance is also locked in the same lock mode. Keep it in mind.
1165 */
1166class ATL_NO_VTABLE SnapshotMachine :
1167 public Machine
1168{
1169public:
1170 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1171
1172 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1173
1174 DECLARE_PROTECT_FINAL_CONSTRUCT()
1175
1176 BEGIN_COM_MAP(SnapshotMachine)
1177 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1178 END_COM_MAP()
1179
1180 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1181
1182 HRESULT FinalConstruct();
1183 void FinalRelease();
1184
1185 // public initializer/uninitializer for internal purposes only
1186 HRESULT init(SessionMachine *aSessionMachine,
1187 IN_GUID aSnapshotId,
1188 const Utf8Str &aStateFilePath);
1189 HRESULT init(Machine *aMachine,
1190 const settings::Hardware &hardware,
1191 const settings::Storage &storage,
1192 IN_GUID aSnapshotId,
1193 const Utf8Str &aStateFilePath);
1194 void uninit();
1195
1196 // util::Lockable interface
1197 RWLockHandle *lockHandle() const;
1198
1199 // public methods only for internal purposes
1200
1201 virtual bool isSnapshotMachine() const
1202 {
1203 return true;
1204 }
1205
1206 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1207
1208 // unsafe inline public methods for internal purposes only (ensure there is
1209 // a caller and a read lock before calling them!)
1210
1211 const Guid& getSnapshotId() const { return mSnapshotId; }
1212
1213private:
1214
1215 Guid mSnapshotId;
1216
1217 friend class Snapshot;
1218};
1219
1220// third party methods that depend on SnapshotMachine definition
1221
1222inline const Guid &Machine::getSnapshotId() const
1223{
1224 return (isSnapshotMachine())
1225 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1226 : Guid::Empty;
1227}
1228
1229
1230#endif // ____H_MACHINEIMPL
1231/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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