VirtualBox

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

Last change on this file since 2644 was 2567, checked in by vboxsync, 18 years ago

Main & All Frontends: replaced the IGuestOSType IMachine::OSType property with the wstring IMachine::OSTypeId property (+ converted IGuest and IGuestOSType to VirtualBoxBaseNEXT semantics).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.2 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 mOSTypeId == that.mOSTypeId &&
217 mSnapshotFolderFull == that.mSnapshotFolderFull);
218 }
219
220 Bstr mName;
221 BOOL mNameSync;
222 Bstr mDescription;
223 Bstr mOSTypeId;
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 ULONG mMonitorCount;
246 TriStateBool_T mHWVirtExEnabled;
247
248 DeviceType_T mBootOrder [SchemaDefs::MaxBootPosition];
249
250 typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
251 SharedFolderList mSharedFolders;
252 ClipboardMode_T mClipboardMode;
253 };
254
255 /**
256 * Hard disk data.
257 *
258 * The usage policy is the same as for HWData, but a separate structure
259 * is necessarym because hard disk data requires different procedures when
260 * taking or discarding snapshots, etc.
261 *
262 * The data variable is |mHWData|.
263 */
264 struct HDData
265 {
266 HDData();
267 ~HDData();
268
269 bool operator== (const HDData &that) const;
270
271 typedef std::list <ComObjPtr <HardDiskAttachment> > HDAttachmentList;
272 HDAttachmentList mHDAttachments;
273
274 /**
275 * Right after Machine::fixupHardDisks(true): |true| if hard disks
276 * were actually changed, |false| otherwise
277 */
278 bool mHDAttachmentsChanged;
279 };
280
281 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Machine)
282
283 DECLARE_NOT_AGGREGATABLE(Machine)
284
285 DECLARE_PROTECT_FINAL_CONSTRUCT()
286
287 BEGIN_COM_MAP(Machine)
288 COM_INTERFACE_ENTRY(ISupportErrorInfo)
289 COM_INTERFACE_ENTRY(IMachine)
290 END_COM_MAP()
291
292 NS_DECL_ISUPPORTS
293
294 DECLARE_EMPTY_CTOR_DTOR (Machine)
295
296 HRESULT FinalConstruct();
297 void FinalRelease();
298
299 enum InitMode { Init_New, Init_Existing, Init_Registered };
300
301 // public initializer/uninitializer for internal purposes only
302 HRESULT init (VirtualBox *aParent, const BSTR aConfigFile,
303 InitMode aMode, const BSTR aName = NULL,
304 BOOL aNameSync = TRUE, const Guid *aId = NULL);
305 void uninit();
306
307 // IMachine properties
308 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
309 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
310 STDMETHOD(COMGETTER(AccessError)) (IVirtualBoxErrorInfo **aAccessError);
311 STDMETHOD(COMGETTER(Name))(BSTR *aName);
312 STDMETHOD(COMSETTER(Name))(INPTR BSTR aName);
313 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
314 STDMETHOD(COMSETTER(Description))(INPTR BSTR aDescription);
315 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
316 STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
317 STDMETHOD(COMSETTER(OSTypeId)) (INPTR BSTR aOSTypeId);
318 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
319 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
320 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
321 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
322 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
323 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
324 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
325 STDMETHOD(COMGETTER(HWVirtExEnabled))(TriStateBool_T *enabled);
326 STDMETHOD(COMSETTER(HWVirtExEnabled))(TriStateBool_T enabled);
327 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
328 STDMETHOD(COMSETTER(SnapshotFolder))(INPTR BSTR aSavedStateFolder);
329 STDMETHOD(COMGETTER(HardDiskAttachments))(IHardDiskAttachmentCollection **attachments);
330 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
331 STDMETHOD(COMGETTER(DVDDrive))(IDVDDrive **dvdDrive);
332 STDMETHOD(COMGETTER(FloppyDrive))(IFloppyDrive **floppyDrive);
333 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
334 STDMETHOD(COMGETTER(USBController))(IUSBController * *a_ppUSBController);
335 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *filePath);
336 STDMETHOD(COMGETTER(SettingsModified))(BOOL *modified);
337 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
338 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
339 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
340 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
341 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
342 STDMETHOD(COMGETTER(StateFilePath)) (BSTR *aStateFilePath);
343 STDMETHOD(COMGETTER(CurrentSnapshot)) (ISnapshot **aCurrentSnapshot);
344 STDMETHOD(COMGETTER(SnapshotCount)) (ULONG *aSnapshotCount);
345 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
346 STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
347 STDMETHOD(COMGETTER(ClipboardMode)) (ClipboardMode_T *aClipboardMode);
348 STDMETHOD(COMSETTER(ClipboardMode)) (ClipboardMode_T aClipboardMode);
349
350 // IMachine methods
351 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
352 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
353 STDMETHOD(AttachHardDisk)(INPTR GUIDPARAM aId, DiskControllerType_T aCtl, LONG aDev);
354 STDMETHOD(GetHardDisk)(DiskControllerType_T aCtl, LONG aDev, IHardDisk **aHardDisk);
355 STDMETHOD(DetachHardDisk) (DiskControllerType_T aCtl, LONG aDev);
356 STDMETHOD(GetNetworkAdapter) (ULONG slot, INetworkAdapter **adapter);
357 STDMETHOD(GetNextExtraDataKey)(INPTR BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
358 STDMETHOD(GetExtraData)(INPTR BSTR aKey, BSTR *aValue);
359 STDMETHOD(SetExtraData)(INPTR BSTR aKey, INPTR BSTR aValue);
360 STDMETHOD(SaveSettings)();
361 STDMETHOD(DiscardSettings)();
362 STDMETHOD(DeleteSettings)();
363 STDMETHOD(GetSnapshot) (INPTR GUIDPARAM aId, ISnapshot **aSnapshot);
364 STDMETHOD(FindSnapshot) (INPTR BSTR aName, ISnapshot **aSnapshot);
365 STDMETHOD(SetCurrentSnapshot) (INPTR GUIDPARAM aId);
366 STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
367 STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
368 STDMETHOD(CanShowConsoleWindow) (BOOL *aCanShow);
369 STDMETHOD(ShowConsoleWindow) (ULONG64 *aWinId);
370
371 // public methods only for internal purposes
372
373 /// @todo (dmik) add lock and make non-inlined after revising classes
374 // that use it (actually, the CHECK_MACHINE_MUTABILITY macro).
375 // Note: these classes should enter Machine lock to keep the returned
376 // information valid!
377 bool isMutable()
378 {
379 return ((!mData->mRegistered) ||
380 (mType == IsSessionMachine &&
381 mData->mMachineState <= MachineState_Paused &&
382 mData->mMachineState != MachineState_Saved));
383 }
384
385 /// @todo (dmik) add lock and make non-inlined after revising classes
386 // that use it (actually, the CHECK_MACHINE_MUTABILITY_IGNORING_SAVED macro).
387 // Note: these classes should enter Machine lock to keep the returned
388 // information valid!
389 bool isMutableIgnoringSavedState()
390 {
391 return ((!mData->mRegistered) ||
392 (mType == IsSessionMachine &&
393 mData->mMachineState <= MachineState_Paused));
394 }
395
396 /// @todo (dmik) add lock and make non-inlined after revising classes
397 // that use it. Note: they should enter Machine lock to keep the returned
398 // information valid!
399 bool isRegistered() { return !!mData->mRegistered; }
400
401 ComObjPtr <SessionMachine> sessionMachine();
402
403 // Note: the below methods are intended to be called only after adding
404 // a caller to the Machine instance and, when necessary, from under
405 // the Machine lock in appropriate mode
406
407 /// @todo (dmik) revise code using these methods: improving incapsulation
408 // should make them not necessary
409
410 const ComObjPtr <VirtualBox, ComWeakRef> &virtualBox() { return mParent; }
411
412 const Shareable <Data> &data() const { return mData; }
413 const Backupable <UserData> &userData() const { return mUserData; }
414 const Backupable <HDData> &hdData() const { return mHDData; }
415
416 const Shareable <SSData> &ssData() const { return mSSData; }
417
418 const ComObjPtr <DVDDrive> &dvdDrive() { return mDVDDrive; }
419 const ComObjPtr <FloppyDrive> &floppyDrive() { return mFloppyDrive; }
420 const ComObjPtr <USBController> &usbController() { return mUSBController; }
421
422 virtual HRESULT onDVDDriveChange() { return S_OK; }
423 virtual HRESULT onFloppyDriveChange() { return S_OK; }
424 virtual HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter) { return S_OK; }
425 virtual HRESULT onVRDPServerChange() { return S_OK; }
426 virtual HRESULT onUSBControllerChange() { return S_OK; }
427
428 int calculateFullPath (const char *aPath, Utf8Str &aResult);
429 void calculateRelativePath (const char *aPath, Utf8Str &aResult);
430
431 void getLogFolder (Utf8Str &aLogFolder);
432
433 HRESULT openSession (IInternalSessionControl *aControl);
434 HRESULT openRemoteSession (IInternalSessionControl *aControl,
435 INPTR BSTR aType, Progress *aProgress);
436 HRESULT openExistingSession (IInternalSessionControl *aControl);
437
438 HRESULT trySetRegistered (BOOL aRegistered);
439
440 HRESULT getSharedFolder (const BSTR aName,
441 ComObjPtr <SharedFolder> &aSharedFolder,
442 bool aSetError = false)
443 {
444 AutoLock alock (this);
445 return findSharedFolder (aName, aSharedFolder, aSetError);
446 }
447
448 // for VirtualBoxSupportErrorInfoImpl
449 static const wchar_t *getComponentName() { return L"Machine"; }
450
451protected:
452
453 enum InstanceType { IsMachine, IsSessionMachine, IsSnapshotMachine };
454
455 HRESULT registeredInit();
456
457 inline Machine *machine();
458
459 void uninitDataAndChildObjects();
460
461 virtual HRESULT setMachineState (MachineState_T aMachineState);
462
463 HRESULT findSharedFolder (const BSTR aName,
464 ComObjPtr <SharedFolder> &aSharedFolder,
465 bool aSetError = false);
466
467 HRESULT loadSettings (bool aRegistered);
468 HRESULT loadSnapshot (CFGNODE aNode, const Guid &aCurSnapshotId,
469 Snapshot *aParentSnapshot);
470 HRESULT loadHardware (CFGNODE aNode);
471 HRESULT loadHardDisks (CFGNODE aNode, bool aRegistered,
472 const Guid *aSnapshotId = NULL);
473
474 HRESULT openConfigLoader (CFGHANDLE *aLoader, bool aIsNew = false);
475 HRESULT closeConfigLoader (CFGHANDLE aLoader, bool aSaveBeforeClose);
476
477 HRESULT findSnapshotNode (Snapshot *aSnapshot, CFGNODE aMachineNode,
478 CFGNODE *aSnapshotsNode, CFGNODE *aSnapshotNode);
479
480 HRESULT findSnapshot (const Guid &aId, ComObjPtr <Snapshot> &aSnapshot,
481 bool aSetError = false);
482 HRESULT findSnapshot (const BSTR aName, ComObjPtr <Snapshot> &aSnapshot,
483 bool aSetError = false);
484
485 HRESULT findHardDiskAttachment (const ComObjPtr <HardDisk> &aHd,
486 ComObjPtr <Machine> *aMachine,
487 ComObjPtr <Snapshot> *aSnapshot,
488 ComObjPtr <HardDiskAttachment> *aHda);
489
490 HRESULT prepareSaveSettings (bool &aRenamed, bool &aNew);
491 HRESULT saveSettings (bool aMarkCurStateAsModified = true,
492 bool aInformCallbacksAnyway = false);
493
494 enum
495 {
496 // ops for #saveSnapshotSettings()
497 SaveSS_NoOp = 0x00, SaveSS_AddOp = 0x01,
498 SaveSS_UpdateAttrsOp = 0x02, SaveSS_UpdateAllOp = 0x03,
499 SaveSS_OpMask = 0xF,
500 // flags for #saveSnapshotSettings()
501 SaveSS_UpdateCurStateModified = 0x40,
502 SaveSS_UpdateCurrentId = 0x80,
503 // flags for #saveStateSettings()
504 SaveSTS_CurStateModified = 0x20,
505 SaveSTS_StateFilePath = 0x40,
506 SaveSTS_StateTimeStamp = 0x80,
507 };
508
509 HRESULT saveSnapshotSettings (Snapshot *aSnapshot, int aOpFlags);
510 HRESULT saveSnapshotSettingsWorker (CFGNODE aMachineNode,
511 Snapshot *aSnapshot, int aOpFlags);
512
513 HRESULT saveSnapshot (CFGNODE aNode, Snapshot *aSnapshot, bool aAttrsOnly);
514 HRESULT saveHardware (CFGNODE aNode);
515 HRESULT saveHardDisks (CFGNODE aNode);
516
517 HRESULT saveStateSettings (int aFlags);
518
519 HRESULT wipeOutImmutableDiffs();
520
521 HRESULT fixupHardDisks (bool aCommit);
522
523 HRESULT createSnapshotDiffs (const Guid *aSnapshotId,
524 const Bstr &aFolder,
525 const ComObjPtr <Progress> &aProgress,
526 bool aOnline);
527 HRESULT deleteSnapshotDiffs (const ComObjPtr <Snapshot> &aSnapshot);
528
529 HRESULT lockConfig();
530 HRESULT unlockConfig();
531
532 /** @note This method is not thread safe */
533 BOOL isConfigLocked()
534 {
535 return !!mData && mData->mHandleCfgFile != NIL_RTFILE;
536 }
537
538 bool isInOwnDir (Utf8Str *aSettingsDir = NULL);
539
540 bool isModified();
541 bool isReallyModified (bool aIgnoreUserData = false);
542 void rollback (bool aNotify);
543 HRESULT commit();
544 void copyFrom (Machine *aThat);
545
546 const InstanceType mType;
547
548 const ComObjPtr <Machine, ComWeakRef> mPeer;
549
550 const ComObjPtr <VirtualBox, ComWeakRef> mParent;
551
552 Shareable <Data> mData;
553 Shareable <SSData> mSSData;
554
555 Backupable <UserData> mUserData;
556 Backupable <HWData> mHWData;
557 Backupable <HDData> mHDData;
558
559 // the following fields need special backup/rollback/commit handling,
560 // so they cannot be a part of HWData
561
562 const ComObjPtr <VRDPServer> mVRDPServer;
563 const ComObjPtr <DVDDrive> mDVDDrive;
564 const ComObjPtr <FloppyDrive> mFloppyDrive;
565 const ComObjPtr <AudioAdapter> mAudioAdapter;
566 const ComObjPtr <USBController> mUSBController;
567 const ComObjPtr <BIOSSettings> mBIOSSettings;
568
569 const ComObjPtr <NetworkAdapter>
570 mNetworkAdapters [SchemaDefs::NetworkAdapterCount];
571
572 friend class SessionMachine;
573 friend class SnapshotMachine;
574};
575
576// SessionMachine class
577////////////////////////////////////////////////////////////////////////////////
578
579/**
580 * @note Notes on locking objects of this class:
581 * SessionMachine shares some data with the primary Machine instance (pointed
582 * to by the |mPeer| member). In order to provide data consistency it also
583 * shares its lock handle. This means that whenever you lock a SessionMachine
584 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
585 * instance is also locked in the same lock mode. Keep it in mind.
586 */
587class ATL_NO_VTABLE SessionMachine :
588 public VirtualBoxSupportTranslation <SessionMachine>,
589 public Machine,
590 public IInternalMachineControl
591{
592public:
593
594 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
595
596 DECLARE_NOT_AGGREGATABLE(SessionMachine)
597
598 DECLARE_PROTECT_FINAL_CONSTRUCT()
599
600 BEGIN_COM_MAP(SessionMachine)
601 COM_INTERFACE_ENTRY(ISupportErrorInfo)
602 COM_INTERFACE_ENTRY(IMachine)
603 COM_INTERFACE_ENTRY(IInternalMachineControl)
604 END_COM_MAP()
605
606 NS_DECL_ISUPPORTS
607
608 DECLARE_EMPTY_CTOR_DTOR (SessionMachine)
609
610 HRESULT FinalConstruct();
611 void FinalRelease();
612
613 // public initializer/uninitializer for internal purposes only
614 HRESULT init (Machine *aMachine);
615 void uninit() { uninit (Uninit::Unexpected); }
616
617 // AutoLock::Lockable interface
618 AutoLock::Handle *lockHandle() const;
619
620 // IInternalMachineControl methods
621 STDMETHOD(UpdateState)(MachineState_T machineState);
622 STDMETHOD(GetIPCId)(BSTR *id);
623 STDMETHOD(GetLogFolder) (BSTR *aLogFolder);
624 STDMETHOD(RunUSBDeviceFilters) (IUSBDevice *aUSBDevice, BOOL *aMatched);
625 STDMETHOD(CaptureUSBDevice) (INPTR GUIDPARAM aId, IUSBDevice **aHostDevice);
626 STDMETHOD(ReleaseUSBDevice) (INPTR GUIDPARAM aId);
627 STDMETHOD(AutoCaptureUSBDevices) (IUSBDeviceCollection **aHostDevices);
628 STDMETHOD(ReleaseAllUSBDevices)();
629 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
630 STDMETHOD(BeginSavingState) (IProgress *aProgress, BSTR *aStateFilePath);
631 STDMETHOD(EndSavingState) (BOOL aSuccess);
632 STDMETHOD(BeginTakingSnapshot) (IConsole *aInitiator,
633 INPTR BSTR aName, INPTR BSTR aDescription,
634 IProgress *aProgress, BSTR *aStateFilePath,
635 IProgress **aServerProgress);
636 STDMETHOD(EndTakingSnapshot) (BOOL aSuccess);
637 STDMETHOD(DiscardSnapshot) (IConsole *aInitiator, INPTR GUIDPARAM aId,
638 MachineState_T *aMachineState, IProgress **aProgress);
639 STDMETHOD(DiscardCurrentState) (
640 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
641 STDMETHOD(DiscardCurrentSnapshotAndState) (
642 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
643
644 // public methods only for internal purposes
645
646 bool checkForDeath();
647#ifdef __WIN__
648 HANDLE ipcSem() { return mIPCSem; }
649#endif
650
651 HRESULT onDVDDriveChange();
652 HRESULT onFloppyDriveChange();
653 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
654 HRESULT onVRDPServerChange();
655 HRESULT onUSBControllerChange();
656 HRESULT onUSBDeviceAttach (IUSBDevice *aDevice);
657 HRESULT onUSBDeviceDetach (INPTR GUIDPARAM aId);
658
659private:
660
661 struct SnapshotData
662 {
663 SnapshotData() : mLastState (MachineState_InvalidMachineState) {}
664
665 MachineState_T mLastState;
666
667 // used when taking snapshot
668 ComObjPtr <Snapshot> mSnapshot;
669 ComObjPtr <Progress> mServerProgress;
670 ComObjPtr <CombinedProgress> mCombinedProgress;
671
672 // used when saving state
673 Guid mProgressId;
674 Bstr mStateFilePath;
675 };
676
677 struct Uninit {
678 enum Reason { Unexpected, Abnormal, Normal };
679 };
680
681 struct Task;
682 struct TakeSnapshotTask;
683 struct DiscardSnapshotTask;
684 struct DiscardCurrentStateTask;
685
686 friend struct TakeSnapshotTask;
687 friend struct DiscardSnapshotTask;
688 friend struct DiscardCurrentStateTask;
689
690 void uninit (Uninit::Reason aReason);
691
692 HRESULT endSavingState (BOOL aSuccess);
693 HRESULT endTakingSnapshot (BOOL aSuccess);
694
695 typedef std::map <ComObjPtr <Machine>, MachineState_T> AffectedMachines;
696
697 void takeSnapshotHandler (TakeSnapshotTask &aTask);
698 void discardSnapshotHandler (DiscardSnapshotTask &aTask);
699 void discardCurrentStateHandler (DiscardCurrentStateTask &aTask);
700
701 HRESULT setMachineState (MachineState_T aMachineState);
702 HRESULT updateMachineStateOnClient();
703
704 SnapshotData mSnapshotData;
705
706 /** interprocess semaphore handle (id) for this machine */
707#if defined(__WIN__)
708 HANDLE mIPCSem;
709 Bstr mIPCSemName;
710#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
711 int mIPCSem;
712#endif
713
714 static DECLCALLBACK(int) taskHandler (RTTHREAD thread, void *pvUser);
715};
716
717// SnapshotMachine class
718////////////////////////////////////////////////////////////////////////////////
719
720/**
721 * @note Notes on locking objects of this class:
722 * SnapshotMachine shares some data with the primary Machine instance (pointed
723 * to by the |mPeer| member). In order to provide data consistency it also
724 * shares its lock handle. This means that whenever you lock a SessionMachine
725 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
726 * instance is also locked in the same lock mode. Keep it in mind.
727 */
728class ATL_NO_VTABLE SnapshotMachine :
729 public VirtualBoxSupportTranslation <SnapshotMachine>,
730 public Machine
731{
732public:
733
734 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
735
736 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
737
738 DECLARE_PROTECT_FINAL_CONSTRUCT()
739
740 BEGIN_COM_MAP(SnapshotMachine)
741 COM_INTERFACE_ENTRY(ISupportErrorInfo)
742 COM_INTERFACE_ENTRY(IMachine)
743 END_COM_MAP()
744
745 NS_DECL_ISUPPORTS
746
747 DECLARE_EMPTY_CTOR_DTOR (SnapshotMachine)
748
749 HRESULT FinalConstruct();
750 void FinalRelease();
751
752 // public initializer/uninitializer for internal purposes only
753 HRESULT init (SessionMachine *aSessionMachine,
754 INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
755 HRESULT init (Machine *aMachine, CFGNODE aHWNode, CFGNODE aHDAsNode,
756 INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
757 void uninit();
758
759 // AutoLock::Lockable interface
760 AutoLock::Handle *lockHandle() const;
761
762 // public methods only for internal purposes
763
764 HRESULT onSnapshotChange (Snapshot *aSnapshot);
765
766private:
767
768 Guid mSnapshotId;
769};
770
771////////////////////////////////////////////////////////////////////////////////
772
773/**
774 * Returns a pointer to the Machine object for this machine that acts like a
775 * parent for complex machine data objects such as shared folders, etc.
776 *
777 * For primary Machine objects and for SnapshotMachine objects, returns this
778 * object's pointer itself. For SessoinMachine objects, returns the peer
779 * (primary) machine pointer.
780 */
781inline Machine *Machine::machine()
782{
783 if (mType == IsSessionMachine)
784 return mPeer;
785 return this;
786}
787
788COM_DECL_READONLY_ENUM_AND_COLLECTION (Machine)
789
790#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