VirtualBox

source: vbox/trunk/include/VBox/settings.h@ 75260

Last change on this file since 75260 was 75260, checked in by vboxsync, 6 years ago

Capturing: Build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 41.6 KB
Line 
1/** @file
2 * Settings file data structures.
3 *
4 * These structures are created by the settings file loader and filled with values
5 * copied from the raw XML data. This was all new with VirtualBox 3.1 and allows us
6 * to finally make the XML reader version-independent and read VirtualBox XML files
7 * from earlier and even newer (future) versions without requiring complicated,
8 * tedious and error-prone XSLT conversions.
9 *
10 * It is this file that defines all structures that map VirtualBox global and
11 * machine settings to XML files. These structures are used by the rest of Main,
12 * even though this header file does not require anything else in Main.
13 *
14 * Note: Headers in Main code have been tweaked to only declare the structures
15 * defined here so that this header need only be included from code files that
16 * actually use these structures.
17 */
18
19/*
20 * Copyright (C) 2007-2018 Oracle Corporation
21 *
22 * This file is part of VirtualBox Open Source Edition (OSE), as
23 * available from http://www.virtualbox.org. This file is free software;
24 * you can redistribute it and/or modify it under the terms of the GNU
25 * General Public License (GPL) as published by the Free Software
26 * Foundation, in version 2 as it comes in the "COPYING" file of the
27 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
28 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
29 *
30 * The contents of this file may alternatively be used under the terms
31 * of the Common Development and Distribution License Version 1.0
32 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
33 * VirtualBox OSE distribution, in which case the provisions of the
34 * CDDL are applicable instead of those of the GPL.
35 *
36 * You may elect to license modified versions of this file under the
37 * terms and conditions of either the GPL or the CDDL or both.
38 */
39
40#ifndef ___VBox_settings_h
41#define ___VBox_settings_h
42
43#include <iprt/time.h>
44
45#include "VBox/com/VirtualBox.h"
46
47#include <VBox/com/Guid.h>
48#include <VBox/com/string.h>
49
50#include <list>
51#include <map>
52#include <vector>
53
54/**
55 * Maximum depth of a medium tree, to prevent stack overflows.
56 * XPCOM has a relatively low stack size for its workers, and we have
57 * to avoid crashes due to exceeding the limit both on reading and
58 * writing config files.
59 */
60#define SETTINGS_MEDIUM_DEPTH_MAX 300
61
62/**
63 * Maximum depth of the snapshot tree, to prevent stack overflows.
64 * XPCOM has a relatively low stack size for its workers, and we have
65 * to avoid crashes due to exceeding the limit both on reading and
66 * writing config files. The bottleneck is reading config files with
67 * deep snapshot nesting, as libxml2 needs quite some stack space,
68 * so with the current stack size the margin isn't big.
69 */
70#define SETTINGS_SNAPSHOT_DEPTH_MAX 250
71
72namespace xml
73{
74 class ElementNode;
75}
76
77namespace settings
78{
79
80class ConfigFileError;
81
82////////////////////////////////////////////////////////////////////////////////
83//
84// Structures shared between Machine XML and VirtualBox.xml
85//
86////////////////////////////////////////////////////////////////////////////////
87
88typedef std::map<com::Utf8Str, com::Utf8Str> StringsMap;
89typedef std::list<com::Utf8Str> StringsList;
90
91/**
92 * USB device filter definition. This struct is used both in MainConfigFile
93 * (for global USB filters) and MachineConfigFile (for machine filters).
94 *
95 * NOTE: If you add any fields in here, you must update a) the constructor and b)
96 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
97 * your settings might never get saved.
98 */
99struct USBDeviceFilter
100{
101 USBDeviceFilter();
102
103 bool operator==(const USBDeviceFilter&u) const;
104
105 com::Utf8Str strName;
106 bool fActive;
107 com::Utf8Str strVendorId,
108 strProductId,
109 strRevision,
110 strManufacturer,
111 strProduct,
112 strSerialNumber,
113 strPort;
114 USBDeviceFilterAction_T action; // only used with host USB filters
115 com::Utf8Str strRemote; // irrelevant for host USB objects
116 uint32_t ulMaskedInterfaces; // irrelevant for host USB objects
117};
118
119typedef std::list<USBDeviceFilter> USBDeviceFiltersList;
120
121struct Medium;
122typedef std::list<Medium> MediaList;
123
124/**
125 * NOTE: If you add any fields in here, you must update a) the constructor and b)
126 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
127 * your settings might never get saved.
128 */
129struct Medium
130{
131 Medium();
132
133 bool operator==(const Medium &m) const;
134
135 com::Guid uuid;
136 com::Utf8Str strLocation;
137 com::Utf8Str strDescription;
138
139 // the following are for hard disks only:
140 com::Utf8Str strFormat;
141 bool fAutoReset; // optional, only for diffs, default is false
142 StringsMap properties;
143 MediumType_T hdType;
144
145 MediaList llChildren; // only used with hard disks
146
147 static const struct Medium Empty;
148};
149
150/**
151 * A media registry. Starting with VirtualBox 3.3, this can appear in both the
152 * VirtualBox.xml file as well as machine XML files with settings version 1.11
153 * or higher, so these lists are now in ConfigFileBase.
154 *
155 * NOTE: If you add any fields in here, you must update a) the constructor and b)
156 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
157 * your settings might never get saved.
158 */
159struct MediaRegistry
160{
161 bool operator==(const MediaRegistry &m) const;
162
163 MediaList llHardDisks,
164 llDvdImages,
165 llFloppyImages;
166};
167
168/**
169 * NOTE: If you add any fields in here, you must update a) the constructor and b)
170 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
171 * your settings might never get saved.
172 */
173struct NATRule
174{
175 NATRule();
176
177 bool operator==(const NATRule &r) const;
178
179 com::Utf8Str strName;
180 NATProtocol_T proto;
181 uint16_t u16HostPort;
182 com::Utf8Str strHostIP;
183 uint16_t u16GuestPort;
184 com::Utf8Str strGuestIP;
185};
186typedef std::map<com::Utf8Str, NATRule> NATRulesMap;
187
188struct NATHostLoopbackOffset
189{
190 NATHostLoopbackOffset();
191
192 bool operator==(const NATHostLoopbackOffset &o) const;
193
194 bool operator==(const com::Utf8Str& strAddr)
195 {
196 return strLoopbackHostAddress == strAddr;
197 }
198
199 bool operator==(uint32_t off)
200 {
201 return u32Offset == off;
202 }
203
204 /** Note: 128/8 is only acceptable */
205 com::Utf8Str strLoopbackHostAddress;
206 uint32_t u32Offset;
207};
208
209typedef std::list<NATHostLoopbackOffset> NATLoopbackOffsetList;
210
211typedef std::vector<uint8_t> IconBlob;
212
213/**
214 * Common base class for both MainConfigFile and MachineConfigFile
215 * which contains some common logic for both.
216 */
217class ConfigFileBase
218{
219public:
220 bool fileExists();
221
222 void copyBaseFrom(const ConfigFileBase &b);
223
224protected:
225 ConfigFileBase(const com::Utf8Str *pstrFilename);
226 /* Note: this copy constructor doesn't create a full copy of other, cause
227 * the file based stuff (xml doc) could not be copied. */
228 ConfigFileBase(const ConfigFileBase &other);
229
230 ~ConfigFileBase();
231
232 typedef enum {Error, HardDisk, DVDImage, FloppyImage} MediaType;
233
234 static const char *stringifyMediaType(MediaType t);
235 SettingsVersion_T parseVersion(const com::Utf8Str &strVersion,
236 const xml::ElementNode *pElm);
237 void parseUUID(com::Guid &guid,
238 const com::Utf8Str &strUUID,
239 const xml::ElementNode *pElm) const;
240 void parseTimestamp(RTTIMESPEC &timestamp,
241 const com::Utf8Str &str,
242 const xml::ElementNode *pElm) const;
243 void parseBase64(IconBlob &binary,
244 const com::Utf8Str &str,
245 const xml::ElementNode *pElm) const;
246 com::Utf8Str stringifyTimestamp(const RTTIMESPEC &tm) const;
247 void toBase64(com::Utf8Str &str,
248 const IconBlob &binary) const;
249
250 void readExtraData(const xml::ElementNode &elmExtraData,
251 StringsMap &map);
252 void readUSBDeviceFilters(const xml::ElementNode &elmDeviceFilters,
253 USBDeviceFiltersList &ll);
254 void readMediumOne(MediaType t, const xml::ElementNode &elmMedium, Medium &med);
255 void readMedium(MediaType t, uint32_t depth, const xml::ElementNode &elmMedium, Medium &med);
256 void readMediaRegistry(const xml::ElementNode &elmMediaRegistry, MediaRegistry &mr);
257 void readNATForwardRulesMap(const xml::ElementNode &elmParent, NATRulesMap &mapRules);
258 void readNATLoopbacks(const xml::ElementNode &elmParent, NATLoopbackOffsetList &llLoopBacks);
259
260 void setVersionAttribute(xml::ElementNode &elm);
261 void specialBackupIfFirstBump();
262 void createStubDocument();
263
264 void buildExtraData(xml::ElementNode &elmParent, const StringsMap &me);
265 void buildUSBDeviceFilters(xml::ElementNode &elmParent,
266 const USBDeviceFiltersList &ll,
267 bool fHostMode);
268 void buildMedium(MediaType t,
269 uint32_t depth,
270 xml::ElementNode &elmMedium,
271 const Medium &mdm);
272 void buildMediaRegistry(xml::ElementNode &elmParent,
273 const MediaRegistry &mr);
274 void buildNATForwardRulesMap(xml::ElementNode &elmParent, const NATRulesMap &mapRules);
275 void buildNATLoopbacks(xml::ElementNode &elmParent, const NATLoopbackOffsetList &natLoopbackList);
276 void clearDocument();
277
278 struct Data;
279 Data *m;
280
281 friend class ConfigFileError;
282};
283
284////////////////////////////////////////////////////////////////////////////////
285//
286// VirtualBox.xml structures
287//
288////////////////////////////////////////////////////////////////////////////////
289
290struct USBDeviceSource
291{
292 com::Utf8Str strName;
293 com::Utf8Str strBackend;
294 com::Utf8Str strAddress;
295 StringsMap properties;
296};
297
298typedef std::list<USBDeviceSource> USBDeviceSourcesList;
299
300struct Host
301{
302 USBDeviceFiltersList llUSBDeviceFilters;
303 USBDeviceSourcesList llUSBDeviceSources;
304};
305
306struct SystemProperties
307{
308 SystemProperties();
309
310 com::Utf8Str strDefaultMachineFolder;
311 com::Utf8Str strDefaultHardDiskFolder;
312 com::Utf8Str strDefaultHardDiskFormat;
313 com::Utf8Str strVRDEAuthLibrary;
314 com::Utf8Str strWebServiceAuthLibrary;
315 com::Utf8Str strDefaultVRDEExtPack;
316 com::Utf8Str strAutostartDatabasePath;
317 com::Utf8Str strDefaultAdditionsISO;
318 com::Utf8Str strDefaultFrontend;
319 com::Utf8Str strLoggingLevel;
320 com::Utf8Str strProxyUrl;
321 uint32_t uProxyMode; /**< ProxyMode_T */
322 uint32_t uLogHistoryCount;
323 bool fExclusiveHwVirt;
324};
325
326struct MachineRegistryEntry
327{
328 com::Guid uuid;
329 com::Utf8Str strSettingsFile;
330};
331
332typedef std::list<MachineRegistryEntry> MachinesRegistry;
333
334struct DhcpOptValue
335{
336 DhcpOptValue();
337 DhcpOptValue(const com::Utf8Str &aText, DhcpOptEncoding_T aEncoding = DhcpOptEncoding_Legacy);
338
339 com::Utf8Str text;
340 DhcpOptEncoding_T encoding;
341};
342
343typedef std::map<DhcpOpt_T, DhcpOptValue> DhcpOptionMap;
344typedef DhcpOptionMap::value_type DhcpOptValuePair;
345typedef DhcpOptionMap::iterator DhcpOptIterator;
346typedef DhcpOptionMap::const_iterator DhcpOptConstIterator;
347
348typedef struct VmNameSlotKey
349{
350 VmNameSlotKey(const com::Utf8Str& aVmName, LONG aSlot);
351
352 bool operator<(const VmNameSlotKey& that) const;
353
354 const com::Utf8Str VmName;
355 LONG Slot;
356} VmNameSlotKey;
357
358typedef std::map<VmNameSlotKey, DhcpOptionMap> VmSlot2OptionsMap;
359typedef VmSlot2OptionsMap::value_type VmSlot2OptionsPair;
360typedef VmSlot2OptionsMap::iterator VmSlot2OptionsIterator;
361typedef VmSlot2OptionsMap::const_iterator VmSlot2OptionsConstIterator;
362
363struct DHCPServer
364{
365 DHCPServer();
366
367 com::Utf8Str strNetworkName,
368 strIPAddress,
369 strIPLower,
370 strIPUpper;
371 bool fEnabled;
372 DhcpOptionMap GlobalDhcpOptions;
373 VmSlot2OptionsMap VmSlot2OptionsM;
374};
375
376typedef std::list<DHCPServer> DHCPServersList;
377
378
379/**
380 * NAT Networking settings (NAT service).
381 */
382struct NATNetwork
383{
384 NATNetwork();
385
386 com::Utf8Str strNetworkName;
387 com::Utf8Str strIPv4NetworkCidr;
388 com::Utf8Str strIPv6Prefix;
389 bool fEnabled;
390 bool fIPv6Enabled;
391 bool fAdvertiseDefaultIPv6Route;
392 bool fNeedDhcpServer;
393 uint32_t u32HostLoopback6Offset;
394 NATLoopbackOffsetList llHostLoopbackOffsetList;
395 NATRulesMap mapPortForwardRules4;
396 NATRulesMap mapPortForwardRules6;
397};
398
399typedef std::list<NATNetwork> NATNetworksList;
400
401
402class MainConfigFile : public ConfigFileBase
403{
404public:
405 MainConfigFile(const com::Utf8Str *pstrFilename);
406
407 void readMachineRegistry(const xml::ElementNode &elmMachineRegistry);
408 void readDHCPServers(const xml::ElementNode &elmDHCPServers);
409 void readDhcpOptions(DhcpOptionMap& map, const xml::ElementNode& options);
410 void readNATNetworks(const xml::ElementNode &elmNATNetworks);
411
412 void write(const com::Utf8Str strFilename);
413
414 Host host;
415 SystemProperties systemProperties;
416 MediaRegistry mediaRegistry;
417 MachinesRegistry llMachines;
418 DHCPServersList llDhcpServers;
419 NATNetworksList llNATNetworks;
420 StringsMap mapExtraDataItems;
421
422private:
423 void bumpSettingsVersionIfNeeded();
424 void buildUSBDeviceSources(xml::ElementNode &elmParent, const USBDeviceSourcesList &ll);
425 void readUSBDeviceSources(const xml::ElementNode &elmDeviceSources, USBDeviceSourcesList &ll);
426 bool convertGuiProxySettings(const com::Utf8Str &strUIProxySettings);
427};
428
429////////////////////////////////////////////////////////////////////////////////
430//
431// Machine XML structures
432//
433////////////////////////////////////////////////////////////////////////////////
434
435/**
436 * NOTE: If you add any fields in here, you must update a) the constructor and b)
437 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
438 * your settings might never get saved.
439 */
440struct VRDESettings
441{
442 VRDESettings();
443
444 bool areDefaultSettings(SettingsVersion_T sv) const;
445
446 bool operator==(const VRDESettings& v) const;
447
448 bool fEnabled;
449 AuthType_T authType;
450 uint32_t ulAuthTimeout;
451 com::Utf8Str strAuthLibrary;
452 bool fAllowMultiConnection,
453 fReuseSingleConnection;
454 com::Utf8Str strVrdeExtPack;
455 StringsMap mapProperties;
456};
457
458/**
459 * NOTE: If you add any fields in here, you must update a) the constructor and b)
460 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
461 * your settings might never get saved.
462 */
463struct BIOSSettings
464{
465 BIOSSettings();
466
467 bool areDefaultSettings() const;
468
469 bool operator==(const BIOSSettings &d) const;
470
471 bool fACPIEnabled,
472 fIOAPICEnabled,
473 fLogoFadeIn,
474 fLogoFadeOut,
475 fPXEDebugEnabled;
476 uint32_t ulLogoDisplayTime;
477 BIOSBootMenuMode_T biosBootMenuMode;
478 APICMode_T apicMode; // requires settings version 1.16 (VirtualBox 5.1)
479 int64_t llTimeOffset;
480 com::Utf8Str strLogoImagePath;
481};
482
483/** List for keeping a capturing feature list. */
484typedef std::map<CaptureFeature_T, bool> CaptureFeatureMap;
485
486struct CaptureScreenSettings
487{
488 CaptureScreenSettings();
489
490 virtual ~CaptureScreenSettings();
491
492 void applyDefaults(void);
493
494 bool areDefaultSettings(void) const;
495
496 bool isFeatureEnabled(CaptureFeature_T enmFeature) const;
497
498 bool operator==(const CaptureScreenSettings &d) const;
499
500 bool fEnabled; // requires settings version 1.14 (VirtualBox 4.3)
501 CaptureDestination_T enmDest; // new since VirtualBox 6.0.
502 CaptureFeatureMap featureMap; // new since VirtualBox 6.0.
503 uint32_t ulMaxTimeS; // requires settings version 1.14 (VirtualBox 4.3)
504 com::Utf8Str strOptions; // new since VirtualBox 5.2.
505
506 struct Audio
507 {
508 Audio()
509 : enmAudioCodec(CaptureAudioCodec_Opus)
510 , uHz(22050)
511 , cBits(16)
512 , cChannels(2) { }
513
514 /** The audio codec type to use. */
515 CaptureAudioCodec_T enmAudioCodec; // new since VirtualBox 6.0.
516 /** Hz rate. */
517 uint16_t uHz; // new since VirtualBox 6.0.
518 /** Bits per sample. */
519 uint8_t cBits; // new since VirtualBox 6.0.
520 /** Number of audio channels. */
521 uint8_t cChannels; // new since VirtualBox 6.0.
522 } Audio;
523
524 struct Video
525 {
526 Video()
527 : enmCodec(CaptureVideoCodec_VP8)
528 , ulWidth(1024)
529 , ulHeight(768)
530 , ulRate(512)
531 , ulFPS(25) { }
532
533 CaptureVideoCodec_T enmCodec; // new since VirtualBox 6.0.
534 uint32_t ulWidth; // requires settings version 1.14 (VirtualBox 4.3)
535 uint32_t ulHeight; // requires settings version 1.14 (VirtualBox 4.3)
536 uint32_t ulRate; // requires settings version 1.14 (VirtualBox 4.3)
537 uint32_t ulFPS; // requires settings version 1.14 (VirtualBox 4.3)
538 } Video;
539
540 struct File
541 {
542 File()
543 : ulMaxSizeMB(0) { }
544
545 uint32_t ulMaxSizeMB; // requires settings version 1.14 (VirtualBox 4.3)
546 com::Utf8Str strName; // requires settings version 1.14 (VirtualBox 4.3)
547 } File;
548};
549
550/** Map for keeping settings per virtual screen. */
551typedef std::map<unsigned long, CaptureScreenSettings> CaptureScreenMap;
552
553/**
554 * NOTE: If you add any fields in here, you must update a) the constructor and b)
555 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
556 * your settings might never get saved.
557 */
558struct CaptureSettings
559{
560 CaptureSettings();
561
562 void applyDefaults(void);
563
564 bool areDefaultSettings(void) const;
565
566 bool operator==(const CaptureSettings &d) const;
567
568 bool fEnabled; // requires settings version 1.14 (VirtualBox 4.3)
569 CaptureScreenMap mapScreens;
570};
571
572/**
573 * NOTE: If you add any fields in here, you must update a) the constructor and b)
574 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
575 * your settings might never get saved.
576 */
577struct USBController
578{
579 USBController();
580
581 bool operator==(const USBController &u) const;
582
583 com::Utf8Str strName;
584 USBControllerType_T enmType;
585};
586
587typedef std::list<USBController> USBControllerList;
588
589struct USB
590{
591 USB();
592
593 bool operator==(const USB &u) const;
594
595 /** List of USB controllers present. */
596 USBControllerList llUSBControllers;
597 /** List of USB device filters. */
598 USBDeviceFiltersList llDeviceFilters;
599};
600
601struct NAT
602{
603 NAT();
604
605 bool areDNSDefaultSettings() const;
606 bool areAliasDefaultSettings() const;
607 bool areTFTPDefaultSettings() const;
608 bool areDefaultSettings() const;
609
610 bool operator==(const NAT &n) const;
611
612 com::Utf8Str strNetwork;
613 com::Utf8Str strBindIP;
614 uint32_t u32Mtu;
615 uint32_t u32SockRcv;
616 uint32_t u32SockSnd;
617 uint32_t u32TcpRcv;
618 uint32_t u32TcpSnd;
619 com::Utf8Str strTFTPPrefix;
620 com::Utf8Str strTFTPBootFile;
621 com::Utf8Str strTFTPNextServer;
622 bool fDNSPassDomain;
623 bool fDNSProxy;
624 bool fDNSUseHostResolver;
625 bool fAliasLog;
626 bool fAliasProxyOnly;
627 bool fAliasUseSamePorts;
628 NATRulesMap mapRules;
629};
630
631/**
632 * NOTE: If you add any fields in here, you must update a) the constructor and b)
633 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
634 * your settings might never get saved.
635 */
636struct NetworkAdapter
637{
638 NetworkAdapter();
639
640 bool areGenericDriverDefaultSettings() const;
641 bool areDefaultSettings(SettingsVersion_T sv) const;
642 bool areDisabledDefaultSettings() const;
643
644 bool operator==(const NetworkAdapter &n) const;
645
646 uint32_t ulSlot;
647
648 NetworkAdapterType_T type;
649 bool fEnabled;
650 com::Utf8Str strMACAddress;
651 bool fCableConnected;
652 uint32_t ulLineSpeed;
653 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
654 bool fTraceEnabled;
655 com::Utf8Str strTraceFile;
656
657 NetworkAttachmentType_T mode;
658 NAT nat;
659 com::Utf8Str strBridgedName;
660 com::Utf8Str strHostOnlyName;
661 com::Utf8Str strInternalNetworkName;
662 com::Utf8Str strGenericDriver;
663 StringsMap genericProperties;
664 com::Utf8Str strNATNetworkName;
665 uint32_t ulBootPriority;
666 com::Utf8Str strBandwidthGroup; // requires settings version 1.13 (VirtualBox 4.2)
667};
668
669typedef std::list<NetworkAdapter> NetworkAdaptersList;
670
671/**
672 * NOTE: If you add any fields in here, you must update a) the constructor and b)
673 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
674 * your settings might never get saved.
675 */
676struct SerialPort
677{
678 SerialPort();
679
680 bool operator==(const SerialPort &n) const;
681
682 uint32_t ulSlot;
683
684 bool fEnabled;
685 uint32_t ulIOBase;
686 uint32_t ulIRQ;
687 PortMode_T portMode;
688 com::Utf8Str strPath;
689 bool fServer;
690 UartType_T uartType;
691};
692
693typedef std::list<SerialPort> SerialPortsList;
694
695/**
696 * NOTE: If you add any fields in here, you must update a) the constructor and b)
697 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
698 * your settings might never get saved.
699 */
700struct ParallelPort
701{
702 ParallelPort();
703
704 bool operator==(const ParallelPort &d) const;
705
706 uint32_t ulSlot;
707
708 bool fEnabled;
709 uint32_t ulIOBase;
710 uint32_t ulIRQ;
711 com::Utf8Str strPath;
712};
713
714typedef std::list<ParallelPort> ParallelPortsList;
715
716/**
717 * NOTE: If you add any fields in here, you must update a) the constructor and b)
718 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
719 * your settings might never get saved.
720 */
721struct AudioAdapter
722{
723 AudioAdapter();
724
725 bool areDefaultSettings(SettingsVersion_T sv) const;
726
727 bool operator==(const AudioAdapter &a) const;
728
729 bool fEnabled;
730 bool fEnabledIn;
731 bool fEnabledOut;
732 AudioControllerType_T controllerType;
733 AudioCodecType_T codecType;
734 AudioDriverType_T driverType;
735 settings::StringsMap properties;
736};
737
738/**
739 * NOTE: If you add any fields in here, you must update a) the constructor and b)
740 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
741 * your settings might never get saved.
742 */
743struct SharedFolder
744{
745 SharedFolder();
746
747 bool operator==(const SharedFolder &a) const;
748
749 com::Utf8Str strName,
750 strHostPath;
751 bool fWritable;
752 bool fAutoMount;
753};
754
755typedef std::list<SharedFolder> SharedFoldersList;
756
757/**
758 * NOTE: If you add any fields in here, you must update a) the constructor and b)
759 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
760 * your settings might never get saved.
761 */
762struct GuestProperty
763{
764 GuestProperty();
765
766 bool operator==(const GuestProperty &g) const;
767
768 com::Utf8Str strName,
769 strValue;
770 uint64_t timestamp;
771 com::Utf8Str strFlags;
772};
773
774typedef std::list<GuestProperty> GuestPropertiesList;
775
776typedef std::map<uint32_t, DeviceType_T> BootOrderMap;
777
778/**
779 * NOTE: If you add any fields in here, you must update a) the constructor and b)
780 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
781 * your settings might never get saved.
782 */
783struct CpuIdLeaf
784{
785 CpuIdLeaf();
786
787 bool operator==(const CpuIdLeaf &c) const;
788
789 uint32_t idx;
790 uint32_t idxSub;
791 uint32_t uEax;
792 uint32_t uEbx;
793 uint32_t uEcx;
794 uint32_t uEdx;
795};
796
797typedef std::list<CpuIdLeaf> CpuIdLeafsList;
798
799/**
800 * NOTE: If you add any fields in here, you must update a) the constructor and b)
801 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
802 * your settings might never get saved.
803 */
804struct Cpu
805{
806 Cpu();
807
808 bool operator==(const Cpu &c) const;
809
810 uint32_t ulId;
811};
812
813typedef std::list<Cpu> CpuList;
814
815/**
816 * NOTE: If you add any fields in here, you must update a) the constructor and b)
817 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
818 * your settings might never get saved.
819 */
820struct BandwidthGroup
821{
822 BandwidthGroup();
823
824 bool operator==(const BandwidthGroup &i) const;
825
826 com::Utf8Str strName;
827 uint64_t cMaxBytesPerSec;
828 BandwidthGroupType_T enmType;
829};
830
831typedef std::list<BandwidthGroup> BandwidthGroupList;
832
833/**
834 * NOTE: If you add any fields in here, you must update a) the constructor and b)
835 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
836 * your settings might never get saved.
837 */
838struct IOSettings
839{
840 IOSettings();
841
842 bool areIOCacheDefaultSettings() const;
843 bool areDefaultSettings() const;
844
845 bool operator==(const IOSettings &i) const;
846
847 bool fIOCacheEnabled;
848 uint32_t ulIOCacheSize;
849 BandwidthGroupList llBandwidthGroups;
850};
851
852/**
853 * NOTE: If you add any fields in here, you must update a) the constructor and b)
854 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
855 * your settings might never get saved.
856 */
857struct HostPCIDeviceAttachment
858{
859 HostPCIDeviceAttachment();
860
861 bool operator==(const HostPCIDeviceAttachment &a) const;
862
863 com::Utf8Str strDeviceName;
864 uint32_t uHostAddress;
865 uint32_t uGuestAddress;
866};
867
868typedef std::list<HostPCIDeviceAttachment> HostPCIDeviceAttachmentList;
869
870/**
871 * A device attached to a storage controller. This can either be a
872 * hard disk or a DVD drive or a floppy drive and also specifies
873 * which medium is "in" the drive; as a result, this is a combination
874 * of the Main IMedium and IMediumAttachment interfaces.
875 *
876 * NOTE: If you add any fields in here, you must update a) the constructor and b)
877 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
878 * your settings might never get saved.
879 */
880struct AttachedDevice
881{
882 AttachedDevice();
883
884 bool operator==(const AttachedDevice &a) const;
885
886 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
887
888 // DVDs can be in pass-through mode:
889 bool fPassThrough;
890
891 // Whether guest-triggered eject of DVDs will keep the medium in the
892 // VM config or not:
893 bool fTempEject;
894
895 // Whether the medium is non-rotational:
896 bool fNonRotational;
897
898 // Whether the medium supports discarding unused blocks:
899 bool fDiscard;
900
901 // Whether the medium is hot-pluggable:
902 bool fHotPluggable;
903
904 int32_t lPort;
905 int32_t lDevice;
906
907 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
908 // this is its UUID; it depends on deviceType which media registry this then needs to
909 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
910 com::Guid uuid;
911
912 // for DVDs and floppies, the attachment can also be a host device:
913 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
914
915 // Bandwidth group the device is attached to.
916 com::Utf8Str strBwGroup;
917};
918
919typedef std::list<AttachedDevice> AttachedDevicesList;
920
921/**
922 * NOTE: If you add any fields in here, you must update a) the constructor and b)
923 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
924 * your settings might never get saved.
925 */
926struct StorageController
927{
928 StorageController();
929
930 bool operator==(const StorageController &s) const;
931
932 com::Utf8Str strName;
933 StorageBus_T storageBus; // _SATA, _SCSI, _IDE, _SAS
934 StorageControllerType_T controllerType;
935 uint32_t ulPortCount;
936 uint32_t ulInstance;
937 bool fUseHostIOCache;
938 bool fBootable;
939
940 // only for when controllerType == StorageControllerType_IntelAhci:
941 int32_t lIDE0MasterEmulationPort,
942 lIDE0SlaveEmulationPort,
943 lIDE1MasterEmulationPort,
944 lIDE1SlaveEmulationPort;
945
946 AttachedDevicesList llAttachedDevices;
947};
948
949typedef std::list<StorageController> StorageControllersList;
950
951/**
952 * We wrap the storage controllers list into an extra struct so we can
953 * use an undefined struct without needing std::list<> in all the headers.
954 *
955 * NOTE: If you add any fields in here, you must update a) the constructor and b)
956 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
957 * your settings might never get saved.
958 */
959struct Storage
960{
961 bool operator==(const Storage &s) const;
962
963 StorageControllersList llStorageControllers;
964};
965
966/**
967 * Representation of Machine hardware; this is used in the MachineConfigFile.hardwareMachine
968 * field.
969 *
970 * NOTE: If you add any fields in here, you must update a) the constructor and b)
971 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
972 * your settings might never get saved.
973 */
974struct Hardware
975{
976 Hardware();
977
978 bool areParavirtDefaultSettings(SettingsVersion_T sv) const;
979 bool areBootOrderDefaultSettings() const;
980 bool areDisplayDefaultSettings() const;
981 bool areAllNetworkAdaptersDefaultSettings(SettingsVersion_T sv) const;
982
983 bool operator==(const Hardware&) const;
984
985 com::Utf8Str strVersion; // hardware version, optional
986 com::Guid uuid; // hardware uuid, optional (null).
987
988 bool fHardwareVirt,
989 fNestedPaging,
990 fLargePages,
991 fVPID,
992 fUnrestrictedExecution,
993 fHardwareVirtForce,
994 fUseNativeApi,
995 fSyntheticCpu,
996 fTripleFaultReset,
997 fPAE,
998 fAPIC, // requires settings version 1.16 (VirtualBox 5.1)
999 fX2APIC; // requires settings version 1.16 (VirtualBox 5.1)
1000 bool fIBPBOnVMExit; //< added out of cycle, after 1.16 was out.
1001 bool fIBPBOnVMEntry; //< added out of cycle, after 1.16 was out.
1002 bool fSpecCtrl; //< added out of cycle, after 1.16 was out.
1003 bool fSpecCtrlByHost; //< added out of cycle, after 1.16 was out.
1004 bool fNestedHWVirt; //< requires settings version 1.17 (VirtualBox 6.0)
1005 typedef enum LongModeType { LongMode_Enabled, LongMode_Disabled, LongMode_Legacy } LongModeType;
1006 LongModeType enmLongMode;
1007 uint32_t cCPUs;
1008 bool fCpuHotPlug; // requires settings version 1.10 (VirtualBox 3.2)
1009 CpuList llCpus; // requires settings version 1.10 (VirtualBox 3.2)
1010 bool fHPETEnabled; // requires settings version 1.10 (VirtualBox 3.2)
1011 uint32_t ulCpuExecutionCap; // requires settings version 1.11 (VirtualBox 3.3)
1012 uint32_t uCpuIdPortabilityLevel; // requires settings version 1.15 (VirtualBox 5.0)
1013 com::Utf8Str strCpuProfile; // requires settings version 1.16 (VirtualBox 5.1)
1014
1015 CpuIdLeafsList llCpuIdLeafs;
1016
1017 uint32_t ulMemorySizeMB;
1018
1019 BootOrderMap mapBootOrder; // item 0 has highest priority
1020
1021 GraphicsControllerType_T graphicsControllerType;
1022 uint32_t ulVRAMSizeMB;
1023 uint32_t cMonitors;
1024 bool fAccelerate3D,
1025 fAccelerate2DVideo; // requires settings version 1.8 (VirtualBox 3.1)
1026
1027 FirmwareType_T firmwareType; // requires settings version 1.9 (VirtualBox 3.1)
1028
1029 PointingHIDType_T pointingHIDType; // requires settings version 1.10 (VirtualBox 3.2)
1030 KeyboardHIDType_T keyboardHIDType; // requires settings version 1.10 (VirtualBox 3.2)
1031
1032 ChipsetType_T chipsetType; // requires settings version 1.11 (VirtualBox 4.0)
1033 ParavirtProvider_T paravirtProvider; // requires settings version 1.15 (VirtualBox 4.4)
1034 com::Utf8Str strParavirtDebug; // requires settings version 1.16 (VirtualBox 5.1)
1035
1036 bool fEmulatedUSBCardReader; // 1.12 (VirtualBox 4.1)
1037
1038 VRDESettings vrdeSettings;
1039
1040 BIOSSettings biosSettings;
1041 CaptureSettings captureSettings;
1042 USB usbSettings;
1043 NetworkAdaptersList llNetworkAdapters;
1044 SerialPortsList llSerialPorts;
1045 ParallelPortsList llParallelPorts;
1046 AudioAdapter audioAdapter;
1047 Storage storage;
1048
1049 // technically these two have no business in the hardware section, but for some
1050 // clever reason <Hardware> is where they are in the XML....
1051 SharedFoldersList llSharedFolders;
1052 ClipboardMode_T clipboardMode;
1053 DnDMode_T dndMode;
1054
1055 uint32_t ulMemoryBalloonSize;
1056 bool fPageFusionEnabled;
1057
1058 GuestPropertiesList llGuestProperties;
1059
1060 IOSettings ioSettings; // requires settings version 1.10 (VirtualBox 3.2)
1061 HostPCIDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
1062
1063 com::Utf8Str strDefaultFrontend; // requires settings version 1.14 (VirtualBox 4.3)
1064};
1065
1066/**
1067 * Settings that has to do with debugging.
1068 */
1069struct Debugging
1070{
1071 Debugging();
1072
1073 bool areDefaultSettings() const;
1074
1075 bool operator==(const Debugging &rOther) const;
1076
1077 bool fTracingEnabled;
1078 bool fAllowTracingToAccessVM;
1079 com::Utf8Str strTracingConfig;
1080};
1081
1082/**
1083 * Settings that has to do with autostart.
1084 */
1085struct Autostart
1086{
1087 Autostart();
1088
1089 bool areDefaultSettings() const;
1090
1091 bool operator==(const Autostart &rOther) const;
1092
1093 bool fAutostartEnabled;
1094 uint32_t uAutostartDelay;
1095 AutostopType_T enmAutostopType;
1096};
1097
1098struct Snapshot;
1099typedef std::list<Snapshot> SnapshotsList;
1100
1101/**
1102 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1103 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1104 * your settings might never get saved.
1105 */
1106struct Snapshot
1107{
1108 Snapshot();
1109
1110 bool operator==(const Snapshot &s) const;
1111
1112 com::Guid uuid;
1113 com::Utf8Str strName,
1114 strDescription; // optional
1115 RTTIMESPEC timestamp;
1116
1117 com::Utf8Str strStateFile; // for online snapshots only
1118
1119 Hardware hardware;
1120
1121 Debugging debugging;
1122 Autostart autostart;
1123
1124 SnapshotsList llChildSnapshots;
1125
1126 static const struct Snapshot Empty;
1127};
1128
1129/**
1130 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1131 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1132 * your settings might never get saved.
1133 */
1134struct MachineUserData
1135{
1136 MachineUserData();
1137
1138 bool operator==(const MachineUserData &c) const;
1139
1140 com::Utf8Str strName;
1141 bool fDirectoryIncludesUUID;
1142 bool fNameSync;
1143 com::Utf8Str strDescription;
1144 StringsList llGroups;
1145 com::Utf8Str strOsType;
1146 com::Utf8Str strSnapshotFolder;
1147 bool fTeleporterEnabled;
1148 uint32_t uTeleporterPort;
1149 com::Utf8Str strTeleporterAddress;
1150 com::Utf8Str strTeleporterPassword;
1151 FaultToleranceState_T enmFaultToleranceState;
1152 uint32_t uFaultTolerancePort;
1153 com::Utf8Str strFaultToleranceAddress;
1154 com::Utf8Str strFaultTolerancePassword;
1155 uint32_t uFaultToleranceInterval;
1156 bool fRTCUseUTC;
1157 IconBlob ovIcon;
1158 com::Utf8Str strVMPriority;
1159};
1160
1161
1162/**
1163 * MachineConfigFile represents an XML machine configuration. All the machine settings
1164 * that go out to the XML (or are read from it) are in here.
1165 *
1166 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1167 * the operator== which is used by Machine::saveSettings(), or otherwise your settings
1168 * might never get saved.
1169 */
1170class MachineConfigFile : public ConfigFileBase
1171{
1172public:
1173 com::Guid uuid;
1174
1175 MachineUserData machineUserData;
1176
1177 com::Utf8Str strStateFile;
1178 bool fCurrentStateModified; // optional, default is true
1179 RTTIMESPEC timeLastStateChange; // optional, defaults to now
1180 bool fAborted; // optional, default is false
1181
1182 com::Guid uuidCurrentSnapshot;
1183
1184 Hardware hardwareMachine;
1185 MediaRegistry mediaRegistry;
1186 Debugging debugging;
1187 Autostart autostart;
1188
1189 StringsMap mapExtraDataItems;
1190
1191 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
1192
1193 MachineConfigFile(const com::Utf8Str *pstrFilename);
1194
1195 bool operator==(const MachineConfigFile &m) const;
1196
1197 bool canHaveOwnMediaRegistry() const;
1198
1199 void importMachineXML(const xml::ElementNode &elmMachine);
1200
1201 void write(const com::Utf8Str &strFilename);
1202
1203 enum
1204 {
1205 BuildMachineXML_IncludeSnapshots = 0x01,
1206 BuildMachineXML_WriteVBoxVersionAttribute = 0x02,
1207 BuildMachineXML_SkipRemovableMedia = 0x04,
1208 BuildMachineXML_MediaRegistry = 0x08,
1209 BuildMachineXML_SuppressSavedState = 0x10
1210 };
1211 void buildMachineXML(xml::ElementNode &elmMachine,
1212 uint32_t fl,
1213 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1214
1215 static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T drv);
1216 static AudioDriverType_T getHostDefaultAudioDriver();
1217
1218private:
1219 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
1220 void readAttachedNetworkMode(const xml::ElementNode &pelmMode, bool fEnabled, NetworkAdapter &nic);
1221 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
1222 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
1223 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
1224 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
1225 void readAudioAdapter(const xml::ElementNode &elmAudioAdapter, AudioAdapter &aa);
1226 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
1227 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
1228 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw);
1229 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
1230 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
1231 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
1232 void readTeleporter(const xml::ElementNode *pElmTeleporter, MachineUserData *pUserData);
1233 void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
1234 void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
1235 void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
1236 bool readSnapshot(const com::Guid &curSnapshotUuid, uint32_t depth, const xml::ElementNode &elmSnapshot, Snapshot &snap);
1237 void convertOldOSType_pre1_5(com::Utf8Str &str);
1238 void readMachine(const xml::ElementNode &elmMachine);
1239
1240 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, uint32_t fl, std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1241 void buildNetworkXML(NetworkAttachmentType_T mode, bool fEnabled, xml::ElementNode &elmParent, const NetworkAdapter &nic);
1242 void buildStorageControllersXML(xml::ElementNode &elmParent,
1243 const Storage &st,
1244 bool fSkipRemovableMedia,
1245 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1246 void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
1247 void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
1248 void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
1249 void buildSnapshotXML(uint32_t depth, xml::ElementNode &elmParent, const Snapshot &snap);
1250
1251 void bumpSettingsVersionIfNeeded();
1252};
1253
1254} // namespace settings
1255
1256
1257#endif /* ___VBox_settings_h */
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