VirtualBox

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

Last change on this file since 58110 was 56788, checked in by vboxsync, 9 years ago

Main/Machine: new attribute (not yet implemented to the level that it works!) for setting the VM process priority, plus the necessary settings change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 44.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-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
960 bool fEmulatedUSBCardReader; // 1.12 (VirtualBox 4.1)
961
962 VRDESettings vrdeSettings;
963
964 BIOSSettings biosSettings;
965 USB usbSettings;
966 NetworkAdaptersList llNetworkAdapters;
967 SerialPortsList llSerialPorts;
968 ParallelPortsList llParallelPorts;
969 AudioAdapter audioAdapter;
970
971 // technically these two have no business in the hardware section, but for some
972 // clever reason <Hardware> is where they are in the XML....
973 SharedFoldersList llSharedFolders;
974 ClipboardMode_T clipboardMode;
975 DnDMode_T dndMode;
976
977 uint32_t ulMemoryBalloonSize;
978 bool fPageFusionEnabled;
979
980 GuestPropertiesList llGuestProperties;
981
982 IOSettings ioSettings; // requires settings version 1.10 (VirtualBox 3.2)
983 HostPCIDeviceAttachmentList pciAttachments; // requires settings version 1.12 (VirtualBox 4.1)
984
985 com::Utf8Str strDefaultFrontend; // requires settings version 1.14 (VirtualBox 4.3)
986};
987
988/**
989 * A device attached to a storage controller. This can either be a
990 * hard disk or a DVD drive or a floppy drive and also specifies
991 * which medium is "in" the drive; as a result, this is a combination
992 * of the Main IMedium and IMediumAttachment interfaces.
993 *
994 * NOTE: If you add any fields in here, you must update a) the constructor and b)
995 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
996 * your settings might never get saved.
997 */
998struct AttachedDevice
999{
1000 AttachedDevice()
1001 : deviceType(DeviceType_Null),
1002 fPassThrough(false),
1003 fTempEject(false),
1004 fNonRotational(false),
1005 fDiscard(false),
1006 fHotPluggable(false),
1007 lPort(0),
1008 lDevice(0)
1009 {}
1010
1011 bool operator==(const AttachedDevice &a) const;
1012
1013 DeviceType_T deviceType; // only HardDisk, DVD or Floppy are allowed
1014
1015 // DVDs can be in pass-through mode:
1016 bool fPassThrough;
1017
1018 // Whether guest-triggered eject of DVDs will keep the medium in the
1019 // VM config or not:
1020 bool fTempEject;
1021
1022 // Whether the medium is non-rotational:
1023 bool fNonRotational;
1024
1025 // Whether the medium supports discarding unused blocks:
1026 bool fDiscard;
1027
1028 // Whether the medium is hot-pluggable:
1029 bool fHotPluggable;
1030
1031 int32_t lPort;
1032 int32_t lDevice;
1033
1034 // if an image file is attached to the device (ISO, RAW, or hard disk image such as VDI),
1035 // this is its UUID; it depends on deviceType which media registry this then needs to
1036 // be looked up in. If no image file (only permitted for DVDs and floppies), then the UUID is NULL
1037 com::Guid uuid;
1038
1039 // for DVDs and floppies, the attachment can also be a host device:
1040 com::Utf8Str strHostDriveSrc; // if != NULL, value of <HostDrive>/@src
1041
1042 // Bandwidth group the device is attached to.
1043 com::Utf8Str strBwGroup;
1044};
1045typedef std::list<AttachedDevice> AttachedDevicesList;
1046
1047/**
1048 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1049 * the operator== which is used by MachineConfigFile::operator==(), or otherwise
1050 * your settings might never get saved.
1051 */
1052struct StorageController
1053{
1054 StorageController()
1055 : storageBus(StorageBus_IDE),
1056 controllerType(StorageControllerType_PIIX3),
1057 ulPortCount(2),
1058 ulInstance(0),
1059 fUseHostIOCache(true),
1060 fBootable(true)
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 strVMPriority("")
1203 {
1204 llGroups.push_back("/");
1205 }
1206
1207 bool operator==(const MachineUserData &c) const
1208 {
1209 return (strName == c.strName)
1210 && (fDirectoryIncludesUUID == c.fDirectoryIncludesUUID)
1211 && (fNameSync == c.fNameSync)
1212 && (strDescription == c.strDescription)
1213 && (llGroups == c.llGroups)
1214 && (strOsType == c.strOsType)
1215 && (strSnapshotFolder == c.strSnapshotFolder)
1216 && (fTeleporterEnabled == c.fTeleporterEnabled)
1217 && (uTeleporterPort == c.uTeleporterPort)
1218 && (strTeleporterAddress == c.strTeleporterAddress)
1219 && (strTeleporterPassword == c.strTeleporterPassword)
1220 && (enmFaultToleranceState == c.enmFaultToleranceState)
1221 && (uFaultTolerancePort == c.uFaultTolerancePort)
1222 && (uFaultToleranceInterval == c.uFaultToleranceInterval)
1223 && (strFaultToleranceAddress == c.strFaultToleranceAddress)
1224 && (strFaultTolerancePassword == c.strFaultTolerancePassword)
1225 && (fRTCUseUTC == c.fRTCUseUTC)
1226 && (ovIcon == c.ovIcon)
1227 && (strVMPriority == c.strVMPriority);
1228 }
1229
1230 com::Utf8Str strName;
1231 bool fDirectoryIncludesUUID;
1232 bool fNameSync;
1233 com::Utf8Str strDescription;
1234 StringsList llGroups;
1235 com::Utf8Str strOsType;
1236 com::Utf8Str strSnapshotFolder;
1237 bool fTeleporterEnabled;
1238 uint32_t uTeleporterPort;
1239 com::Utf8Str strTeleporterAddress;
1240 com::Utf8Str strTeleporterPassword;
1241 FaultToleranceState_T enmFaultToleranceState;
1242 uint32_t uFaultTolerancePort;
1243 com::Utf8Str strFaultToleranceAddress;
1244 com::Utf8Str strFaultTolerancePassword;
1245 uint32_t uFaultToleranceInterval;
1246 bool fRTCUseUTC;
1247 com::Utf8Str ovIcon;
1248 com::Utf8Str strVMPriority;
1249};
1250
1251extern const struct Snapshot g_SnapshotEmpty;
1252
1253/**
1254 * MachineConfigFile represents an XML machine configuration. All the machine settings
1255 * that go out to the XML (or are read from it) are in here.
1256 *
1257 * NOTE: If you add any fields in here, you must update a) the constructor and b)
1258 * the operator== which is used by Machine::saveSettings(), or otherwise your settings
1259 * might never get saved.
1260 */
1261class MachineConfigFile : public ConfigFileBase
1262{
1263public:
1264 com::Guid uuid;
1265
1266 MachineUserData machineUserData;
1267
1268 com::Utf8Str strStateFile;
1269 bool fCurrentStateModified; // optional, default is true
1270 RTTIMESPEC timeLastStateChange; // optional, defaults to now
1271 bool fAborted; // optional, default is false
1272
1273 com::Guid uuidCurrentSnapshot;
1274
1275 Hardware hardwareMachine;
1276 Storage storageMachine;
1277 MediaRegistry mediaRegistry;
1278 Debugging debugging;
1279 Autostart autostart;
1280
1281 StringsMap mapExtraDataItems;
1282
1283 SnapshotsList llFirstSnapshot; // first snapshot or empty list if there's none
1284
1285 MachineConfigFile(const com::Utf8Str *pstrFilename);
1286
1287 bool operator==(const MachineConfigFile &m) const;
1288
1289 bool canHaveOwnMediaRegistry() const;
1290
1291 void importMachineXML(const xml::ElementNode &elmMachine);
1292
1293 void write(const com::Utf8Str &strFilename);
1294
1295 enum
1296 {
1297 BuildMachineXML_IncludeSnapshots = 0x01,
1298 BuildMachineXML_WriteVBoxVersionAttribute = 0x02,
1299 BuildMachineXML_SkipRemovableMedia = 0x04,
1300 BuildMachineXML_MediaRegistry = 0x08,
1301 BuildMachineXML_SuppressSavedState = 0x10
1302 };
1303 void buildMachineXML(xml::ElementNode &elmMachine,
1304 uint32_t fl,
1305 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1306
1307 static bool isAudioDriverAllowedOnThisHost(AudioDriverType_T drv);
1308 static AudioDriverType_T getHostDefaultAudioDriver();
1309
1310private:
1311 void readNetworkAdapters(const xml::ElementNode &elmHardware, NetworkAdaptersList &ll);
1312 void readAttachedNetworkMode(const xml::ElementNode &pelmMode, bool fEnabled, NetworkAdapter &nic);
1313 void readCpuIdTree(const xml::ElementNode &elmCpuid, CpuIdLeafsList &ll);
1314 void readCpuTree(const xml::ElementNode &elmCpu, CpuList &ll);
1315 void readSerialPorts(const xml::ElementNode &elmUART, SerialPortsList &ll);
1316 void readParallelPorts(const xml::ElementNode &elmLPT, ParallelPortsList &ll);
1317 void readAudioAdapter(const xml::ElementNode &elmAudioAdapter, AudioAdapter &aa);
1318 void readGuestProperties(const xml::ElementNode &elmGuestProperties, Hardware &hw);
1319 void readStorageControllerAttributes(const xml::ElementNode &elmStorageController, StorageController &sctl);
1320 void readHardware(const xml::ElementNode &elmHardware, Hardware &hw, Storage &strg);
1321 void readHardDiskAttachments_pre1_7(const xml::ElementNode &elmHardDiskAttachments, Storage &strg);
1322 void readStorageControllers(const xml::ElementNode &elmStorageControllers, Storage &strg);
1323 void readDVDAndFloppies_pre1_9(const xml::ElementNode &elmHardware, Storage &strg);
1324 void readTeleporter(const xml::ElementNode *pElmTeleporter, MachineUserData *pUserData);
1325 void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
1326 void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
1327 void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
1328 bool readSnapshot(const com::Guid &curSnapshotUuid, uint32_t depth, const xml::ElementNode &elmSnapshot, Snapshot &snap);
1329 void convertOldOSType_pre1_5(com::Utf8Str &str);
1330 void readMachine(const xml::ElementNode &elmMachine);
1331
1332 void buildHardwareXML(xml::ElementNode &elmParent, const Hardware &hw, const Storage &strg);
1333 void buildNetworkXML(NetworkAttachmentType_T mode, xml::ElementNode &elmParent, bool fEnabled, const NetworkAdapter &nic);
1334 void buildStorageControllersXML(xml::ElementNode &elmParent,
1335 const Storage &st,
1336 bool fSkipRemovableMedia,
1337 std::list<xml::ElementNode*> *pllElementsWithUuidAttributes);
1338 void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
1339 void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
1340 void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
1341 void buildSnapshotXML(uint32_t depth, xml::ElementNode &elmParent, const Snapshot &snap);
1342
1343 void bumpSettingsVersionIfNeeded();
1344};
1345
1346} // namespace settings
1347
1348
1349#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