VirtualBox

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

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

enabled shared clipboard support for Linux hosts (guest=>host only)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 53.2 KB
Line 
1/* $Id: MachineImpl.h 42261 2012-07-20 13:27:47Z vboxsync $ */
2/** @file
3 * Implementation of IMachine in VBoxSVC - Header.
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_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 DragAndDropMode_T mDragAndDropMode;
285
286 typedef std::list<GuestProperty> GuestPropertyList;
287 GuestPropertyList mGuestProperties;
288 Utf8Str mGuestPropertyNotificationPatterns;
289
290 FirmwareType_T mFirmwareType;
291 KeyboardHidType_T mKeyboardHidType;
292 PointingHidType_T mPointingHidType;
293 ChipsetType_T mChipsetType;
294 BOOL mEmulatedUSBCardReaderEnabled;
295
296 BOOL mIoCacheEnabled;
297 ULONG mIoCacheSize;
298
299 typedef std::list<ComObjPtr<PciDeviceAttachment> > PciDeviceAssignmentList;
300 PciDeviceAssignmentList mPciDeviceAssignments;
301
302 settings::Debugging mDebugging;
303 settings::Autostart mAutostart;
304 };
305
306 /**
307 * Hard disk and other media data.
308 *
309 * The usage policy is the same as for HWData, but a separate structure
310 * is necessary because hard disk data requires different procedures when
311 * taking or deleting snapshots, etc.
312 *
313 * The data variable is |mMediaData|.
314 */
315 struct MediaData
316 {
317 MediaData();
318 ~MediaData();
319
320 typedef std::list<ComObjPtr<MediumAttachment> > AttachmentList;
321 AttachmentList mAttachments;
322 };
323
324 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Machine, IMachine)
325
326 DECLARE_NOT_AGGREGATABLE(Machine)
327
328 DECLARE_PROTECT_FINAL_CONSTRUCT()
329
330 BEGIN_COM_MAP(Machine)
331 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
332 END_COM_MAP()
333
334 DECLARE_EMPTY_CTOR_DTOR(Machine)
335
336 HRESULT FinalConstruct();
337 void FinalRelease();
338
339 // public initializer/uninitializer for internal purposes only:
340
341 // initializer for creating a new, empty machine
342 HRESULT init(VirtualBox *aParent,
343 const Utf8Str &strConfigFile,
344 const Utf8Str &strName,
345 const StringsList &llGroups,
346 GuestOSType *aOsType,
347 const Guid &aId,
348 bool fForceOverwrite);
349
350 // initializer for loading existing machine XML (either registered or not)
351 HRESULT init(VirtualBox *aParent,
352 const Utf8Str &strConfigFile,
353 const Guid *aId);
354
355 // initializer for machine config in memory (OVF import)
356 HRESULT init(VirtualBox *aParent,
357 const Utf8Str &strName,
358 const settings::MachineConfigFile &config);
359
360 void uninit();
361
362#ifdef VBOX_WITH_RESOURCE_USAGE_API
363 // Needed from VirtualBox, for the delayed metrics cleanup.
364 void unregisterMetrics(PerformanceCollector *aCollector, Machine *aMachine);
365#endif /* VBOX_WITH_RESOURCE_USAGE_API */
366
367protected:
368 HRESULT initImpl(VirtualBox *aParent,
369 const Utf8Str &strConfigFile);
370 HRESULT initDataAndChildObjects();
371 HRESULT registeredInit();
372 HRESULT tryCreateMachineConfigFile(bool fForceOverwrite);
373 void uninitDataAndChildObjects();
374
375public:
376 // IMachine properties
377 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
378 STDMETHOD(COMGETTER(Accessible))(BOOL *aAccessible);
379 STDMETHOD(COMGETTER(AccessError))(IVirtualBoxErrorInfo **aAccessError);
380 STDMETHOD(COMGETTER(Name))(BSTR *aName);
381 STDMETHOD(COMSETTER(Name))(IN_BSTR aName);
382 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
383 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
384 STDMETHOD(COMGETTER(Id))(BSTR *aId);
385 STDMETHOD(COMGETTER(Groups))(ComSafeArrayOut(BSTR, aGroups));
386 STDMETHOD(COMSETTER(Groups))(ComSafeArrayIn(IN_BSTR, aGroups));
387 STDMETHOD(COMGETTER(OSTypeId))(BSTR *aOSTypeId);
388 STDMETHOD(COMSETTER(OSTypeId))(IN_BSTR aOSTypeId);
389 STDMETHOD(COMGETTER(HardwareVersion))(BSTR *aVersion);
390 STDMETHOD(COMSETTER(HardwareVersion))(IN_BSTR aVersion);
391 STDMETHOD(COMGETTER(HardwareUUID))(BSTR *aUUID);
392 STDMETHOD(COMSETTER(HardwareUUID))(IN_BSTR aUUID);
393 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
394 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
395 STDMETHOD(COMGETTER(CPUCount))(ULONG *cpuCount);
396 STDMETHOD(COMSETTER(CPUCount))(ULONG cpuCount);
397 STDMETHOD(COMGETTER(CPUHotPlugEnabled))(BOOL *enabled);
398 STDMETHOD(COMSETTER(CPUHotPlugEnabled))(BOOL enabled);
399 STDMETHOD(COMGETTER(CPUExecutionCap))(ULONG *aExecutionCap);
400 STDMETHOD(COMSETTER(CPUExecutionCap))(ULONG aExecutionCap);
401 STDMETHOD(COMGETTER(EmulatedUSBCardReaderEnabled))(BOOL *enabled);
402 STDMETHOD(COMSETTER(EmulatedUSBCardReaderEnabled))(BOOL enabled);
403 STDMETHOD(COMGETTER(EmulatedUSBWebcameraEnabled))(BOOL *enabled);
404 STDMETHOD(COMSETTER(EmulatedUSBWebcameraEnabled))(BOOL enabled);
405 STDMETHOD(COMGETTER(HpetEnabled))(BOOL *enabled);
406 STDMETHOD(COMSETTER(HpetEnabled))(BOOL enabled);
407 STDMETHOD(COMGETTER(MemoryBalloonSize))(ULONG *memoryBalloonSize);
408 STDMETHOD(COMSETTER(MemoryBalloonSize))(ULONG memoryBalloonSize);
409 STDMETHOD(COMGETTER(PageFusionEnabled))(BOOL *enabled);
410 STDMETHOD(COMSETTER(PageFusionEnabled))(BOOL enabled);
411 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
412 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
413 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
414 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
415 STDMETHOD(COMGETTER(Accelerate3DEnabled))(BOOL *enabled);
416 STDMETHOD(COMSETTER(Accelerate3DEnabled))(BOOL enabled);
417 STDMETHOD(COMGETTER(Accelerate2DVideoEnabled))(BOOL *enabled);
418 STDMETHOD(COMSETTER(Accelerate2DVideoEnabled))(BOOL enabled);
419 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
420 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
421 STDMETHOD(COMSETTER(SnapshotFolder))(IN_BSTR aSavedStateFolder);
422 STDMETHOD(COMGETTER(MediumAttachments))(ComSafeArrayOut(IMediumAttachment *, aAttachments));
423 STDMETHOD(COMGETTER(VRDEServer))(IVRDEServer **vrdeServer);
424 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
425 STDMETHOD(COMGETTER(USBController))(IUSBController * *aUSBController);
426 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *aFilePath);
427 STDMETHOD(COMGETTER(SettingsModified))(BOOL *aModified);
428 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
429 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
430 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
431 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
432 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
433 STDMETHOD(COMGETTER(StateFilePath))(BSTR *aStateFilePath);
434 STDMETHOD(COMGETTER(LogFolder))(BSTR *aLogFolder);
435 STDMETHOD(COMGETTER(CurrentSnapshot))(ISnapshot **aCurrentSnapshot);
436 STDMETHOD(COMGETTER(SnapshotCount))(ULONG *aSnapshotCount);
437 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
438 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
439 STDMETHOD(COMGETTER(ClipboardMode))(ClipboardMode_T *aClipboardMode);
440 STDMETHOD(COMSETTER(ClipboardMode))(ClipboardMode_T aClipboardMode);
441 STDMETHOD(COMGETTER(DragAndDropMode))(DragAndDropMode_T *aDragAndDropMode);
442 STDMETHOD(COMSETTER(DragAndDropMode))(DragAndDropMode_T aDragAndDropMode);
443 STDMETHOD(COMGETTER(GuestPropertyNotificationPatterns))(BSTR *aPattern);
444 STDMETHOD(COMSETTER(GuestPropertyNotificationPatterns))(IN_BSTR aPattern);
445 STDMETHOD(COMGETTER(StorageControllers))(ComSafeArrayOut(IStorageController *, aStorageControllers));
446 STDMETHOD(COMGETTER(TeleporterEnabled))(BOOL *aEnabled);
447 STDMETHOD(COMSETTER(TeleporterEnabled))(BOOL aEnabled);
448 STDMETHOD(COMGETTER(TeleporterPort))(ULONG *aPort);
449 STDMETHOD(COMSETTER(TeleporterPort))(ULONG aPort);
450 STDMETHOD(COMGETTER(TeleporterAddress))(BSTR *aAddress);
451 STDMETHOD(COMSETTER(TeleporterAddress))(IN_BSTR aAddress);
452 STDMETHOD(COMGETTER(TeleporterPassword))(BSTR *aPassword);
453 STDMETHOD(COMSETTER(TeleporterPassword))(IN_BSTR aPassword);
454 STDMETHOD(COMGETTER(FaultToleranceState))(FaultToleranceState_T *aEnabled);
455 STDMETHOD(COMSETTER(FaultToleranceState))(FaultToleranceState_T aEnabled);
456 STDMETHOD(COMGETTER(FaultToleranceAddress))(BSTR *aAddress);
457 STDMETHOD(COMSETTER(FaultToleranceAddress))(IN_BSTR aAddress);
458 STDMETHOD(COMGETTER(FaultTolerancePort))(ULONG *aPort);
459 STDMETHOD(COMSETTER(FaultTolerancePort))(ULONG aPort);
460 STDMETHOD(COMGETTER(FaultTolerancePassword))(BSTR *aPassword);
461 STDMETHOD(COMSETTER(FaultTolerancePassword))(IN_BSTR aPassword);
462 STDMETHOD(COMGETTER(FaultToleranceSyncInterval))(ULONG *aInterval);
463 STDMETHOD(COMSETTER(FaultToleranceSyncInterval))(ULONG aInterval);
464 STDMETHOD(COMGETTER(RTCUseUTC))(BOOL *aEnabled);
465 STDMETHOD(COMSETTER(RTCUseUTC))(BOOL aEnabled);
466 STDMETHOD(COMGETTER(FirmwareType)) (FirmwareType_T *aFirmware);
467 STDMETHOD(COMSETTER(FirmwareType)) (FirmwareType_T aFirmware);
468 STDMETHOD(COMGETTER(KeyboardHidType)) (KeyboardHidType_T *aKeyboardHidType);
469 STDMETHOD(COMSETTER(KeyboardHidType)) (KeyboardHidType_T aKeyboardHidType);
470 STDMETHOD(COMGETTER(PointingHidType)) (PointingHidType_T *aPointingHidType);
471 STDMETHOD(COMSETTER(PointingHidType)) (PointingHidType_T aPointingHidType);
472 STDMETHOD(COMGETTER(ChipsetType)) (ChipsetType_T *aChipsetType);
473 STDMETHOD(COMSETTER(ChipsetType)) (ChipsetType_T aChipsetType);
474 STDMETHOD(COMGETTER(IoCacheEnabled)) (BOOL *aEnabled);
475 STDMETHOD(COMSETTER(IoCacheEnabled)) (BOOL aEnabled);
476 STDMETHOD(COMGETTER(IoCacheSize)) (ULONG *aIoCacheSize);
477 STDMETHOD(COMSETTER(IoCacheSize)) (ULONG aIoCacheSize);
478 STDMETHOD(COMGETTER(PciDeviceAssignments))(ComSafeArrayOut(IPciDeviceAttachment *, aAssignments));
479 STDMETHOD(COMGETTER(BandwidthControl))(IBandwidthControl **aBandwidthControl);
480 STDMETHOD(COMGETTER(TracingEnabled))(BOOL *pfEnabled);
481 STDMETHOD(COMSETTER(TracingEnabled))(BOOL fEnabled);
482 STDMETHOD(COMGETTER(TracingConfig))(BSTR *pbstrConfig);
483 STDMETHOD(COMSETTER(TracingConfig))(IN_BSTR bstrConfig);
484 STDMETHOD(COMGETTER(AllowTracingToAccessVM))(BOOL *pfAllow);
485 STDMETHOD(COMSETTER(AllowTracingToAccessVM))(BOOL fAllow);
486 STDMETHOD(COMGETTER(AutostartEnabled))(BOOL *pfEnabled);
487 STDMETHOD(COMSETTER(AutostartEnabled))(BOOL fEnabled);
488 STDMETHOD(COMGETTER(AutostartDelay))(ULONG *puDelay);
489 STDMETHOD(COMSETTER(AutostartDelay))(ULONG uDelay);
490 STDMETHOD(COMGETTER(AutostopType))(AutostopType_T *penmAutostopType);
491 STDMETHOD(COMSETTER(AutostopType))(AutostopType_T enmAutostopType);
492
493 // IMachine methods
494 STDMETHOD(LockMachine)(ISession *aSession, LockType_T lockType);
495 STDMETHOD(LaunchVMProcess)(ISession *aSession, IN_BSTR aType, IN_BSTR aEnvironment, IProgress **aProgress);
496
497 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
498 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
499 STDMETHOD(AttachDevice)(IN_BSTR aControllerName, LONG aControllerPort,
500 LONG aDevice, DeviceType_T aType, IMedium *aMedium);
501 STDMETHOD(DetachDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice);
502 STDMETHOD(PassthroughDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aPassthrough);
503 STDMETHOD(TemporaryEjectDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aTempEject);
504 STDMETHOD(NonRotationalDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aNonRotational);
505 STDMETHOD(SetAutoDiscardForDevice)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice, BOOL aDiscard);
506 STDMETHOD(SetBandwidthGroupForDevice)(IN_BSTR aControllerName, LONG aControllerPort,
507 LONG aDevice, IBandwidthGroup *aBandwidthGroup);
508 STDMETHOD(MountMedium)(IN_BSTR aControllerName, LONG aControllerPort,
509 LONG aDevice, IMedium *aMedium, BOOL aForce);
510 STDMETHOD(GetMedium)(IN_BSTR aControllerName, LONG aControllerPort, LONG aDevice,
511 IMedium **aMedium);
512 STDMETHOD(GetSerialPort)(ULONG slot, ISerialPort **port);
513 STDMETHOD(GetParallelPort)(ULONG slot, IParallelPort **port);
514 STDMETHOD(GetNetworkAdapter)(ULONG slot, INetworkAdapter **adapter);
515 STDMETHOD(GetExtraDataKeys)(ComSafeArrayOut(BSTR, aKeys));
516 STDMETHOD(GetExtraData)(IN_BSTR aKey, BSTR *aValue);
517 STDMETHOD(SetExtraData)(IN_BSTR aKey, IN_BSTR aValue);
518 STDMETHOD(GetCPUProperty)(CPUPropertyType_T property, BOOL *aVal);
519 STDMETHOD(SetCPUProperty)(CPUPropertyType_T property, BOOL aVal);
520 STDMETHOD(GetCPUIDLeaf)(ULONG id, ULONG *aValEax, ULONG *aValEbx, ULONG *aValEcx, ULONG *aValEdx);
521 STDMETHOD(SetCPUIDLeaf)(ULONG id, ULONG aValEax, ULONG aValEbx, ULONG aValEcx, ULONG aValEdx);
522 STDMETHOD(RemoveCPUIDLeaf)(ULONG id);
523 STDMETHOD(RemoveAllCPUIDLeaves)();
524 STDMETHOD(GetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL *aVal);
525 STDMETHOD(SetHWVirtExProperty)(HWVirtExPropertyType_T property, BOOL aVal);
526 STDMETHOD(SaveSettings)();
527 STDMETHOD(DiscardSettings)();
528 STDMETHOD(Unregister)(CleanupMode_T cleanupMode, ComSafeArrayOut(IMedium*, aMedia));
529 STDMETHOD(Delete)(ComSafeArrayIn(IMedium*, aMedia), IProgress **aProgress);
530 STDMETHOD(Export)(IAppliance *aAppliance, IN_BSTR location, IVirtualSystemDescription **aDescription);
531 STDMETHOD(FindSnapshot)(IN_BSTR aNameOrId, ISnapshot **aSnapshot);
532 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
533 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
534 STDMETHOD(CanShowConsoleWindow)(BOOL *aCanShow);
535 STDMETHOD(ShowConsoleWindow)(LONG64 *aWinId);
536 STDMETHOD(GetGuestProperty)(IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
537 STDMETHOD(GetGuestPropertyValue)(IN_BSTR aName, BSTR *aValue);
538 STDMETHOD(GetGuestPropertyTimestamp)(IN_BSTR aName, LONG64 *aTimestamp);
539 STDMETHOD(SetGuestProperty)(IN_BSTR aName, IN_BSTR aValue, IN_BSTR aFlags);
540 STDMETHOD(SetGuestPropertyValue)(IN_BSTR aName, IN_BSTR aValue);
541 STDMETHOD(DeleteGuestProperty)(IN_BSTR aName);
542 STDMETHOD(EnumerateGuestProperties)(IN_BSTR aPattern, ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues), ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
543 STDMETHOD(GetMediumAttachmentsOfController)(IN_BSTR aName, ComSafeArrayOut(IMediumAttachment *, aAttachments));
544 STDMETHOD(GetMediumAttachment)(IN_BSTR aConstrollerName, LONG aControllerPort, LONG aDevice, IMediumAttachment **aAttachment);
545 STDMETHOD(AddStorageController)(IN_BSTR aName, StorageBus_T aConnectionType, IStorageController **controller);
546 STDMETHOD(RemoveStorageController(IN_BSTR aName));
547 STDMETHOD(GetStorageControllerByName(IN_BSTR aName, IStorageController **storageController));
548 STDMETHOD(GetStorageControllerByInstance(ULONG aInstance, IStorageController **storageController));
549 STDMETHOD(SetStorageControllerBootable)(IN_BSTR aName, BOOL fBootable);
550 STDMETHOD(QuerySavedGuestScreenInfo)(ULONG uScreenId, ULONG *puOriginX, ULONG *puOriginY, ULONG *puWidth, ULONG *puHeight, BOOL *pfEnabled);
551 STDMETHOD(QuerySavedThumbnailSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
552 STDMETHOD(ReadSavedThumbnailToArray)(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
553 STDMETHOD(ReadSavedThumbnailPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
554 STDMETHOD(QuerySavedScreenshotPNGSize)(ULONG aScreenId, ULONG *aSize, ULONG *aWidth, ULONG *aHeight);
555 STDMETHOD(ReadSavedScreenshotPNGToArray)(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ComSafeArrayOut(BYTE, aData));
556 STDMETHOD(HotPlugCPU(ULONG aCpu));
557 STDMETHOD(HotUnplugCPU(ULONG aCpu));
558 STDMETHOD(GetCPUStatus(ULONG aCpu, BOOL *aCpuAttached));
559 STDMETHOD(QueryLogFilename(ULONG aIdx, BSTR *aName));
560 STDMETHOD(ReadLog(ULONG aIdx, LONG64 aOffset, LONG64 aSize, ComSafeArrayOut(BYTE, aData)));
561 STDMETHOD(AttachHostPciDevice(LONG hostAddress, LONG desiredGuestAddress, BOOL tryToUnbind));
562 STDMETHOD(DetachHostPciDevice(LONG hostAddress));
563 STDMETHOD(CloneTo(IMachine *pTarget, CloneMode_T mode, ComSafeArrayIn(CloneOptions_T, options), IProgress **pProgress));
564 // public methods only for internal purposes
565
566 virtual bool isSnapshotMachine() const
567 {
568 return false;
569 }
570
571 virtual bool isSessionMachine() const
572 {
573 return false;
574 }
575
576 /**
577 * Override of the default locking class to be used for validating lock
578 * order with the standard member lock handle.
579 */
580 virtual VBoxLockingClass getLockingClass() const
581 {
582 return LOCKCLASS_MACHINEOBJECT;
583 }
584
585 /// @todo (dmik) add lock and make non-inlined after revising classes
586 // that use it. Note: they should enter Machine lock to keep the returned
587 // information valid!
588 bool isRegistered() { return !!mData->mRegistered; }
589
590 // unsafe inline public methods for internal purposes only (ensure there is
591 // a caller and a read lock before calling them!)
592
593 /**
594 * Returns the VirtualBox object this machine belongs to.
595 *
596 * @note This method doesn't check this object's readiness. Intended to be
597 * used by ready Machine children (whose readiness is bound to the parent's
598 * one) or after doing addCaller() manually.
599 */
600 VirtualBox* getVirtualBox() const { return mParent; }
601
602 /**
603 * Checks if this machine is accessible, without attempting to load the
604 * config file.
605 *
606 * @note This method doesn't check this object's readiness. Intended to be
607 * used by ready Machine children (whose readiness is bound to the parent's
608 * one) or after doing addCaller() manually.
609 */
610 bool isAccessible() const { return !!mData->mAccessible; }
611
612 /**
613 * Returns this machine ID.
614 *
615 * @note This method doesn't check this object's readiness. Intended to be
616 * used by ready Machine children (whose readiness is bound to the parent's
617 * one) or after adding a caller manually.
618 */
619 const Guid& getId() const { return mData->mUuid; }
620
621 /**
622 * Returns the snapshot ID this machine represents or an empty UUID if this
623 * instance is not SnapshotMachine.
624 *
625 * @note This method doesn't check this object's readiness. Intended to be
626 * used by ready Machine children (whose readiness is bound to the parent's
627 * one) or after adding a caller manually.
628 */
629 inline const Guid& getSnapshotId() const;
630
631 /**
632 * Returns this machine's full settings file path.
633 *
634 * @note This method doesn't lock this object or check its readiness.
635 * Intended to be used only after doing addCaller() manually and locking it
636 * for reading.
637 */
638 const Utf8Str& getSettingsFileFull() const { return mData->m_strConfigFileFull; }
639
640 /**
641 * Returns this machine name.
642 *
643 * @note This method doesn't lock this object or check its readiness.
644 * Intended to be used only after doing addCaller() manually and locking it
645 * for reading.
646 */
647 const Utf8Str& getName() const { return mUserData->s.strName; }
648
649 enum
650 {
651 IsModified_MachineData = 0x0001,
652 IsModified_Storage = 0x0002,
653 IsModified_NetworkAdapters = 0x0008,
654 IsModified_SerialPorts = 0x0010,
655 IsModified_ParallelPorts = 0x0020,
656 IsModified_VRDEServer = 0x0040,
657 IsModified_AudioAdapter = 0x0080,
658 IsModified_USB = 0x0100,
659 IsModified_BIOS = 0x0200,
660 IsModified_SharedFolders = 0x0400,
661 IsModified_Snapshots = 0x0800,
662 IsModified_BandwidthControl = 0x1000
663 };
664
665 /**
666 * Checks if this machine is accessible, without attempting to load the
667 * config file.
668 *
669 * @note This method doesn't check this object's readiness. Intended to be
670 * used by ready Machine children (whose readiness is bound to the parent's
671 * one) or after doing addCaller() manually.
672 */
673 ChipsetType_T getChipsetType() const { return mHWData->mChipsetType; }
674
675 void setModified(uint32_t fl, bool fAllowStateModification = true);
676 void setModifiedLock(uint32_t fl, bool fAllowStateModification = true);
677
678 bool isStateModificationAllowed() const { return mData->m_fAllowStateModification; }
679 void allowStateModification() { mData->m_fAllowStateModification = true; }
680 void disallowStateModification() { mData->m_fAllowStateModification = false; }
681
682 // callback handlers
683 virtual HRESULT onNetworkAdapterChange(INetworkAdapter * /* networkAdapter */, BOOL /* changeAdapter */) { return S_OK; }
684 virtual HRESULT onNATRedirectRuleChange(ULONG /* slot */, BOOL /* fRemove */ , IN_BSTR /* name */,
685 NATProtocol_T /* protocol */, IN_BSTR /* host ip */, LONG /* host port */, IN_BSTR /* guest port */, LONG /* guest port */ ) { return S_OK; }
686 virtual HRESULT onSerialPortChange(ISerialPort * /* serialPort */) { return S_OK; }
687 virtual HRESULT onParallelPortChange(IParallelPort * /* parallelPort */) { return S_OK; }
688 virtual HRESULT onVRDEServerChange(BOOL /* aRestart */) { return S_OK; }
689 virtual HRESULT onUSBControllerChange() { return S_OK; }
690 virtual HRESULT onStorageControllerChange() { return S_OK; }
691 virtual HRESULT onCPUChange(ULONG /* aCPU */, BOOL /* aRemove */) { return S_OK; }
692 virtual HRESULT onCPUExecutionCapChange(ULONG /* aExecutionCap */) { return S_OK; }
693 virtual HRESULT onMediumChange(IMediumAttachment * /* mediumAttachment */, BOOL /* force */) { return S_OK; }
694 virtual HRESULT onSharedFolderChange() { return S_OK; }
695 virtual HRESULT onClipboardModeChange(ClipboardMode_T /* aClipboardMode */) { return S_OK; }
696 virtual HRESULT onDragAndDropModeChange(DragAndDropMode_T /* aDragAndDropMode */) { return S_OK; }
697 virtual HRESULT onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
698 virtual HRESULT onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */) { return S_OK; }
699
700 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
701
702 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
703 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
704
705 void getLogFolder(Utf8Str &aLogFolder);
706 Utf8Str queryLogFilename(ULONG idx);
707
708 void composeSavedStateFilename(Utf8Str &strStateFilePath);
709
710 HRESULT launchVMProcess(IInternalSessionControl *aControl,
711 const Utf8Str &strType,
712 const Utf8Str &strEnvironment,
713 ProgressProxy *aProgress);
714
715 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
716 {
717 HRESULT rc;
718 *directControl = mData->mSession.mDirectControl;
719
720 if (!*directControl)
721 rc = E_ACCESSDENIED;
722 else
723 rc = S_OK;
724
725 return rc;
726 }
727
728#if defined(RT_OS_WINDOWS)
729
730 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
731 ComPtr<IInternalSessionControl> *aControl = NULL,
732 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
733 bool isSessionSpawning(RTPROCESS *aPID = NULL);
734
735 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
736 ComPtr<IInternalSessionControl> *aControl = NULL,
737 HANDLE *aIPCSem = NULL)
738 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
739
740#elif defined(RT_OS_OS2)
741
742 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
743 ComPtr<IInternalSessionControl> *aControl = NULL,
744 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
745
746 bool isSessionSpawning(RTPROCESS *aPID = NULL);
747
748 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
749 ComPtr<IInternalSessionControl> *aControl = NULL,
750 HMTX *aIPCSem = NULL)
751 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
752
753#else
754
755 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
756 ComPtr<IInternalSessionControl> *aControl = NULL,
757 bool aAllowClosing = false);
758 bool isSessionSpawning();
759
760 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
761 ComPtr<IInternalSessionControl> *aControl = NULL)
762 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
763
764#endif
765
766 bool checkForSpawnFailure();
767
768 HRESULT prepareRegister();
769
770 HRESULT getSharedFolder(CBSTR aName,
771 ComObjPtr<SharedFolder> &aSharedFolder,
772 bool aSetError = false)
773 {
774 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
775 return findSharedFolder(aName, aSharedFolder, aSetError);
776 }
777
778 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
779 MachineState_T *aState = NULL,
780 BOOL *aRegistered = NULL);
781 void releaseStateDependency();
782
783 HRESULT getBandwidthGroup(const Utf8Str &strBandwidthGroup,
784 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
785 bool fSetError = false)
786 {
787 return mBandwidthControl->getBandwidthGroupByName(strBandwidthGroup,
788 pBandwidthGroup,
789 fSetError);
790 }
791
792protected:
793
794 HRESULT checkStateDependency(StateDependency aDepType);
795
796 Machine *getMachine();
797
798 void ensureNoStateDependencies();
799
800 virtual HRESULT setMachineState(MachineState_T aMachineState);
801
802 HRESULT findSharedFolder(const Utf8Str &aName,
803 ComObjPtr<SharedFolder> &aSharedFolder,
804 bool aSetError = false);
805
806 HRESULT loadSettings(bool aRegistered);
807 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
808 const Guid *puuidRegistry);
809 HRESULT loadSnapshot(const settings::Snapshot &data,
810 const Guid &aCurSnapshotId,
811 Snapshot *aParentSnapshot);
812 HRESULT loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
813 const settings::Autostart *pAutostart);
814 HRESULT loadDebugging(const settings::Debugging *pDbg);
815 HRESULT loadAutostart(const settings::Autostart *pAutostart);
816 HRESULT loadStorageControllers(const settings::Storage &data,
817 const Guid *puuidRegistry,
818 const Guid *puuidSnapshot);
819 HRESULT loadStorageDevices(StorageController *aStorageController,
820 const settings::StorageController &data,
821 const Guid *puuidRegistry,
822 const Guid *puuidSnapshot);
823
824 HRESULT findSnapshotById(const Guid &aId,
825 ComObjPtr<Snapshot> &aSnapshot,
826 bool aSetError = false);
827 HRESULT findSnapshotByName(const Utf8Str &strName,
828 ComObjPtr<Snapshot> &aSnapshot,
829 bool aSetError = false);
830
831 HRESULT getStorageControllerByName(const Utf8Str &aName,
832 ComObjPtr<StorageController> &aStorageController,
833 bool aSetError = false);
834
835 HRESULT getMediumAttachmentsOfController(CBSTR aName,
836 MediaData::AttachmentList &aAttachments);
837
838 enum
839 {
840 /* flags for #saveSettings() */
841 SaveS_ResetCurStateModified = 0x01,
842 SaveS_InformCallbacksAnyway = 0x02,
843 SaveS_Force = 0x04,
844 /* flags for #saveStateSettings() */
845 SaveSTS_CurStateModified = 0x20,
846 SaveSTS_StateFilePath = 0x40,
847 SaveSTS_StateTimeStamp = 0x80
848 };
849
850 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
851 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
852
853 void copyMachineDataToSettings(settings::MachineConfigFile &config);
854 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
855 HRESULT saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
856 settings::Autostart *pAutostart);
857 HRESULT saveStorageControllers(settings::Storage &data);
858 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
859 settings::StorageController &data);
860 HRESULT saveStateSettings(int aFlags);
861
862 void addMediumToRegistry(ComObjPtr<Medium> &pMedium);
863
864 HRESULT createImplicitDiffs(IProgress *aProgress,
865 ULONG aWeight,
866 bool aOnline);
867 HRESULT deleteImplicitDiffs();
868
869 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
870 IN_BSTR aControllerName,
871 LONG aControllerPort,
872 LONG aDevice);
873 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
874 ComObjPtr<Medium> pMedium);
875 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
876 Guid &id);
877
878 HRESULT detachDevice(MediumAttachment *pAttach,
879 AutoWriteLock &writeLock,
880 Snapshot *pSnapshot);
881
882 HRESULT detachAllMedia(AutoWriteLock &writeLock,
883 Snapshot *pSnapshot,
884 CleanupMode_T cleanupMode,
885 MediaList &llMedia);
886
887 void commitMedia(bool aOnline = false);
888 void rollbackMedia();
889
890 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
891
892 void rollback(bool aNotify);
893 void commit();
894 void copyFrom(Machine *aThat);
895 bool isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
896
897 struct DeleteTask;
898 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
899 HRESULT deleteTaskWorker(DeleteTask &task);
900
901#ifdef VBOX_WITH_GUEST_PROPS
902 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
903 LONG64 *aTimestamp, BSTR *aFlags) const;
904 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
905 LONG64 *aTimestamp, BSTR *aFlags) const;
906 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
907 IN_BSTR aFlags);
908 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
909 IN_BSTR aFlags);
910 HRESULT enumerateGuestPropertiesInService
911 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
912 ComSafeArrayOut(BSTR, aValues),
913 ComSafeArrayOut(LONG64, aTimestamps),
914 ComSafeArrayOut(BSTR, aFlags));
915 HRESULT enumerateGuestPropertiesOnVM
916 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
917 ComSafeArrayOut(BSTR, aValues),
918 ComSafeArrayOut(LONG64, aTimestamps),
919 ComSafeArrayOut(BSTR, aFlags));
920#endif /* VBOX_WITH_GUEST_PROPS */
921
922#ifdef VBOX_WITH_RESOURCE_USAGE_API
923 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
924
925 pm::CollectorGuest *mCollectorGuest;
926#endif /* VBOX_WITH_RESOURCE_USAGE_API */
927
928 Machine* const mPeer;
929
930 VirtualBox * const mParent;
931
932 Shareable<Data> mData;
933 Shareable<SSData> mSSData;
934
935 Backupable<UserData> mUserData;
936 Backupable<HWData> mHWData;
937 Backupable<MediaData> mMediaData;
938
939 // the following fields need special backup/rollback/commit handling,
940 // so they cannot be a part of HWData
941
942 const ComObjPtr<VRDEServer> mVRDEServer;
943 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
944 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
945 const ComObjPtr<AudioAdapter> mAudioAdapter;
946 const ComObjPtr<USBController> mUSBController;
947 const ComObjPtr<BIOSSettings> mBIOSSettings;
948 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
949 NetworkAdapterVector mNetworkAdapters;
950 const ComObjPtr<BandwidthControl> mBandwidthControl;
951
952 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
953 Backupable<StorageControllerList> mStorageControllers;
954
955 uint64_t uRegistryNeedsSaving;
956
957 friend class SessionMachine;
958 friend class SnapshotMachine;
959 friend class Appliance;
960 friend class VirtualBox;
961
962 friend class MachineCloneVM;
963};
964
965// SessionMachine class
966////////////////////////////////////////////////////////////////////////////////
967
968/**
969 * @note Notes on locking objects of this class:
970 * SessionMachine shares some data with the primary Machine instance (pointed
971 * to by the |mPeer| member). In order to provide data consistency it also
972 * shares its lock handle. This means that whenever you lock a SessionMachine
973 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
974 * instance is also locked in the same lock mode. Keep it in mind.
975 */
976class ATL_NO_VTABLE SessionMachine :
977 public Machine,
978 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
979{
980public:
981 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
982
983 DECLARE_NOT_AGGREGATABLE(SessionMachine)
984
985 DECLARE_PROTECT_FINAL_CONSTRUCT()
986
987 BEGIN_COM_MAP(SessionMachine)
988 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
989 COM_INTERFACE_ENTRY(IInternalMachineControl)
990 END_COM_MAP()
991
992 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
993
994 HRESULT FinalConstruct();
995 void FinalRelease();
996
997 // public initializer/uninitializer for internal purposes only
998 HRESULT init(Machine *aMachine);
999 void uninit() { uninit(Uninit::Unexpected); }
1000
1001 // util::Lockable interface
1002 RWLockHandle *lockHandle() const;
1003
1004 // IInternalMachineControl methods
1005 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
1006 STDMETHOD(UpdateState)(MachineState_T machineState);
1007 STDMETHOD(GetIPCId)(BSTR *id);
1008 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
1009 STDMETHOD(EndPowerUp)(LONG iResult);
1010 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
1011 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
1012 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
1013 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
1014 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
1015 STDMETHOD(AutoCaptureUSBDevices)();
1016 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
1017 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
1018 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
1019 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
1020 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
1021 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
1022 IN_BSTR aName,
1023 IN_BSTR aDescription,
1024 IProgress *aConsoleProgress,
1025 BOOL fTakingSnapshotOnline,
1026 BSTR *aStateFilePath);
1027 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
1028 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aStartId,
1029 IN_BSTR aEndID, BOOL fDeleteAllChildren,
1030 MachineState_T *aMachineState, IProgress **aProgress);
1031 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
1032 IMedium *aSource, IMedium *aTarget,
1033 BOOL fMergeForward,
1034 IMedium *pParentForTarget,
1035 ComSafeArrayIn(IMedium *, aChildrenToReparent));
1036 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1037 ISnapshot *aSnapshot,
1038 MachineState_T *aMachineState,
1039 IProgress **aProgress);
1040 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1041 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1042 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1043 LONG64 aTimestamp, IN_BSTR aFlags);
1044 STDMETHOD(LockMedia)() { return lockMedia(); }
1045 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
1046 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1047 IMediumAttachment **aNewAttachment);
1048 STDMETHOD(ReportGuestStatistics)(ULONG aValidStats, ULONG aCpuUser,
1049 ULONG aCpuKernel, ULONG aCpuIdle,
1050 ULONG aMemTotal, ULONG aMemFree,
1051 ULONG aMemBalloon, ULONG aMemShared,
1052 ULONG aMemCache, ULONG aPageTotal,
1053 ULONG aAllocVMM, ULONG aFreeVMM,
1054 ULONG aBalloonedVMM, ULONG aSharedVMM);
1055
1056 // public methods only for internal purposes
1057
1058 virtual bool isSessionMachine() const
1059 {
1060 return true;
1061 }
1062
1063 bool checkForDeath();
1064
1065 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1066 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1067 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
1068 HRESULT onStorageControllerChange();
1069 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1070 HRESULT onSerialPortChange(ISerialPort *serialPort);
1071 HRESULT onParallelPortChange(IParallelPort *parallelPort);
1072 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
1073 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1074 HRESULT onVRDEServerChange(BOOL aRestart);
1075 HRESULT onUSBControllerChange();
1076 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
1077 IVirtualBoxErrorInfo *aError,
1078 ULONG aMaskedIfs);
1079 HRESULT onUSBDeviceDetach(IN_BSTR aId,
1080 IVirtualBoxErrorInfo *aError);
1081 HRESULT onSharedFolderChange();
1082 HRESULT onClipboardModeChange(ClipboardMode_T aClipboardMode);
1083 HRESULT onDragAndDropModeChange(DragAndDropMode_T aDragAndDropMode);
1084 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1085 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove);
1086
1087 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1088
1089private:
1090
1091 struct ConsoleTaskData
1092 {
1093 ConsoleTaskData()
1094 : mLastState(MachineState_Null)
1095 { }
1096
1097 MachineState_T mLastState;
1098 ComObjPtr<Progress> mProgress;
1099
1100 // used when taking snapshot
1101 ComObjPtr<Snapshot> mSnapshot;
1102
1103 // used when saving state (either as part of a snapshot or separate)
1104 Utf8Str strStateFilePath;
1105 };
1106
1107 struct Uninit
1108 {
1109 enum Reason { Unexpected, Abnormal, Normal };
1110 };
1111
1112 struct SnapshotTask;
1113 struct DeleteSnapshotTask;
1114 struct RestoreSnapshotTask;
1115
1116 friend struct DeleteSnapshotTask;
1117 friend struct RestoreSnapshotTask;
1118
1119 void uninit(Uninit::Reason aReason);
1120
1121 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1122 void releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1123
1124 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1125 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1126
1127 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1128 const Guid &machineId,
1129 const Guid &snapshotId,
1130 bool fOnlineMergePossible,
1131 MediumLockList *aVMMALockList,
1132 ComObjPtr<Medium> &aSource,
1133 ComObjPtr<Medium> &aTarget,
1134 bool &fMergeForward,
1135 ComObjPtr<Medium> &pParentForTarget,
1136 MediaList &aChildrenToReparent,
1137 bool &fNeedOnlineMerge,
1138 MediumLockList * &aMediumLockList);
1139 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1140 const ComObjPtr<Medium> &aSource,
1141 const MediaList &aChildrenToReparent,
1142 bool fNeedsOnlineMerge,
1143 MediumLockList *aMediumLockList,
1144 const Guid &aMediumId,
1145 const Guid &aSnapshotId);
1146 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1147 const ComObjPtr<Medium> &aSource,
1148 const ComObjPtr<Medium> &aTarget,
1149 bool fMergeForward,
1150 const ComObjPtr<Medium> &pParentForTarget,
1151 const MediaList &aChildrenToReparent,
1152 MediumLockList *aMediumLockList,
1153 ComObjPtr<Progress> &aProgress,
1154 bool *pfNeedsMachineSaveSettings);
1155
1156 HRESULT lockMedia();
1157 void unlockMedia();
1158
1159 HRESULT setMachineState(MachineState_T aMachineState);
1160 HRESULT updateMachineStateOnClient();
1161
1162 HRESULT mRemoveSavedState;
1163
1164 ConsoleTaskData mConsoleTaskData;
1165
1166 /** interprocess semaphore handle for this machine */
1167#if defined(RT_OS_WINDOWS)
1168 HANDLE mIPCSem;
1169 Bstr mIPCSemName;
1170 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1171 ComPtr<IInternalSessionControl> *aControl,
1172 HANDLE *aIPCSem, bool aAllowClosing);
1173#elif defined(RT_OS_OS2)
1174 HMTX mIPCSem;
1175 Bstr mIPCSemName;
1176 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1177 ComPtr<IInternalSessionControl> *aControl,
1178 HMTX *aIPCSem, bool aAllowClosing);
1179#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1180 int mIPCSem;
1181# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1182 Bstr mIPCKey;
1183# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1184#else
1185# error "Port me!"
1186#endif
1187
1188 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1189};
1190
1191// SnapshotMachine class
1192////////////////////////////////////////////////////////////////////////////////
1193
1194/**
1195 * @note Notes on locking objects of this class:
1196 * SnapshotMachine shares some data with the primary Machine instance (pointed
1197 * to by the |mPeer| member). In order to provide data consistency it also
1198 * shares its lock handle. This means that whenever you lock a SessionMachine
1199 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1200 * instance is also locked in the same lock mode. Keep it in mind.
1201 */
1202class ATL_NO_VTABLE SnapshotMachine :
1203 public Machine
1204{
1205public:
1206 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1207
1208 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1209
1210 DECLARE_PROTECT_FINAL_CONSTRUCT()
1211
1212 BEGIN_COM_MAP(SnapshotMachine)
1213 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1214 END_COM_MAP()
1215
1216 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1217
1218 HRESULT FinalConstruct();
1219 void FinalRelease();
1220
1221 // public initializer/uninitializer for internal purposes only
1222 HRESULT init(SessionMachine *aSessionMachine,
1223 IN_GUID aSnapshotId,
1224 const Utf8Str &aStateFilePath);
1225 HRESULT initFromSettings(Machine *aMachine,
1226 const settings::Hardware &hardware,
1227 const settings::Debugging *pDbg,
1228 const settings::Autostart *pAutostart,
1229 const settings::Storage &storage,
1230 IN_GUID aSnapshotId,
1231 const Utf8Str &aStateFilePath);
1232 void uninit();
1233
1234 // util::Lockable interface
1235 RWLockHandle *lockHandle() const;
1236
1237 // public methods only for internal purposes
1238
1239 virtual bool isSnapshotMachine() const
1240 {
1241 return true;
1242 }
1243
1244 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1245
1246 // unsafe inline public methods for internal purposes only (ensure there is
1247 // a caller and a read lock before calling them!)
1248
1249 const Guid& getSnapshotId() const { return mSnapshotId; }
1250
1251private:
1252
1253 Guid mSnapshotId;
1254
1255 friend class Snapshot;
1256};
1257
1258// third party methods that depend on SnapshotMachine definition
1259
1260inline const Guid &Machine::getSnapshotId() const
1261{
1262 return (isSnapshotMachine())
1263 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1264 : Guid::Empty;
1265}
1266
1267
1268#endif // ____H_MACHINEIMPL
1269/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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