VirtualBox

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

Last change on this file since 55675 was 55675, checked in by vboxsync, 10 years ago

Main,VBoxManage,Settings: Changed the boolean syntheticCPU setting into a 32-bit CPUIDPortabilityLevel property.

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