VirtualBox

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

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

Main/VirtualBox+Machine: add support for VM groups (incomplete, saving of settings is not implemented), remaining code adjusted accordingly, use better parameter checking macros, make XSLT generators process setter attributes using safearrays correctly, various cleanups and warning fixes
Frontends/VBoxManage: first traces of groups support

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