VirtualBox

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

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

allow to change the clipboard mode during runtime (API change including 'VBoxManage controlvm' change)

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