VirtualBox

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

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

Main: Implement API to configure autostart/-stop for virtual machines

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.5 KB
Line 
1/* $Id: MachineImpl.h 41914 2012-06-26 09:17:43Z 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 onBandwidthGroupChange(IBandwidthGroup * /* aBandwidthGroup */) { return S_OK; }
690 virtual HRESULT onStorageDeviceChange(IMediumAttachment * /* mediumAttachment */, BOOL /* remove */) { return S_OK; }
691
692 HRESULT saveRegistryEntry(settings::MachineRegistryEntry &data);
693
694 int calculateFullPath(const Utf8Str &strPath, Utf8Str &aResult);
695 void copyPathRelativeToMachine(const Utf8Str &strSource, Utf8Str &strTarget);
696
697 void getLogFolder(Utf8Str &aLogFolder);
698 Utf8Str queryLogFilename(ULONG idx);
699
700 void composeSavedStateFilename(Utf8Str &strStateFilePath);
701
702 HRESULT launchVMProcess(IInternalSessionControl *aControl,
703 const Utf8Str &strType,
704 const Utf8Str &strEnvironment,
705 ProgressProxy *aProgress);
706
707 HRESULT getDirectControl(ComPtr<IInternalSessionControl> *directControl)
708 {
709 HRESULT rc;
710 *directControl = mData->mSession.mDirectControl;
711
712 if (!*directControl)
713 rc = E_ACCESSDENIED;
714 else
715 rc = S_OK;
716
717 return rc;
718 }
719
720#if defined(RT_OS_WINDOWS)
721
722 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
723 ComPtr<IInternalSessionControl> *aControl = NULL,
724 HANDLE *aIPCSem = NULL, bool aAllowClosing = false);
725 bool isSessionSpawning(RTPROCESS *aPID = NULL);
726
727 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
728 ComPtr<IInternalSessionControl> *aControl = NULL,
729 HANDLE *aIPCSem = NULL)
730 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
731
732#elif defined(RT_OS_OS2)
733
734 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
735 ComPtr<IInternalSessionControl> *aControl = NULL,
736 HMTX *aIPCSem = NULL, bool aAllowClosing = false);
737
738 bool isSessionSpawning(RTPROCESS *aPID = NULL);
739
740 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
741 ComPtr<IInternalSessionControl> *aControl = NULL,
742 HMTX *aIPCSem = NULL)
743 { return isSessionOpen(aMachine, aControl, aIPCSem, true /* aAllowClosing */); }
744
745#else
746
747 bool isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
748 ComPtr<IInternalSessionControl> *aControl = NULL,
749 bool aAllowClosing = false);
750 bool isSessionSpawning();
751
752 bool isSessionOpenOrClosing(ComObjPtr<SessionMachine> &aMachine,
753 ComPtr<IInternalSessionControl> *aControl = NULL)
754 { return isSessionOpen(aMachine, aControl, true /* aAllowClosing */); }
755
756#endif
757
758 bool checkForSpawnFailure();
759
760 HRESULT prepareRegister();
761
762 HRESULT getSharedFolder(CBSTR aName,
763 ComObjPtr<SharedFolder> &aSharedFolder,
764 bool aSetError = false)
765 {
766 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
767 return findSharedFolder(aName, aSharedFolder, aSetError);
768 }
769
770 HRESULT addStateDependency(StateDependency aDepType = AnyStateDep,
771 MachineState_T *aState = NULL,
772 BOOL *aRegistered = NULL);
773 void releaseStateDependency();
774
775 HRESULT getBandwidthGroup(const Utf8Str &strBandwidthGroup,
776 ComObjPtr<BandwidthGroup> &pBandwidthGroup,
777 bool fSetError = false)
778 {
779 return mBandwidthControl->getBandwidthGroupByName(strBandwidthGroup,
780 pBandwidthGroup,
781 fSetError);
782 }
783
784protected:
785
786 HRESULT checkStateDependency(StateDependency aDepType);
787
788 Machine *getMachine();
789
790 void ensureNoStateDependencies();
791
792 virtual HRESULT setMachineState(MachineState_T aMachineState);
793
794 HRESULT findSharedFolder(const Utf8Str &aName,
795 ComObjPtr<SharedFolder> &aSharedFolder,
796 bool aSetError = false);
797
798 HRESULT loadSettings(bool aRegistered);
799 HRESULT loadMachineDataFromSettings(const settings::MachineConfigFile &config,
800 const Guid *puuidRegistry);
801 HRESULT loadSnapshot(const settings::Snapshot &data,
802 const Guid &aCurSnapshotId,
803 Snapshot *aParentSnapshot);
804 HRESULT loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
805 const settings::Autostart *pAutostart);
806 HRESULT loadDebugging(const settings::Debugging *pDbg);
807 HRESULT loadAutostart(const settings::Autostart *pAutostart);
808 HRESULT loadStorageControllers(const settings::Storage &data,
809 const Guid *puuidRegistry,
810 const Guid *puuidSnapshot);
811 HRESULT loadStorageDevices(StorageController *aStorageController,
812 const settings::StorageController &data,
813 const Guid *puuidRegistry,
814 const Guid *puuidSnapshot);
815
816 HRESULT findSnapshotById(const Guid &aId,
817 ComObjPtr<Snapshot> &aSnapshot,
818 bool aSetError = false);
819 HRESULT findSnapshotByName(const Utf8Str &strName,
820 ComObjPtr<Snapshot> &aSnapshot,
821 bool aSetError = false);
822
823 HRESULT getStorageControllerByName(const Utf8Str &aName,
824 ComObjPtr<StorageController> &aStorageController,
825 bool aSetError = false);
826
827 HRESULT getMediumAttachmentsOfController(CBSTR aName,
828 MediaData::AttachmentList &aAttachments);
829
830 enum
831 {
832 /* flags for #saveSettings() */
833 SaveS_ResetCurStateModified = 0x01,
834 SaveS_InformCallbacksAnyway = 0x02,
835 SaveS_Force = 0x04,
836 /* flags for #saveStateSettings() */
837 SaveSTS_CurStateModified = 0x20,
838 SaveSTS_StateFilePath = 0x40,
839 SaveSTS_StateTimeStamp = 0x80
840 };
841
842 HRESULT prepareSaveSettings(bool *pfNeedsGlobalSaveSettings);
843 HRESULT saveSettings(bool *pfNeedsGlobalSaveSettings, int aFlags = 0);
844
845 void copyMachineDataToSettings(settings::MachineConfigFile &config);
846 HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
847 HRESULT saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
848 settings::Autostart *pAutostart);
849 HRESULT saveStorageControllers(settings::Storage &data);
850 HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
851 settings::StorageController &data);
852 HRESULT saveStateSettings(int aFlags);
853
854 void addMediumToRegistry(ComObjPtr<Medium> &pMedium);
855
856 HRESULT createImplicitDiffs(IProgress *aProgress,
857 ULONG aWeight,
858 bool aOnline);
859 HRESULT deleteImplicitDiffs();
860
861 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
862 IN_BSTR aControllerName,
863 LONG aControllerPort,
864 LONG aDevice);
865 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
866 ComObjPtr<Medium> pMedium);
867 MediumAttachment* findAttachment(const MediaData::AttachmentList &ll,
868 Guid &id);
869
870 HRESULT detachDevice(MediumAttachment *pAttach,
871 AutoWriteLock &writeLock,
872 Snapshot *pSnapshot);
873
874 HRESULT detachAllMedia(AutoWriteLock &writeLock,
875 Snapshot *pSnapshot,
876 CleanupMode_T cleanupMode,
877 MediaList &llMedia);
878
879 void commitMedia(bool aOnline = false);
880 void rollbackMedia();
881
882 bool isInOwnDir(Utf8Str *aSettingsDir = NULL) const;
883
884 void rollback(bool aNotify);
885 void commit();
886 void copyFrom(Machine *aThat);
887 bool isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
888
889 struct DeleteTask;
890 static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
891 HRESULT deleteTaskWorker(DeleteTask &task);
892
893#ifdef VBOX_WITH_GUEST_PROPS
894 HRESULT getGuestPropertyFromService(IN_BSTR aName, BSTR *aValue,
895 LONG64 *aTimestamp, BSTR *aFlags) const;
896 HRESULT getGuestPropertyFromVM(IN_BSTR aName, BSTR *aValue,
897 LONG64 *aTimestamp, BSTR *aFlags) const;
898 HRESULT setGuestPropertyToService(IN_BSTR aName, IN_BSTR aValue,
899 IN_BSTR aFlags);
900 HRESULT setGuestPropertyToVM(IN_BSTR aName, IN_BSTR aValue,
901 IN_BSTR aFlags);
902 HRESULT enumerateGuestPropertiesInService
903 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
904 ComSafeArrayOut(BSTR, aValues),
905 ComSafeArrayOut(LONG64, aTimestamps),
906 ComSafeArrayOut(BSTR, aFlags));
907 HRESULT enumerateGuestPropertiesOnVM
908 (IN_BSTR aPatterns, ComSafeArrayOut(BSTR, aNames),
909 ComSafeArrayOut(BSTR, aValues),
910 ComSafeArrayOut(LONG64, aTimestamps),
911 ComSafeArrayOut(BSTR, aFlags));
912#endif /* VBOX_WITH_GUEST_PROPS */
913
914#ifdef VBOX_WITH_RESOURCE_USAGE_API
915 void registerMetrics(PerformanceCollector *aCollector, Machine *aMachine, RTPROCESS pid);
916
917 pm::CollectorGuest *mCollectorGuest;
918#endif /* VBOX_WITH_RESOURCE_USAGE_API */
919
920 Machine* const mPeer;
921
922 VirtualBox * const mParent;
923
924 Shareable<Data> mData;
925 Shareable<SSData> mSSData;
926
927 Backupable<UserData> mUserData;
928 Backupable<HWData> mHWData;
929 Backupable<MediaData> mMediaData;
930
931 // the following fields need special backup/rollback/commit handling,
932 // so they cannot be a part of HWData
933
934 const ComObjPtr<VRDEServer> mVRDEServer;
935 const ComObjPtr<SerialPort> mSerialPorts[SchemaDefs::SerialPortCount];
936 const ComObjPtr<ParallelPort> mParallelPorts[SchemaDefs::ParallelPortCount];
937 const ComObjPtr<AudioAdapter> mAudioAdapter;
938 const ComObjPtr<USBController> mUSBController;
939 const ComObjPtr<BIOSSettings> mBIOSSettings;
940 typedef std::vector<ComObjPtr<NetworkAdapter> > NetworkAdapterVector;
941 NetworkAdapterVector mNetworkAdapters;
942 const ComObjPtr<BandwidthControl> mBandwidthControl;
943
944 typedef std::list<ComObjPtr<StorageController> > StorageControllerList;
945 Backupable<StorageControllerList> mStorageControllers;
946
947 uint64_t uRegistryNeedsSaving;
948
949 friend class SessionMachine;
950 friend class SnapshotMachine;
951 friend class Appliance;
952 friend class VirtualBox;
953
954 friend class MachineCloneVM;
955};
956
957// SessionMachine class
958////////////////////////////////////////////////////////////////////////////////
959
960/**
961 * @note Notes on locking objects of this class:
962 * SessionMachine shares some data with the primary Machine instance (pointed
963 * to by the |mPeer| member). In order to provide data consistency it also
964 * shares its lock handle. This means that whenever you lock a SessionMachine
965 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
966 * instance is also locked in the same lock mode. Keep it in mind.
967 */
968class ATL_NO_VTABLE SessionMachine :
969 public Machine,
970 VBOX_SCRIPTABLE_IMPL(IInternalMachineControl)
971{
972public:
973 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SessionMachine, IMachine)
974
975 DECLARE_NOT_AGGREGATABLE(SessionMachine)
976
977 DECLARE_PROTECT_FINAL_CONSTRUCT()
978
979 BEGIN_COM_MAP(SessionMachine)
980 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
981 COM_INTERFACE_ENTRY(IInternalMachineControl)
982 END_COM_MAP()
983
984 DECLARE_EMPTY_CTOR_DTOR(SessionMachine)
985
986 HRESULT FinalConstruct();
987 void FinalRelease();
988
989 // public initializer/uninitializer for internal purposes only
990 HRESULT init(Machine *aMachine);
991 void uninit() { uninit(Uninit::Unexpected); }
992
993 // util::Lockable interface
994 RWLockHandle *lockHandle() const;
995
996 // IInternalMachineControl methods
997 STDMETHOD(SetRemoveSavedStateFile)(BOOL aRemove);
998 STDMETHOD(UpdateState)(MachineState_T machineState);
999 STDMETHOD(GetIPCId)(BSTR *id);
1000 STDMETHOD(BeginPowerUp)(IProgress *aProgress);
1001 STDMETHOD(EndPowerUp)(LONG iResult);
1002 STDMETHOD(BeginPoweringDown)(IProgress **aProgress);
1003 STDMETHOD(EndPoweringDown)(LONG aResult, IN_BSTR aErrMsg);
1004 STDMETHOD(RunUSBDeviceFilters)(IUSBDevice *aUSBDevice, BOOL *aMatched, ULONG *aMaskedIfs);
1005 STDMETHOD(CaptureUSBDevice)(IN_BSTR aId);
1006 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, BOOL aDone);
1007 STDMETHOD(AutoCaptureUSBDevices)();
1008 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
1009 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
1010 STDMETHOD(BeginSavingState)(IProgress **aProgress, BSTR *aStateFilePath);
1011 STDMETHOD(EndSavingState)(LONG aResult, IN_BSTR aErrMsg);
1012 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
1013 STDMETHOD(BeginTakingSnapshot)(IConsole *aInitiator,
1014 IN_BSTR aName,
1015 IN_BSTR aDescription,
1016 IProgress *aConsoleProgress,
1017 BOOL fTakingSnapshotOnline,
1018 BSTR *aStateFilePath);
1019 STDMETHOD(EndTakingSnapshot)(BOOL aSuccess);
1020 STDMETHOD(DeleteSnapshot)(IConsole *aInitiator, IN_BSTR aStartId,
1021 IN_BSTR aEndID, BOOL fDeleteAllChildren,
1022 MachineState_T *aMachineState, IProgress **aProgress);
1023 STDMETHOD(FinishOnlineMergeMedium)(IMediumAttachment *aMediumAttachment,
1024 IMedium *aSource, IMedium *aTarget,
1025 BOOL fMergeForward,
1026 IMedium *pParentForTarget,
1027 ComSafeArrayIn(IMedium *, aChildrenToReparent));
1028 STDMETHOD(RestoreSnapshot)(IConsole *aInitiator,
1029 ISnapshot *aSnapshot,
1030 MachineState_T *aMachineState,
1031 IProgress **aProgress);
1032 STDMETHOD(PullGuestProperties)(ComSafeArrayOut(BSTR, aNames), ComSafeArrayOut(BSTR, aValues),
1033 ComSafeArrayOut(LONG64, aTimestamps), ComSafeArrayOut(BSTR, aFlags));
1034 STDMETHOD(PushGuestProperty)(IN_BSTR aName, IN_BSTR aValue,
1035 LONG64 aTimestamp, IN_BSTR aFlags);
1036 STDMETHOD(LockMedia)() { return lockMedia(); }
1037 STDMETHOD(UnlockMedia)() { unlockMedia(); return S_OK; }
1038 STDMETHOD(EjectMedium)(IMediumAttachment *aAttachment,
1039 IMediumAttachment **aNewAttachment);
1040 STDMETHOD(ReportGuestStatistics)(ULONG aValidStats, ULONG aCpuUser,
1041 ULONG aCpuKernel, ULONG aCpuIdle,
1042 ULONG aMemTotal, ULONG aMemFree,
1043 ULONG aMemBalloon, ULONG aMemShared,
1044 ULONG aMemCache, ULONG aPageTotal,
1045 ULONG aAllocVMM, ULONG aFreeVMM,
1046 ULONG aBalloonedVMM, ULONG aSharedVMM);
1047
1048 // public methods only for internal purposes
1049
1050 virtual bool isSessionMachine() const
1051 {
1052 return true;
1053 }
1054
1055 bool checkForDeath();
1056
1057 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter, BOOL changeAdapter);
1058 HRESULT onNATRedirectRuleChange(ULONG ulSlot, BOOL aNatRuleRemove, IN_BSTR aRuleName,
1059 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
1060 HRESULT onStorageControllerChange();
1061 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
1062 HRESULT onSerialPortChange(ISerialPort *serialPort);
1063 HRESULT onParallelPortChange(IParallelPort *parallelPort);
1064 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
1065 HRESULT onCPUExecutionCapChange(ULONG aCpuExecutionCap);
1066 HRESULT onVRDEServerChange(BOOL aRestart);
1067 HRESULT onUSBControllerChange();
1068 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice,
1069 IVirtualBoxErrorInfo *aError,
1070 ULONG aMaskedIfs);
1071 HRESULT onUSBDeviceDetach(IN_BSTR aId,
1072 IVirtualBoxErrorInfo *aError);
1073 HRESULT onSharedFolderChange();
1074 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
1075 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove);
1076
1077 bool hasMatchingUSBFilter(const ComObjPtr<HostUSBDevice> &aDevice, ULONG *aMaskedIfs);
1078
1079private:
1080
1081 struct ConsoleTaskData
1082 {
1083 ConsoleTaskData()
1084 : mLastState(MachineState_Null)
1085 { }
1086
1087 MachineState_T mLastState;
1088 ComObjPtr<Progress> mProgress;
1089
1090 // used when taking snapshot
1091 ComObjPtr<Snapshot> mSnapshot;
1092
1093 // used when saving state (either as part of a snapshot or separate)
1094 Utf8Str strStateFilePath;
1095 };
1096
1097 struct Uninit
1098 {
1099 enum Reason { Unexpected, Abnormal, Normal };
1100 };
1101
1102 struct SnapshotTask;
1103 struct DeleteSnapshotTask;
1104 struct RestoreSnapshotTask;
1105
1106 friend struct DeleteSnapshotTask;
1107 friend struct RestoreSnapshotTask;
1108
1109 void uninit(Uninit::Reason aReason);
1110
1111 HRESULT endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
1112 void releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
1113
1114 void deleteSnapshotHandler(DeleteSnapshotTask &aTask);
1115 void restoreSnapshotHandler(RestoreSnapshotTask &aTask);
1116
1117 HRESULT prepareDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1118 const Guid &machineId,
1119 const Guid &snapshotId,
1120 bool fOnlineMergePossible,
1121 MediumLockList *aVMMALockList,
1122 ComObjPtr<Medium> &aSource,
1123 ComObjPtr<Medium> &aTarget,
1124 bool &fMergeForward,
1125 ComObjPtr<Medium> &pParentForTarget,
1126 MediaList &aChildrenToReparent,
1127 bool &fNeedOnlineMerge,
1128 MediumLockList * &aMediumLockList);
1129 void cancelDeleteSnapshotMedium(const ComObjPtr<Medium> &aHD,
1130 const ComObjPtr<Medium> &aSource,
1131 const MediaList &aChildrenToReparent,
1132 bool fNeedsOnlineMerge,
1133 MediumLockList *aMediumLockList,
1134 const Guid &aMediumId,
1135 const Guid &aSnapshotId);
1136 HRESULT onlineMergeMedium(const ComObjPtr<MediumAttachment> &aMediumAttachment,
1137 const ComObjPtr<Medium> &aSource,
1138 const ComObjPtr<Medium> &aTarget,
1139 bool fMergeForward,
1140 const ComObjPtr<Medium> &pParentForTarget,
1141 const MediaList &aChildrenToReparent,
1142 MediumLockList *aMediumLockList,
1143 ComObjPtr<Progress> &aProgress,
1144 bool *pfNeedsMachineSaveSettings);
1145
1146 HRESULT lockMedia();
1147 void unlockMedia();
1148
1149 HRESULT setMachineState(MachineState_T aMachineState);
1150 HRESULT updateMachineStateOnClient();
1151
1152 HRESULT mRemoveSavedState;
1153
1154 ConsoleTaskData mConsoleTaskData;
1155
1156 /** interprocess semaphore handle for this machine */
1157#if defined(RT_OS_WINDOWS)
1158 HANDLE mIPCSem;
1159 Bstr mIPCSemName;
1160 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1161 ComPtr<IInternalSessionControl> *aControl,
1162 HANDLE *aIPCSem, bool aAllowClosing);
1163#elif defined(RT_OS_OS2)
1164 HMTX mIPCSem;
1165 Bstr mIPCSemName;
1166 friend bool Machine::isSessionOpen(ComObjPtr<SessionMachine> &aMachine,
1167 ComPtr<IInternalSessionControl> *aControl,
1168 HMTX *aIPCSem, bool aAllowClosing);
1169#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
1170 int mIPCSem;
1171# ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
1172 Bstr mIPCKey;
1173# endif /*VBOX_WITH_NEW_SYS_V_KEYGEN */
1174#else
1175# error "Port me!"
1176#endif
1177
1178 static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
1179};
1180
1181// SnapshotMachine class
1182////////////////////////////////////////////////////////////////////////////////
1183
1184/**
1185 * @note Notes on locking objects of this class:
1186 * SnapshotMachine shares some data with the primary Machine instance (pointed
1187 * to by the |mPeer| member). In order to provide data consistency it also
1188 * shares its lock handle. This means that whenever you lock a SessionMachine
1189 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
1190 * instance is also locked in the same lock mode. Keep it in mind.
1191 */
1192class ATL_NO_VTABLE SnapshotMachine :
1193 public Machine
1194{
1195public:
1196 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(SnapshotMachine, IMachine)
1197
1198 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
1199
1200 DECLARE_PROTECT_FINAL_CONSTRUCT()
1201
1202 BEGIN_COM_MAP(SnapshotMachine)
1203 VBOX_DEFAULT_INTERFACE_ENTRIES(IMachine)
1204 END_COM_MAP()
1205
1206 DECLARE_EMPTY_CTOR_DTOR(SnapshotMachine)
1207
1208 HRESULT FinalConstruct();
1209 void FinalRelease();
1210
1211 // public initializer/uninitializer for internal purposes only
1212 HRESULT init(SessionMachine *aSessionMachine,
1213 IN_GUID aSnapshotId,
1214 const Utf8Str &aStateFilePath);
1215 HRESULT initFromSettings(Machine *aMachine,
1216 const settings::Hardware &hardware,
1217 const settings::Debugging *pDbg,
1218 const settings::Autostart *pAutostart,
1219 const settings::Storage &storage,
1220 IN_GUID aSnapshotId,
1221 const Utf8Str &aStateFilePath);
1222 void uninit();
1223
1224 // util::Lockable interface
1225 RWLockHandle *lockHandle() const;
1226
1227 // public methods only for internal purposes
1228
1229 virtual bool isSnapshotMachine() const
1230 {
1231 return true;
1232 }
1233
1234 HRESULT onSnapshotChange(Snapshot *aSnapshot);
1235
1236 // unsafe inline public methods for internal purposes only (ensure there is
1237 // a caller and a read lock before calling them!)
1238
1239 const Guid& getSnapshotId() const { return mSnapshotId; }
1240
1241private:
1242
1243 Guid mSnapshotId;
1244
1245 friend class Snapshot;
1246};
1247
1248// third party methods that depend on SnapshotMachine definition
1249
1250inline const Guid &Machine::getSnapshotId() const
1251{
1252 return (isSnapshotMachine())
1253 ? static_cast<const SnapshotMachine*>(this)->getSnapshotId()
1254 : Guid::Empty;
1255}
1256
1257
1258#endif // ____H_MACHINEIMPL
1259/* 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