VirtualBox

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

Last change on this file since 1634 was 1077, checked in by vboxsync, 18 years ago

Main: Added new IMachine attributes: description, sessionType and sessionPid.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.0 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class declaration
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_MACHINEIMPL
23#define ____H_MACHINEIMPL
24
25#include "VirtualBoxBase.h"
26#include "VirtualBoxXMLUtil.h"
27#include "ProgressImpl.h"
28#include "SnapshotImpl.h"
29#include "VRDPServerImpl.h"
30#include "DVDDriveImpl.h"
31#include "FloppyDriveImpl.h"
32#include "HardDiskAttachmentImpl.h"
33#include "Collection.h"
34#include "NetworkAdapterImpl.h"
35#include "AudioAdapterImpl.h"
36#include "BIOSSettingsImpl.h"
37
38// generated header
39#include "SchemaDefs.h"
40
41#include <VBox/types.h>
42#include <VBox/cfgldr.h>
43#include <iprt/file.h>
44#include <iprt/thread.h>
45
46#include <list>
47
48// defines
49////////////////////////////////////////////////////////////////////////////////
50
51/**
52 * Checks whether the given Machine object is mutable (allows for calling setters)
53 * or not. When the machine is not mutable, sets error info and returns E_ACCESSDENIED.
54 * The translatable error message is defined in null context.
55 *
56 * This macro <b>must</b> be used within setters of all Machine children
57 * (DVDDrive, NetworkAdapter, AudioAdapter, etc.).
58 *
59 * @param machine the machine object (must cast to Machine *)
60 */
61#define CHECK_MACHINE_MUTABILITY(machine) \
62 do { \
63 if (!machine->isMutable()) \
64 return setError (E_ACCESSDENIED, tr ("The machine is not mutable")); \
65 } while (0)
66/** like CHECK_MACHINE_MUTABILITY but a saved state is ok, too */
67#define CHECK_MACHINE_MUTABILITY_IGNORING_SAVED(machine) \
68 do { \
69 if (!machine->isMutableIgnoringSavedState()) \
70 return setError (E_ACCESSDENIED, tr ("The machine is not mutable or in saved state")); \
71 } while (0)
72
73
74// helper declarations
75////////////////////////////////////////////////////////////////////////////////
76
77class VirtualBox;
78class Progress;
79class CombinedProgress;
80class Keyboard;
81class Mouse;
82class Display;
83class MachineDebugger;
84class USBController;
85class Snapshot;
86class SharedFolder;
87
88class SessionMachine;
89
90// Machine class
91////////////////////////////////////////////////////////////////////////////////
92
93class ATL_NO_VTABLE Machine :
94 public VirtualBoxBaseWithChildrenNEXT,
95 public VirtualBoxXMLUtil,
96 public VirtualBoxSupportErrorInfoImpl <Machine, IMachine>,
97 public VirtualBoxSupportTranslation <Machine>,
98 public IMachine
99{
100 Q_OBJECT
101
102public:
103
104 /**
105 * Internal machine data.
106 *
107 * Only one instance of this data exists per every machine --
108 * it is shared by the Machine, SessionMachine and all SnapshotMachine
109 * instances associated with the given machine using the util::Shareable
110 * template through the mData variable.
111 *
112 * @note |const| members are persistent during lifetime so can be
113 * accessed without locking.
114 *
115 * @note There is no need to lock anything inside init() or uninit()
116 * methods, because they are always serialized (see AutoCaller).
117 */
118 struct Data
119 {
120 /**
121 * Data structure to hold information about sessions opened for the
122 * given machine.
123 */
124 struct Session
125 {
126 /** Control of the direct session opened by openSession() */
127 ComPtr <IInternalSessionControl> mDirectControl;
128
129 typedef std::list <ComPtr <IInternalSessionControl> > RemoteControlList;
130
131 /** list of controls of all opened remote sessions */
132 RemoteControlList mRemoteControls;
133
134 /** openRemoteSession() and OnSessionEnd() progress indicator */
135 ComObjPtr <Progress> mProgress;
136
137 /**
138 * PID of the session object that must be passed to openSession()
139 * to finalize the openRemoteSession() request
140 * (i.e., PID of the process created by openRemoteSession())
141 */
142 RTPROCESS mPid;
143
144 /** Current session state */
145 SessionState_T mState;
146
147 /** Session type string (for indirect sessions) */
148 Bstr mType;
149
150 /** Sesison machine object */
151 ComObjPtr <SessionMachine> mMachine;
152 };
153
154 Data();
155 ~Data();
156
157 const Guid mUuid;
158 BOOL mRegistered;
159
160 Bstr mConfigFile;
161 Bstr mConfigFileFull;
162
163 BOOL mAccessible;
164 com::ErrorInfo mAccessError;
165
166 MachineState_T mMachineState;
167 LONG64 mLastStateChange;
168
169 BOOL mCurrentStateModified;
170
171 RTFILE mHandleCfgFile;
172
173 Session mSession;
174
175 ComObjPtr <Snapshot> mFirstSnapshot;
176 ComObjPtr <Snapshot> mCurrentSnapshot;
177 };
178
179 /**
180 * Saved state data.
181 *
182 * It's actually only the state file path string, but it needs to be
183 * separate from Data, because Machine and SessionMachine instances
184 * share it, while SnapshotMachine does not.
185 *
186 * The data variable is |mSSData|.
187 */
188 struct SSData
189 {
190 Bstr mStateFilePath;
191 };
192
193 /**
194 * User changeable machine data.
195 *
196 * This data is common for all machine snapshots, i.e. it is shared
197 * by all SnapshotMachine instances associated with the given machine
198 * using the util::Backupable template through the |mUserData| variable.
199 *
200 * SessionMachine instances can alter this data and discard changes.
201 *
202 * @note There is no need to lock anything inside init() or uninit()
203 * methods, because they are always serialized (see AutoCaller).
204 */
205 struct UserData
206 {
207 UserData();
208 ~UserData();
209
210 bool operator== (const UserData &that) const
211 {
212 return this == &that ||
213 (mName == that.mName &&
214 mNameSync == that.mNameSync &&
215 mDescription == that.mDescription &&
216 mOSType.equalsTo (that.mOSType) &&
217 mSnapshotFolderFull == that.mSnapshotFolderFull);
218 }
219
220 Bstr mName;
221 BOOL mNameSync;
222 Bstr mDescription;
223 ComPtr <IGuestOSType> mOSType;
224 Bstr mSnapshotFolder;
225 Bstr mSnapshotFolderFull;
226 };
227
228 /**
229 * Hardware data.
230 *
231 * This data is unique for a machine and for every machine snapshot.
232 * Stored using the util::Backupable template in the |mHWData| variable.
233 *
234 * SessionMachine instances can alter this data and discard changes.
235 */
236 struct HWData
237 {
238 HWData();
239 ~HWData();
240
241 bool operator== (const HWData &that) const;
242
243 ULONG mMemorySize;
244 ULONG mVRAMSize;
245 TriStateBool_T mHWVirtExEnabled;
246
247 DeviceType_T mBootOrder [SchemaDefs::MaxBootPosition];
248
249 typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
250 SharedFolderList mSharedFolders;
251 ClipboardMode_T mClipboardMode;
252 };
253
254 /**
255 * Hard disk data.
256 *
257 * The usage policy is the same as for HWData, but a separate structure
258 * is necessarym because hard disk data requires different procedures when
259 * taking or discarding snapshots, etc.
260 *
261 * The data variable is |mHWData|.
262 */
263 struct HDData
264 {
265 HDData();
266 ~HDData();
267
268 bool operator== (const HDData &that) const;
269
270 typedef std::list <ComObjPtr <HardDiskAttachment> > HDAttachmentList;
271 HDAttachmentList mHDAttachments;
272
273 /**
274 * Right after Machine::fixupHardDisks(true): |true| if hard disks
275 * were actually changed, |false| otherwise
276 */
277 bool mHDAttachmentsChanged;
278 };
279
280 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Machine)
281
282 DECLARE_NOT_AGGREGATABLE(Machine)
283
284 DECLARE_PROTECT_FINAL_CONSTRUCT()
285
286 BEGIN_COM_MAP(Machine)
287 COM_INTERFACE_ENTRY(ISupportErrorInfo)
288 COM_INTERFACE_ENTRY(IMachine)
289 END_COM_MAP()
290
291 NS_DECL_ISUPPORTS
292
293 DECLARE_EMPTY_CTOR_DTOR (Machine)
294
295 HRESULT FinalConstruct();
296 void FinalRelease();
297
298 enum InitMode { Init_New, Init_Existing, Init_Registered };
299
300 // public initializer/uninitializer for internal purposes only
301 HRESULT init (VirtualBox *aParent, const BSTR aConfigFile,
302 InitMode aMode, const BSTR aName = NULL,
303 BOOL aNameSync = TRUE, const Guid *aId = NULL);
304 void uninit();
305
306 // IMachine properties
307 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
308 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
309 STDMETHOD(COMGETTER(AccessError)) (IVirtualBoxErrorInfo **aAccessError);
310 STDMETHOD(COMGETTER(Name))(BSTR *aName);
311 STDMETHOD(COMSETTER(Name))(INPTR BSTR aName);
312 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
313 STDMETHOD(COMSETTER(Description))(INPTR BSTR aDescription);
314 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
315 STDMETHOD(COMGETTER(OSType)) (IGuestOSType **aOSType);
316 STDMETHOD(COMSETTER(OSType)) (IGuestOSType *aOSType);
317 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
318 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
319 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
320 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
321 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
322 STDMETHOD(COMGETTER(HWVirtExEnabled))(TriStateBool_T *enabled);
323 STDMETHOD(COMSETTER(HWVirtExEnabled))(TriStateBool_T enabled);
324 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
325 STDMETHOD(COMSETTER(SnapshotFolder))(INPTR BSTR aSavedStateFolder);
326 STDMETHOD(COMGETTER(HardDiskAttachments))(IHardDiskAttachmentCollection **attachments);
327 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
328 STDMETHOD(COMGETTER(DVDDrive))(IDVDDrive **dvdDrive);
329 STDMETHOD(COMGETTER(FloppyDrive))(IFloppyDrive **floppyDrive);
330 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
331 STDMETHOD(COMGETTER(USBController))(IUSBController * *a_ppUSBController);
332 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *filePath);
333 STDMETHOD(COMGETTER(SettingsModified))(BOOL *modified);
334 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
335 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
336 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
337 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
338 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
339 STDMETHOD(COMGETTER(StateFilePath)) (BSTR *aStateFilePath);
340 STDMETHOD(COMGETTER(CurrentSnapshot)) (ISnapshot **aCurrentSnapshot);
341 STDMETHOD(COMGETTER(SnapshotCount)) (ULONG *aSnapshotCount);
342 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
343 STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
344 STDMETHOD(COMGETTER(ClipboardMode)) (ClipboardMode_T *aClipboardMode);
345 STDMETHOD(COMSETTER(ClipboardMode)) (ClipboardMode_T aClipboardMode);
346
347 // IMachine methods
348 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
349 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
350 STDMETHOD(AttachHardDisk)(INPTR GUIDPARAM aId, DiskControllerType_T aCtl, LONG aDev);
351 STDMETHOD(GetHardDisk)(DiskControllerType_T aCtl, LONG aDev, IHardDisk **aHardDisk);
352 STDMETHOD(DetachHardDisk) (DiskControllerType_T aCtl, LONG aDev);
353 STDMETHOD(GetNetworkAdapter) (ULONG slot, INetworkAdapter **adapter);
354 STDMETHOD(GetNextExtraDataKey)(INPTR BSTR key, BSTR *nextKey, BSTR *nextValue);
355 STDMETHOD(GetExtraData)(INPTR BSTR key, BSTR *value);
356 STDMETHOD(SetExtraData)(INPTR BSTR key, INPTR BSTR value);
357 STDMETHOD(SaveSettings)();
358 STDMETHOD(DiscardSettings)();
359 STDMETHOD(DeleteSettings)();
360 STDMETHOD(GetSnapshot) (INPTR GUIDPARAM aId, ISnapshot **aSnapshot);
361 STDMETHOD(FindSnapshot) (INPTR BSTR aName, ISnapshot **aSnapshot);
362 STDMETHOD(SetCurrentSnapshot) (INPTR GUIDPARAM aId);
363 STDMETHOD(CreateSharedFolder)(INPTR BSTR aName, INPTR BSTR aHostPath);
364 STDMETHOD(RemoveSharedFolder)(INPTR BSTR aName);
365
366 // public methods only for internal purposes
367
368 /// @todo (dmik) add lock and make non-inlined after revising classes
369 // that use it (actually, the CHECK_MACHINE_MUTABILITY macro).
370 // Note: these classes should enter Machine lock to keep the returned
371 // information valid!
372 bool isMutable()
373 {
374 return ((!mData->mRegistered) ||
375 (mType == IsSessionMachine &&
376 mData->mMachineState <= MachineState_Paused &&
377 mData->mMachineState != MachineState_Saved));
378 }
379
380 /// @todo (dmik) add lock and make non-inlined after revising classes
381 // that use it (actually, the CHECK_MACHINE_MUTABILITY_IGNORING_SAVED macro).
382 // Note: these classes should enter Machine lock to keep the returned
383 // information valid!
384 bool isMutableIgnoringSavedState()
385 {
386 return ((!mData->mRegistered) ||
387 (mType == IsSessionMachine &&
388 mData->mMachineState <= MachineState_Paused));
389 }
390
391 /// @todo (dmik) add lock and make non-inlined after revising classes
392 // that use it. Note: they should enter Machine lock to keep the returned
393 // information valid!
394 bool isRegistered() { return !!mData->mRegistered; }
395
396 ComObjPtr <SessionMachine> sessionMachine();
397
398 // Note: the below methods are intended to be called only after adding
399 // a caller to the Machine instance and, when necessary, from under
400 // the Machine lock in appropriate mode
401
402 /// @todo (dmik) revise code using these methods: improving incapsulation
403 // should make them not necessary
404
405 const ComObjPtr <VirtualBox, ComWeakRef> &virtualBox() { return mParent; }
406
407 const Shareable <Data> &data() const { return mData; }
408 const Backupable <UserData> &userData() const { return mUserData; }
409 const Backupable <HDData> &hdData() const { return mHDData; }
410
411 const Shareable <SSData> &ssData() const { return mSSData; }
412
413 const ComObjPtr <DVDDrive> &dvdDrive() { return mDVDDrive; }
414 const ComObjPtr <FloppyDrive> &floppyDrive() { return mFloppyDrive; }
415 const ComObjPtr <USBController> &usbController() { return mUSBController; }
416
417 virtual HRESULT onDVDDriveChange() { return S_OK; }
418 virtual HRESULT onFloppyDriveChange() { return S_OK; }
419 virtual HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter) { return S_OK; }
420 virtual HRESULT onVRDPServerChange() { return S_OK; }
421 virtual HRESULT onUSBControllerChange() { return S_OK; }
422
423 int calculateFullPath (const char *aPath, Utf8Str &aResult);
424 void calculateRelativePath (const char *aPath, Utf8Str &aResult);
425
426 void getLogFolder (Utf8Str &aLogFolder);
427
428 HRESULT openSession (IInternalSessionControl *aControl);
429 HRESULT openRemoteSession (IInternalSessionControl *aControl,
430 INPTR BSTR aType, Progress *aProgress);
431 HRESULT openExistingSession (IInternalSessionControl *aControl);
432
433 HRESULT trySetRegistered (BOOL aRegistered);
434
435 HRESULT getSharedFolder (const BSTR aName,
436 ComObjPtr <SharedFolder> &aSharedFolder,
437 bool aSetError = false)
438 {
439 AutoLock alock (this);
440 return findSharedFolder (aName, aSharedFolder, aSetError);
441 }
442
443 // for VirtualBoxSupportErrorInfoImpl
444 static const wchar_t *getComponentName() { return L"Machine"; }
445
446protected:
447
448 enum InstanceType { IsMachine, IsSessionMachine, IsSnapshotMachine };
449
450 HRESULT registeredInit();
451
452 inline Machine *machine();
453
454 void uninitDataAndChildObjects();
455
456 virtual HRESULT setMachineState (MachineState_T aMachineState);
457
458 HRESULT findSharedFolder (const BSTR aName,
459 ComObjPtr <SharedFolder> &aSharedFolder,
460 bool aSetError = false);
461
462 HRESULT loadSettings (bool aRegistered);
463 HRESULT loadSnapshot (CFGNODE aNode, const Guid &aCurSnapshotId,
464 Snapshot *aParentSnapshot);
465 HRESULT loadHardware (CFGNODE aNode);
466 HRESULT loadHardDisks (CFGNODE aNode, bool aRegistered,
467 const Guid *aSnapshotId = NULL);
468
469 HRESULT openConfigLoader (CFGHANDLE *aLoader, bool aIsNew = false);
470 HRESULT closeConfigLoader (CFGHANDLE aLoader, bool aSaveBeforeClose);
471
472 HRESULT findSnapshotNode (Snapshot *aSnapshot, CFGNODE aMachineNode,
473 CFGNODE *aSnapshotsNode, CFGNODE *aSnapshotNode);
474
475 HRESULT findSnapshot (const Guid &aId, ComObjPtr <Snapshot> &aSnapshot,
476 bool aSetError = false);
477 HRESULT findSnapshot (const BSTR aName, ComObjPtr <Snapshot> &aSnapshot,
478 bool aSetError = false);
479
480 HRESULT findHardDiskAttachment (const ComObjPtr <HardDisk> &aHd,
481 ComObjPtr <Machine> *aMachine,
482 ComObjPtr <Snapshot> *aSnapshot,
483 ComObjPtr <HardDiskAttachment> *aHda);
484
485 HRESULT prepareSaveSettings (bool &aRenamed, bool &aNew);
486 HRESULT saveSettings (bool aMarkCurStateAsModified = true,
487 bool aInformCallbacksAnyway = false);
488
489 enum
490 {
491 // ops for #saveSnapshotSettings()
492 SaveSS_NoOp = 0x00, SaveSS_AddOp = 0x01,
493 SaveSS_UpdateAttrsOp = 0x02, SaveSS_UpdateAllOp = 0x03,
494 SaveSS_OpMask = 0xF,
495 // flags for #saveSnapshotSettings()
496 SaveSS_UpdateCurStateModified = 0x40,
497 SaveSS_UpdateCurrentId = 0x80,
498 // flags for #saveStateSettings()
499 SaveSTS_CurStateModified = 0x20,
500 SaveSTS_StateFilePath = 0x40,
501 SaveSTS_StateTimeStamp = 0x80,
502 };
503
504 HRESULT saveSnapshotSettings (Snapshot *aSnapshot, int aOpFlags);
505 HRESULT saveSnapshotSettingsWorker (CFGNODE aMachineNode,
506 Snapshot *aSnapshot, int aOpFlags);
507
508 HRESULT saveSnapshot (CFGNODE aNode, Snapshot *aSnapshot, bool aAttrsOnly);
509 HRESULT saveHardware (CFGNODE aNode);
510 HRESULT saveHardDisks (CFGNODE aNode);
511
512 HRESULT saveStateSettings (int aFlags);
513
514 HRESULT wipeOutImmutableDiffs();
515
516 HRESULT fixupHardDisks (bool aCommit);
517
518 HRESULT createSnapshotDiffs (const Guid *aSnapshotId,
519 const Bstr &aFolder,
520 const ComObjPtr <Progress> &aProgress,
521 bool aOnline);
522 HRESULT deleteSnapshotDiffs (const ComObjPtr <Snapshot> &aSnapshot);
523
524 HRESULT lockConfig();
525 HRESULT unlockConfig();
526
527 /** @note This method is not thread safe */
528 BOOL isConfigLocked()
529 {
530 return !!mData && mData->mHandleCfgFile != NIL_RTFILE;
531 }
532
533 bool isInOwnDir (Utf8Str *aSettingsDir = NULL);
534
535 bool isModified();
536 bool isReallyModified (bool aIgnoreUserData = false);
537 void rollback (bool aNotify);
538 HRESULT commit();
539 void copyFrom (Machine *aThat);
540
541 const InstanceType mType;
542
543 const ComObjPtr <Machine, ComWeakRef> mPeer;
544
545 const ComObjPtr <VirtualBox, ComWeakRef> mParent;
546
547 Shareable <Data> mData;
548 Shareable <SSData> mSSData;
549
550 Backupable <UserData> mUserData;
551 Backupable <HWData> mHWData;
552 Backupable <HDData> mHDData;
553
554 // the following fields need special backup/rollback/commit handling,
555 // so they cannot be a part of HWData
556
557 const ComObjPtr <VRDPServer> mVRDPServer;
558 const ComObjPtr <DVDDrive> mDVDDrive;
559 const ComObjPtr <FloppyDrive> mFloppyDrive;
560 const ComObjPtr <AudioAdapter> mAudioAdapter;
561 const ComObjPtr <USBController> mUSBController;
562 const ComObjPtr <BIOSSettings> mBIOSSettings;
563
564 const ComObjPtr <NetworkAdapter>
565 mNetworkAdapters [SchemaDefs::NetworkAdapterCount];
566
567 friend class SessionMachine;
568 friend class SnapshotMachine;
569};
570
571// SessionMachine class
572////////////////////////////////////////////////////////////////////////////////
573
574/**
575 * @note Notes on locking objects of this class:
576 * SessionMachine shares some data with the primary Machine instance (pointed
577 * to by the |mPeer| member). In order to provide data consistency it also
578 * shares its lock handle. This means that whenever you lock a SessionMachine
579 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
580 * instance is also locked in the same lock mode. Keep it in mind.
581 */
582class ATL_NO_VTABLE SessionMachine :
583 public VirtualBoxSupportTranslation <SessionMachine>,
584 public Machine,
585 public IInternalMachineControl
586{
587public:
588
589 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
590
591 DECLARE_NOT_AGGREGATABLE(SessionMachine)
592
593 DECLARE_PROTECT_FINAL_CONSTRUCT()
594
595 BEGIN_COM_MAP(SessionMachine)
596 COM_INTERFACE_ENTRY(ISupportErrorInfo)
597 COM_INTERFACE_ENTRY(IMachine)
598 COM_INTERFACE_ENTRY(IInternalMachineControl)
599 END_COM_MAP()
600
601 NS_DECL_ISUPPORTS
602
603 DECLARE_EMPTY_CTOR_DTOR (SessionMachine)
604
605 HRESULT FinalConstruct();
606 void FinalRelease();
607
608 // public initializer/uninitializer for internal purposes only
609 HRESULT init (Machine *aMachine);
610 void uninit() { uninit (Uninit::Unexpected); }
611
612 // AutoLock::Lockable interface
613 AutoLock::Handle *lockHandle() const;
614
615 // IInternalMachineControl methods
616 STDMETHOD(UpdateState)(MachineState_T machineState);
617 STDMETHOD(GetIPCId)(BSTR *id);
618 STDMETHOD(GetLogFolder) (BSTR *aLogFolder);
619 STDMETHOD(RunUSBDeviceFilters) (IUSBDevice *aUSBDevice, BOOL *aMatched);
620 STDMETHOD(CaptureUSBDevice) (INPTR GUIDPARAM aId, IUSBDevice **aHostDevice);
621 STDMETHOD(ReleaseUSBDevice) (INPTR GUIDPARAM aId);
622 STDMETHOD(AutoCaptureUSBDevices) (IUSBDeviceCollection **aHostDevices);
623 STDMETHOD(ReleaseAllUSBDevices)();
624 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
625 STDMETHOD(BeginSavingState) (IProgress *aProgress, BSTR *aStateFilePath);
626 STDMETHOD(EndSavingState) (BOOL aSuccess);
627 STDMETHOD(BeginTakingSnapshot) (IConsole *aInitiator,
628 INPTR BSTR aName, INPTR BSTR aDescription,
629 IProgress *aProgress, BSTR *aStateFilePath,
630 IProgress **aServerProgress);
631 STDMETHOD(EndTakingSnapshot) (BOOL aSuccess);
632 STDMETHOD(DiscardSnapshot) (IConsole *aInitiator, INPTR GUIDPARAM aId,
633 MachineState_T *aMachineState, IProgress **aProgress);
634 STDMETHOD(DiscardCurrentState) (
635 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
636 STDMETHOD(DiscardCurrentSnapshotAndState) (
637 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
638
639 // public methods only for internal purposes
640
641 bool checkForDeath();
642#ifdef __WIN__
643 HANDLE ipcSem() { return mIPCSem; }
644#endif
645
646 HRESULT onDVDDriveChange();
647 HRESULT onFloppyDriveChange();
648 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
649 HRESULT onVRDPServerChange();
650 HRESULT onUSBControllerChange();
651 HRESULT onUSBDeviceAttach (IUSBDevice *aDevice);
652 HRESULT onUSBDeviceDetach (INPTR GUIDPARAM aId);
653
654private:
655
656 struct SnapshotData
657 {
658 SnapshotData() : mLastState (MachineState_InvalidMachineState) {}
659
660 MachineState_T mLastState;
661
662 // used when taking snapshot
663 ComObjPtr <Snapshot> mSnapshot;
664 ComObjPtr <Progress> mServerProgress;
665 ComObjPtr <CombinedProgress> mCombinedProgress;
666
667 // used when saving state
668 Guid mProgressId;
669 Bstr mStateFilePath;
670 };
671
672 struct Uninit {
673 enum Reason { Unexpected, Abnormal, Normal };
674 };
675
676 struct Task;
677 struct TakeSnapshotTask;
678 struct DiscardSnapshotTask;
679 struct DiscardCurrentStateTask;
680
681 friend struct TakeSnapshotTask;
682 friend struct DiscardSnapshotTask;
683 friend struct DiscardCurrentStateTask;
684
685 void uninit (Uninit::Reason aReason);
686
687 HRESULT endSavingState (BOOL aSuccess);
688 HRESULT endTakingSnapshot (BOOL aSuccess);
689
690 typedef std::map <ComObjPtr <Machine>, MachineState_T> AffectedMachines;
691
692 void takeSnapshotHandler (TakeSnapshotTask &aTask);
693 void discardSnapshotHandler (DiscardSnapshotTask &aTask);
694 void discardCurrentStateHandler (DiscardCurrentStateTask &aTask);
695
696 HRESULT setMachineState (MachineState_T aMachineState);
697 HRESULT updateMachineStateOnClient();
698
699 SnapshotData mSnapshotData;
700
701 /** interprocess semaphore handle (id) for this machine */
702#if defined(__WIN__)
703 HANDLE mIPCSem;
704 Bstr mIPCSemName;
705#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
706 int mIPCSem;
707#endif
708
709 static DECLCALLBACK(int) taskHandler (RTTHREAD thread, void *pvUser);
710};
711
712// SnapshotMachine class
713////////////////////////////////////////////////////////////////////////////////
714
715/**
716 * @note Notes on locking objects of this class:
717 * SnapshotMachine shares some data with the primary Machine instance (pointed
718 * to by the |mPeer| member). In order to provide data consistency it also
719 * shares its lock handle. This means that whenever you lock a SessionMachine
720 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
721 * instance is also locked in the same lock mode. Keep it in mind.
722 */
723class ATL_NO_VTABLE SnapshotMachine :
724 public VirtualBoxSupportTranslation <SnapshotMachine>,
725 public Machine
726{
727public:
728
729 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
730
731 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
732
733 DECLARE_PROTECT_FINAL_CONSTRUCT()
734
735 BEGIN_COM_MAP(SnapshotMachine)
736 COM_INTERFACE_ENTRY(ISupportErrorInfo)
737 COM_INTERFACE_ENTRY(IMachine)
738 END_COM_MAP()
739
740 NS_DECL_ISUPPORTS
741
742 DECLARE_EMPTY_CTOR_DTOR (SnapshotMachine)
743
744 HRESULT FinalConstruct();
745 void FinalRelease();
746
747 // public initializer/uninitializer for internal purposes only
748 HRESULT init (SessionMachine *aSessionMachine,
749 INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
750 HRESULT init (Machine *aMachine, CFGNODE aHWNode, CFGNODE aHDAsNode,
751 INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
752 void uninit();
753
754 // AutoLock::Lockable interface
755 AutoLock::Handle *lockHandle() const;
756
757 // public methods only for internal purposes
758
759 HRESULT onSnapshotChange (Snapshot *aSnapshot);
760
761private:
762
763 Guid mSnapshotId;
764};
765
766////////////////////////////////////////////////////////////////////////////////
767
768/**
769 * Returns a pointer to the Machine object for this machine that acts like a
770 * parent for complex machine data objects such as shared folders, etc.
771 *
772 * For primary Machine objects and for SnapshotMachine objects, returns this
773 * object's pointer itself. For SessoinMachine objects, returns the peer
774 * (primary) machine pointer.
775 */
776inline Machine *Machine::machine()
777{
778 if (mType == IsSessionMachine)
779 return mPeer;
780 return this;
781}
782
783COM_DECL_READONLY_ENUM_AND_COLLECTION (Machine)
784
785#endif // ____H_MACHINEIMPL
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette