VirtualBox

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

Last change on this file since 59012 was 58437, checked in by vboxsync, 9 years ago

Main: Added paravirtdebug options.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 44.7 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 codecType(AudioCodecType_STAC9700),
699 driverType(AudioDriverType_Null)
700 {}
701
702 bool operator==(const AudioAdapter &a) const
703 {
704 return (this == &a)
705 || ( (fEnabled == a.fEnabled)
706 && (controllerType == a.controllerType)
707 && (codecType == a.codecType)
708 && (driverType == a.driverType)
709 && (properties == a.properties)
710 );
711 }
712
713 bool fEnabled;
714 AudioControllerType_T controllerType;
715 AudioCodecType_T codecType;
716 AudioDriverType_T driverType;
717 settings::StringsMap properties;
718};
719
720/**
721 * NOTE: If you add any fields in here, you must update a) the constructor and b)
722 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
723 * your settings might never get saved.
724 */
725struct SharedFolder
726{
727 SharedFolder()
728 : fWritable(false)
729 , fAutoMount(false)
730 {}
731
732 bool operator==(const SharedFolder &a) const;
733
734 com::Utf8Str strName,
735 strHostPath;
736 bool fWritable;
737 bool fAutoMount;
738};
739typedef std::list<SharedFolder> SharedFoldersList;
740
741/**
742 * NOTE: If you add any fields in here, you must update a) the constructor and b)
743 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
744 * your settings might never get saved.
745 */
746struct GuestProperty
747{
748 GuestProperty()
749 : timestamp(0)
750 {};
751
752 bool operator==(const GuestProperty &g) const;
753
754 com::Utf8Str strName,
755 strValue;
756 uint64_t timestamp;
757 com::Utf8Str strFlags;
758};
759typedef std::list<GuestProperty> GuestPropertiesList;
760
761typedef std::map<uint32_t, DeviceType_T> BootOrderMap;
762
763/**
764 * NOTE: If you add any fields in here, you must update a) the constructor and b)
765 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
766 * your settings might never get saved.
767 */
768struct CpuIdLeaf
769{
770 CpuIdLeaf()
771 : ulId(UINT32_MAX),
772 ulEax(0),
773 ulEbx(0),
774 ulEcx(0),
775 ulEdx(0)
776 {}
777
778 bool operator==(const CpuIdLeaf &c) const
779 {
780 return ( (this == &c)
781 || ( (ulId == c.ulId)
782 && (ulEax == c.ulEax)
783 && (ulEbx == c.ulEbx)
784 && (ulEcx == c.ulEcx)
785 && (ulEdx == c.ulEdx)
786 )
787 );
788 }
789
790 uint32_t ulId;
791 uint32_t ulEax;
792 uint32_t ulEbx;
793 uint32_t ulEcx;
794 uint32_t ulEdx;
795};
796typedef std::list<CpuIdLeaf> CpuIdLeafsList;
797
798/**
799 * NOTE: If you add any fields in here, you must update a) the constructor and b)
800 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
801 * your settings might never get saved.
802 */
803struct Cpu
804{
805 Cpu()
806 : ulId(UINT32_MAX)
807 {}
808
809 bool operator==(const Cpu &c) const
810 {
811 return (ulId == c.ulId);
812 }
813
814 uint32_t ulId;
815};
816typedef std::list<Cpu> CpuList;
817
818/**
819 * NOTE: If you add any fields in here, you must update a) the constructor and b)
820 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
821 * your settings might never get saved.
822 */
823struct BandwidthGroup
824{
825 BandwidthGroup()
826 : cMaxBytesPerSec(0),
827 enmType(BandwidthGroupType_Null)
828 {}
829
830 bool operator==(const BandwidthGroup &i) const
831 {
832 return ( (strName == i.strName)
833 && (cMaxBytesPerSec == i.cMaxBytesPerSec)
834 && (enmType == i.enmType));
835 }
836
837 com::Utf8Str strName;
838 uint64_t cMaxBytesPerSec;
839 BandwidthGroupType_T enmType;
840};
841typedef std::list<BandwidthGroup> BandwidthGroupList;
842
843/**
844 * NOTE: If you add any fields in here, you must update a) the constructor and b)
845 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
846 * your settings might never get saved.
847 */
848struct IOSettings
849{
850 IOSettings();
851
852 bool operator==(const IOSettings &i) const
853 {
854 return ( (fIOCacheEnabled == i.fIOCacheEnabled)
855 && (ulIOCacheSize == i.ulIOCacheSize)
856 && (llBandwidthGroups == i.llBandwidthGroups));
857 }
858
859 bool fIOCacheEnabled;
860 uint32_t ulIOCacheSize;
861 BandwidthGroupList llBandwidthGroups;
862};
863
864/**
865 * NOTE: If you add any fields in here, you must update a) the constructor and b)
866 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
867 * your settings might never get saved.
868 */
869struct HostPCIDeviceAttachment
870{
871 HostPCIDeviceAttachment()
872 : uHostAddress(0),
873 uGuestAddress(0)
874 {}
875
876 bool operator==(const HostPCIDeviceAttachment &a) const
877 {
878 return ( (uHostAddress == a.uHostAddress)
879 && (uGuestAddress == a.uGuestAddress)
880 && (strDeviceName == a.strDeviceName)
881 );
882 }
883
884 com::Utf8Str strDeviceName;
885 uint32_t uHostAddress;
886 uint32_t uGuestAddress;
887};
888typedef std::list<HostPCIDeviceAttachment> HostPCIDeviceAttachmentList;
889
890/**
891 * Representation of Machine hardware; this is used in the MachineConfigFile.hardwareMachine
892 * field.
893 *
894 * NOTE: If you add any fields in here, you must update a) the constructor and b)
895 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
896 * your settings might never get saved.
897 */
898struct Hardware
899{
900 Hardware();
901
902 bool operator==(const Hardware&) const;
903
904 bool areParavirtDefaultSettings() const
905 {
906 return paravirtProvider == ParavirtProvider_Legacy;
907 }
908
909 com::Utf8Str strVersion; // hardware version, optional
910 com::Guid uuid; // hardware uuid, optional (null).
911
912 bool fHardwareVirt,
913 fNestedPaging,
914 fLargePages,
915 fVPID,
916 fUnrestrictedExecution,
917 fHardwareVirtForce,
918 fSyntheticCpu,
919 fTripleFaultReset,
920 fPAE;
921 typedef enum LongModeType { LongMode_Enabled, LongMode_Disabled, LongMode_Legacy } LongModeType;
922 LongModeType enmLongMode;
923 uint32_t cCPUs;
924 bool fCpuHotPlug; // requires settings version 1.10 (VirtualBox 3.2)
925 CpuList llCpus; // requires settings version 1.10 (VirtualBox 3.2)
926 bool fHPETEnabled; // requires settings version 1.10 (VirtualBox 3.2)
927 uint32_t ulCpuExecutionCap; // requires settings version 1.11 (VirtualBox 3.3)
928 uint32_t uCpuIdPortabilityLevel; // requires settings version 1.15 (VirtualBox 5.0)
929
930 CpuIdLeafsList llCpuIdLeafs;
931
932 uint32_t ulMemorySizeMB;
933
934 BootOrderMap mapBootOrder; // item 0 has highest priority
935
936 GraphicsControllerType_T graphicsControllerType;
937 uint32_t ulVRAMSizeMB;
938 uint32_t cMonitors;
939 bool fAccelerate3D,
940 fAccelerate2DVideo; // requires settings version 1.8 (VirtualBox 3.1)
941
942 uint32_t ulVideoCaptureHorzRes; // requires settings version 1.14 (VirtualBox 4.3)
943 uint32_t ulVideoCaptureVertRes; // requires settings version 1.14 (VirtualBox 4.3)
944 uint32_t ulVideoCaptureRate; // requires settings version 1.14 (VirtualBox 4.3)
945 uint32_t ulVideoCaptureFPS; // requires settings version 1.14 (VirtualBox 4.3)
946 uint32_t ulVideoCaptureMaxTime; // requires settings version 1.14 (VirtualBox 4.3)
947 uint32_t ulVideoCaptureMaxSize; // requires settings version 1.14 (VirtualBox 4.3)
948 bool fVideoCaptureEnabled; // requires settings version 1.14 (VirtualBox 4.3)
949 uint64_t u64VideoCaptureScreens; // requires settings version 1.14 (VirtualBox 4.3)
950 com::Utf8Str strVideoCaptureFile; // requires settings version 1.14 (VirtualBox 4.3)
951
952 FirmwareType_T firmwareType; // requires settings version 1.9 (VirtualBox 3.1)
953
954 PointingHIDType_T pointingHIDType; // requires settings version 1.10 (VirtualBox 3.2)
955 KeyboardHIDType_T keyboardHIDType; // requires settings version 1.10 (VirtualBox 3.2)
956
957 ChipsetType_T chipsetType; // requires settings version 1.11 (VirtualBox 4.0)
958 ParavirtProvider_T paravirtProvider; // requires settings version 1.15 (VirtualBox 4.4)
959 com::Utf8Str strParavirtDebug; // requires settings version 1.16 (VirtualBox 5.1)
960
961 bool fEmulatedUSBCardReader; // 1.12 (VirtualBox 4.1)
962
963 VRDESettings vrdeSettings;
964
965 BIOSSettings biosSettings;
966 USB usbSettings;
967 NetworkAdaptersList llNetworkAdapters;
968 SerialPortsList llSerialPorts;
969 ParallelPortsList llParallelPorts;
970 AudioAdapter audioAdapter;
971
972 // technically these two have no business in the hardware section, but for some
973 // clever reason <Hardware> is where they are in the XML....
974 SharedFoldersList llSharedFolders;
975 ClipboardMode_T clipboardMode;
976 DnDMode_T dndMode;
977
978 uint32_t ulMemoryBalloonSize;
979 bool fPageFusionEnabled;
980
981 GuestPropertiesList llGuestProperties;
982
983 IOSettings ioSettings; // requires settings version 1.10 (VirtualBox 3.2)
984 HostPCIDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
985
986 com::Utf8Str strDefaultFrontend; // requires settings version 1.14 (VirtualBox 4.3)
987};
988
989/**
990 * A device attached to a storage controller. This can either be a
991 * hard disk or a DVD drive or a floppy drive and also specifies
992 * which medium is "in" the drive; as a result, this is a combination
993 * of the Main IMedium and IMediumAttachment interfaces.
994 *
995 * NOTE: If you add any fields in here, you must update a) the constructor and b)
996 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
997 * your settings might never get saved.
998 */
999struct AttachedDevice
1000{
1001 AttachedDevice()
1002 : deviceType(DeviceType_Null),
1003 fPassThrough(false),
1004 fTempEject(false),
1005 fNonRotational(false),
1006 fDiscard(false),
1007 fHotPluggable(false),
1008 lPort(0),
1009 lDevice(0)
1010 {}
1011
1012 bool operator==(const AttachedDevice &a) const;
1013
1014 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
1015
1016 // DVDs can be in pass-through mode:
1017 bool fPassThrough;
1018
1019 // Whether guest-triggered eject of DVDs will keep the medium in the
1020 // VM config or not:
1021 bool fTempEject;
1022
1023 // Whether the medium is non-rotational:
1024 bool fNonRotational;
1025
1026 // Whether the medium supports discarding unused blocks:
1027 bool fDiscard;
1028
1029 // Whether the medium is hot-pluggable:
1030 bool fHotPluggable;
1031
1032 int32_t lPort;
1033 int32_t lDevice;
1034
1035 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
1036 // this is its UUID; it depends on deviceType which media registry this then needs to
1037 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
1038 com::Guid uuid;
1039
1040 // for DVDs and floppies, the attachment can also be a host device:
1041 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
1042
1043 // Bandwidth group the device is attached to.
1044 com::Utf8Str strBwGroup;
1045};
1046typedef std::list<AttachedDevice> AttachedDevicesList;
1047
1048/**
1049 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1050 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1051 * your settings might never get saved.
1052 */
1053struct StorageController
1054{
1055 StorageController()
1056 : storageBus(StorageBus_IDE),
1057 controllerType(StorageControllerType_PIIX3),
1058 ulPortCount(2),
1059 ulInstance(0),
1060 fUseHostIOCache(true),
1061 fBootable(true)
1062 {}
1063
1064 bool operator==(const StorageController &s) const;
1065
1066 com::Utf8Str strName;
1067 StorageBus_T storageBus; // _SATA, _SCSI, _IDE, _SAS
1068 StorageControllerType_T controllerType;
1069 uint32_t ulPortCount;
1070 uint32_t ulInstance;
1071 bool fUseHostIOCache;
1072 bool fBootable;
1073
1074 // only for when controllerType == StorageControllerType_IntelAhci:
1075 int32_t lIDE0MasterEmulationPort,
1076 lIDE0SlaveEmulationPort,
1077 lIDE1MasterEmulationPort,
1078 lIDE1SlaveEmulationPort;
1079
1080 AttachedDevicesList llAttachedDevices;
1081};
1082typedef std::list<StorageController> StorageControllersList;
1083
1084/**
1085 * We wrap the storage controllers list into an extra struct so we can
1086 * use an undefined struct without needing std::list<> in all the headers.
1087 *
1088 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1089 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1090 * your settings might never get saved.
1091 */
1092struct Storage
1093{
1094 bool operator==(const Storage &s) const;
1095
1096 StorageControllersList llStorageControllers;
1097};
1098
1099/**
1100 * Settings that has to do with debugging.
1101 */
1102struct Debugging
1103{
1104 Debugging()
1105 : fTracingEnabled(false),
1106 fAllowTracingToAccessVM(false),
1107 strTracingConfig()
1108 { }
1109
1110 bool operator==(const Debugging &rOther) const
1111 {
1112 return fTracingEnabled == rOther.fTracingEnabled
1113 && fAllowTracingToAccessVM == rOther.fAllowTracingToAccessVM
1114 && strTracingConfig == rOther.strTracingConfig;
1115 }
1116
1117 bool areDefaultSettings() const
1118 {
1119 return !fTracingEnabled
1120 && !fAllowTracingToAccessVM
1121 && strTracingConfig.isEmpty();
1122 }
1123
1124 bool fTracingEnabled;
1125 bool fAllowTracingToAccessVM;
1126 com::Utf8Str strTracingConfig;
1127};
1128
1129/**
1130 * Settings that has to do with autostart.
1131 */
1132struct Autostart
1133{
1134 Autostart()
1135 : fAutostartEnabled(false),
1136 uAutostartDelay(0),
1137 enmAutostopType(AutostopType_Disabled)
1138 { }
1139
1140 bool operator==(const Autostart &rOther) const
1141 {
1142 return fAutostartEnabled == rOther.fAutostartEnabled
1143 && uAutostartDelay == rOther.uAutostartDelay
1144 && enmAutostopType == rOther.enmAutostopType;
1145 }
1146
1147 bool areDefaultSettings() const
1148 {
1149 return !fAutostartEnabled
1150 && !uAutostartDelay
1151 && enmAutostopType == AutostopType_Disabled;
1152 }
1153
1154 bool fAutostartEnabled;
1155 uint32_t uAutostartDelay;
1156 AutostopType_T enmAutostopType;
1157};
1158
1159struct Snapshot;
1160typedef std::list<Snapshot> SnapshotsList;
1161
1162/**
1163 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1164 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1165 * your settings might never get saved.
1166 */
1167struct Snapshot
1168{
1169 Snapshot()
1170 {
1171 RTTimeSpecSetNano(&timestamp, 0);
1172 }
1173
1174 bool operator==(const Snapshot &s) const;
1175
1176 com::Guid uuid;
1177 com::Utf8Str strName,
1178 strDescription; // optional
1179 RTTIMESPEC timestamp;
1180
1181 com::Utf8Str strStateFile; // for online snapshots only
1182
1183 Hardware hardware;
1184 Storage storage;
1185
1186 Debugging debugging;
1187 Autostart autostart;
1188
1189 SnapshotsList llChildSnapshots;
1190};
1191
1192struct MachineUserData
1193{
1194 MachineUserData()
1195 : fDirectoryIncludesUUID(false),
1196 fNameSync(true),
1197 fTeleporterEnabled(false),
1198 uTeleporterPort(0),
1199 enmFaultToleranceState(FaultToleranceState_Inactive),
1200 uFaultTolerancePort(0),
1201 uFaultToleranceInterval(0),
1202 fRTCUseUTC(false),
1203 strVMPriority("")
1204 {
1205 llGroups.push_back("/");
1206 }
1207
1208 bool operator==(const MachineUserData &c) const
1209 {
1210 return (strName == c.strName)
1211 && (fDirectoryIncludesUUID == c.fDirectoryIncludesUUID)
1212 && (fNameSync == c.fNameSync)
1213 && (strDescription == c.strDescription)
1214 && (llGroups == c.llGroups)
1215 && (strOsType == c.strOsType)
1216 && (strSnapshotFolder == c.strSnapshotFolder)
1217 && (fTeleporterEnabled == c.fTeleporterEnabled)
1218 && (uTeleporterPort == c.uTeleporterPort)
1219 && (strTeleporterAddress == c.strTeleporterAddress)
1220 && (strTeleporterPassword == c.strTeleporterPassword)
1221 && (enmFaultToleranceState == c.enmFaultToleranceState)
1222 && (uFaultTolerancePort == c.uFaultTolerancePort)
1223 && (uFaultToleranceInterval == c.uFaultToleranceInterval)
1224 && (strFaultToleranceAddress == c.strFaultToleranceAddress)
1225 && (strFaultTolerancePassword == c.strFaultTolerancePassword)
1226 && (fRTCUseUTC == c.fRTCUseUTC)
1227 && (ovIcon == c.ovIcon)
1228 && (strVMPriority == c.strVMPriority);
1229 }
1230
1231 com::Utf8Str strName;
1232 bool fDirectoryIncludesUUID;
1233 bool fNameSync;
1234 com::Utf8Str strDescription;
1235 StringsList llGroups;
1236 com::Utf8Str strOsType;
1237 com::Utf8Str strSnapshotFolder;
1238 bool fTeleporterEnabled;
1239 uint32_t uTeleporterPort;
1240 com::Utf8Str strTeleporterAddress;
1241 com::Utf8Str strTeleporterPassword;
1242 FaultToleranceState_T enmFaultToleranceState;
1243 uint32_t uFaultTolerancePort;
1244 com::Utf8Str strFaultToleranceAddress;
1245 com::Utf8Str strFaultTolerancePassword;
1246 uint32_t uFaultToleranceInterval;
1247 bool fRTCUseUTC;
1248 com::Utf8Str ovIcon;
1249 com::Utf8Str strVMPriority;
1250};
1251
1252extern const struct Snapshot g_SnapshotEmpty;
1253
1254/**
1255 * MachineConfigFile represents an XML machine configuration. All the machine settings
1256 * that go out to the XML (or are read from it) are in here.
1257 *
1258 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1259 * the operator== which is used by Machine::saveSettings(), or otherwise your settings
1260 * might never get saved.
1261 */
1262class MachineConfigFile : public ConfigFileBase
1263{
1264public:
1265 com::Guid uuid;
1266
1267 MachineUserData machineUserData;
1268
1269 com::Utf8Str strStateFile;
1270 bool fCurrentStateModified; // optional, default is true
1271 RTTIMESPEC timeLastStateChange; // optional, defaults to now
1272 bool fAborted; // optional, default is false
1273
1274 com::Guid uuidCurrentSnapshot;
1275
1276 Hardware hardwareMachine;
1277 Storage storageMachine;
1278 MediaRegistry mediaRegistry;
1279 Debugging debugging;
1280 Autostart autostart;
1281
1282 StringsMap mapExtraDataItems;
1283
1284 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
1285
1286 MachineConfigFile(const com::Utf8Str *pstrFilename);
1287
1288 bool operator==(const MachineConfigFile &m) const;
1289
1290 bool canHaveOwnMediaRegistry() const;
1291
1292 void importMachineXML(const xml::ElementNode &elmMachine);
1293
1294 void write(const com::Utf8Str &strFilename);
1295
1296 enum
1297 {
1298 BuildMachineXML_IncludeSnapshots = 0x01,
1299 BuildMachineXML_WriteVBoxVersionAttribute = 0x02,
1300 BuildMachineXML_SkipRemovableMedia = 0x04,
1301 BuildMachineXML_MediaRegistry = 0x08,
1302 BuildMachineXML_SuppressSavedState = 0x10
1303 };
1304 void buildMachineXML(xml::ElementNode &elmMachine,
1305 uint32_t fl,
1306 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1307
1308 static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T drv);
1309 static AudioDriverType_T getHostDefaultAudioDriver();
1310
1311private:
1312 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
1313 void readAttachedNetworkMode(const xml::ElementNode &pelmMode, bool fEnabled, NetworkAdapter &nic);
1314 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
1315 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
1316 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
1317 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
1318 void readAudioAdapter(const xml::ElementNode &elmAudioAdapter, AudioAdapter &aa);
1319 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
1320 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
1321 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw, Storage &strg);
1322 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
1323 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
1324 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
1325 void readTeleporter(const xml::ElementNode *pElmTeleporter, MachineUserData *pUserData);
1326 void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
1327 void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
1328 void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
1329 bool readSnapshot(const com::Guid &curSnapshotUuid, uint32_t depth, const xml::ElementNode &elmSnapshot, Snapshot &snap);
1330 void convertOldOSType_pre1_5(com::Utf8Str &str);
1331 void readMachine(const xml::ElementNode &elmMachine);
1332
1333 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, const Storage &strg);
1334 void buildNetworkXML(NetworkAttachmentType_T mode, xml::ElementNode &elmParent, bool fEnabled, const NetworkAdapter &nic);
1335 void buildStorageControllersXML(xml::ElementNode &elmParent,
1336 const Storage &st,
1337 bool fSkipRemovableMedia,
1338 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1339 void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
1340 void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
1341 void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
1342 void buildSnapshotXML(uint32_t depth, xml::ElementNode &elmParent, const Snapshot &snap);
1343
1344 void bumpSettingsVersionIfNeeded();
1345};
1346
1347} // namespace settings
1348
1349
1350#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