VirtualBox

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

Last change on this file since 47991 was 47991, checked in by vboxsync, 12 years ago

Main: Made the exclusive HW virtualization use setting global rather than per-VM.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette