VirtualBox

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

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

Be -pedantic about trailing comma at the end of an enum for the sake of 4.3.

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