VirtualBox

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

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

Parallel port support. Contributed by: Alexander Eichner

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.2 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class declaration
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek 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 "SerialPortImpl.h"
37#include "ParallelPortImpl.h"
38#include "BIOSSettingsImpl.h"
39
40// generated header
41#include "SchemaDefs.h"
42
43#include <VBox/types.h>
44#include <VBox/cfgldr.h>
45#include <iprt/file.h>
46#include <iprt/thread.h>
47
48#include <list>
49
50// defines
51////////////////////////////////////////////////////////////////////////////////
52
53// helper declarations
54////////////////////////////////////////////////////////////////////////////////
55
56class VirtualBox;
57class Progress;
58class CombinedProgress;
59class Keyboard;
60class Mouse;
61class Display;
62class MachineDebugger;
63class USBController;
64class Snapshot;
65class SharedFolder;
66
67class SessionMachine;
68
69// Machine class
70////////////////////////////////////////////////////////////////////////////////
71
72class ATL_NO_VTABLE Machine :
73 public VirtualBoxBaseWithChildrenNEXT,
74 public VirtualBoxXMLUtil,
75 public VirtualBoxSupportErrorInfoImpl <Machine, IMachine>,
76 public VirtualBoxSupportTranslation <Machine>,
77 public IMachine
78{
79 Q_OBJECT
80
81public:
82
83 /**
84 * Internal machine data.
85 *
86 * Only one instance of this data exists per every machine --
87 * it is shared by the Machine, SessionMachine and all SnapshotMachine
88 * instances associated with the given machine using the util::Shareable
89 * template through the mData variable.
90 *
91 * @note |const| members are persistent during lifetime so can be
92 * accessed without locking.
93 *
94 * @note There is no need to lock anything inside init() or uninit()
95 * methods, because they are always serialized (see AutoCaller).
96 */
97 struct Data
98 {
99 /**
100 * Data structure to hold information about sessions opened for the
101 * given machine.
102 */
103 struct Session
104 {
105 /** Control of the direct session opened by openSession() */
106 ComPtr <IInternalSessionControl> mDirectControl;
107
108 typedef std::list <ComPtr <IInternalSessionControl> > RemoteControlList;
109
110 /** list of controls of all opened remote sessions */
111 RemoteControlList mRemoteControls;
112
113 /** openRemoteSession() and OnSessionEnd() progress indicator */
114 ComObjPtr <Progress> mProgress;
115
116 /**
117 * PID of the session object that must be passed to openSession()
118 * to finalize the openRemoteSession() request
119 * (i.e., PID of the process created by openRemoteSession())
120 */
121 RTPROCESS mPid;
122
123 /** Current session state */
124 SessionState_T mState;
125
126 /** Session type string (for indirect sessions) */
127 Bstr mType;
128
129 /** Sesison machine object */
130 ComObjPtr <SessionMachine> mMachine;
131 };
132
133 Data();
134 ~Data();
135
136 const Guid mUuid;
137 BOOL mRegistered;
138
139 Bstr mConfigFile;
140 Bstr mConfigFileFull;
141
142 BOOL mAccessible;
143 com::ErrorInfo mAccessError;
144
145 MachineState_T mMachineState;
146 LONG64 mLastStateChange;
147
148 uint32_t mMachineStateDeps;
149 RTSEMEVENT mZeroMachineStateDepsSem;
150 BOOL mWaitingStateDeps;
151
152 BOOL mCurrentStateModified;
153
154 RTFILE mHandleCfgFile;
155
156 Session mSession;
157
158 ComObjPtr <Snapshot> mFirstSnapshot;
159 ComObjPtr <Snapshot> mCurrentSnapshot;
160 };
161
162 /**
163 * Saved state data.
164 *
165 * It's actually only the state file path string, but it needs to be
166 * separate from Data, because Machine and SessionMachine instances
167 * share it, while SnapshotMachine does not.
168 *
169 * The data variable is |mSSData|.
170 */
171 struct SSData
172 {
173 Bstr mStateFilePath;
174 };
175
176 /**
177 * User changeable machine data.
178 *
179 * This data is common for all machine snapshots, i.e. it is shared
180 * by all SnapshotMachine instances associated with the given machine
181 * using the util::Backupable template through the |mUserData| variable.
182 *
183 * SessionMachine instances can alter this data and discard changes.
184 *
185 * @note There is no need to lock anything inside init() or uninit()
186 * methods, because they are always serialized (see AutoCaller).
187 */
188 struct UserData
189 {
190 UserData();
191 ~UserData();
192
193 bool operator== (const UserData &that) const
194 {
195 return this == &that ||
196 (mName == that.mName &&
197 mNameSync == that.mNameSync &&
198 mDescription == that.mDescription &&
199 mOSTypeId == that.mOSTypeId &&
200 mSnapshotFolderFull == that.mSnapshotFolderFull);
201 }
202
203 Bstr mName;
204 BOOL mNameSync;
205 Bstr mDescription;
206 Bstr mOSTypeId;
207 Bstr mSnapshotFolder;
208 Bstr mSnapshotFolderFull;
209 };
210
211 /**
212 * Hardware data.
213 *
214 * This data is unique for a machine and for every machine snapshot.
215 * Stored using the util::Backupable template in the |mHWData| variable.
216 *
217 * SessionMachine instances can alter this data and discard changes.
218 */
219 struct HWData
220 {
221 HWData();
222 ~HWData();
223
224 bool operator== (const HWData &that) const;
225
226 ULONG mMemorySize;
227 ULONG mVRAMSize;
228 ULONG mMonitorCount;
229 TriStateBool_T mHWVirtExEnabled;
230
231 DeviceType_T mBootOrder [SchemaDefs::MaxBootPosition];
232
233 typedef std::list <ComObjPtr <SharedFolder> > SharedFolderList;
234 SharedFolderList mSharedFolders;
235 ClipboardMode_T mClipboardMode;
236 };
237
238 /**
239 * Hard disk data.
240 *
241 * The usage policy is the same as for HWData, but a separate structure
242 * is necessarym because hard disk data requires different procedures when
243 * taking or discarding snapshots, etc.
244 *
245 * The data variable is |mHWData|.
246 */
247 struct HDData
248 {
249 HDData();
250 ~HDData();
251
252 bool operator== (const HDData &that) const;
253
254 typedef std::list <ComObjPtr <HardDiskAttachment> > HDAttachmentList;
255 HDAttachmentList mHDAttachments;
256
257 /**
258 * Right after Machine::fixupHardDisks(true): |true| if hard disks
259 * were actually changed, |false| otherwise
260 */
261 bool mHDAttachmentsChanged;
262 };
263
264 enum StateDependency
265 {
266 AnyStateDep = 0, MutableStateDep, MutableOrSavedStateDep
267 };
268
269 /**
270 * Helper class that safely manages the machine state dependency by
271 * calling Machine::addStateDependency() on construction and
272 * Machine::releaseStateDependency() on destruction. Intended for Machine
273 * children. The usage pattern is:
274 *
275 * @code
276 * AutoCaller autoCaller (this);
277 * CheckComRCReturnRC (autoCaller.rc());
278 *
279 * Machine::AutoStateDependency <MutableStateDep> adep (mParent);
280 * CheckComRCReturnRC (stateDep.rc());
281 * ...
282 * // code that depends on the particular machine state
283 * ...
284 * @endcode
285 *
286 * Note that it is more convenient to use the following individual
287 * shortcut classes instead of using this template directly:
288 * AutoAnyStateDependency, AutoMutableStateDependency and
289 * AutoMutableOrSavedStateDependency. The usage pattern is exactly the
290 * same as above except that there is no need to specify the template
291 * argument because it is already done by the shortcut class.
292 *
293 * @param taDepType Dependecy type to manage.
294 */
295 template <StateDependency taDepType = AnyStateDep>
296 class AutoStateDependency
297 {
298 public:
299
300 AutoStateDependency (Machine *aThat)
301 : mThat (aThat), mRC (S_OK)
302 , mMachineState (MachineState_InvalidMachineState)
303 , mRegistered (FALSE)
304 {
305 Assert (aThat);
306 mRC = aThat->addStateDependency (taDepType, &mMachineState,
307 &mRegistered);
308 }
309 ~AutoStateDependency()
310 {
311 if (SUCCEEDED (mRC))
312 mThat->releaseStateDependency();
313 }
314
315 /** Decreases the number of dependencies before the instance is
316 * destroyed. Note that will reset #rc() to E_FAIL. */
317 void release()
318 {
319 AssertReturnVoid (SUCCEEDED (mRC));
320 mThat->releaseStateDependency();
321 mRC = E_FAIL;
322 }
323
324 /** Restores the number of callers after by #release(). #rc() will be
325 * reset to the result of calling addStateDependency() and must be
326 * rechecked to ensure the operation succeeded. */
327 void add()
328 {
329 AssertReturnVoid (!SUCCEEDED (mRC));
330 mRC = mThat->addStateDependency (taDepType, &mMachineState,
331 &mRegistered);
332 }
333
334 /** Returns the result of Machine::addStateDependency(). */
335 HRESULT rc() const { return mRC; }
336
337 /** Shortcut to SUCCEEDED (rc()). */
338 bool isOk() const { return SUCCEEDED (mRC); }
339
340 /** Returns the machine state value as returned by
341 * Machine::addStateDependency(). */
342 MachineState_T machineState() const { return mMachineState; }
343
344 /** Returns the machine state value as returned by
345 * Machine::addStateDependency(). */
346 BOOL machineRegistered() const { return mRegistered; }
347
348 protected:
349
350 Machine *mThat;
351 HRESULT mRC;
352 MachineState_T mMachineState;
353 BOOL mRegistered;
354
355 private:
356
357 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP (AutoStateDependency)
358 DECLARE_CLS_NEW_DELETE_NOOP (AutoStateDependency)
359 };
360
361 /**
362 * Shortcut to AutoStateDependency <AnyStateDep>.
363 * See AutoStateDependency to get the usage pattern.
364 *
365 * Accepts any machine state and guarantees the state won't change before
366 * this object is destroyed. If the machine state cannot be protected (as
367 * a result of the state change currently in progress), this instance's
368 * #rc() method will indicate a failure, and the caller is not allowed to
369 * rely on any particular machine state and should return the failed
370 * result code to the upper level.
371 */
372 typedef AutoStateDependency <AnyStateDep> AutoAnyStateDependency;
373
374 /**
375 * Shortcut to AutoStateDependency <MutableStateDep>.
376 * See AutoStateDependency to get the usage pattern.
377 *
378 * Succeeds only if the machine state is in one of the mutable states, and
379 * guarantees the given mutable state won't change before this object is
380 * destroyed. If the machine is not mutable, this instance's #rc() method
381 * will indicate a failure, and the caller is not allowed to rely on any
382 * particular machine state and should return the failed result code to
383 * the upper level.
384 *
385 * Intended to be used within all setter methods of IMachine
386 * children objects (DVDDrive, NetworkAdapter, AudioAdapter, etc.) to
387 * provide data protection and consistency.
388 */
389 typedef AutoStateDependency <MutableStateDep> AutoMutableStateDependency;
390
391 /**
392 * Shortcut to AutoStateDependency <MutableOrSavedStateDep>.
393 * See AutoStateDependency to get the usage pattern.
394 *
395 * Succeeds only if the machine state is in one of the mutable states, or
396 * if the machine is in the Saved state, and guarantees the given mutable
397 * state won't change before this object is destroyed. If the machine is
398 * not mutable, this instance's #rc() method will indicate a failure, and
399 * the caller is not allowed to rely on any particular machine state and
400 * should return the failed result code to the upper level.
401 *
402 * Intended to be used within setter methods of IMachine
403 * children objects that may also operate on Saved machines.
404 */
405 typedef AutoStateDependency <MutableOrSavedStateDep> AutoMutableOrSavedStateDependency;
406
407
408 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT (Machine)
409
410 DECLARE_NOT_AGGREGATABLE(Machine)
411
412 DECLARE_PROTECT_FINAL_CONSTRUCT()
413
414 BEGIN_COM_MAP(Machine)
415 COM_INTERFACE_ENTRY(ISupportErrorInfo)
416 COM_INTERFACE_ENTRY(IMachine)
417 END_COM_MAP()
418
419 NS_DECL_ISUPPORTS
420
421 DECLARE_EMPTY_CTOR_DTOR (Machine)
422
423 HRESULT FinalConstruct();
424 void FinalRelease();
425
426 enum InitMode { Init_New, Init_Existing, Init_Registered };
427
428 // public initializer/uninitializer for internal purposes only
429 HRESULT init (VirtualBox *aParent, const BSTR aConfigFile,
430 InitMode aMode, const BSTR aName = NULL,
431 BOOL aNameSync = TRUE, const Guid *aId = NULL);
432 void uninit();
433
434 // IMachine properties
435 STDMETHOD(COMGETTER(Parent))(IVirtualBox **aParent);
436 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
437 STDMETHOD(COMGETTER(AccessError)) (IVirtualBoxErrorInfo **aAccessError);
438 STDMETHOD(COMGETTER(Name))(BSTR *aName);
439 STDMETHOD(COMSETTER(Name))(INPTR BSTR aName);
440 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
441 STDMETHOD(COMSETTER(Description))(INPTR BSTR aDescription);
442 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT aId);
443 STDMETHOD(COMGETTER(OSTypeId)) (BSTR *aOSTypeId);
444 STDMETHOD(COMSETTER(OSTypeId)) (INPTR BSTR aOSTypeId);
445 STDMETHOD(COMGETTER(MemorySize))(ULONG *memorySize);
446 STDMETHOD(COMSETTER(MemorySize))(ULONG memorySize);
447 STDMETHOD(COMGETTER(VRAMSize))(ULONG *memorySize);
448 STDMETHOD(COMSETTER(VRAMSize))(ULONG memorySize);
449 STDMETHOD(COMGETTER(MonitorCount))(ULONG *monitorCount);
450 STDMETHOD(COMSETTER(MonitorCount))(ULONG monitorCount);
451 STDMETHOD(COMGETTER(BIOSSettings))(IBIOSSettings **biosSettings);
452 STDMETHOD(COMGETTER(HWVirtExEnabled))(TriStateBool_T *enabled);
453 STDMETHOD(COMSETTER(HWVirtExEnabled))(TriStateBool_T enabled);
454 STDMETHOD(COMGETTER(SnapshotFolder))(BSTR *aSavedStateFolder);
455 STDMETHOD(COMSETTER(SnapshotFolder))(INPTR BSTR aSavedStateFolder);
456 STDMETHOD(COMGETTER(HardDiskAttachments))(IHardDiskAttachmentCollection **attachments);
457 STDMETHOD(COMGETTER(VRDPServer))(IVRDPServer **vrdpServer);
458 STDMETHOD(COMGETTER(DVDDrive))(IDVDDrive **dvdDrive);
459 STDMETHOD(COMGETTER(FloppyDrive))(IFloppyDrive **floppyDrive);
460 STDMETHOD(COMGETTER(AudioAdapter))(IAudioAdapter **audioAdapter);
461 STDMETHOD(COMGETTER(USBController))(IUSBController * *a_ppUSBController);
462 STDMETHOD(COMGETTER(SettingsFilePath))(BSTR *filePath);
463 STDMETHOD(COMGETTER(SettingsModified))(BOOL *modified);
464 STDMETHOD(COMGETTER(SessionState))(SessionState_T *aSessionState);
465 STDMETHOD(COMGETTER(SessionType))(BSTR *aSessionType);
466 STDMETHOD(COMGETTER(SessionPid))(ULONG *aSessionPid);
467 STDMETHOD(COMGETTER(State))(MachineState_T *machineState);
468 STDMETHOD(COMGETTER(LastStateChange))(LONG64 *aLastStateChange);
469 STDMETHOD(COMGETTER(StateFilePath)) (BSTR *aStateFilePath);
470 STDMETHOD(COMGETTER(LogFolder)) (BSTR *aLogFolder);
471 STDMETHOD(COMGETTER(CurrentSnapshot)) (ISnapshot **aCurrentSnapshot);
472 STDMETHOD(COMGETTER(SnapshotCount)) (ULONG *aSnapshotCount);
473 STDMETHOD(COMGETTER(CurrentStateModified))(BOOL *aCurrentStateModified);
474 STDMETHOD(COMGETTER(SharedFolders)) (ISharedFolderCollection **aSharedFolders);
475 STDMETHOD(COMGETTER(ClipboardMode)) (ClipboardMode_T *aClipboardMode);
476 STDMETHOD(COMSETTER(ClipboardMode)) (ClipboardMode_T aClipboardMode);
477
478 // IMachine methods
479 STDMETHOD(SetBootOrder)(ULONG aPosition, DeviceType_T aDevice);
480 STDMETHOD(GetBootOrder)(ULONG aPosition, DeviceType_T *aDevice);
481 STDMETHOD(AttachHardDisk)(INPTR GUIDPARAM aId, DiskControllerType_T aCtl, LONG aDev);
482 STDMETHOD(GetHardDisk)(DiskControllerType_T aCtl, LONG aDev, IHardDisk **aHardDisk);
483 STDMETHOD(DetachHardDisk) (DiskControllerType_T aCtl, LONG aDev);
484 STDMETHOD(GetSerialPort) (ULONG slot, ISerialPort **port);
485 STDMETHOD(GetParallelPort) (ULONG slot, IParallelPort **port);
486 STDMETHOD(GetNetworkAdapter) (ULONG slot, INetworkAdapter **adapter);
487 STDMETHOD(GetNextExtraDataKey)(INPTR BSTR aKey, BSTR *aNextKey, BSTR *aNextValue);
488 STDMETHOD(GetExtraData)(INPTR BSTR aKey, BSTR *aValue);
489 STDMETHOD(SetExtraData)(INPTR BSTR aKey, INPTR BSTR aValue);
490 STDMETHOD(SaveSettings)();
491 STDMETHOD(DiscardSettings)();
492 STDMETHOD(DeleteSettings)();
493 STDMETHOD(GetSnapshot) (INPTR GUIDPARAM aId, ISnapshot **aSnapshot);
494 STDMETHOD(FindSnapshot) (INPTR BSTR aName, ISnapshot **aSnapshot);
495 STDMETHOD(SetCurrentSnapshot) (INPTR GUIDPARAM aId);
496 STDMETHOD(CreateSharedFolder) (INPTR BSTR aName, INPTR BSTR aHostPath);
497 STDMETHOD(RemoveSharedFolder) (INPTR BSTR aName);
498 STDMETHOD(CanShowConsoleWindow) (BOOL *aCanShow);
499 STDMETHOD(ShowConsoleWindow) (ULONG64 *aWinId);
500
501 // public methods only for internal purposes
502
503 /// @todo (dmik) add lock and make non-inlined after revising classes
504 // that use it. Note: they should enter Machine lock to keep the returned
505 // information valid!
506 bool isRegistered() { return !!mData->mRegistered; }
507
508 ComObjPtr <SessionMachine> sessionMachine();
509
510 // Note: the below methods are intended to be called only after adding
511 // a caller to the Machine instance and, when necessary, from under
512 // the Machine lock in appropriate mode
513
514 /// @todo (dmik) revise code using these methods: improving incapsulation
515 // should make them not necessary
516
517 const ComObjPtr <VirtualBox, ComWeakRef> &virtualBox() { return mParent; }
518
519 const Shareable <Data> &data() const { return mData; }
520 const Backupable <UserData> &userData() const { return mUserData; }
521 const Backupable <HDData> &hdData() const { return mHDData; }
522
523 const Shareable <SSData> &ssData() const { return mSSData; }
524
525 const ComObjPtr <DVDDrive> &dvdDrive() { return mDVDDrive; }
526 const ComObjPtr <FloppyDrive> &floppyDrive() { return mFloppyDrive; }
527 const ComObjPtr <USBController> &usbController() { return mUSBController; }
528
529 virtual HRESULT onDVDDriveChange() { return S_OK; }
530 virtual HRESULT onFloppyDriveChange() { return S_OK; }
531 virtual HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter) { return S_OK; }
532 virtual HRESULT onSerialPortChange(ISerialPort *serialPort) { return S_OK; }
533 virtual HRESULT onParallelPortChange(IParallelPort *ParallelPort) { return S_OK; }
534 virtual HRESULT onVRDPServerChange() { return S_OK; }
535 virtual HRESULT onUSBControllerChange() { return S_OK; }
536
537 int calculateFullPath (const char *aPath, Utf8Str &aResult);
538 void calculateRelativePath (const char *aPath, Utf8Str &aResult);
539
540 void getLogFolder (Utf8Str &aLogFolder);
541
542 HRESULT openSession (IInternalSessionControl *aControl);
543 HRESULT openRemoteSession (IInternalSessionControl *aControl,
544 INPTR BSTR aType, Progress *aProgress);
545 HRESULT openExistingSession (IInternalSessionControl *aControl);
546
547 HRESULT trySetRegistered (BOOL aRegistered);
548
549 HRESULT getSharedFolder (const BSTR aName,
550 ComObjPtr <SharedFolder> &aSharedFolder,
551 bool aSetError = false)
552 {
553 AutoLock alock (this);
554 return findSharedFolder (aName, aSharedFolder, aSetError);
555 }
556
557 HRESULT addStateDependency (StateDependency aDepType = AnyStateDep,
558 MachineState_T *aState = NULL,
559 BOOL *aRegistered = NULL);
560 void releaseStateDependency();
561
562 // for VirtualBoxSupportErrorInfoImpl
563 static const wchar_t *getComponentName() { return L"Machine"; }
564
565protected:
566
567 enum InstanceType { IsMachine, IsSessionMachine, IsSnapshotMachine };
568
569 HRESULT registeredInit();
570
571 HRESULT checkStateDependency (StateDependency aDepType);
572
573 inline Machine *machine();
574
575 void uninitDataAndChildObjects();
576
577 void checkStateDependencies (AutoLock &aLock);
578
579 virtual HRESULT setMachineState (MachineState_T aMachineState);
580
581 HRESULT findSharedFolder (const BSTR aName,
582 ComObjPtr <SharedFolder> &aSharedFolder,
583 bool aSetError = false);
584
585 HRESULT loadSettings (bool aRegistered);
586 HRESULT loadSnapshot (CFGNODE aNode, const Guid &aCurSnapshotId,
587 Snapshot *aParentSnapshot);
588 HRESULT loadHardware (CFGNODE aNode);
589 HRESULT loadHardDisks (CFGNODE aNode, bool aRegistered,
590 const Guid *aSnapshotId = NULL);
591
592 HRESULT openConfigLoader (CFGHANDLE *aLoader, bool aIsNew = false);
593 HRESULT closeConfigLoader (CFGHANDLE aLoader, bool aSaveBeforeClose);
594
595 HRESULT findSnapshotNode (Snapshot *aSnapshot, CFGNODE aMachineNode,
596 CFGNODE *aSnapshotsNode, CFGNODE *aSnapshotNode);
597
598 HRESULT findSnapshot (const Guid &aId, ComObjPtr <Snapshot> &aSnapshot,
599 bool aSetError = false);
600 HRESULT findSnapshot (const BSTR aName, ComObjPtr <Snapshot> &aSnapshot,
601 bool aSetError = false);
602
603 HRESULT findHardDiskAttachment (const ComObjPtr <HardDisk> &aHd,
604 ComObjPtr <Machine> *aMachine,
605 ComObjPtr <Snapshot> *aSnapshot,
606 ComObjPtr <HardDiskAttachment> *aHda);
607
608 HRESULT prepareSaveSettings (bool &aRenamed, bool &aNew);
609 HRESULT saveSettings (bool aMarkCurStateAsModified = true,
610 bool aInformCallbacksAnyway = false);
611
612 enum
613 {
614 // ops for #saveSnapshotSettings()
615 SaveSS_NoOp = 0x00, SaveSS_AddOp = 0x01,
616 SaveSS_UpdateAttrsOp = 0x02, SaveSS_UpdateAllOp = 0x03,
617 SaveSS_OpMask = 0xF,
618 // flags for #saveSnapshotSettings()
619 SaveSS_UpdateCurStateModified = 0x40,
620 SaveSS_UpdateCurrentId = 0x80,
621 // flags for #saveStateSettings()
622 SaveSTS_CurStateModified = 0x20,
623 SaveSTS_StateFilePath = 0x40,
624 SaveSTS_StateTimeStamp = 0x80,
625 };
626
627 HRESULT saveSnapshotSettings (Snapshot *aSnapshot, int aOpFlags);
628 HRESULT saveSnapshotSettingsWorker (CFGNODE aMachineNode,
629 Snapshot *aSnapshot, int aOpFlags);
630
631 HRESULT saveSnapshot (CFGNODE aNode, Snapshot *aSnapshot, bool aAttrsOnly);
632 HRESULT saveHardware (CFGNODE aNode);
633 HRESULT saveHardDisks (CFGNODE aNode);
634
635 HRESULT saveStateSettings (int aFlags);
636
637 HRESULT wipeOutImmutableDiffs();
638
639 HRESULT fixupHardDisks (bool aCommit);
640
641 HRESULT createSnapshotDiffs (const Guid *aSnapshotId,
642 const Bstr &aFolder,
643 const ComObjPtr <Progress> &aProgress,
644 bool aOnline);
645 HRESULT deleteSnapshotDiffs (const ComObjPtr <Snapshot> &aSnapshot);
646
647 HRESULT lockConfig();
648 HRESULT unlockConfig();
649
650 /** @note This method is not thread safe */
651 BOOL isConfigLocked()
652 {
653 return !!mData && mData->mHandleCfgFile != NIL_RTFILE;
654 }
655
656 bool isInOwnDir (Utf8Str *aSettingsDir = NULL);
657
658 bool isModified();
659 bool isReallyModified (bool aIgnoreUserData = false);
660 void rollback (bool aNotify);
661 HRESULT commit();
662 void copyFrom (Machine *aThat);
663
664 const InstanceType mType;
665
666 const ComObjPtr <Machine, ComWeakRef> mPeer;
667
668 const ComObjPtr <VirtualBox, ComWeakRef> mParent;
669
670 Shareable <Data> mData;
671 Shareable <SSData> mSSData;
672
673 Backupable <UserData> mUserData;
674 Backupable <HWData> mHWData;
675 Backupable <HDData> mHDData;
676
677 // the following fields need special backup/rollback/commit handling,
678 // so they cannot be a part of HWData
679
680 const ComObjPtr <VRDPServer> mVRDPServer;
681 const ComObjPtr <DVDDrive> mDVDDrive;
682 const ComObjPtr <FloppyDrive> mFloppyDrive;
683 const ComObjPtr <SerialPort>
684 mSerialPorts [SchemaDefs::SerialPortCount];
685 const ComObjPtr <ParallelPort>
686 mParallelPorts [SchemaDefs::ParallelPortCount];
687 const ComObjPtr <AudioAdapter> mAudioAdapter;
688 const ComObjPtr <USBController> mUSBController;
689 const ComObjPtr <BIOSSettings> mBIOSSettings;
690 const ComObjPtr <NetworkAdapter>
691 mNetworkAdapters [SchemaDefs::NetworkAdapterCount];
692
693 friend class SessionMachine;
694 friend class SnapshotMachine;
695};
696
697// SessionMachine class
698////////////////////////////////////////////////////////////////////////////////
699
700/**
701 * @note Notes on locking objects of this class:
702 * SessionMachine shares some data with the primary Machine instance (pointed
703 * to by the |mPeer| member). In order to provide data consistency it also
704 * shares its lock handle. This means that whenever you lock a SessionMachine
705 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
706 * instance is also locked in the same lock mode. Keep it in mind.
707 */
708class ATL_NO_VTABLE SessionMachine :
709 public VirtualBoxSupportTranslation <SessionMachine>,
710 public Machine,
711 public IInternalMachineControl
712{
713public:
714
715 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SessionMachine)
716
717 DECLARE_NOT_AGGREGATABLE(SessionMachine)
718
719 DECLARE_PROTECT_FINAL_CONSTRUCT()
720
721 BEGIN_COM_MAP(SessionMachine)
722 COM_INTERFACE_ENTRY(ISupportErrorInfo)
723 COM_INTERFACE_ENTRY(IMachine)
724 COM_INTERFACE_ENTRY(IInternalMachineControl)
725 END_COM_MAP()
726
727 NS_DECL_ISUPPORTS
728
729 DECLARE_EMPTY_CTOR_DTOR (SessionMachine)
730
731 HRESULT FinalConstruct();
732 void FinalRelease();
733
734 // public initializer/uninitializer for internal purposes only
735 HRESULT init (Machine *aMachine);
736 void uninit() { uninit (Uninit::Unexpected); }
737
738 // AutoLock::Lockable interface
739 AutoLock::Handle *lockHandle() const;
740
741 // IInternalMachineControl methods
742 STDMETHOD(UpdateState)(MachineState_T machineState);
743 STDMETHOD(GetIPCId)(BSTR *id);
744 STDMETHOD(RunUSBDeviceFilters) (IUSBDevice *aUSBDevice, BOOL *aMatched);
745 STDMETHOD(CaptureUSBDevice) (INPTR GUIDPARAM aId);
746 STDMETHOD(DetachUSBDevice) (INPTR GUIDPARAM aId, BOOL aDone);
747 STDMETHOD(AutoCaptureUSBDevices)();
748 STDMETHOD(DetachAllUSBDevices)(BOOL aDone);
749 STDMETHOD(OnSessionEnd)(ISession *aSession, IProgress **aProgress);
750 STDMETHOD(BeginSavingState) (IProgress *aProgress, BSTR *aStateFilePath);
751 STDMETHOD(EndSavingState) (BOOL aSuccess);
752 STDMETHOD(BeginTakingSnapshot) (IConsole *aInitiator,
753 INPTR BSTR aName, INPTR BSTR aDescription,
754 IProgress *aProgress, BSTR *aStateFilePath,
755 IProgress **aServerProgress);
756 STDMETHOD(EndTakingSnapshot) (BOOL aSuccess);
757 STDMETHOD(DiscardSnapshot) (IConsole *aInitiator, INPTR GUIDPARAM aId,
758 MachineState_T *aMachineState, IProgress **aProgress);
759 STDMETHOD(DiscardCurrentState) (
760 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
761 STDMETHOD(DiscardCurrentSnapshotAndState) (
762 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress);
763
764 // public methods only for internal purposes
765
766 bool checkForDeath();
767
768#if defined (__WIN__)
769 HANDLE ipcSem() { return mIPCSem; }
770#elif defined (__OS2__)
771 HMTX ipcSem() { return mIPCSem; }
772#endif
773
774 HRESULT onDVDDriveChange();
775 HRESULT onFloppyDriveChange();
776 HRESULT onNetworkAdapterChange(INetworkAdapter *networkAdapter);
777 HRESULT onSerialPortChange(ISerialPort *serialPort);
778 HRESULT onParallelPortChange(IParallelPort *parallelPort);
779 HRESULT onVRDPServerChange();
780 HRESULT onUSBControllerChange();
781 HRESULT onUSBDeviceAttach (IUSBDevice *aDevice,
782 IVirtualBoxErrorInfo *aError);
783 HRESULT onUSBDeviceDetach (INPTR GUIDPARAM aId,
784 IVirtualBoxErrorInfo *aError);
785
786private:
787
788 struct SnapshotData
789 {
790 SnapshotData() : mLastState (MachineState_InvalidMachineState) {}
791
792 MachineState_T mLastState;
793
794 // used when taking snapshot
795 ComObjPtr <Snapshot> mSnapshot;
796 ComObjPtr <Progress> mServerProgress;
797 ComObjPtr <CombinedProgress> mCombinedProgress;
798
799 // used when saving state
800 Guid mProgressId;
801 Bstr mStateFilePath;
802 };
803
804 struct Uninit {
805 enum Reason { Unexpected, Abnormal, Normal };
806 };
807
808 struct Task;
809 struct TakeSnapshotTask;
810 struct DiscardSnapshotTask;
811 struct DiscardCurrentStateTask;
812
813 friend struct TakeSnapshotTask;
814 friend struct DiscardSnapshotTask;
815 friend struct DiscardCurrentStateTask;
816
817 void uninit (Uninit::Reason aReason);
818
819 HRESULT endSavingState (BOOL aSuccess);
820 HRESULT endTakingSnapshot (BOOL aSuccess);
821
822 typedef std::map <ComObjPtr <Machine>, MachineState_T> AffectedMachines;
823
824 void takeSnapshotHandler (TakeSnapshotTask &aTask);
825 void discardSnapshotHandler (DiscardSnapshotTask &aTask);
826 void discardCurrentStateHandler (DiscardCurrentStateTask &aTask);
827
828 HRESULT setMachineState (MachineState_T aMachineState);
829 HRESULT updateMachineStateOnClient();
830
831 SnapshotData mSnapshotData;
832
833 /** interprocess semaphore handle (id) for this machine */
834#if defined(__WIN__)
835 HANDLE mIPCSem;
836 Bstr mIPCSemName;
837#elif defined(__OS2__)
838 HMTX mIPCSem;
839 Bstr mIPCSemName;
840#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
841 int mIPCSem;
842#else
843# error "Port me!"
844#endif
845
846 static DECLCALLBACK(int) taskHandler (RTTHREAD thread, void *pvUser);
847};
848
849// SnapshotMachine class
850////////////////////////////////////////////////////////////////////////////////
851
852/**
853 * @note Notes on locking objects of this class:
854 * SnapshotMachine shares some data with the primary Machine instance (pointed
855 * to by the |mPeer| member). In order to provide data consistency it also
856 * shares its lock handle. This means that whenever you lock a SessionMachine
857 * instance using Auto[Reader]Lock or AutoMultiLock, the corresponding Machine
858 * instance is also locked in the same lock mode. Keep it in mind.
859 */
860class ATL_NO_VTABLE SnapshotMachine :
861 public VirtualBoxSupportTranslation <SnapshotMachine>,
862 public Machine
863{
864public:
865
866 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(SnapshotMachine)
867
868 DECLARE_NOT_AGGREGATABLE(SnapshotMachine)
869
870 DECLARE_PROTECT_FINAL_CONSTRUCT()
871
872 BEGIN_COM_MAP(SnapshotMachine)
873 COM_INTERFACE_ENTRY(ISupportErrorInfo)
874 COM_INTERFACE_ENTRY(IMachine)
875 END_COM_MAP()
876
877 NS_DECL_ISUPPORTS
878
879 DECLARE_EMPTY_CTOR_DTOR (SnapshotMachine)
880
881 HRESULT FinalConstruct();
882 void FinalRelease();
883
884 // public initializer/uninitializer for internal purposes only
885 HRESULT init (SessionMachine *aSessionMachine,
886 INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
887 HRESULT init (Machine *aMachine, CFGNODE aHWNode, CFGNODE aHDAsNode,
888 INPTR GUIDPARAM aSnapshotId, INPTR BSTR aStateFilePath);
889 void uninit();
890
891 // AutoLock::Lockable interface
892 AutoLock::Handle *lockHandle() const;
893
894 // public methods only for internal purposes
895
896 HRESULT onSnapshotChange (Snapshot *aSnapshot);
897
898private:
899
900 Guid mSnapshotId;
901};
902
903////////////////////////////////////////////////////////////////////////////////
904
905/**
906 * Returns a pointer to the Machine object for this machine that acts like a
907 * parent for complex machine data objects such as shared folders, etc.
908 *
909 * For primary Machine objects and for SnapshotMachine objects, returns this
910 * object's pointer itself. For SessoinMachine objects, returns the peer
911 * (primary) machine pointer.
912 */
913inline Machine *Machine::machine()
914{
915 if (mType == IsSessionMachine)
916 return mPeer;
917 return this;
918}
919
920COM_DECL_READONLY_ENUM_AND_COLLECTION (Machine)
921
922#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