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