VirtualBox

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

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

Main/xml/Settings.cpp: limit snapshot depth to 250, avoiding crashes
Main/Snapshot: limit snapshot depth to 250
Main/Medium: eliminate some spurious error messages when saving a VM config

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